Skip to content

Commit 41aed21

Browse files
authored
Merge pull request #414 from lsst/tickets/DM-51462
DM-51462: Include science mask plane in template coverage check
2 parents 3f0dcc2 + 30158f4 commit 41aed21

File tree

1 file changed

+9
-6
lines changed

1 file changed

+9
-6
lines changed

python/lsst/ip/diffim/subtractImages.py

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -426,7 +426,7 @@ def run(self, template, science, sources, visitSummary=None):
426426
except (RuntimeError, lsst.pex.exceptions.Exception) as e:
427427
self.log.warning("Failed to match template. Checking coverage")
428428
# Raise NoWorkFound if template fraction is insufficient
429-
checkTemplateIsSufficient(template[science.getBBox()], self.log,
429+
checkTemplateIsSufficient(template[science.getBBox()], science, self.log,
430430
self.config.minTemplateFractionForExpectedSuccess,
431431
exceptionMessage="Template coverage lower than expected to succeed."
432432
f" Failure is tolerable: {e}")
@@ -835,7 +835,7 @@ def _prepareInputs(self, template, science, visitSummary=None):
835835
if visitSummary is not None:
836836
self._applyExternalCalibrations(science, visitSummary=visitSummary)
837837
templateCoverageFraction = checkTemplateIsSufficient(
838-
template[science.getBBox()], self.log,
838+
template[science.getBBox()], science, self.log,
839839
requiredTemplateFraction=self.config.requiredTemplateFraction,
840840
exceptionMessage="Not attempting subtraction. To force subtraction,"
841841
" set config requiredTemplateFraction=0"
@@ -1044,7 +1044,7 @@ def run(self, template, science, sources, visitSummary=None):
10441044
except (RuntimeError, lsst.pex.exceptions.Exception) as e:
10451045
self.log.warning("Failed to match template. Checking coverage")
10461046
# Raise NoWorkFound if template fraction is insufficient
1047-
checkTemplateIsSufficient(template[science.getBBox()], self.log,
1047+
checkTemplateIsSufficient(template[science.getBBox()], science, self.log,
10481048
self.config.minTemplateFractionForExpectedSuccess,
10491049
exceptionMessage="Template coverage lower than expected to succeed."
10501050
f" Failure is tolerable: {e}")
@@ -1129,7 +1129,7 @@ def runPreconvolve(self, template, science, matchedScience, selectSources, preCo
11291129
kernelSources=kernelSources)
11301130

11311131

1132-
def checkTemplateIsSufficient(templateExposure, logger, requiredTemplateFraction=0.,
1132+
def checkTemplateIsSufficient(templateExposure, scienceExposure, logger, requiredTemplateFraction=0.,
11331133
exceptionMessage=""):
11341134
"""Raise NoWorkFound if template coverage < requiredTemplateFraction
11351135
@@ -1159,8 +1159,11 @@ def checkTemplateIsSufficient(templateExposure, logger, requiredTemplateFraction
11591159
"""
11601160
# Count the number of pixels with the NO_DATA mask bit set
11611161
# counting NaN pixels is insufficient because pixels without data are often intepolated over)
1162-
pixNoData = np.count_nonzero(templateExposure.mask.array
1163-
& templateExposure.mask.getPlaneBitMask('NO_DATA'))
1162+
noTemplate = templateExposure.mask.array & templateExposure.mask.getPlaneBitMask('NO_DATA')
1163+
# Also need to account for missing data in the science image,
1164+
# because template coverage there doesn't help
1165+
noScience = scienceExposure.mask.array & scienceExposure.mask.getPlaneBitMask('NO_DATA')
1166+
pixNoData = np.count_nonzero(noTemplate | noScience)
11641167
pixGood = templateExposure.getBBox().getArea() - pixNoData
11651168
templateCoverageFraction = pixGood/templateExposure.getBBox().getArea()
11661169
logger.info("template has %d good pixels (%.1f%%)", pixGood, 100*templateCoverageFraction)

0 commit comments

Comments
 (0)