Coverage for python/lsst/faro/measurement/MatchedCatalogTableMeasurement.py: 28%

64 statements  

« prev     ^ index     » next       coverage.py v6.5.0, created at 2023-01-14 03:52 -0800

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 

22 

23import lsst.pipe.base as pipeBase 

24import lsst.pex.config as pexConfig 

25 

26from lsst.faro.base.CatalogMeasurementBase import ( 

27 CatalogMeasurementBaseConnections, 

28 CatalogMeasurementBaseConfig, 

29 CatalogMeasurementBaseTask, 

30) 

31from lsst.faro.utils.filter_map import FilterMap 

32 

33__all__ = ( 

34 "TractMatchedCatalogTableMeasurementConnections", 

35 "TractMatchedCatalogTableMeasurementConfig", 

36 "TractMatchedCatalogTableMeasurementTask", 

37 "TractMatchedCatalogMultiBandTableMeasurementConnections", 

38 "TractMatchedCatalogMultiBandTableMeasurementConfig", 

39 "TractMatchedCatalogMultiBandTableMeasurementTask", 

40) 

41 

42 

43class TractMatchedCatalogTableMeasurementConnections( 

44 CatalogMeasurementBaseConnections, 

45 dimensions=("tract", "skymap", "band"), 

46 defaultTemplates={"individualSourceCatalogName": "isolated_star_sources"} 

47): 

48 

49 individualSourceCatalog = pipeBase.connectionTypes.Input( 

50 doc='Catalog of individual sources for the isolated stars', 

51 name="{individualSourceCatalogName}", 

52 storageClass='DataFrame', 

53 dimensions=('instrument', 'tract', 'skymap'), 

54 deferLoad=True, 

55 ) 

56 

57 measurement = pipeBase.connectionTypes.Output( 

58 doc="Per-tract measurement.", 

59 dimensions=("tract", "skymap", "band"), 

60 storageClass="MetricValue", 

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

62 ) 

63 

64 

65class TractMatchedCatalogTableMeasurementConfig( 

66 CatalogMeasurementBaseConfig, pipelineConnections=TractMatchedCatalogTableMeasurementConnections 

67): 

68 """Configuration for TractMatchedCatalogTableMeasurementTask.""" 

69 

70 instrument = pexConfig.Field( 

71 doc="Instrument.", 

72 dtype=str, 

73 default='hsc', 

74 ) 

75 

76 

77class TractMatchedCatalogTableMeasurementTask(CatalogMeasurementBaseTask): 

78 """Base class for per-band science performance metrics measured on single-tract matched catalogs.""" 

79 

80 ConfigClass = TractMatchedCatalogTableMeasurementConfig 

81 _DefaultName = "tractMatchedCatalogTableMeasurementTask" 

82 

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

84 inputs = butlerQC.get(inputRefs) 

85 kwargs = {"currentBands": butlerQC.quantum.dataId['band']} 

86 

87 columns = list(self.config.measure.columns.values()) 

88 for column in self.config.measure.columnsBand.values(): 

89 columns.append(kwargs["currentBands"] + '_' + column) 

90 columnsWithSelectors = self._getTableColumnsSelectors(columns, kwargs["currentBands"]) 

91 catalog = inputs["individualSourceCatalog"].get(parameters={"columns": columnsWithSelectors}) 

92 sel = (catalog[self.config.measure._getColumnName("band")] == kwargs["currentBands"]) 

93 kwargs["catalog"] = catalog.loc[sel, :] 

94 

95 if self.config.connections.refDataset != "": 

96 refCats = inputs.pop("refCat") 

97 filter_map = FilterMap() 

98 filterList = filter_map.getFilters(self.config.instrument, 

99 [kwargs["currentBands"]]) 

100 

101 # TODO: add capability to select the reference epoch 

102 epoch = None 

