Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DM-41108: Add missing template coverage fraction metric #302

Merged
merged 1 commit into from
Mar 15, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
25 changes: 17 additions & 8 deletions python/lsst/ip/diffim/subtractImages.py
Original file line number Diff line number Diff line change
Expand Up @@ -825,10 +825,13 @@ def _prepareInputs(self, template, science, visitSummary=None):
self._validateExposures(template, science)
if visitSummary is not None:
self._applyExternalCalibrations(science, visitSummary=visitSummary)
checkTemplateIsSufficient(template[science.getBBox()], self.log,
requiredTemplateFraction=self.config.requiredTemplateFraction,
exceptionMessage="Not attempting subtraction. To force subtraction,"
" set config requiredTemplateFraction=0")
templateCoverageFraction = checkTemplateIsSufficient(
template[science.getBBox()], self.log,
requiredTemplateFraction=self.config.requiredTemplateFraction,
exceptionMessage="Not attempting subtraction. To force subtraction,"
" set config requiredTemplateFraction=0"
)
self.metadata.add("templateCoveragePercent", 100*templateCoverageFraction)

if self.config.doScaleVariance:
# Scale the variance of the template and science images before
Expand Down Expand Up @@ -1112,6 +1115,11 @@ def checkTemplateIsSufficient(templateExposure, logger, requiredTemplateFraction
Message to include in the exception raised if the template coverage
is insufficient.

Returns
-------
templateCoverageFraction: `float`
Fraction of pixels in the template with data.

Raises
------
lsst.pipe.base.NoWorkFound
Expand All @@ -1123,14 +1131,15 @@ def checkTemplateIsSufficient(templateExposure, logger, requiredTemplateFraction
pixNoData = np.count_nonzero(templateExposure.mask.array
& templateExposure.mask.getPlaneBitMask('NO_DATA'))
pixGood = templateExposure.getBBox().getArea() - pixNoData
logger.info("template has %d good pixels (%.1f%%)", pixGood,
100*pixGood/templateExposure.getBBox().getArea())
templateCoverageFraction = pixGood/templateExposure.getBBox().getArea()
logger.info("template has %d good pixels (%.1f%%)", pixGood, 100*templateCoverageFraction)

if pixGood/templateExposure.getBBox().getArea() < requiredTemplateFraction:
if templateCoverageFraction < requiredTemplateFraction:
message = ("Insufficient Template Coverage. (%.1f%% < %.1f%%)" % (
100*pixGood/templateExposure.getBBox().getArea(),
100*templateCoverageFraction,
100*requiredTemplateFraction))
raise lsst.pipe.base.NoWorkFound(message + " " + exceptionMessage)
return templateCoverageFraction


def _subtractImages(science, template, backgroundModel=None):
Expand Down