Skip to content

Commit f8bc214

Browse files
committed
Merge branch 'tickets/DM-45318'
2 parents a1f12eb + 1d4010f commit f8bc214

File tree

2 files changed

+33
-6
lines changed

2 files changed

+33
-6
lines changed

python/lsst/meas/algorithms/detection.py

+9-6
Original file line numberDiff line numberDiff line change
@@ -774,7 +774,7 @@ def detectFootprints(self, exposure, doSmooth=True, sigma=None, clearMask=True,
774774
convolveResults = self.convolveImage(maskedImage, psf, doSmooth=doSmooth)
775775
middle = convolveResults.middle
776776
sigma = convolveResults.sigma
777-
self.removeBadPixels(middle)
777+
self.removeBadPixels(middle, exposure.maskedImage.mask)
778778

779779
results = self.applyThreshold(middle, maskedImage.getBBox())
780780
results.background = background if background is not None else afwMath.BackgroundList()
@@ -799,17 +799,20 @@ def detectFootprints(self, exposure, doSmooth=True, sigma=None, clearMask=True,
799799

800800
return results
801801

802-
def removeBadPixels(self, middle):
802+
def removeBadPixels(self, middle, mask):
803803
"""Set the significance of flagged pixels to zero.
804804
805805
Parameters
806806
----------
807-
middle : `lsst.afw.image.ExposureF`
808-
Score or maximum likelihood difference image.
807+
middle : `lsst.afw.image.Exposure` or `lsst.afw.image.MaskedImage`
808+
Convolved image to zero certain mask planes from.
809809
The image plane will be modified in place.
810+
mask : `lsst.afw.image.Mask`
811+
Mask to select planes from to zero the image; will be restricted
812+
to the image's bounding box.
810813
"""
811-
badPixelMask = lsst.afw.image.Mask.getPlaneBitMask(self.config.excludeMaskPlanes)
812-
badPixels = middle.mask.array & badPixelMask > 0
814+
badPixelMask = mask.getPlaneBitMask(self.config.excludeMaskPlanes)
815+
badPixels = mask.subset(middle.getBBox()).array & badPixelMask > 0
813816
middle.image.array[badPixels] = 0
814817

815818
def setPeakSignificance(self, exposure, footprints, threshold, negative=False):

tests/test_detection.py

+24
Original file line numberDiff line numberDiff line change
@@ -216,6 +216,30 @@ def checkExposure(original, doTempLocalBackground, doTempWideBackground):
216216
checkExposure(original, False, True)
217217
checkExposure(original, True, True)
218218

219+
def test_removeBadPixels(self):
220+
"""Test that if we set a NO_DATA region on top of a source,
221+
One fewer sources is detected than when we don't do that."""
222+
badMaskPlanes = ["NO_DATA", ]
223+
exposure_regular, schema, numX, numY, starSigma = self._create_exposure()
224+
exposure_removed = exposure_regular.clone()
225+
226+
# Define a region on one test exposure we will set to NO_DATA, blocking out one source
227+
region = lsst.geom.Box2I(exposure_removed.getXY0(), lsst.geom.Extent2I(25, 35))
228+
exposure_removed[region].mask.array |= exposure_removed.mask.getPlaneBitMask(badMaskPlanes)
229+
230+
config = SourceDetectionTask.ConfigClass()
231+
config.reEstimateBackground = False
232+
config.thresholdType = "stdev"
233+
config.excludeMaskPlanes = badMaskPlanes
234+
task = SourceDetectionTask(config=config, schema=schema)
235+
236+
# The regular test exposure finds 25 sources
237+
self._check_detectFootprints(exposure_regular, numX, numY, starSigma, task, config, doSmooth=True)
238+
239+
# Modify numx and numy, which check_detectFootprints multiplies, to yield 24 instead of 25
240+
self.assertEqual(numX, numY)
241+
self._check_detectFootprints(exposure_removed, numX-1, numY+1, starSigma, task, config, doSmooth=True)
242+
219243

220244
class TestMemory(lsst.utils.tests.MemoryTestCase):
221245
pass

0 commit comments

Comments
 (0)