Skip to content

Commit 495290a

Browse files
authored
Merge pull request #1018 from lsst/tickets/DM-47738
DM-47738: Update for scarlet lite changes
2 parents 4465070 + 6a56dbf commit 495290a

File tree

4 files changed

+53
-6
lines changed

4 files changed

+53
-6
lines changed

python/lsst/pipe/tasks/deblendCoaddSourcesPipeline.py

Lines changed: 29 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,13 @@ class DeblendCoaddSourcesMultiConnections(PipelineTaskConnections,
134134
multiple=True,
135135
dimensions=("tract", "patch", "band", "skymap")
136136
)
137+
deconvolvedCoadds = cT.Input(
138+
doc="Deconvolved coadds",
139+
name="deconvolved_{inputCoaddName}_coadd",
140+
storageClass="ExposureF",
141+
multiple=True,
142+
dimensions=("tract", "patch", "band", "skymap")
143+
)
137144
outputSchema = cT.InitOutput(
138145
doc="Output of the schema used in deblending task",
139146
name="{outputCoaddName}Coadd_deblendedFlux_schema",
@@ -169,6 +176,12 @@ class DeblendCoaddSourcesMultiConnections(PipelineTaskConnections,
169176
storageClass="ScarletModelData",
170177
dimensions=("tract", "patch", "skymap"),
171178
)
179+
objectParents = cT.Output(
180+
doc="Parents of the deblended objects",
181+
name="object_parents",
182+
storageClass="SourceCatalog",
183+
dimensions=("tract", "patch", "skymap"),
184+
)
172185

173186
def __init__(self, *, config=None):
174187
super().__init__(config=config)
@@ -286,21 +299,33 @@ def runQuantum(self, butlerQC, inputRefs, outputRefs):
286299
coadds = exposures
287300
else:
288301
coadds = inputs.pop("coadds")
302+
303+
# Ensure that the coadd bands and deconvolved coadd bands match
304+
deconvBands = [dRef.dataId["band"] for dRef in inputRefs.deconvolvedCoadds]
305+
if bands != deconvBands:
306+
self.log.error("Coadd bands %s != deconvolved coadd bands %s", bands, deconvBands)
307+
raise RuntimeError("Number of coadd bands and deconvolved coadd bands do not match")
308+
309+
deconvolvedCoadds = inputs.pop("deconvolvedCoadds")
310+
311+
# Check that all inputs have been extracted correctly.
289312
assert not inputs, "runQuantum got extra inputs"
313+
290314
outputs = self.run(
291315
coadds=coadds,
292316
bands=bands,
293317
mergedDetections=mergedDetections,
294318
idFactory=self.config.idGenerator.apply(butlerQC.quantum.dataId).make_table_id_factory(),
319+
deconvolvedCoadds=deconvolvedCoadds,
295320
)
296321
butlerQC.put(outputs, outputRefs)
297322

298-
def run(self, coadds, bands, mergedDetections, idFactory):
323+
def run(self, coadds, bands, mergedDetections, deconvolvedCoadds, idFactory):
299324
sources = self._makeSourceCatalog(mergedDetections, idFactory)
300325
multiExposure = afwImage.MultibandExposure.fromExposures(bands, coadds)
301-
catalog, modelData = self.multibandDeblend.run(multiExposure, sources)
302-
retStruct = Struct(deblendedCatalog=catalog, scarletModelData=modelData)
303-
return retStruct
326+
mDeconvolved = afwImage.MultibandExposure.fromExposures(bands, deconvolvedCoadds)
327+
result = self.multibandDeblend.run(multiExposure, mDeconvolved, sources)
328+
return result
304329

305330
def _makeSourceCatalog(self, mergedDetections, idFactory):
306331
# There may be gaps in the mergeDet catalog, which will cause the

schemas/Object.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1099,6 +1099,9 @@ refFlags:
10991099
- deblend_peak_center_x
11001100
- deblend_peak_center_y
11011101
- deblend_logL
1102+
- deblend_chi2
1103+
- deblend_blendId
1104+
- deblend_blendNChild
11021105
- slot_Shape_flag
11031106
flags:
11041107
# flags are columns taken and exploded per-band from the meas tables

schemas/initial_stars_detector_standardized.yaml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,10 @@ flags:
174174
- deblend_rampedTemplate
175175
- deblend_skipped
176176
- deblend_tooManyPeaks
177+
- deblend_logL
178+
- deblend_chi2
179+
- deblend_blendId
180+
- deblend_blendNChild
177181
- sky_source
178182
- detect_isPrimary
179183

@@ -189,4 +193,3 @@ flag_rename_rules:
189193
- ['ext_shapeHSM_Hsm', 'hsm']
190194
- ['base_', '']
191195
- ['slot_', '']
192-

tests/test_isPrimaryFlag.py

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
from lsst.meas.algorithms import SourceDetectionTask, SkyObjectsTask, SetPrimaryFlagsTask
3434
import lsst.meas.extensions.scarlet as mes
3535
from lsst.meas.extensions.scarlet.scarletDeblendTask import ScarletDeblendTask
36+
from lsst.meas.extensions.scarlet.deconvolveExposureTask import DeconvolveExposureTask
3637
from lsst.meas.base import SingleFrameMeasurementTask
3738
from lsst.afw.table import SourceCatalog
3839

@@ -214,6 +215,10 @@ def testIsScarletPrimaryFlag(self):
214215
skySourcesTask = SkyObjectsTask(name="skySources", config=skyConfig)
215216
schema.addField("merge_peak_sky", type="Flag")
216217

218+
# Initialize the deconvolution task
219+
deconvolveConfig = DeconvolveExposureTask.ConfigClass()
220+
deconvolveTask = DeconvolveExposureTask(config=deconvolveConfig)
221+
217222
# Initialize the deblender task
218223
scarletConfig = ScarletDeblendTask.ConfigClass()
219224
scarletConfig.maxIter = 20
@@ -243,8 +248,18 @@ def testIsScarletPrimaryFlag(self):
243248
src = catalog.addNew()
244249
src.setFootprint(foot)
245250
src.set("merge_peak_sky", True)
251+
# deconvolve the images
252+
deconvolved = deconvolveTask.run(coadds["test"], catalog).deconvolved
253+
mDeconvolved = afwImage.MultibandExposure.fromExposures(["test"], [deconvolved])
246254
# deblend
247-
catalog, modelData = deblendTask.run(coadds, catalog)
255+
# This is a hack because the variance is not calibrated properly
256+
# (it is 3 orders of magnitude too high), which causes the deblender
257+
# to improperly deblend most sources due to the sparsity constraint.
258+
coadds.variance.array[:] = 2e-1
259+
mDeconvolved.variance.array[:] = 2e-1
260+
result = deblendTask.run(coadds, mDeconvolved, catalog)
261+
modelData = result.scarletModelData
262+
catalog = result.deblendedCatalog
248263
# Attach footprints to the catalog
249264
mes.io.updateCatalogFootprints(
250265
modelData=modelData,
@@ -254,6 +269,7 @@ def testIsScarletPrimaryFlag(self):
254269
removeScarletData=True,
255270
updateFluxColumns=True,
256271
)
272+
257273
# measure
258274
measureTask.run(catalog, self.exposure)
259275
outputCat = catalog

0 commit comments

Comments
 (0)