diff --git a/python/lsst/ip/diffim/subtractImages.py b/python/lsst/ip/diffim/subtractImages.py index 75717ee4..cffced91 100644 --- a/python/lsst/ip/diffim/subtractImages.py +++ b/python/lsst/ip/diffim/subtractImages.py @@ -195,12 +195,12 @@ class AlardLuptonSubtractBaseConfig(lsst.pex.config.Config): ) badMaskPlanes = lsst.pex.config.ListField( dtype=str, - default=("NO_DATA", "BAD", "SAT", "EDGE"), + default=("NO_DATA", "BAD", "SAT", "EDGE", "FAKE"), doc="Mask planes to exclude when selecting sources for PSF matching." ) preserveTemplateMask = lsst.pex.config.ListField( dtype=str, - default=("NO_DATA", "BAD", "SAT"), + default=("NO_DATA", "BAD", "SAT", "FAKE"), doc="Mask planes from the template to propagate to the image difference." ) @@ -457,7 +457,8 @@ def runConvolveTemplate(self, template, science, selectSources): psfMatchingKernel=kernelResult.psfMatchingKernel) def runConvolveScience(self, template, science, selectSources): - """Convolve the science image with a PSF-matching kernel and subtract the template image. + """Convolve the science image with a PSF-matching kernel and subtract + the template image. Parameters ---------- @@ -560,6 +561,24 @@ def finalize(self, template, science, difference, kernel, mask = difference.mask mask &= ~(mask.getPlaneBitMask("DETECTED") | mask.getPlaneBitMask("DETECTED_NEGATIVE")) + # propagate the mask plane related to Fake source injection + # NOTE: the fake source injection sets FAKE plane, but it should be INJECTED + diffInjectedBitMask = mask.addMaskPlane("INJECTED") + diffInjectedTemplateBitMask = mask.addMaskPlane("INJECTED_TEMPLATE") + + scienceFakeBit = science.mask.getPlaneBitMask('FAKE') + templateFakeBit = template.mask.getPlaneBitMask('FAKE') + + deltaBitScience = diffInjectedBitMask - scienceFakeBit + deltaBitTemplate = diffInjectedTemplateBitMask - templateFakeBit + + # get the arrays from the template and science that are flagged as FAKE + injectedScienceMaskArray = (science.mask.array & scienceFakeBit) * (2**deltaBitScience) + injectedTemplateMaskArray = (template.mask.array & templateFakeBit) * (2**deltaBitTemplate) + + mask.array |= injectedScienceMaskArray + mask.array |= injectedTemplateMaskArray + # We have cleared the template mask plane, so copy the mask plane of # the image difference so that we can calculate correct statistics # during decorrelation. Do this regardless of whether decorrelation is @@ -570,7 +589,8 @@ def finalize(self, template, science, difference, kernel, # We have cleared the template mask plane, so copy the mask plane of # the image difference so that we can calculate correct statistics # during decorrelation - template[science.getBBox()].mask.array[...] = difference.mask.array[...] + # NOTE: following line is already being run outside the if statement. + # template[science.getBBox()].mask.array[...] = difference.mask.array[...] correctedExposure = self.decorrelate.run(science, template[science.getBBox()], difference, kernel, templateMatched=templateMatched, preConvMode=preConvMode,