Skip to content

Commit

Permalink
Merge pull request #41 from lsst/tickets/DM-29888
Browse files Browse the repository at this point in the history
DM-29888: Run deblender on a subset of sources in CI
  • Loading branch information
fred3m committed Apr 29, 2021
2 parents 0a72219 + b2c9c72 commit 574b836
Showing 1 changed file with 45 additions and 0 deletions.
45 changes: 45 additions & 0 deletions python/lsst/meas/extensions/scarlet/scarletDeblendTask.py
Original file line number Diff line number Diff line change
Expand Up @@ -454,6 +454,26 @@ class ScarletDeblendConfig(pexConfig.Config):
doc="Names of flags which should never be deblended."
)

# Testing options
# Some obs packages and ci packages run the full pipeline on a small
# subset of data to test that the pipeline is functioning properly.
# This is not meant as scientific validation, so it can be useful
# to only run on a small subset of the data that is large enough to
# test the desired pipeline features but not so long that the deblender
# is the tall pole in terms of execution times.
useCiLimits = pexConfig.Field(
dtype=bool, default=False,
doc="Limit the number of sources deblended for CI to prevent long build times")
ciDeblendChildRange = pexConfig.ListField(
dtype=int, default=[5, 10],
doc="Only deblend parent Footprints with a number of peaks in the (inclusive) range indicated."
"If `useCiLimits==False` then this parameter is ignored.")
ciNumParentsToDeblend = pexConfig.Field(
dtype=int, default=10,
doc="Only use the first `ciNumParentsToDeblend` parent footprints with a total peak count "
"within `ciDebledChildRange`. "
"If `useCiLimits==False` then this parameter is ignored.")


class ScarletDeblendTask(pipeBase.Task):
"""ScarletDeblendTask
Expand Down Expand Up @@ -628,6 +648,31 @@ def deblend(self, mExposure, catalog):
"""
import time

# Cull footprints if required by ci
if self.config.useCiLimits:
self.log.info(f"Using CI catalog limits, "
f"the original number of sources to deblend was {len(catalog)}.")
# Select parents with a number of children in the range
# config.ciDeblendChildRange
minChildren, maxChildren = self.config.ciDeblendChildRange
nPeaks = np.array([len(src.getFootprint().peaks) for src in catalog])
childrenInRange = np.where((nPeaks >= minChildren) & (nPeaks <= maxChildren))[0]
if len(childrenInRange) < self.config.ciNumParentsToDeblend:
raise ValueError("Fewer than ciNumParentsToDeblend children were contained in the range "
"indicated by ciDeblendChildRange. Adjust this range to include more "
"parents.")
# Keep all of the isolated parents and the first
# `ciNumParentsToDeblend` children
parents = nPeaks == 1
children = np.zeros((len(catalog),), dtype=bool)
children[childrenInRange[:self.config.ciNumParentsToDeblend]] = True
catalog = catalog[parents | children]
# We need to update the IdFactory, otherwise the the source ids
# will not be sequential
idFactory = catalog.getIdFactory()
maxId = np.max(catalog["id"])
idFactory.notify(maxId)

filters = mExposure.filters
self.log.info(f"Deblending {len(catalog)} sources in {len(mExposure)} exposure bands")

Expand Down

0 comments on commit 574b836

Please sign in to comment.