From 751dde3d4318a784a808e58de84c17a4b0c06130 Mon Sep 17 00:00:00 2001 From: Ian Sullivan Date: Tue, 5 Aug 2025 14:27:42 -0700 Subject: [PATCH 1/2] Clear the difference_image image plane for pixels masked as NO_DATA --- python/lsst/ip/diffim/detectAndMeasure.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/python/lsst/ip/diffim/detectAndMeasure.py b/python/lsst/ip/diffim/detectAndMeasure.py index ff0b4031d..552ae98ed 100644 --- a/python/lsst/ip/diffim/detectAndMeasure.py +++ b/python/lsst/ip/diffim/detectAndMeasure.py @@ -752,6 +752,12 @@ def processResults(self, science, matchedTemplate, difference, sources, idFactor if self.config.doForcedMeasurement: self.measureForcedSources(diaSources, science, difference.getWcs()) + # Clear the image plane for regions with NO_DATA. + # These regions are most often caused by insufficient template coverage. + # Do this for the final difference image after detection and measurement + # since the subtasks should all be configured to handle NO_DATA properly + difference.image.array[difference.mask.array & difference.mask.getPlaneBitMask('NO_DATA') > 0] = 0 + measurementResults.subtractedMeasuredExposure = difference if self.config.doMaskStreaks and self.config.writeStreakInfo: From 2a354c687f8d61c73608de01085b98cfba48cebb Mon Sep 17 00:00:00 2001 From: Ian Sullivan Date: Tue, 5 Aug 2025 14:28:19 -0700 Subject: [PATCH 2/2] Explicitly set the mask ignored mask planes for background subtraction --- python/lsst/ip/diffim/detectAndMeasure.py | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/python/lsst/ip/diffim/detectAndMeasure.py b/python/lsst/ip/diffim/detectAndMeasure.py index 552ae98ed..713573afb 100644 --- a/python/lsst/ip/diffim/detectAndMeasure.py +++ b/python/lsst/ip/diffim/detectAndMeasure.py @@ -348,12 +348,24 @@ def setDefaults(self): self.subtractInitialBackground.useApprox = False self.subtractInitialBackground.statisticsProperty = "MEDIAN" self.subtractInitialBackground.doFilterSuperPixels = True + self.subtractInitialBackground.ignoredPixelMask = ["BAD", + "EDGE", + "DETECTED", + "DETECTED_NEGATIVE", + "NO_DATA", + ] # Use a larger binsize for the final background subtraction, to reduce # over-subtraction of bright objects. self.subtractFinalBackground.binSize = 40 self.subtractFinalBackground.useApprox = False self.subtractFinalBackground.statisticsProperty = "MEDIAN" self.subtractFinalBackground.doFilterSuperPixels = True + self.subtractFinalBackground.ignoredPixelMask = ["BAD", + "EDGE", + "DETECTED", + "DETECTED_NEGATIVE", + "NO_DATA", + ] # DiaSource Detection self.detection.thresholdPolarity = "both" self.detection.thresholdValue = 5.0