22__all__ = [
"DeblendCoaddSourcesSingleConfig",
"DeblendCoaddSourcesSingleTask",
23 "DeblendCoaddSourcesMultiConfig",
"DeblendCoaddSourcesMultiTask"]
27from lsst.pipe.base import (Struct, PipelineTask, PipelineTaskConfig, PipelineTaskConnections)
28import lsst.pipe.base.connectionTypes
as cT
33from lsst.meas.extensions.scarlet
import ScarletDeblendTask
38from .makeWarp
import reorderRefs
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 pipelineConnections=DeblendCoaddSourceSingleConnections):
85 target=SourceDeblendTask,
86 doc=
"Task to deblend an image in one band"
88 idGenerator = SkyMapIdGeneratorConfig.make_field()
96 dimensions=(
"tract",
"patch",
"skymap"),
97 defaultTemplates=deblendBaseTemplates):
98 inputSchema = cT.InitInput(
99 doc=
"Input schema to use in the deblend catalog",
100 name=
"{inputCoaddName}Coadd_mergeDet_schema",
101 storageClass=
"SourceCatalog"
103 peakSchema = cT.InitInput(
104 doc=
"Schema of the footprint peak catalogs",
105 name=
"{inputCoaddName}Coadd_peak_schema",
106 storageClass=
"PeakCatalog"
108 mergedDetections = cT.Input(
109 doc=
"Detection catalog merged across bands",
110 name=
"{inputCoaddName}Coadd_mergeDet",
111 storageClass=
"SourceCatalog",
112 dimensions=(
"tract",
"patch",
"skymap")
115 doc=
"Exposure on which to run deblending",
116 name=
"{inputCoaddName}Coadd_calexp",
117 storageClass=
"ExposureF",
119 dimensions=(
"tract",
"patch",
"band",
"skymap")
121 outputSchema = cT.InitOutput(
122 doc=
"Output of the schema used in deblending task",
123 name=
"{outputCoaddName}Coadd_deblendedFlux_schema",
124 storageClass=
"SourceCatalog"
126 fluxCatalogs = cT.Output(
127 doc=
"Flux weighted catalogs produced by multiband deblending",
128 name=
"{outputCoaddName}Coadd_deblendedFlux",
129 storageClass=
"SourceCatalog",
130 dimensions=(
"tract",
"patch",
"band",
"skymap"),
133 templateCatalogs = cT.Output(
134 doc=
"Template catalogs produced by multiband deblending",
135 name=
"{outputCoaddName}Coadd_deblendedModel",
136 storageClass=
"SourceCatalog",
137 dimensions=(
"tract",
"patch",
"band",
"skymap"),
140 deblendedCatalog = cT.Output(
141 doc=
"Catalogs produced by multiband deblending",
142 name=
"{outputCoaddName}Coadd_deblendedCatalog",
143 storageClass=
"SourceCatalog",
144 dimensions=(
"tract",
"patch",
"skymap"),
146 scarletModelData = cT.Output(
147 doc=
"Multiband scarlet models produced by the deblender",
148 name=
"{outputCoaddName}Coadd_scarletModelData",
149 storageClass=
"ScarletModelData",
150 dimensions=(
"tract",
"patch",
"skymap"),
157 self.outputs -=
set((
"fluxCatalogs",
"templateCatalogs"))
161 pipelineConnections=DeblendCoaddSourcesMultiConnections):
163 target=ScarletDeblendTask,
164 doc=
"Task to deblend an images in multiple bands"
166 idGenerator = SkyMapIdGeneratorConfig.make_field()
171 super().
__init__(initInputs=initInputs, **kwargs)
172 schema = initInputs[
"inputSchema"].schema
179 inputs = butlerQC.get(inputRefs)
180 inputs[
"idFactory"] = self.config.idGenerator.apply(butlerQC.quantum.dataId).make_table_id_factory()
181 outputs = self.run(**inputs)
182 butlerQC.put(outputs, outputRefs)
188 maxId = np.max(mergedDetections[
"id"])
189 idFactory.notify(maxId)
190 table = afwTable.SourceTable.make(self.
schema, idFactory)
197 ConfigClass = DeblendCoaddSourcesSingleConfig
198 _DefaultName =
"deblendCoaddSourcesSingle"
201 super().
__init__(initInputs=initInputs, **kwargs)
202 self.makeSubtask(
"singleBandDeblend", schema=self.
schema, peakSchema=self.
peakSchema)
205 def run(self, coadd, mergedDetections, idFactory):
207 self.singleBandDeblend.run(coadd, sources)
208 if not sources.isContiguous():
209 sources = sources.copy(deep=
True)
210 return Struct(measureCatalog=sources)
214 ConfigClass = DeblendCoaddSourcesMultiConfig
215 _DefaultName =
"deblendCoaddSourcesMulti"
218 super().
__init__(initInputs=initInputs, **kwargs)
219 self.makeSubtask(
"multibandDeblend", schema=self.
schema, peakSchema=self.
peakSchema)
225 bandOrder = [dRef.dataId[
"band"]
for dRef
in inputRefs.coadds]
227 inputRefs = reorderRefs(inputRefs, bandOrder, dataIdKey=
"band")
228 inputs = butlerQC.get(inputRefs)
229 inputs[
"idFactory"] = self.config.idGenerator.apply(butlerQC.quantum.dataId).make_table_id_factory()
230 inputs[
"filters"] = [dRef.dataId[
"band"]
for dRef
in inputRefs.coadds]
231 outputs = self.
run(**inputs)
232 butlerQC.put(outputs, outputRefs)
234 def run(self, coadds, filters, mergedDetections, idFactory):
236 multiExposure = afwImage.MultibandExposure.fromExposures(filters, coadds)
237 catalog, modelData = self.multibandDeblend.run(multiExposure, sources)
238 retStruct = Struct(deblendedCatalog=catalog, scarletModelData=modelData)
A mapping between the keys of two Schemas, used to copy data between them.
_makeSourceCatalog(self, mergedDetections, idFactory)
runQuantum(self, butlerQC, inputRefs, outputRefs)
__init__(self, initInputs, **kwargs)
__init__(self, *config=None)
__init__(self, initInputs, **kwargs)
run(self, coadds, filters, mergedDetections, idFactory)
runQuantum(self, butlerQC, inputRefs, outputRefs)
__init__(self, initInputs, **kwargs)
daf::base::PropertySet * set