103 refCatFrame = self._getReferenceCatalog( 

104 butlerQC, 

105 [ref.datasetRef.dataId for ref in inputRefs.refCat], 

106 refCats, 

107 filterList, 

108 epoch, 

109 ) 

110 kwargs["refCatFrame"] = refCatFrame 

111 

112 outputs = self.run(**kwargs) 

113 if outputs.measurement is not None: 

114 butlerQC.put(outputs, outputRefs) 

115 else: 

116 self.log.debugf( 

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

118 self, 

119 inputRefs, 

120 ) 

121 

122 

123class TractMatchedCatalogMultiBandTableMeasurementConnections( 

124 TractMatchedCatalogTableMeasurementConnections, 

125 dimensions=("tract", "skymap"), 

126 defaultTemplates={"individualSourceCatalogName": "isolated_star_sources"} 

127): 

128 

129 individualSourceCatalog = pipeBase.connectionTypes.Input( 

130 doc='Catalog of individual sources for the isolated stars', 

131 name="{individualSourceCatalogName}", 

132 storageClass='DataFrame', 

133 dimensions=('instrument', 'tract', 'skymap'), 

134 deferLoad=True, 

135 ) 

136 

137 measurement = pipeBase.connectionTypes.Output( 

138 doc="Per-tract measurement.", 

139 dimensions=("tract", "skymap"), 

140 storageClass="MetricValue", 

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

142 ) 

143 

144 

145class TractMatchedCatalogMultiBandTableMeasurementConfig( 

146 TractMatchedCatalogTableMeasurementConfig, 

147 pipelineConnections=TractMatchedCatalogMultiBandTableMeasurementConnections, 

148): 

149 """Configuration for TractMatchedCatalogMultiBandTableMeasurementTask.""" 

150 

151 bands = pexConfig.ListField( 

152 doc="Bands for band-specific column loading from objectTable_tract.", 

153 dtype=str, 

154 default=["g", "r", "i", "z", "y"], 

155 ) 

156 

157 

158class TractMatchedCatalogMultiBandTableMeasurementTask(TractMatchedCatalogTableMeasurementTask): 

159 

160 """Base class for science performance metrics measured on single-tract object catalogs, multi-band.""" 

161 

162 ConfigClass = TractMatchedCatalogMultiBandTableMeasurementConfig 

163 _DefaultName = "tractMatchedCatalogMultiBandTableMeasurementTask" 

164 

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

166 inputs = butlerQC.get(inputRefs) 

167 

168 kwargs = {"currentBands": self.config.bands.list()} 

169 

170 columns = list(self.config.measure.columns.values()) 

171 for band in self.config.bands: 

172 for column in self.config.measure.columnsBand.values(): 

173 columns.append(band + "_" + column) 

174 columnsWithSelectors = self._getTableColumnsSelectors(columns, kwargs["currentBands"]) 

175 catalog = inputs["individualSourceCatalog"].get(parameters={"columns": columnsWithSelectors}) 

176 sel = catalog[self.config.measure._getColumnName("band")].isin(kwargs["currentBands"]) 

177 kwargs["catalog"] = catalog.loc[sel, :] 

178 

179 if self.config.connections.refDataset != "": 

180 refCats = inputs.pop("refCat") 

181 filter_map = FilterMap() 

182 filterList = filter_map.getFilters(self.config.instrument, 

183 self.config.bands) 

184 

185 # TODO: add capability to select the reference epoch 

186 epoch = None 

187 refCat = self._getReferenceCatalog( 

188 butlerQC, 

189 [ref.datasetRef.dataId for ref in inputRefs.refCat], 

190 refCats, 

191 filterList, 

192 epoch, 

193 ) 

194 kwargs["refCat"] = refCat 

195 

196 outputs = self.run(**kwargs) 

197 if outputs.measurement is not None: 

198 butlerQC.put(outputs, outputRefs) 

199 else: 

200 self.log.debugf( 

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

202 self, 

203 inputRefs, 

204 )