Skip to content

Commit

Permalink
Respond to review
Browse files Browse the repository at this point in the history
  • Loading branch information
isullivan committed Dec 9, 2023
1 parent 31bc42c commit dfe3531
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 13 deletions.
22 changes: 13 additions & 9 deletions python/lsst/ip/diffim/detectAndMeasure.py
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ class DetectAndMeasureConfig(pipeBase.PipelineTaskConfig,
)
badSourceFlags = lsst.pex.config.ListField(
dtype=str,
doc="Do not include sources with any of these flags set in the output catalog.",
doc="Sources with any of these flags set are removed before writing the output catalog.",
default=("base_PixelFlags_flag_offimage",
),
)
Expand Down Expand Up @@ -397,17 +397,21 @@ def removeBadSources(self, diaSources):
The updated catalog of detected sources, with any source that has a
flag in ``config.badSourceFlags`` set removed.
"""
flags = np.ones(len(diaSources), dtype=bool)
nBadTotal = 0
selector = np.ones(len(diaSources), dtype=bool)
for flag in self.config.badSourceFlags:
try:
flags &= ~diaSources[flag]
except Exception as e:
flags = diaSources[flag]
except KeyError as e:
self.log.warning("Could not apply source flag: %s", e)
nBad = np.count_nonzero(~flags)
if nBad > 0:
self.log.warning(f"Found and removed {nBad} unphysical sources.")
diaSources = diaSources[flags].copy(deep=True)
self.metadata.add("nRemovedBadFlaggedSources", nBad)
continue
nBad = np.count_nonzero(flags)
if nBad > 0:
self.log.info("Found and removed %d unphysical sources with flag %s.", nBad, flag)
selector &= ~flags
nBadTotal += nBad
diaSources = diaSources[selector].copy(deep=True)
self.metadata.add("nRemovedBadFlaggedSources", nBadTotal)
return diaSources

def addSkySources(self, diaSources, mask, seed):
Expand Down
7 changes: 3 additions & 4 deletions tests/test_detectAndMeasure.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ def _check_values(self, values, minValue=None, maxValue=None):
self.assertTrue(np.all(values <= maxValue))

def _setup_detection(self, doApCorr=False, doMerge=False,
doSkySources=False, doForcedMeasurement=False, nSkySources=5, badSourceFlags=[]):
doSkySources=False, doForcedMeasurement=False, nSkySources=5, **kwargs):
"""Setup and configure the detection and measurement PipelineTask.
Parameters
Expand All @@ -117,9 +117,9 @@ def _setup_detection(self, doApCorr=False, doMerge=False,
config.doMerge = doMerge
config.doSkySources = doSkySources
config.doForcedMeasurement = doForcedMeasurement
config.badSourceFlags = badSourceFlags
if doSkySources:
config.skySources.nSources = nSkySources
config.update(**kwargs)
return self.detectionTask(config=config)


Expand Down Expand Up @@ -191,9 +191,8 @@ def test_measurements_finite(self):
self._check_values(output.diaSources.getPsfInstFlux())

def test_remove_unphysical(self):
"""Check that sources with specified flags are removed from the catalog.
"""
"""

# Set up the simulated images
noiseLevel = 1.
staticSeed = 1
Expand Down

0 comments on commit dfe3531

Please sign in to comment.