diff --git a/python/lsst/ip/diffim/subtractImages.py b/python/lsst/ip/diffim/subtractImages.py index cffced91..b4174181 100644 --- a/python/lsst/ip/diffim/subtractImages.py +++ b/python/lsst/ip/diffim/subtractImages.py @@ -558,23 +558,30 @@ def finalize(self, template, science, difference, kernel, """ # Erase existing detection mask planes. # We don't want the detection mask from the science image + bbox = science.getBBox() 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") + self.log.info("Adding injected mask planes") + diffInjectedMaskPlane = mask.addMaskPlane("INJECTED") + diffInjectedTemplateMaskPlane = mask.addMaskPlane("INJECTED_TEMPLATE") + + scienceFakeMaskPlane = science.mask.getMaskPlane('FAKE') + scienceFakeBitMask = science.mask.getPlaneBitMask('FAKE') + templateFakeMaskPlane = template.mask.getMaskPlane('FAKE') + templateFakeBitMask = template[bbox].mask.getPlaneBitMask('FAKE') - scienceFakeBit = science.mask.getPlaneBitMask('FAKE') - templateFakeBit = template.mask.getPlaneBitMask('FAKE') + # self.log.info(f"Adding {np.sum(scienceFakeBitMask> 0)} pixels from science to Injected mask") + # self.log.info(f"and {np.sum(templateFakeBitMask>0)} pixels from templated to Injected mask") - deltaBitScience = diffInjectedBitMask - scienceFakeBit - deltaBitTemplate = diffInjectedTemplateBitMask - templateFakeBit + deltaMaskPlaneScience = 2**(diffInjectedMaskPlane - scienceFakeMaskPlane) + deltaMaskPlaneTemplate = 2**(diffInjectedTemplateMaskPlane - templateFakeMaskPlane) # 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) + injectedScienceMaskArray = (science.mask.array & scienceFakeBitMask) * deltaMaskPlaneScience + injectedTemplateMaskArray = (template[bbox].mask.array & templateFakeBitMask) * deltaMaskPlaneTemplate mask.array |= injectedScienceMaskArray mask.array |= injectedTemplateMaskArray