Coverage for python / lsst / drp / tasks / make_coadd_input_summary.py: 37%

61 statements  

« prev     ^ index     » next       coverage.py v7.13.5, created at 2026-05-07 08:43 +0000

1# This file is part of drp_tasks. 

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__all__ = [ 

23 "MakeCoaddInputSummaryTractConnections", 

24 "MakeCoaddInputSummaryTractConfig", 

25 "MakeCoaddInputSummaryTract", 

26 "MakeCoaddInputSummaryConnections", 

27 "MakeCoaddInputSummaryConfig", 

28 "MakeCoaddInputSummary", 

29] 

30 

31import numpy as np 

32from astropy.table import Table 

33 

34import lsst.pex.config 

35import lsst.pipe.base 

36from lsst.obs.base import TableVStack 

37 

38 

39class MakeCoaddInputSummaryTractConnections( 

40 lsst.pipe.base.PipelineTaskConnections, 

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

42): 

43 coadd_inputs_handles = lsst.pipe.base.connectionTypes.Input( 

44 name="deep_coadd_predetection.coaddInputs", 

45 doc="Coadd inputs.", 

46 storageClass="CoaddInputs", 

47 dimensions=("skymap", "tract", "patch", "band"), 

48 deferLoad=True, 

49 multiple=True, 

50 ) 

51 coadd_input_summary_tract = lsst.pipe.base.connectionTypes.Output( 

52 name="coadd_input_summary_tract", 

53 doc="Summary table aggregating coaddInputs from multiple coadds (including " 

54 "all coaddInputs tables in a tract for a single band).", 

55 storageClass="ArrowAstropy", 

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

57 ) 

58 

59 

60class MakeCoaddInputSummaryTractConfig( 

61 lsst.pipe.base.PipelineTaskConfig, 

62 pipelineConnections=MakeCoaddInputSummaryTractConnections, 

63): 

64 pass 

65 

66 

67class MakeCoaddInputSummaryTract(lsst.pipe.base.PipelineTask): 

68 """Task to make coadd input summary by tract/band.""" 

69 

70 ConfigClass = MakeCoaddInputSummaryTractConfig 

71 _DefaultName = "make_coadd_input_summary_tract" 

72 

73 def run(self, *, coadd_inputs_handles): 

74 """Run the AggregateCoaddInputsTract task. 

75 

76 Parameters 

77 ---------- 

78 coadd_inputs : `list` [`lsst.daf.butler.DeferredDatasetHandle`] 

79 List of coadd input handles to aggregate. 

80 

81 Returns 

82 ------- 

83 result : `lsst.pipe.base.Struct` 

84 Result struct containing: 

85 ``coadd_input_summary_tract`` : `astropy.table.Table` 

86 

87 Notes 

88 ----- 

89 The output table contains the the following columns: 

90 

91 tract : `int` 

92 The tract number. 

93 patch : `int` 

94 The patch number. 

95 visit : `int` 

96 The visit number. 

97 detector : `int` 

98 The detector number. 

99 weight : `float` 

100 The weight that was used as an input to the coadd. 

101 goodpix : `int` 

102 The number of pixels from the visit/detector in the patch. 

103 band : `str` 

104 The band for the visit. 

105 """ 

106 self.log.info("Summarizing %d coadd input catalogs", len(coadd_inputs_handles)) 

107 n_inputs = 0 

108 detector_table_dict = {} 

109 bands = set() 

110 for coadd_inputs_handle in coadd_inputs_handles: 

111 data_id = coadd_inputs_handle.dataId 

112 tract = data_id["tract"] 

113 patch = data_id["patch"] 

114 band = data_id["band"] 

115 

116 bands.add(band) 

117 

118 coadd_inputs = coadd_inputs_handle.get() 

119 

120 detector_table_dict[(tract, patch, band)] = coadd_inputs.ccds 

121 n_inputs += len(coadd_inputs.ccds) 

122 

123 self.log.info("Found %d coadd input rows to summarize", n_inputs) 

124 

125 coadd_input_summary_tract = Table() 

126 coadd_input_summary_tract["tract"] = np.zeros(n_inputs, dtype=np.int32) 

127 coadd_input_summary_tract["patch"] = np.zeros(n_inputs, dtype=np.int32) 

