Coverage for python/lsst/faro/measurement/MatchedCatalogMeasurement.py: 67%

44 statements  

« prev     ^ index     » next       coverage.py v7.2.1, created at 2023-03-13 04:26 +0000

1# This file is part of faro. 

2# 

3# Developed for the LSST Data Management System. 

4# This product includes software developed by the LSST Project 

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

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

7# for details of code ownership. 

8# 

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

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

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

12# (at your option) any later version. 

13# 

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

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

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

17# GNU General Public License for more details. 

18# 

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

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

21 

22import traceback 

23 

24import lsst.pipe.base as pipeBase 

25from lsst.verify.tasks import MetricComputationError 

26 

27from lsst.faro.base.CatalogMeasurementBase import ( 

28 CatalogMeasurementBaseConnections, 

29 CatalogMeasurementBaseConfig, 

30 CatalogMeasurementBaseTask, 

31) 

32 

33__all__ = ( 

34 "PatchMatchedMeasurementConnections", 

35 "PatchMatchedMeasurementConfig", 

36 "PatchMatchedMeasurementTask", 

37 "TractMatchedMeasurementConnections", 

38 "TractMatchedMeasurementConfig", 

39 "TractMatchedMeasurementTask", 

40 "PatchMatchedMultiBandMeasurementConnections", 

41 "PatchMatchedMultiBandMeasurementConfig", 

42 "PatchMatchedMultiBandMeasurementTask", 

43) 

44 

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

46# the inputs and outputs that our task requires 

47 

48 

49class PatchMatchedMeasurementConnections( 

50 CatalogMeasurementBaseConnections, 

51 dimensions=("tract", "patch", "band", "instrument", "skymap"), 

52): 

53 matchedCatalog = pipeBase.connectionTypes.Input( 

54 doc="Input matched catalog.", 

55 dimensions=("tract", "patch", "instrument", "band"), 

56 storageClass="SimpleCatalog", 

57 name="matchedCatalogPatch", 

58 ) 

59 measurement = pipeBase.connectionTypes.Output( 

60 doc="Resulting matched catalog.", 

61 dimensions=("tract", "patch", "instrument", "band"), 

62 storageClass="MetricValue", 

63 name="metricvalue_{package}_{metric}", 

64 ) 

65 

66 

67class PatchMatchedMeasurementConfig( 

68 CatalogMeasurementBaseConfig, pipelineConnections=PatchMatchedMeasurementConnections 

69): 

70 pass 

71 

72 

73class PatchMatchedMeasurementTask(CatalogMeasurementBaseTask): 

74 ConfigClass = PatchMatchedMeasurementConfig 

75 _DefaultName = "patchMatchedMeasurementTask" 

76 

77 

78class TractMatchedMeasurementConnections( 

79 PatchMatchedMeasurementConnections, 

80 dimensions=("tract", "instrument", "band", "skymap"), 

81): 

82 matchedCatalog = pipeBase.connectionTypes.Input( 

83 doc="Input matched catalog.", 

84 dimensions=("tract", "instrument", "band"), 

85 storageClass="SimpleCatalog", 

86 name="matchedCatalogTract", 

87 ) 

88 measurement = pipeBase.connectionTypes.Output( 

89 doc="Resulting matched catalog.", 

90 dimensions=("tract", "instrument", "band"), 

91 storageClass="MetricValue", 

92 name="metricvalue_{package}_{metric}", 

93 ) 

94 

95 

96class TractMatchedMeasurementConfig( 

97 CatalogMeasurementBaseConfig, pipelineConnections=TractMatchedMeasurementConnections 

98): 

99 pass 

100 

101 

102class TractMatchedMeasurementTask(CatalogMeasurementBaseTask): 

103 ConfigClass = TractMatchedMeasurementConfig 

104 _DefaultName = "tractMatchedMeasurementTask" 

105 

106 

107class PatchMatchedMultiBandMeasurementConnections( 

108 CatalogMeasurementBaseConnections, 

109 dimensions=("tract", "patch", "band", "instrument", "skymap"), 

110): 

111 matchedCatalogMulti = pipeBase.connectionTypes.Input( 

112 doc="Input matched catalog.", 

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

114 storageClass="SimpleCatalog", 

115 name="matchedCatalogPatchMultiBand", 

116 ) 

117 measurement = pipeBase.connectionTypes.Output( 

118 doc="Resulting matched catalog.", 

119 dimensions=("tract", "patch", "instrument", "band"), 

120 storageClass="MetricValue", 

121 name="metricvalue_{package}_{metric}", 

122 ) 

123 

124 

125class PatchMatchedMultiBandMeasurementConfig( 

126 CatalogMeasurementBaseConfig, 

127 pipelineConnections=PatchMatchedMultiBandMeasurementConnections, 

128): 

129 pass 

130 

131 

132class PatchMatchedMultiBandMeasurementTask(CatalogMeasurementBaseTask): 

133 ConfigClass = PatchMatchedMultiBandMeasurementConfig 

134 _DefaultName = "patchMatchedMultiBandMeasurementTask" 

135 

136 def run(self, matchedCatalogMulti, in_id, out_id): 

137 return self.measure.run( 

138 self.config.connections.metric, matchedCatalogMulti, in_id, out_id 

139 ) 

140 

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

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

143 This specialization of runQuantum performs error-handling specific to 

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

145 activators in the future. 

146 """ 

147 try: 

148 in_id = butlerQC.registry.expandDataId(inputRefs.matchedCatalogMulti.dataId) 

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

150 inputs = butlerQC.get(inputRefs) 

151 inputs["in_id"] = in_id 

152 inputs["out_id"] = out_id 

153 outputs = self.run(**inputs) 

154 if outputs.measurement is not None: 

155 butlerQC.put(outputs, outputRefs) 

156 else: 

157 self.log.debug( 

158 "Skipping measurement of {!r} on {} " "as not applicable.", 

159 self, 

160 inputRefs, 

161 ) 

162 except MetricComputationError as e: 

163 self.log.error( 

164 "Measurement of {!r} failed on {}->{}\n{}\n,%s", 

165 self, 

166 inputRefs, 

167 outputRefs, 

168 traceback.format_exc(), 

169 e.msg, 

170 )