Skip to content

Commit

Permalink
Added mask planes from template and science fake plane into difference
Browse files Browse the repository at this point in the history
  • Loading branch information
BrunoSanchez committed Sep 13, 2023
1 parent 286849a commit 143cdf1
Showing 1 changed file with 24 additions and 4 deletions.
28 changes: 24 additions & 4 deletions python/lsst/ip/diffim/subtractImages.py
Original file line number Diff line number Diff line change
Expand Up @@ -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."
)

Expand Down Expand Up @@ -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
----------
Expand Down Expand Up @@ -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
Expand All @@ -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,
Expand Down

0 comments on commit 143cdf1

Please sign in to comment.