128 coadd_input_summary_tract["visit"] = np.zeros(n_inputs, dtype=np.int64) 

129 coadd_input_summary_tract["detector"] = np.zeros(n_inputs, dtype=np.int32) 

130 coadd_input_summary_tract["weight"] = np.zeros(n_inputs) 

131 coadd_input_summary_tract["goodpix"] = np.zeros(n_inputs, dtype=np.int32) 

132 coadd_input_summary_tract["band"] = np.zeros(n_inputs, dtype="U3") 

133 

134 counter = 0 

135 for (tract, patch, band), detectors in detector_table_dict.items(): 

136 ndet = len(detectors) 

137 

138 coadd_input_summary_tract["tract"][counter : counter + ndet] = tract 

139 coadd_input_summary_tract["patch"][counter : counter + ndet] = patch 

140 coadd_input_summary_tract["band"][counter : counter + ndet] = band 

141 

142 coadd_input_summary_tract["visit"][counter : counter + ndet] = detectors["visit"] 

143 coadd_input_summary_tract["detector"][counter : counter + ndet] = detectors["ccd"] 

144 coadd_input_summary_tract["weight"][counter : counter + ndet] = detectors["weight"] 

145 coadd_input_summary_tract["goodpix"][counter : counter + ndet] = detectors["goodpix"] 

146 

147 counter += ndet 

148 

149 return lsst.pipe.base.Struct(coadd_input_summary_tract=coadd_input_summary_tract) 

150 

151 

152class MakeCoaddInputSummaryConnections( 

153 lsst.pipe.base.PipelineTaskConnections, 

154 dimensions=("skymap",), 

155): 

156 coadd_input_summary_tract_handles = lsst.pipe.base.connectionTypes.Input( 

157 name="coadd_input_summary_tract", 

158 doc="Summary table aggregating coaddInputs from multiple coadds (including " 

159 "all coaddInputs tables in a tract for a single band).", 

160 storageClass="ArrowAstropy", 

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

162 deferLoad=True, 

163 multiple=True, 

164 ) 

165 coadd_input_summary = lsst.pipe.base.connectionTypes.Output( 

166 name="coadd_input_summary", 

167 doc="Summary table aggregating coaddInputs from all coadds, including all tracts and bands.", 

168 storageClass="ArrowAstropy", 

169 dimensions=("skymap",), 

170 ) 

171 

172 

173class MakeCoaddInputSummaryConfig( 

174 lsst.pipe.base.PipelineTaskConfig, 

175 pipelineConnections=MakeCoaddInputSummaryConnections, 

176): 

177 pass 

178 

179 

180class MakeCoaddInputSummary(lsst.pipe.base.PipelineTask): 

181 """Task to summarize coadd inputs over a full run.""" 

182 

183 ConfigClass = MakeCoaddInputSummaryConfig 

184 _DefaultName = "make_coadd_input_summary" 

185 

186 def run(self, *, coadd_input_summary_tract_handles): 

187 """Run the MakeCoaddInputSummary task. 

188 

189 Parameters 

190 ---------- 

191 coadd_input_summary_tract_handles : `list` 

192 [`lsst.daf.butler.DeferredDatasetHandle`] 

193 List of summarized coadd inputs to combine. 

194 

195 Returns 

196 ------- 

197 result : `lsst.pipe.base.Struct` 

198 Result struct containing: 

199 ``coadd_input_summary`` : `astropy.table.Table` 

200 

201 Notes 

202 ----- 

203 The output table contains the the following columns: 

204 

205 tract : `int` 

206 The tract number. 

207 patch : `int` 

208 The patch number. 

209 visit : `int` 

210 The visit number. 

211 detector : `int` 

212 The detector number. 

213 weight : `float` 

214 The weight that was used as an input to the coadd. 

215 goodpix : `int` 

216 The number of pixels from the visit/detector in the patch. 

217 band : `str` 

218 The band for the visit. 

219 """ 

220 self.log.info("Combining %d summarized coadd input catalogs", len(coadd_input_summary_tract_handles)) 

221 

222 coadd_input_summary = TableVStack.vstack_handles(coadd_input_summary_tract_handles) 

223 

224 return lsst.pipe.base.Struct(coadd_input_summary=coadd_input_summary)