Skip to content

Commit

Permalink
Exclude bad pixels from detection
Browse files Browse the repository at this point in the history
  • Loading branch information
isullivan committed May 11, 2023
1 parent f28172b commit 40e069e
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions python/lsst/meas/algorithms/detection.py
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,11 @@ class SourceDetectionConfig(pexConfig.Config):
doc="Mask planes to ignore when calculating statistics of image (for thresholdType=stdev)",
default=['BAD', 'SAT', 'EDGE', 'NO_DATA'],
)
badMaskPlanes = lsst.pex.config.ListField(
dtype=str,
default=("NO_DATA", "BAD", "EDGE"),
doc="Mask planes to exclude when detecting sources."
)

def setDefaults(self):
self.tempLocalBackground.binSize = 64
Expand Down Expand Up @@ -756,6 +761,7 @@ def detectFootprints(self, exposure, doSmooth=True, sigma=None, clearMask=True,
convolveResults = self.convolveImage(maskedImage, psf, doSmooth=doSmooth)
middle = convolveResults.middle
sigma = convolveResults.sigma
self.removeBadPixels(middle)

results = self.applyThreshold(middle, maskedImage.getBBox())
results.background = afwMath.BackgroundList()
Expand All @@ -779,6 +785,19 @@ def detectFootprints(self, exposure, doSmooth=True, sigma=None, clearMask=True,

return results

def removeBadPixels(self, middle):
"""Set the significance of flagged pixels to zero.
Parameters
----------
middle : `lsst.afw.image.ExposureF`
Score or maximum likelihood difference image.
The image plane will be modified in place.
"""
badPixelMask = lsst.afw.image.Mask.getPlaneBitMask(self.config.badMaskPlanes)
badPixels = middle.mask.array & badPixelMask > 0
middle.image.array[badPixels] = 0

def setPeakSignificance(self, exposure, footprints, threshold, negative=False):
"""Set the significance of each detected peak to the pixel value divided
by the appropriate standard-deviation for ``config.thresholdType``.
Expand Down

0 comments on commit 40e069e

Please sign in to comment.