22 from lsst.pipe.base import (Struct, PipelineTask, PipelineTaskConfig, PipelineTaskConnections)
27 from lsst.meas.extensions.scarlet
import ScarletDeblendTask
33 __all__ = (
"DeblendCoaddSourcesSingleConfig",
"DeblendCoaddSourcesSingleTask",
34 "DeblendCoaddSourcesMultiConfig",
"DeblendCoaddSourcesMultiTask")
37 deblendBaseTemplates = {
"inputCoaddName":
"deep",
"outputCoaddName":
"deep"}
41 dimensions=(
"tract",
"patch",
"band",
"skymap"),
42 defaultTemplates=deblendBaseTemplates):
43 inputSchema = cT.InitInput(
44 doc=
"Input schema to use in the deblend catalog",
45 name=
"{inputCoaddName}Coadd_mergeDet_schema",
46 storageClass=
"SourceCatalog"
48 peakSchema = cT.InitInput(
49 doc=
"Schema of the footprint peak catalogs",
50 name=
"{inputCoaddName}Coadd_peak_schema",
51 storageClass=
"PeakCatalog"
53 mergedDetections = cT.Input(
54 doc=
"Detection catalog merged across bands",
55 name=
"{inputCoaddName}Coadd_mergeDet",
56 storageClass=
"SourceCatalog",
57 dimensions=(
"tract",
"patch",
"skymap")
60 doc=
"Exposure on which to run deblending",
61 name=
"{inputCoaddName}Coadd_calexp",
62 storageClass=
"ExposureF",
63 dimensions=(
"tract",
"patch",
"band",
"skymap")
65 measureCatalog = cT.Output(
66 doc=
"The output measurement catalog of deblended sources",
67 name=
"{outputCoaddName}Coadd_deblendedFlux",
68 storageClass=
"SourceCatalog",
69 dimensions=(
"tract",
"patch",
"band",
"skymap")
71 outputSchema = cT.InitOutput(
72 doc=
"Output of the schema used in deblending task",
73 name=
"{outputCoaddName}Coadd_deblendedFlux_schema",
74 storageClass=
"SourceCatalog"
79 self.singleBandDeblend.propagateAllPeaks =
True
83 pipelineConnections=DeblendCoaddSourceSingleConnections):
85 target=SourceDeblendTask,
86 doc=
"Task to deblend an image in one band"
91 dimensions=(
"tract",
"patch",
"skymap"),
92 defaultTemplates=deblendBaseTemplates):
93 inputSchema = cT.InitInput(
94 doc=
"Input schema to use in the deblend catalog",
95 name=
"{inputCoaddName}Coadd_mergeDet_schema",
96 storageClass=
"SourceCatalog"
98 peakSchema = cT.InitInput(
99 doc=
"Schema of the footprint peak catalogs",
100 name=
"{inputCoaddName}Coadd_peak_schema",
101 storageClass=
"PeakCatalog"
103 mergedDetections = cT.Input(
104 doc=
"Detection catalog merged across bands",
105 name=
"{inputCoaddName}Coadd_mergeDet",
106 storageClass=
"SourceCatalog",
107 dimensions=(
"tract",
"patch",
"skymap")
110 doc=
"Exposure on which to run deblending",
111 name=
"{inputCoaddName}Coadd_calexp",
112 storageClass=
"ExposureF",
114 dimensions=(
"tract",
"patch",
"band",
"skymap")
116 outputSchema = cT.InitOutput(
117 doc=
"Output of the schema used in deblending task",
118 name=
"{outputCoaddName}Coadd_deblendedFlux_schema",
119 storageClass=
"SourceCatalog"
121 templateCatalogs = cT.Output(
122 doc=
"Template catalogs produced by multiband deblending",
123 name=
"{outputCoaddName}Coadd_deblendedFlux",
124 storageClass=
"SourceCatalog",
125 dimensions=(
"tract",
"patch",
"band",
"skymap"),
131 pipelineConnections=DeblendCoaddSourcesMultiConnections):
133 target=ScarletDeblendTask,
134 doc=
"Task to deblend an images in multiple bands"
140 super().
__init__(initInputs=initInputs, **kwargs)
141 schema = initInputs[
"inputSchema"].schema
148 inputs = butlerQC.get(inputRefs)
149 inputs[
"idFactory"] = ExposureIdInfo.fromDataId(
150 butlerQC.quantum.dataId,
152 ).makeSourceIdFactory()
153 outputs = self.
runrun(**inputs)
154 butlerQC.put(outputs, outputRefs)
156 def _makeSourceCatalog(self, mergedDetections, idFactory):
157 table = afwTable.SourceTable.make(self.
schemaschema, idFactory)
159 sources.extend(mergedDetections, self.
schemaMapperschemaMapper)
164 ConfigClass = DeblendCoaddSourcesSingleConfig
165 _DefaultName =
"deblendCoaddSourcesSingle"
168 super().
__init__(initInputs=initInputs, **kwargs)
172 def run(self, coadd, mergedDetections, idFactory):
174 self.singleBandDeblend.
run(coadd, sources)
175 if not sources.isContiguous():
176 sources = sources.copy(deep=
True)
177 return Struct(measureCatalog=sources)
181 ConfigClass = DeblendCoaddSourcesMultiConfig
182 _DefaultName =
"deblendCoaddSourcesMulti"
185 super().
__init__(initInputs=initInputs, **kwargs)
190 inputs = butlerQC.get(inputRefs)
191 exposureIdInfo = ExposureIdInfo.fromDataId(butlerQC.quantum.dataId,
"tract_patch")
192 inputs[
"idFactory"] = exposureIdInfo.makeSourceIdFactory()
193 inputs[
"filters"] = [dRef.dataId[
"band"]
for dRef
in inputRefs.coadds]
194 outputs = self.
runrunrun(**inputs)
195 sortedTemplateCatalogs = []
196 for outRef
in outputRefs.templateCatalogs:
197 band = outRef.dataId[
'band']
198 sortedTemplateCatalogs.append(outputs.templateCatalogs[band])
199 outputs.templateCatalogs = sortedTemplateCatalogs
200 butlerQC.put(outputs, outputRefs)
202 def run(self, coadds, filters, mergedDetections, idFactory):
204 multiExposure = afwImage.MultibandExposure.fromExposures(filters, coadds)
205 templateCatalogs = self.multibandDeblend.
run(multiExposure, sources)
206 retStruct =
Struct(templateCatalogs=templateCatalogs)
A mapping between the keys of two Schemas, used to copy data between them.
def makeSubtask(self, name, **keyArgs)
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.