LSSTApplications  19.0.0-14-gb0260a2+72efe9b372,20.0.0+7927753e06,20.0.0+8829bf0056,20.0.0+995114c5d2,20.0.0+b6f4b2abd1,20.0.0+bddc4f4cbe,20.0.0-1-g253301a+8829bf0056,20.0.0-1-g2b7511a+0d71a2d77f,20.0.0-1-g5b95a8c+7461dd0434,20.0.0-12-g321c96ea+23efe4bbff,20.0.0-16-gfab17e72e+fdf35455f6,20.0.0-2-g0070d88+ba3ffc8f0b,20.0.0-2-g4dae9ad+ee58a624b3,20.0.0-2-g61b8584+5d3db074ba,20.0.0-2-gb780d76+d529cf1a41,20.0.0-2-ged6426c+226a441f5f,20.0.0-2-gf072044+8829bf0056,20.0.0-2-gf1f7952+ee58a624b3,20.0.0-20-geae50cf+e37fec0aee,20.0.0-25-g3dcad98+544a109665,20.0.0-25-g5eafb0f+ee58a624b3,20.0.0-27-g64178ef+f1f297b00a,20.0.0-3-g4cc78c6+e0676b0dc8,20.0.0-3-g8f21e14+4fd2c12c9a,20.0.0-3-gbd60e8c+187b78b4b8,20.0.0-3-gbecbe05+48431fa087,20.0.0-38-ge4adf513+a12e1f8e37,20.0.0-4-g97dc21a+544a109665,20.0.0-4-gb4befbc+087873070b,20.0.0-4-gf910f65+5d3db074ba,20.0.0-5-gdfe0fee+199202a608,20.0.0-5-gfbfe500+d529cf1a41,20.0.0-6-g64f541c+d529cf1a41,20.0.0-6-g9a5b7a1+a1cd37312e,20.0.0-68-ga3f3dda+5fca18c6a4,20.0.0-9-g4aef684+e18322736b,w.2020.45
LSSTDataManagementBasePackage
deblendCoaddSourcesPipeline.py
Go to the documentation of this file.
1 # This file is part of pipe_tasks.
2 #
3 # Developed for the LSST Data Management System.
4 # This product includes software developed by the LSST Project
5 # (https://www.lsst.org).
6 # See the COPYRIGHT file at the top-level directory of this distribution
7 # for details of code ownership.
8 #
9 # This program is free software: you can redistribute it and/or modify
10 # it under the terms of the GNU General Public License as published by
11 # the Free Software Foundation, either version 3 of the License, or
12 # (at your option) any later version.
13 #
14 # This program is distributed in the hope that it will be useful,
15 # but WITHOUT ANY WARRANTY; without even the implied warranty of
16 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 # GNU General Public License for more details.
18 #
19 # You should have received a copy of the GNU General Public License
20 # along with this program. If not, see <https://www.gnu.org/licenses/>.
21 
22 from lsst.pipe.base import (Struct, PipelineTask, PipelineTaskConfig, PipelineTaskConnections)
24 
25 from lsst.pex.config import ConfigurableField
26 from lsst.meas.deblender import SourceDeblendTask
27 from lsst.meas.extensions.scarlet import ScarletDeblendTask
28 
29 import lsst.afw.image as afwImage
30 import lsst.afw.table as afwTable
31 
32 __all__ = ("DeblendCoaddSourcesSingleConfig", "DeblendCoaddSourcesSingleTask",
33  "DeblendCoaddSourcesMultiConfig", "DeblendCoaddSourcesMultiTask")
34 
35 
36 deblendBaseTemplates = {"inputCoaddName": "deep", "outputCoaddName": "deep"}
37 
38 
40  dimensions=("tract", "patch", "band", "skymap"),
41  defaultTemplates=deblendBaseTemplates):
42  inputSchema = cT.InitInput(
43  doc="Input schema to use in the deblend catalog",
44  name="{inputCoaddName}Coadd_mergeDet_schema",
45  storageClass="SourceCatalog"
46  )
47  peakSchema = cT.InitInput(
48  doc="Schema of the footprint peak catalogs",
49  name="{inputCoaddName}Coadd_peak_schema",
50  storageClass="PeakCatalog"
51  )
52  mergedDetections = cT.Input(
53  doc="Detection catalog merged across bands",
54  name="{inputCoaddName}Coadd_mergeDet",
55  storageClass="SourceCatalog",
56  dimensions=("tract", "patch", "skymap")
57  )
58  coadd = cT.Input(
59  doc="Exposure on which to run deblending",
60  name="{inputCoaddName}Coadd_calexp",
61  storageClass="ExposureF",
62  dimensions=("tract", "patch", "band", "skymap")
63  )
64  measureCatalog = cT.Output(
65  doc="The output measurement catalog of deblended sources",
66  name="{outputCoaddName}Coadd_deblendedFlux",
67  storageClass="SourceCatalog",
68  dimensions=("tract", "patch", "band", "skymap")
69  )
70  outputSchema = cT.InitOutput(
71  doc="Output of the schema used in deblending task",
72  name="{outputCoaddName}Coadd_deblendedFlux_schema",
73  storageClass="SourceCatalog"
74  )
75 
76  def setDefaults(self):
77  super().setDefaults()
78  self.singleBandDeblend.propagateAllPeaks = True
79 
80 
82  pipelineConnections=DeblendCoaddSourceSingleConnections):
83  singleBandDeblend = ConfigurableField(
84  target=SourceDeblendTask,
85  doc="Task to deblend an image in one band"
86  )
87 
88 
90  dimensions=("tract", "patch", "skymap"),
91  defaultTemplates=deblendBaseTemplates):
92  inputSchema = cT.InitInput(
93  doc="Input schema to use in the deblend catalog",
94  name="{inputCoaddName}Coadd_mergeDet_schema",
95  storageClass="SourceCatalog"
96  )
97  peakSchema = cT.InitInput(
98  doc="Schema of the footprint peak catalogs",
99  name="{inputCoaddName}Coadd_peak_schema",
100  storageClass="PeakCatalog"
101  )
102  mergedDetections = cT.Input(
103  doc="Detection catalog merged across bands",
104  name="{inputCoaddName}Coadd_mergeDet",
105  storageClass="SourceCatalog",
106  dimensions=("tract", "patch", "skymap")
107  )
108  coadds = cT.Input(
109  doc="Exposure on which to run deblending",
110  name="{inputCoaddName}Coadd_calexp",
111  storageClass="ExposureF",
112  multiple=True,
113  dimensions=("tract", "patch", "band", "skymap")
114  )
115  outputSchema = cT.InitOutput(
116  doc="Output of the schema used in deblending task",
117  name="{outputCoaddName}Coadd_deblendedModel_schema",
118  storageClass="SourceCatalog"
119  )
120  fluxCatalogs = cT.Output(
121  doc="Flux catalogs produced by multiband deblending, not written "
122  "if conserve flux is turned off",
123  name="{outputCoaddName}Coadd_deblendedFlux",
124  storageClass="SourceCatalog",
125  dimensions=("tract", "patch", "band", "skymap")
126  )
127  templateCatalogs = cT.Output(
128  doc="Template catalogs produced by multiband deblending",
129  name="{outputCoaddName}Coadd_deblendedModel",
130  storageClass="SourceCatalog",
131  dimensions=("tract", "patch", "band", "skymap")
132  )
133 
134  def __init__(self, *, config=None):
135  super().__init__(config=config)
136  if not config.multibandDeblend.conserveFlux:
137  self.outputs -= set(("fluxCatalogs",))
138 
139 
141  pipelineConnections=DeblendCoaddSourcesMultiConnections):
142  multibandDeblend = ConfigurableField(
143  target=ScarletDeblendTask,
144  doc="Task to deblend an images in multiple bands"
145  )
146 
147 
149  def __init__(self, initInputs, **kwargs):
150  super().__init__(initInputs=initInputs, **kwargs)
151  schema = initInputs["inputSchema"].schema
152  self.peakSchema = initInputs["peakSchema"].schema
154  self.schemaMapper.addMinimalSchema(schema)
155  self.schema = self.schemaMapper.getOutputSchema()
156 
157  def runQuantum(self, butlerQC, inputRefs, outputRefs):
158  inputs = butlerQC.get(inputRefs)
159  packedId, maxBits = butlerQC.quantum.dataId.pack("tract_patch", returnMaxBits=True)
160  inputs["idFactory"] = afwTable.IdFactory.makeSource(packedId, 64 - maxBits)
161  outputs = self.run(**inputs)
162  butlerQC.put(outputs, outputRefs)
163 
164  def _makeSourceCatalog(self, mergedDetections, idFactory):
165  table = afwTable.SourceTable.make(self.schema, idFactory)
166  sources = afwTable.SourceCatalog(table)
167  sources.extend(mergedDetections, self.schemaMapper)
168  return sources
169 
170 
172  ConfigClass = DeblendCoaddSourcesSingleConfig
173  _DefaultName = "deblendCoaddSourcesSingle"
174 
175  def __init__(self, initInputs, **kwargs):
176  super().__init__(initInputs=initInputs, **kwargs)
177  self.makeSubtask("singleBandDeblend", schema=self.schema, peakSchema=self.peakSchema)
179 
180  def run(self, coadd, mergedDetections, idFactory):
181  sources = self._makeSourceCatalog(mergedDetections, idFactory)
182  self.singleBandDeblend.run(coadd, sources)
183  if not sources.isContiguous():
184  sources = sources.copy(deep=True)
185  return Struct(measureCatalog=sources)
186 
187 
189  ConfigClass = DeblendCoaddSourcesMultiConfig
190  _DefaultName = "deblendCoaddSourcesMulti"
191 
192  def __init__(self, initInputs, **kwargs):
193  super().__init__(initInputs=initInputs, **kwargs)
194  self.makeSubtask("multibandDeblend", schema=self.schema, peakSchema=self.peakSchema)
196 
197  def runQuantum(self, butlerQC, inputRefs, outputRefs):
198  inputs = butlerQC.get(inputRefs)
199  packedId, maxBits = butlerQC.quantum.dataId.pack("tract_patch", returnMaxBits=True)
200  inputs["idFactory"] = afwTable.IdFactory.makeSource(packedId, 64 - maxBits)
201  inputs["filters"] = [dRef.dataId["band"] for dRef in inputRefs.coadds]
202  outputs = self.run(**inputs)
203  butlerQC.put(outputs, outputRefs)
204 
205  def run(self, coadds, filters, mergedDetections, idFactory):
206  sources = self._makeSourceCatalog(mergedDetections, idFactory)
207  multiExposure = afwImage.MultibandExposure.fromExposures(filters, coadds)
208  fluxCatalogs, templateCatalogs = self.multibandDeblend.run(multiExposure, sources)
209  retStruct = Struct(templateCatalogs)
210  if self.config.multibandDeblend.conserveFlux:
211  retStruct.fluxCatalogs = fluxCatalogs
212  return retStruct
lsst::afw::image
Backwards-compatibility support for depersisting the old Calib (FluxMag0/FluxMag0Err) objects.
Definition: imageAlgorithm.dox:1
lsst.pipe.tasks.deblendCoaddSourcesPipeline.DeblendCoaddSourceSingleConnections.setDefaults
def setDefaults(self)
Definition: deblendCoaddSourcesPipeline.py:76
lsst.pipe.base.connections.PipelineTaskConnections.outputs
outputs
Definition: connections.py:367
lsst.pipe.base.pipelineTask.PipelineTask.run
def run(self, **kwargs)
Definition: pipelineTask.py:88
lsst.pipe.tasks.deblendCoaddSourcesPipeline.DeblendCoaddSourcesSingleTask
Definition: deblendCoaddSourcesPipeline.py:171
lsst.pipe.tasks.deblendCoaddSourcesPipeline.DeblendCoaddSourcesMultiTask.run
def run(self, coadds, filters, mergedDetections, idFactory)
Definition: deblendCoaddSourcesPipeline.py:205
lsst.pipe.tasks.deblendCoaddSourcesPipeline.DeblendCoaddSourcesMultiConnections
Definition: deblendCoaddSourcesPipeline.py:91
lsst.pex.config.configurableField.ConfigurableField
Definition: configurableField.py:170
lsst.pipe.tasks.deblendCoaddSourcesPipeline.DeblendCoaddSourcesSingleConfig
Definition: deblendCoaddSourcesPipeline.py:82
lsst.pipe.tasks.deblendCoaddSourcesPipeline.DeblendCoaddSourcesBaseTask.schema
schema
Definition: deblendCoaddSourcesPipeline.py:155
lsst.pipe.tasks.deblendCoaddSourcesPipeline.DeblendCoaddSourcesBaseTask._makeSourceCatalog
def _makeSourceCatalog(self, mergedDetections, idFactory)
Definition: deblendCoaddSourcesPipeline.py:164
lsst.pipe.base.task.Task.makeSubtask
def makeSubtask(self, name, **keyArgs)
Definition: task.py:299
lsst.pipe.tasks.deblendCoaddSourcesPipeline.DeblendCoaddSourcesMultiTask.outputSchema
outputSchema
Definition: deblendCoaddSourcesPipeline.py:195
lsst.pipe.base.pipelineTask.PipelineTask
Definition: pipelineTask.py:32
lsst.pipe.base.struct.Struct
Definition: struct.py:26
lsst.pipe.tasks.deblendCoaddSourcesPipeline.DeblendCoaddSourcesSingleTask.outputSchema
outputSchema
Definition: deblendCoaddSourcesPipeline.py:178
lsst.pex.config
Definition: __init__.py:1
lsst.pipe.tasks.deblendCoaddSourcesPipeline.DeblendCoaddSourcesSingleTask.run
def run(self, coadd, mergedDetections, idFactory)
Definition: deblendCoaddSourcesPipeline.py:180
lsst.pipe.tasks.deblendCoaddSourcesPipeline.DeblendCoaddSourcesBaseTask
Definition: deblendCoaddSourcesPipeline.py:148
lsst::afw::table._source.SourceCatalog
Definition: _source.py:32
lsst.pipe.base.task.Task.config
config
Definition: task.py:162
lsst.pipe.tasks.deblendCoaddSourcesPipeline.DeblendCoaddSourceSingleConnections
Definition: deblendCoaddSourcesPipeline.py:41
lsst::afw::table::SchemaMapper
A mapping between the keys of two Schemas, used to copy data between them.
Definition: SchemaMapper.h:21
lsst.pipe.tasks.deblendCoaddSourcesPipeline.DeblendCoaddSourcesBaseTask.__init__
def __init__(self, initInputs, **kwargs)
Definition: deblendCoaddSourcesPipeline.py:149
lsst.pipe.base.connections.PipelineTaskConnections
Definition: connections.py:260
lsst.pipe.tasks.deblendCoaddSourcesPipeline.DeblendCoaddSourcesBaseTask.schemaMapper
schemaMapper
Definition: deblendCoaddSourcesPipeline.py:153
lsst::afw::table
Definition: table.dox:3
lsst.pipe.tasks.deblendCoaddSourcesPipeline.DeblendCoaddSourcesMultiConnections.__init__
def __init__(self, *config=None)
Definition: deblendCoaddSourcesPipeline.py:134
lsst::meas::deblender
Definition: BaselineUtils.h:17
lsst.pipe.base.config.PipelineTaskConfig
Definition: config.py:115
lsst.pipe.tasks.deblendCoaddSourcesPipeline.DeblendCoaddSourcesMultiConfig
Definition: deblendCoaddSourcesPipeline.py:141
lsst.pipe.tasks.deblendCoaddSourcesPipeline.DeblendCoaddSourcesBaseTask.peakSchema
peakSchema
Definition: deblendCoaddSourcesPipeline.py:152
lsst.pipe.tasks.deblendCoaddSourcesPipeline.DeblendCoaddSourcesMultiTask
Definition: deblendCoaddSourcesPipeline.py:188
lsst.pipe.tasks.deblendCoaddSourcesPipeline.DeblendCoaddSourcesBaseTask.runQuantum
def runQuantum(self, butlerQC, inputRefs, outputRefs)
Definition: deblendCoaddSourcesPipeline.py:157
lsst.pipe.tasks.deblendCoaddSourcesPipeline.DeblendCoaddSourcesMultiTask.__init__
def __init__(self, initInputs, **kwargs)
Definition: deblendCoaddSourcesPipeline.py:192
lsst.pipe.tasks.deblendCoaddSourcesPipeline.DeblendCoaddSourcesSingleTask.__init__
def __init__(self, initInputs, **kwargs)
Definition: deblendCoaddSourcesPipeline.py:175
lsst.pipe.base
Definition: __init__.py:1
lsst.pipe.tasks.deblendCoaddSourcesPipeline.DeblendCoaddSourcesMultiTask.runQuantum
def runQuantum(self, butlerQC, inputRefs, outputRefs)
Definition: deblendCoaddSourcesPipeline.py:197
set
daf::base::PropertySet * set
Definition: fits.cc:912
lsst.pipe.base.connectionTypes
Definition: connectionTypes.py:1