183 deconvolvedRefs = inputRefs.deconvolvedCoadds
184 bandOrder = [dRef.dataId[
"band"]
for dRef
in deconvolvedRefs]
186 inputRefs = reorderRefs(inputRefs, bandOrder, dataIdKey=
"band")
187 inputs = butlerQC.get(inputRefs)
188 bands = [dRef.dataId[
"band"]
for dRef
in deconvolvedRefs]
189 mergedDetections = inputs.pop(
"mergedDetections")
190 match self.config.imageType:
192 if self.config.useCellCoadds:
193 exposures = [mcc.stitch().asExposure()
for mcc
in inputs.pop(
"coadds_cell")]
194 backgrounds = inputs.pop(
"backgrounds")
195 for exposure, background
in zip(exposures, backgrounds):
196 exposure.image -= background.getImage()
198 coaddRefs = inputRefs.coadds_cell
200 coadds = inputs.pop(
"coadds")
201 coaddRefs = inputRefs.coadds
203 coadds = inputs.pop(
"coadds")
204 coaddRefs = inputRefs.coadds
206 raise AssertionError(f
"Invalid choice {self.config.imageType!r} for imageType.")
209 coaddBands = [dRef.dataId[
"band"]
for dRef
in coaddRefs]
210 if bands != coaddBands:
211 self.log.error(
"Coadd bands %s != deconvolved coadd bands %s", bands, coaddBands)
213 "Number of coadd bands and deconvolved coadd bands do not match. "
214 "This should never happen and indicates a bug in reorderRefs."
217 deconvolvedCoadds = inputs.pop(
"deconvolvedCoadds")
220 assert not inputs,
"runQuantum got extra inputs"
225 mergedDetections=mergedDetections,
226 idFactory=self.config.idGenerator.apply(butlerQC.quantum.dataId).make_table_id_factory(),
227 deconvolvedCoadds=deconvolvedCoadds,
229 butlerQC.put(outputs, outputRefs)
231 def run(self, coadds, bands, mergedDetections, deconvolvedCoadds, idFactory):
232 """Deblend coadds from multiple bands together.
236 coadds : `list` [`lsst.afw.image.Exposure` | \
237 `lsst.images.cells.CellCoadd`]
239 bands : `list` [`str`]
240 Names or the bands for ``coadds`` (zip-iteration compatible).
241 mergedDetections : `lsst.afw.table.SourceCatalog`
242 Input catalog of detections, already merged across bands.
243 deconvolvedCoadds : `list` [`lsst.afw.image.Exposure` | \
244 `lsst.images.MaskedImage`]
245 Deconvolved versions of ``coadds`` (zip-iteration compatible).
246 idFactory : `lsst.afw.table.IdFactory`
247 Factory used to generate output source IDs.
251 struct : `lsst.pipe.base.Struct`
252 Unmodified outputs of the ``multibandDeblend`` subtask.
254 coadds = [c.to_legacy()
if isinstance(c, CellCoadd)
else c
for c
in coadds]
257 multiExposure = afwImage.MultibandExposure.fromExposures(bands, coadds)
258 mDeconvolved = afwImage.MultibandExposure.fromExposures(bands, deconvolvedCoadds)
259 result = self.multibandDeblend.run(multiExposure, mDeconvolved, sources)
263 self, deconvolved: afwImage.Exposure | imgs.MaskedImage, coadd: afwImage.Exposure
264 ) -> afwImage.Exposure:
265 if isinstance(deconvolved, imgs.MaskedImage):
266 deconvolved = afwImage.Exposure(
267 maskedImage=deconvolved.to_legacy(plane_map=imgs.get_legacy_deep_coadd_mask_planes()),
268 exposureInfo=coadd.getInfo(),
269 dtype=deconvolved.image.array.dtype,
277 maxId = np.max(mergedDetections[
"id"])
278 idFactory.notify(maxId)
279 table = afwTable.SourceTable.make(self.
schema, idFactory)
280 sources = afwTable.SourceCatalog(table)