Skip to content

Commit

Permalink
Fixed masks. Although I find them tmplt and science to be reversed fo…
Browse files Browse the repository at this point in the history
…r some reason
  • Loading branch information
BrunoSanchez committed Sep 14, 2023
1 parent 143cdf1 commit b77c97a
Showing 1 changed file with 15 additions and 8 deletions.
23 changes: 15 additions & 8 deletions python/lsst/ip/diffim/subtractImages.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit b77c97a

Please sign in to comment.