Coverage for python/lsst/faro/measurement/ForcedSourceTableMeasurement.py: 61%

Shortcuts 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

40 statements  

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) 

31 

32__all__ = ( 

33 "ForcedSourceTableMeasurementConnections", 

34 "ForcedSourceTableMeasurementConfig", 

35 "ForcedSourceTableMeasurementTask", 

36 "ForcedSourceMultiBandTableMeasurementConnections", 

37 "ForcedSourceMultiBandTableMeasurementConfig", 

38 "ForcedSourceMultiBandTableMeasurementTask", 

39) 

40 

41 

42class ForcedSourceTableMeasurementConnections( 

43 CatalogMeasurementBaseConnections, 

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

45): 

46 

47 catalog = pipeBase.connectionTypes.Input( 

48 doc="Forced source table in parquet format, per tract", 

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

50 storageClass="DataFrame", 

51 name="forcedSourceTable_tract", 

52 deferLoad=True, 

53 ) 

54 

55 measurement = pipeBase.connectionTypes.Output( 

56 doc="Per-tract measurement.", 

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

58 storageClass="MetricValue", 

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

60 ) 

61 

62 

63class ForcedSourceTableMeasurementConfig( 

64 CatalogMeasurementBaseConfig, pipelineConnections=ForcedSourceTableMeasurementConnections 

65): 

66 """Configuration for ForcedSourceTableMeasurementTask.""" 

67 

68 columns = pexConfig.ListField( 

69 doc="Band-independent columns from forcedSourceTable_tract to load.", 

70 dtype=str, 

71 default=["coord_ra", "coord_dec", "band", "detect_isPrimary", "psfFlux", "psfFluxErr"], 

72 ) 

73 

74 

75class ForcedSourceTableMeasurementTask(CatalogMeasurementBaseTask): 

76 """Base class for per-band science performance metrics measured on multi-visit forced source catalogs.""" 

77 

78 ConfigClass = ForcedSourceTableMeasurementConfig 

79 _DefaultName = "forcedSourceTableMeasurementTask" 

80 

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

82 inputs = butlerQC.get(inputRefs) 

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

84 

85 columns = self.config.columns.list() 

86 tmp_catalog = inputs["catalog"].get(parameters={"columns": columns}) 

87 # Extract only the entries from the band of interest: 

88 kwargs["catalog"] = tmp_catalog[tmp_catalog.band == kwargs["band"]] 

89 

90 outputs = self.run(**kwargs) 

91 if outputs.measurement is not None: 

92 butlerQC.put(outputs, outputRefs) 

93 else: 

94 self.log.debugf( 

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

96 self, 

97 inputRefs, 

98 ) 

99 

100 

101class ForcedSourceMultiBandTableMeasurementConnections( 

102 CatalogMeasurementBaseConnections, 

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

104): 

105 

106 catalog = pipeBase.connectionTypes.Input( 

107 doc="Forced source table in parquet format, per tract", 

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

109 storageClass="DataFrame", 

110 name="forcedSourceTable_tract", 

111 deferLoad=True, 

112 ) 

113 

114 measurement = pipeBase.connectionTypes.Output( 

115 doc="Per-tract measurement.", 

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

117 storageClass="MetricValue", 

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

119 ) 

120 

121 

122class ForcedSourceMultiBandTableMeasurementConfig( 

123 ForcedSourceTableMeasurementConfig, 

124 pipelineConnections=ForcedSourceMultiBandTableMeasurementConnections 

125): 

126 """Configuration for ForcedSourceMultiBandTableMeasurementTask.""" 

127 

128 bands = pexConfig.ListField( 

129 doc="Bands for band-specific column loading from ForcedSourceTable_tract.", 

130 dtype=str, 

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

132 ) 

133 

134 

135class ForcedSourceMultiBandTableMeasurementTask(CatalogMeasurementBaseTask): 

136 """Base class for multi-band science performance metrics measured on 

137 multi-visit forced source catalogs.""" 

138 

139 ConfigClass = ForcedSourceMultiBandTableMeasurementConfig 

140 _DefaultName = "forcedSourceMultiBandTableMeasurementTask" 

141 

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

143 inputs = butlerQC.get(inputRefs) 

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

145 

146 columns = self.config.columns.list() 

147 tmp_catalog = inputs["catalog"].get(parameters={"columns": columns}) 

148 # Extract only the entries from the band of interest: 

149 kwargs["catalog"] = tmp_catalog[tmp_catalog.band.isin(kwargs["bands"])] 

150 

151 outputs = self.run(**kwargs) 

152 if outputs.measurement is not None: 

153 butlerQC.put(outputs, outputRefs) 

154 else: 

155 self.log.debugf( 

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

157 self, 

158 inputRefs, 

159 )