From a42174992bc38dec90e95de57bdafe03946d98d0 Mon Sep 17 00:00:00 2001
From: Ian Sullivan <sullii@uw.edu>
Date: Wed, 4 Dec 2024 22:25:44 -0800
Subject: [PATCH] Clear the streak-specific detected mask plane before streak
 detection

---
 python/lsst/ip/diffim/detectAndMeasure.py | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/python/lsst/ip/diffim/detectAndMeasure.py b/python/lsst/ip/diffim/detectAndMeasure.py
index 645a7dfa..9d0af699 100644
--- a/python/lsst/ip/diffim/detectAndMeasure.py
+++ b/python/lsst/ip/diffim/detectAndMeasure.py
@@ -724,6 +724,8 @@ def _runStreakMasking(self, difference):
                                              self.config.streakBinFactor)
         binnedExposure = afwImage.ExposureF(binnedMaskedImage.getBBox())
         binnedExposure.setMaskedImage(binnedMaskedImage)
+        # Clear the DETECTED mask plane before streak detection
+        binnedExposure.mask &= ~binnedExposure.mask.getPlaneBitMask('DETECTED')
         # Rerun detection to set the DETECTED mask plane on binnedExposure
         sigma = difference.psf.computeShape(difference.psf.getAveragePosition()).getDeterminantRadius()
         _table = afwTable.SourceTable.make(afwTable.SourceTable.makeMinimalSchema())