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-10454: Add check that science and template have matching bands. #335

Merged
merged 1 commit into from
Aug 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 7 additions & 4 deletions python/lsst/ip/diffim/subtractImages.py
Original file line number Diff line number Diff line change
Expand Up @@ -695,8 +695,8 @@ def _calculateMagLim(self, exposure, nsigma=5.0, fallbackPsfSize=None):

@staticmethod
def _validateExposures(template, science):
"""Check that the WCS of the two Exposures match, and the template bbox
contains the science bbox.
"""Check that the WCS of the two Exposures match, the template bbox
contains the science bbox, and that the bands match.

Parameters
----------
Expand All @@ -709,13 +709,16 @@ def _validateExposures(template, science):
------
AssertionError
Raised if the WCS of the template is not equal to the science WCS,
or if the science image is not fully contained in the template
bounding box.
if the science image is not fully contained in the template
bounding box, or if the bands do not match.
"""
assert template.wcs == science.wcs, \
"Template and science exposure WCS are not identical."
templateBBox = template.getBBox()
scienceBBox = science.getBBox()
assert science.filter.bandLabel == template.filter.bandLabel, \
"Science and template exposures have different bands: %s, %s" % \
(science.filter, template.filter)

assert templateBBox.contains(scienceBBox), \
"Template bbox does not contain all of the science image."
Expand Down
3 changes: 3 additions & 0 deletions python/lsst/ip/diffim/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -1139,6 +1139,8 @@ def makeTestImage(seed=5, nSrc=20, psfSize=2., noiseLevel=5.,
flux=None,
clearEdgeMask=False,
addMaskPlanes=None,
band="g",
physicalFilter="g NotACamera"
):
"""Make a reproduceable PSF-convolved exposure for testing.

Expand Down Expand Up @@ -1243,6 +1245,7 @@ def makeTestImage(seed=5, nSrc=20, psfSize=2., noiseLevel=5.,
if background is not None:
modelExposure.image += background
modelExposure.maskedImage /= calibration
modelExposure.setFilter(afwImage.FilterLabel(band, physicalFilter))
modelExposure.info.setId(seed)
if doApplyCalibration:
modelExposure.maskedImage = modelExposure.photoCalib.calibrateImage(modelExposure.maskedImage)
Expand Down
15 changes: 15 additions & 0 deletions tests/test_subtractTask.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,21 @@ def test_mismatched_template(self):
with self.assertRaises(AssertionError):
task.run(template, science, sources)

def test_mismatched_filter(self):
"""Test that an error is raised if the science and template have
different bands.
"""
xSize = 200
ySize = 200
science, sources = makeTestImage(psfSize=2.4, xSize=xSize + 20, ySize=ySize + 20,
band="g", physicalFilter="g noCamera")
template, _ = makeTestImage(psfSize=2.4, xSize=xSize, ySize=ySize, doApplyCalibration=True,
band="not-g", physicalFilter="not-g noCamera")
config = subtractImages.AlardLuptonSubtractTask.ConfigClass()
task = subtractImages.AlardLuptonSubtractTask(config=config)
with self.assertRaises(AssertionError):
task.run(template, science, sources)

def test_incomplete_template_coverage(self):
noiseLevel = 1.
border = 20
Expand Down
Loading