24from lsst.pipe.base import (Struct, PipelineTask, PipelineTaskConfig, PipelineTaskConnections)
25import lsst.pipe.base.connectionTypes
as cT
29from lsst.meas.extensions.scarlet
import ScarletDeblendTask
35from .makeCoaddTempExp
import reorderRefs
37__all__ = (
"DeblendCoaddSourcesSingleConfig",
"DeblendCoaddSourcesSingleTask",
38 "DeblendCoaddSourcesMultiConfig",
"DeblendCoaddSourcesMultiTask")
41deblendBaseTemplates = {
"inputCoaddName":
"deep",
"outputCoaddName":
"deep"}
45 dimensions=(
"tract",
"patch",
"band",
"skymap"),
46 defaultTemplates=deblendBaseTemplates):
47 inputSchema = cT.InitInput(
48 doc=
"Input schema to use in the deblend catalog",
49 name=
"{inputCoaddName}Coadd_mergeDet_schema",
50 storageClass=
"SourceCatalog"
52 peakSchema = cT.InitInput(
53 doc=
"Schema of the footprint peak catalogs",
54 name=
"{inputCoaddName}Coadd_peak_schema",
55 storageClass=
"PeakCatalog"
57 mergedDetections = cT.Input(
58 doc=
"Detection catalog merged across bands",
59 name=
"{inputCoaddName}Coadd_mergeDet",
60 storageClass=
"SourceCatalog",
61 dimensions=(
"tract",
"patch",
"skymap")
64 doc=
"Exposure on which to run deblending",
65 name=
"{inputCoaddName}Coadd_calexp",
66 storageClass=
"ExposureF",
67 dimensions=(
"tract",
"patch",
"band",
"skymap")
69 measureCatalog = cT.Output(
70 doc=
"The output measurement catalog of deblended sources",
71 name=
"{outputCoaddName}Coadd_deblendedFlux",
72 storageClass=
"SourceCatalog",
73 dimensions=(
"tract",
"patch",
"band",
"skymap")
75 outputSchema = cT.InitOutput(
76 doc=
"Output of the schema used in deblending task",
77 name=
"{outputCoaddName}Coadd_deblendedFlux_schema",
78 storageClass=
"SourceCatalog"
83 self.singleBandDeblend.propagateAllPeaks =
True
87 pipelineConnections=DeblendCoaddSourceSingleConnections):
89 target=SourceDeblendTask,
90 doc=
"Task to deblend an image in one band"
95 dimensions=(
"tract",
"patch",
"skymap"),
96 defaultTemplates=deblendBaseTemplates):
97 inputSchema = cT.InitInput(
98 doc=
"Input schema to use in the deblend catalog",
99 name=
"{inputCoaddName}Coadd_mergeDet_schema",
100 storageClass=
"SourceCatalog"
102 peakSchema = cT.InitInput(
103 doc=
"Schema of the footprint peak catalogs",
104 name=
"{inputCoaddName}Coadd_peak_schema",
105 storageClass=
"PeakCatalog"
107 mergedDetections = cT.Input(
108 doc=
"Detection catalog merged across bands",
109 name=
"{inputCoaddName}Coadd_mergeDet",
110 storageClass=
"SourceCatalog",
111 dimensions=(
"tract",
"patch",
"skymap")
114 doc=
"Exposure on which to run deblending",
115 name=
"{inputCoaddName}Coadd_calexp",
116 storageClass=
"ExposureF",
118 dimensions=(
"tract",
"patch",
"band",
"skymap")
120 outputSchema = cT.InitOutput(
121 doc=
"Output of the schema used in deblending task",
122 name=
"{outputCoaddName}Coadd_deblendedFlux_schema",
123 storageClass=
"SourceCatalog"
125 fluxCatalogs = cT.Output(
126 doc=
"Flux weighted catalogs produced by multiband deblending",
127 name=
"{outputCoaddName}Coadd_deblendedFlux",
128 storageClass=
"SourceCatalog",
129 dimensions=(
"tract",
"patch",
"band",
"skymap"),
132 templateCatalogs = cT.Output(
133 doc=
"Template catalogs produced by multiband deblending",
134 name=
"{outputCoaddName}Coadd_deblendedModel",
135 storageClass=
"SourceCatalog",
136 dimensions=(
"tract",
"patch",
"band",
"skymap"),
139 deblendedCatalog = cT.Output(
140 doc=
"Catalogs produced by multiband deblending",
141 name=
"{outputCoaddName}Coadd_deblendedCatalog",
142 storageClass=
"SourceCatalog",
143 dimensions=(
"tract",
"patch",
"skymap"),
145 scarletModelData = cT.Output(
146 doc=
"Multiband scarlet models produced by the deblender",
147 name=
"{outputCoaddName}Coadd_scarletModelData",
148 storageClass=
"ScarletModelData",
149 dimensions=(
"tract",
"patch",
"skymap"),
156 self.outputs -=
set((
"fluxCatalogs",
"templateCatalogs"))
160 pipelineConnections=DeblendCoaddSourcesMultiConnections):
162 target=ScarletDeblendTask,
163 doc=
"Task to deblend an images in multiple bands"
169 super().
__init__(initInputs=initInputs, **kwargs)
170 schema = initInputs[
"inputSchema"].schema
177 inputs = butlerQC.get(inputRefs)
178 inputs[
"idFactory"] = ExposureIdInfo.fromDataId(
179 butlerQC.quantum.dataId,
181 ).makeSourceIdFactory()
182 outputs = self.run(**inputs)
183 butlerQC.put(outputs, outputRefs)
185 def _makeSourceCatalog(self, mergedDetections, idFactory):
189 maxId = np.max(mergedDetections[
"id"])
190 idFactory.notify(maxId)
191 table = afwTable.SourceTable.make(self.
schemaschema, idFactory)
193 sources.extend(mergedDetections, self.
schemaMapperschemaMapper)
198 ConfigClass = DeblendCoaddSourcesSingleConfig
199 _DefaultName =
"deblendCoaddSourcesSingle"
202 super().
__init__(initInputs=initInputs, **kwargs)
203 self.makeSubtask(
"singleBandDeblend", schema=self.
schemaschema, peakSchema=self.
peakSchemapeakSchema)
206 def run(self, coadd, mergedDetections, idFactory):
208 self.singleBandDeblend.
run(coadd, sources)
209 if not sources.isContiguous():
210 sources = sources.copy(deep=
True)
211 return Struct(measureCatalog=sources)
215 ConfigClass = DeblendCoaddSourcesMultiConfig
216 _DefaultName =
"deblendCoaddSourcesMulti"
219 super().
__init__(initInputs=initInputs, **kwargs)
220 self.makeSubtask(
"multibandDeblend", schema=self.
schemaschema, peakSchema=self.
peakSchemapeakSchema)
226 bandOrder = [dRef.dataId[
"band"]
for dRef
in inputRefs.coadds]
228 inputRefs = reorderRefs(inputRefs, bandOrder, dataIdKey=
"band")
229 inputs = butlerQC.get(inputRefs)
230 exposureIdInfo = ExposureIdInfo.fromDataId(butlerQC.quantum.dataId,
"tract_patch")
231 inputs[
"idFactory"] = exposureIdInfo.makeSourceIdFactory()
232 inputs[
"filters"] = [dRef.dataId[
"band"]
for dRef
in inputRefs.coadds]
233 outputs = self.
runrun(**inputs)
234 butlerQC.put(outputs, outputRefs)
236 def run(self, coadds, filters, mergedDetections, idFactory):
238 multiExposure = afwImage.MultibandExposure.fromExposures(filters, coadds)
239 catalog, modelData = self.multibandDeblend.
run(multiExposure, sources)
240 retStruct = Struct(deblendedCatalog=catalog, scarletModelData=modelData)
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 __init__(self, *config=None)
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)
daf::base::PropertySet * set
Backwards-compatibility support for depersisting the old Calib (FluxMag0/FluxMag0Err) objects.