203 deconvolvedRefs = inputRefs.deconvolvedCoadds
204 bandOrder = [dRef.dataId[
"band"]
for dRef
in deconvolvedRefs]
206 inputRefs = reorderRefs(inputRefs, bandOrder, dataIdKey=
"band")
207 inputs = butlerQC.get(inputRefs)
208 bands = [dRef.dataId[
"band"]
for dRef
in deconvolvedRefs]
209 mergedDetections = inputs.pop(
"mergedDetections")
210 match self.config.imageType:
212 if self.config.useCellCoadds:
213 exposures = [mcc.stitch().asExposure()
for mcc
in inputs.pop(
"coadds_cell")]
214 backgrounds = inputs.pop(
"backgrounds")
215 for exposure, background
in zip(exposures, backgrounds):
216 exposure.image -= background.getImage()
218 coaddRefs = inputRefs.coadds_cell
220 coadds = inputs.pop(
"coadds")
221 coaddRefs = inputRefs.coadds
223 coadds = inputs.pop(
"coadds")
224 coaddRefs = inputRefs.coadds
226 raise AssertionError(f
"Invalid choice {self.config.imageType!r} for imageType.")
229 coaddBands = [dRef.dataId[
"band"]
for dRef
in coaddRefs]
230 if bands != coaddBands:
231 self.log.error(
"Coadd bands %s != deconvolved coadd bands %s", bands, coaddBands)
233 "Number of coadd bands and deconvolved coadd bands do not match. "
234 "This should never happen and indicates a bug in reorderRefs."
237 deconvolvedCoadds = inputs.pop(
"deconvolvedCoadds")
240 assert not inputs,
"runQuantum got extra inputs"
245 mergedDetections=mergedDetections,
246 idFactory=self.config.idGenerator.apply(butlerQC.quantum.dataId).make_table_id_factory(),
247 deconvolvedCoadds=deconvolvedCoadds,
249 butlerQC.put(outputs, outputRefs)
251 def run(self, coadds, bands, mergedDetections, deconvolvedCoadds, idFactory):
252 """Deblend coadds from multiple bands together.
256 coadds : `list` [`lsst.afw.image.Exposure` | \
257 `lsst.images.cells.CellCoadd`]
259 bands : `list` [`str`]
260 Names or the bands for ``coadds`` (zip-iteration compatible).
261 mergedDetections : `lsst.afw.table.SourceCatalog`
262 Input catalog of detections, already merged across bands.
263 deconvolvedCoadds : `list` [`lsst.afw.image.Exposure` | \
264 `lsst.images.MaskedImage`]
265 Deconvolved versions of ``coadds`` (zip-iteration compatible).
266 idFactory : `lsst.afw.table.IdFactory`
267 Factory used to generate output source IDs.
271 struct : `lsst.pipe.base.Struct`
272 Unmodified outputs of the ``multibandDeblend`` subtask.
274 coadds = [c.to_legacy()
if isinstance(c, CellCoadd)
else c
for c
in coadds]
277 multiExposure = afwImage.MultibandExposure.fromExposures(bands, coadds)
278 mDeconvolved = afwImage.MultibandExposure.fromExposures(bands, deconvolvedCoadds)
279 result = self.multibandDeblend.run(multiExposure, mDeconvolved, sources)
283 self, deconvolved: afwImage.Exposure | imgs.MaskedImage, coadd: afwImage.Exposure
284 ) -> afwImage.Exposure:
285 if isinstance(deconvolved, imgs.MaskedImage):
286 deconvolved = afwImage.Exposure(
287 maskedImage=deconvolved.to_legacy(plane_map=imgs.get_legacy_deep_coadd_mask_planes()),
288 exposureInfo=coadd.getInfo(),
289 dtype=deconvolved.image.array.dtype,
297 maxId = np.max(mergedDetections[
"id"])
298 idFactory.notify(maxId)
299 table = afwTable.SourceTable.make(self.
schema, idFactory)
300 sources = afwTable.SourceCatalog(table)