Hide keyboard shortcuts

Hot-keys on this page

r m x p   toggle line displays

j k   next/prev highlighted chunk

0   (zero) top of page

1   (one) first highlighted chunk

1# This product includes software developed by the LSST Project 

2# (https://www.lsst.org). 

3# See the COPYRIGHT file at the top-level directory of this distribution 

4# for details of code ownership. 

5# 

6# This program is free software: you can redistribute it and/or modify 

7# it under the terms of the GNU General Public License as published by 

8# the Free Software Foundation, either version 3 of the License, or 

9# (at your option) any later version. 

10# 

11# This program is distributed in the hope that it will be useful, 

12# but WITHOUT ANY WARRANTY; without even the implied warranty of 

13# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 

14# GNU General Public License for more details. 

15# 

16# You should have received a copy of the GNU General Public License 

17# along with this program. If not, see <https://www.gnu.org/licenses/>. 

18 

19import traceback 

20 

21import lsst.pipe.base as pipeBase 

22from lsst.verify.tasks import MetricConnections, MetricComputationError 

23 

24from lsst.faro.base.CatalogMeasurementBase import CatalogMeasurementBaseConfig, CatalogMeasurementBaseTask 

25 

26__all__ = ("PatchMatchedMeasurementConnections", "PatchMatchedMeasurementConfig", 

27 "PatchMatchedMeasurementTask", 

28 "TractMatchedMeasurementConnections", "TractMatchedMeasurementConfig", 

29 "TractMatchedMeasurementTask", 

30 "PatchMatchedMultiBandMeasurementConnections", "PatchMatchedMultiBandMeasurementConfig", 

31 "PatchMatchedMultiBandMeasurementTask") 

32 

33# The first thing to do is to define a Connections class. This will define all 

34# the inputs and outputs that our task requires 

35 

36 

37class PatchMatchedMeasurementConnections(MetricConnections, 

38 dimensions=("tract", "patch", "band", 

39 "instrument", "skymap")): 

40 cat = pipeBase.connectionTypes.Input(doc="Input matched catalog.", 

41 dimensions=("tract", "patch", "instrument", 

42 "band"), 

43 storageClass="SimpleCatalog", 

44 name="matchedCatalogPatch") 

45 measurement = pipeBase.connectionTypes.Output(doc="Resulting matched catalog.", 

46 dimensions=("tract", "patch", 

47 "instrument", "band"), 

48 storageClass="MetricValue", 

49 name="metricvalue_{package}_{metric}") 

50 

51 

52class PatchMatchedMeasurementConfig(CatalogMeasurementBaseConfig, 

53 pipelineConnections=PatchMatchedMeasurementConnections): 

54 pass 

55 

56 

57class PatchMatchedMeasurementTask(CatalogMeasurementBaseTask): 

58 ConfigClass = PatchMatchedMeasurementConfig 

59 _DefaultName = "patchMatchedMeasurementTask" 

60 

61 

62class TractMatchedMeasurementConnections(PatchMatchedMeasurementConnections, 

63 dimensions=("tract", "instrument", 

64 "band", "skymap")): 

65 cat = pipeBase.connectionTypes.Input(doc="Input matched catalog.", 

66 dimensions=("tract", "instrument", 

67 "band"), 

68 storageClass="SimpleCatalog", 

69 name="matchedCatalogTract") 

70 measurement = pipeBase.connectionTypes.Output(doc="Resulting matched catalog.", 

71 dimensions=("tract", 

72 "instrument", "band"), 

73 storageClass="MetricValue", 

74 name="metricvalue_{package}_{metric}") 

75 

76 

77class TractMatchedMeasurementConfig(CatalogMeasurementBaseConfig, 

78 pipelineConnections=TractMatchedMeasurementConnections): 

79 pass 

80 

81 

82class TractMatchedMeasurementTask(CatalogMeasurementBaseTask): 

83 ConfigClass = TractMatchedMeasurementConfig 

84 _DefaultName = "tractMatchedMeasurementTask" 

85 

86 

87class PatchMatchedMultiBandMeasurementConnections(MetricConnections, 

88 dimensions=("tract", "patch", "band", 

89 "instrument", "skymap")): 

90 cat = pipeBase.connectionTypes.Input(doc="Input matched catalog.", 

91 dimensions=("tract", "patch", "instrument"), 

92 storageClass="SimpleCatalog", 

93 name="matchedCatalogPatchMultiBand") 

94 measurement = pipeBase.connectionTypes.Output(doc="Resulting matched catalog.", 

95 dimensions=("tract", "patch", 

96 "instrument", "band"), 

97 storageClass="MetricValue", 

98 name="metricvalue_{package}_{metric}") 

99 

100 

101class PatchMatchedMultiBandMeasurementConfig( 

102 CatalogMeasurementBaseConfig, 

103 pipelineConnections=PatchMatchedMultiBandMeasurementConnections): 

104 pass 

105 

106 

107class PatchMatchedMultiBandMeasurementTask(CatalogMeasurementBaseTask): 

108 ConfigClass = PatchMatchedMultiBandMeasurementConfig 

109 _DefaultName = "patchMatchedMultiBandMeasurementTask" 

110 

111 def run(self, cat, in_id, out_id): 

112 return self.measure.run(cat, self.config.connections.metric, in_id, out_id) 

113 

114 def runQuantum(self, butlerQC, inputRefs, outputRefs): 

115 """Do Butler I/O to provide in-memory objects for run. 

116 This specialization of runQuantum performs error-handling specific to 

117 MetricTasks. Most or all of this functionality may be moved to 

118 activators in the future. 

119 """ 

120 try: 

121 in_id = butlerQC.registry.expandDataId(inputRefs.cat.dataId) 

122 out_id = butlerQC.registry.expandDataId(outputRefs.measurement.dataId) 

123 inputs = butlerQC.get(inputRefs) 

124 inputs['in_id'] = in_id 

125 inputs['out_id'] = out_id 

126 outputs = self.run(**inputs) 

127 if outputs.measurement is not None: 

128 butlerQC.put(outputs, outputRefs) 

129 else: 

130 self.log.debug("Skipping measurement of {!r} on {} " 

131 "as not applicable.", self, inputRefs) 

132 except MetricComputationError as e: 

133 self.log.error("Measurement of {!r} failed on {}->{}\n{}\n,%s", 

134 self, inputRefs, outputRefs, traceback.format_exc(), e.msg)