22 from lsst.pipe.base import (Struct, PipelineTask, PipelineTaskConfig, PipelineTaskConnections)
25 from lsst.pex.config
import ConfigurableField
31 __all__ = (
"DeblendCoaddSourcesSingleConfig",
"DeblendCoaddSourcesSingleTask",
32 "DeblendCoaddSourcesMultiConfig",
"DeblendCoaddSourcesMultiTask")
35 deblendBaseTemplates = {
"inputCoaddName":
"deep",
"outputCoaddName":
"deep"}
39 dimensions=(
"tract",
"patch",
"abstract_filter",
"skymap"),
40 defaultTemplates=deblendBaseTemplates):
41 inputSchema = cT.InitInput(
42 doc=
"Input schema to use in the deblend catalog",
43 name=
"{inputCoaddName}Coadd_mergeDet_schema",
44 storageClass=
"SourceCatalog" 46 peakSchema = cT.InitInput(
47 doc=
"Schema of the footprint peak catalogs",
48 name=
"{inputCoaddName}Coadd_peak_schema",
49 storageClass=
"PeakCatalog" 51 mergedDetections = cT.Input(
52 doc=
"Detection catalog merged across bands",
53 name=
"{inputCoaddName}Coadd_mergeDet",
54 storageClass=
"SourceCatalog",
55 dimensions=(
"tract",
"patch",
"skymap")
58 doc=
"Exposure on which to run deblending",
59 name=
"{inputCoaddName}Coadd_calexp",
60 storageClass=
"ExposureF",
61 dimensions=(
"tract",
"patch",
"abstract_filter",
"skymap")
63 measureCatalog = cT.Output(
64 doc=
"The output measurement catalog of deblended sources",
65 name=
"{outputCoaddName}Coadd_deblendedFlux",
66 storageClass=
"SourceCatalog",
67 dimensions=(
"tract",
"patch",
"abstract_filter",
"skymap")
69 outputSchema = cT.InitOutput(
70 doc=
"Output of the schema used in deblending task",
71 name=
"{outputCoaddName}Coadd_deblendedFlux_schema",
72 storageClass=
"SourceCatalog" 77 self.singleBandDeblend.propagateAllPeaks =
True 81 pipelineConnections=DeblendCoaddSourceSingleConnections):
82 singleBandDeblend = ConfigurableField(
83 target=SourceDeblendTask,
84 doc=
"Task to deblend an image in one band" 89 dimensions=(
"tract",
"patch",
"skymap"),
90 defaultTemplates=deblendBaseTemplates):
91 inputSchema = cT.InitInput(
92 doc=
"Input schema to use in the deblend catalog",
93 name=
"{inputCoaddName}Coadd_mergeDet_schema",
94 storageClass=
"SourceCatalog" 96 peakSchema = cT.InitInput(
97 doc=
"Schema of the footprint peak catalogs",
98 name=
"{inputCoaddName}Coadd_peak_schema",
99 storageClass=
"PeakCatalog" 101 mergedDetections = cT.Input(
102 doc=
"Detection catalog merged across bands",
103 name=
"{inputCoaddName}Coadd_mergeDet",
104 storageClass=
"SourceCatalog",
105 dimensions=(
"tract",
"patch",
"skymap")
108 doc=
"Exposure on which to run deblending",
109 name=
"{inputCoaddName}Coadd_calexp",
110 storageClass=
"ExposureF",
112 dimensions=(
"tract",
"patch",
"abstract_filter",
"skymap")
114 outputSchema = cT.InitOutput(
115 doc=
"Output of the schema used in deblending task",
116 name=
"{outputCoaddName}Coadd_deblendedModel_schema",
117 storageClass=
"SourceCatalog" 119 fluxCatalogs = cT.Output(
120 doc=
"Flux catalogs produced by multiband deblending, not written " 121 "if conserve flux is turned off",
122 name=
"{outputCoaddName}Coadd_deblendedFlux",
123 storageClass=
"SourceCatalog",
124 dimensions=(
"tract",
"patch",
"abstract_filter",
"skymap")
126 templateCatalogs = cT.Output(
127 doc=
"Template catalogs produced by multiband deblending",
128 name=
"{outputCoaddName}Coadd_deblendedModel",
129 storageClass=
"SourceCatalog",
130 dimensions=(
"tract",
"patch",
"abstract_filter",
"skymap")
135 if not config.multibandDeblend.conserveFlux:
136 self.outputs -=
set((
"fluxCatalogs",))
140 pipelineConnections=DeblendCoaddSourcesMultiConnections):
141 multibandDeblend = ConfigurableField(
142 target=MultibandDeblendTask,
143 doc=
"Task to deblend an images in multiple bands" 149 super().
__init__(initInputs=initInputs, **kwargs)
150 schema = initInputs[
"inputSchema"].schema
157 inputs = butlerQC.get(inputRefs)
158 packedId, maxBits = butlerQC.quantum.dataId.pack(
"tract_patch", returnMaxBits=
True)
159 inputs[
"idFactory"] = afwTable.IdFactory.makeSource(packedId, 64 - maxBits)
160 outputs = self.run(**inputs)
161 butlerQC.put(outputs, outputRefs)
163 def _makeSourceCatalog(self, mergedDetections, idFactory):
164 table = afwTable.SourceTable.make(self.
schema, idFactory)
171 ConfigClass = DeblendCoaddSourcesSingleConfig
172 _DefaultName =
"deblendCoaddSourcesSingle" 175 super().
__init__(initInputs=initInputs, **kwargs)
176 self.makeSubtask(
"singleBandDeblend", schema=self.
schema, peakSchema=self.
peakSchema)
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.
schema, peakSchema=self.
peakSchema)
197 inputs = butlerQC.get(inputRefs)
198 packedId, maxBits = butlerQC.quantum.dataId.pack(
"tract_patch", returnMaxBits=
True)
199 inputs[
"idFactory"] = afwTable.IdFactory.makeSource(packedId, 64 - maxBits)
200 inputs[
"filters"] = [dRef.dataId[
"abstract_filter"]
for dRef
in inputRefs.coadds]
201 outputs = self.
run(**inputs)
202 butlerQC.put(outputs, outputRefs)
204 def run(self, coadds, filters, mergedDetections, idFactory):
206 multiExposure = afwImage.MultibandExposure.fromExposures(filters, coadds)
207 fluxCatalogs, templateCatalogs = self.multibandDeblend.
run(multiExposure, sources)
208 retStruct = Struct(templateCatalogs)
209 if self.config.multibandDeblend.conserveFlux:
210 retStruct.fluxCatalogs = fluxCatalogs
def _makeSourceCatalog(self, mergedDetections, idFactory)
def __init__(self, initInputs, kwargs)
def runQuantum(self, butlerQC, inputRefs, outputRefs)
A mapping between the keys of two Schemas, used to copy data between them.
def run(self, coadds, filters, mergedDetections, idFactory)
daf::base::PropertySet * set
def __init__(self, config=None)
def __init__(self, initInputs, kwargs)
def run(self, coadd, mergedDetections, idFactory)
def __init__(self, initInputs, kwargs)
def runQuantum(self, butlerQC, inputRefs, outputRefs)
Backwards-compatibility support for depersisting the old Calib (FluxMag0/FluxMag0Err) objects...