Skip to content

Commit

Permalink
Skip sky objects and other pseudo sources
Browse files Browse the repository at this point in the history
  • Loading branch information
fred3m committed Mar 22, 2021
1 parent c9f9cee commit d2ad248
Showing 1 changed file with 39 additions and 2 deletions.
41 changes: 39 additions & 2 deletions python/lsst/meas/extensions/scarlet/scarletDeblendTask.py
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,30 @@ def getFootprintMask(footprint, mExposure):
return fpMask


def isPseudoSource(source, pseudoColumns):
"""Check if a source is a pseudo source.
This is mostly for skipping sky objects,
but any other column can also be added to disable
deblending on a parent or individual source when
set to `True`.
Parameters
----------
source : `lsst.afw.table.source.source.SourceRecord`
The source to check for the pseudo bit.
pseudoColumns : list of str
A list of columns to check for pseudo sources.
"""
isPseudo = False
for col in pseudoColumns:
try:
isPseudo |= source[col]
except KeyError:
pass
return isPseudo


def deblend(mExposure, footprint, config):
"""Deblend a parent footprint
Expand Down Expand Up @@ -238,7 +262,11 @@ def deblend(mExposure, footprint, config):
# Convert the centers to pixel coordinates
xmin = bbox.getMinX()
ymin = bbox.getMinY()
centers = [np.array([peak.getIy()-ymin, peak.getIx()-xmin], dtype=int) for peak in footprint.peaks]
centers = [
np.array([peak.getIy()-ymin, peak.getIx()-xmin], dtype=int)
for peak in footprint.peaks
if not isPseudoSource(peak, config.pseudoColumns)
]

# Choose whether or not to use the improved spectral initialization
if config.setSpectra:
Expand Down Expand Up @@ -426,6 +454,10 @@ class ScarletDeblendConfig(pexConfig.Config):
"The key is the name of the column for the parent record, "
"the value is the name of the column to use for the child."
)
pseudoColumns = pexConfig.ListField(
dtype=str, default=['merge_peak_sky', 'sky_source'],
doc="Names of flags which should never be deblended."
)


class ScarletDeblendTask(pipeBase.Task):
Expand Down Expand Up @@ -631,14 +663,19 @@ def deblend(self, mExposure, catalog):
# Note: this does not flag isolated sources as skipped or
# set the NOT_DEBLENDED mask in the exposure,
# since these aren't really a skipped blends.
if len(peaks) < 2 and not self.config.processSingles:
# We also skip pseudo sources, like sky objects, which
# are intended to be skipped
if ((len(peaks) < 2 and not self.config.processSingles)
or isPseudoSource(parent, self.config.pseudoColumns)):
self._updateParentRecord(
parent=parent,
nPeaks=len(peaks),
nChild=0,
runtime=np.nan,
iterations=0,
logL=np.nan,
spectrumInit=False,
converged=False,
)
continue

Expand Down

0 comments on commit d2ad248

Please sign in to comment.