24 from lsst.pipe.base import (Struct, PipelineTask, PipelineTaskConfig, PipelineTaskConnections)
25 import lsst.pipe.base.connectionTypes
as cT
29 from lsst.meas.extensions.scarlet
import ScarletDeblendTask
35 __all__ = (
"DeblendCoaddSourcesSingleConfig",
"DeblendCoaddSourcesSingleTask",
36 "DeblendCoaddSourcesMultiConfig",
"DeblendCoaddSourcesMultiTask")
39 deblendBaseTemplates = {
"inputCoaddName":
"deep",
"outputCoaddName":
"deep"}
43 dimensions=(
"tract",
"patch",
"band",
"skymap"),
44 defaultTemplates=deblendBaseTemplates):
45 inputSchema = cT.InitInput(
46 doc=
"Input schema to use in the deblend catalog",
47 name=
"{inputCoaddName}Coadd_mergeDet_schema",
48 storageClass=
"SourceCatalog"
50 peakSchema = cT.InitInput(
51 doc=
"Schema of the footprint peak catalogs",
52 name=
"{inputCoaddName}Coadd_peak_schema",
53 storageClass=
"PeakCatalog"
55 mergedDetections = cT.Input(
56 doc=
"Detection catalog merged across bands",
57 name=
"{inputCoaddName}Coadd_mergeDet",
58 storageClass=
"SourceCatalog",
59 dimensions=(
"tract",
"patch",
"skymap")
62 doc=
"Exposure on which to run deblending",
63 name=
"{inputCoaddName}Coadd_calexp",
64 storageClass=
"ExposureF",
65 dimensions=(
"tract",
"patch",
"band",
"skymap")
67 measureCatalog = cT.Output(
68 doc=
"The output measurement catalog of deblended sources",
69 name=
"{outputCoaddName}Coadd_deblendedFlux",
70 storageClass=
"SourceCatalog",
71 dimensions=(
"tract",
"patch",
"band",
"skymap")
73 outputSchema = cT.InitOutput(
74 doc=
"Output of the schema used in deblending task",
75 name=
"{outputCoaddName}Coadd_deblendedFlux_schema",
76 storageClass=
"SourceCatalog"
81 self.singleBandDeblend.propagateAllPeaks =
True
85 pipelineConnections=DeblendCoaddSourceSingleConnections):
87 target=SourceDeblendTask,
88 doc=
"Task to deblend an image in one band"
93 dimensions=(
"tract",
"patch",
"skymap"),
94 defaultTemplates=deblendBaseTemplates):
95 inputSchema = cT.InitInput(
96 doc=
"Input schema to use in the deblend catalog",
97 name=
"{inputCoaddName}Coadd_mergeDet_schema",
98 storageClass=
"SourceCatalog"
100 peakSchema = cT.InitInput(
101 doc=
"Schema of the footprint peak catalogs",
102 name=
"{inputCoaddName}Coadd_peak_schema",
103 storageClass=
"PeakCatalog"
105 mergedDetections = cT.Input(
106 doc=
"Detection catalog merged across bands",
107 name=
"{inputCoaddName}Coadd_mergeDet",
108 storageClass=
"SourceCatalog",
109 dimensions=(
"tract",
"patch",
"skymap")
112 doc=
"Exposure on which to run deblending",
113 name=
"{inputCoaddName}Coadd_calexp",
114 storageClass=
"ExposureF",
116 dimensions=(
"tract",
"patch",
"band",
"skymap")
118 outputSchema = cT.InitOutput(
119 doc=
"Output of the schema used in deblending task",
120 name=
"{outputCoaddName}Coadd_deblendedFlux_schema",
121 storageClass=
"SourceCatalog"
123 templateCatalogs = cT.Output(
124 doc=
"Template catalogs produced by multiband deblending",
125 name=
"{outputCoaddName}Coadd_deblendedFlux",
126 storageClass=
"SourceCatalog",
127 dimensions=(
"tract",
"patch",
"band",
"skymap"),
133 pipelineConnections=DeblendCoaddSourcesMultiConnections):
135 target=ScarletDeblendTask,
136 doc=
"Task to deblend an images in multiple bands"
142 super().
__init__(initInputs=initInputs, **kwargs)
143 schema = initInputs[
"inputSchema"].schema
150 inputs = butlerQC.get(inputRefs)
151 inputs[
"idFactory"] = ExposureIdInfo.fromDataId(
152 butlerQC.quantum.dataId,
154 ).makeSourceIdFactory()
155 outputs = self.run(**inputs)
156 butlerQC.put(outputs, outputRefs)
158 def _makeSourceCatalog(self, mergedDetections, idFactory):
162 maxId = np.max(mergedDetections[
"id"])
163 idFactory.notify(maxId)
164 table = afwTable.SourceTable.make(self.
schemaschema, idFactory)
166 sources.extend(mergedDetections, self.
schemaMapperschemaMapper)
171 ConfigClass = DeblendCoaddSourcesSingleConfig
172 _DefaultName =
"deblendCoaddSourcesSingle"
175 super().
__init__(initInputs=initInputs, **kwargs)
176 self.makeSubtask(
"singleBandDeblend", schema=self.
schemaschema, peakSchema=self.
peakSchemapeakSchema)
179 def run(self, coadd, mergedDetections, idFactory):
181 self.singleBandDeblend.
run(coadd, sources)
182 if not sources.isContiguous():
183 sources = sources.copy(deep=
True)
184 return Struct(measureCatalog=sources)
188 ConfigClass = DeblendCoaddSourcesMultiConfig
189 _DefaultName =
"deblendCoaddSourcesMulti"
192 super().
__init__(initInputs=initInputs, **kwargs)
193 self.makeSubtask(
"multibandDeblend", schema=self.
schemaschema, peakSchema=self.
peakSchemapeakSchema)
197 inputs = butlerQC.get(inputRefs)
198 exposureIdInfo = ExposureIdInfo.fromDataId(butlerQC.quantum.dataId,
"tract_patch")
199 inputs[
"idFactory"] = exposureIdInfo.makeSourceIdFactory()
200 inputs[
"filters"] = [dRef.dataId[
"band"]
for dRef
in inputRefs.coadds]
201 outputs = self.
runrun(**inputs)
202 for outRef
in outputRefs.templateCatalogs:
203 band = outRef.dataId[
'band']
204 if (catalog := outputs.templateCatalogs.get(band))
is not None:
205 butlerQC.put(catalog, outRef)
207 def run(self, coadds, filters, mergedDetections, idFactory):
209 multiExposure = afwImage.MultibandExposure.fromExposures(filters, coadds)
210 templateCatalogs = self.multibandDeblend.
run(multiExposure, sources)
211 retStruct = Struct(templateCatalogs=templateCatalogs)
A mapping between the keys of two Schemas, used to copy data between them.
def __init__(self, initInputs, **kwargs)
def _makeSourceCatalog(self, mergedDetections, idFactory)
def runQuantum(self, butlerQC, inputRefs, outputRefs)
def runQuantum(self, butlerQC, inputRefs, outputRefs)
def run(self, coadds, filters, mergedDetections, idFactory)
def __init__(self, initInputs, **kwargs)
def __init__(self, initInputs, **kwargs)
def run(self, coadd, mergedDetections, idFactory)
Backwards-compatibility support for depersisting the old Calib (FluxMag0/FluxMag0Err) objects.