Skip to content

Commit

Permalink
Add check that science and template have matching bands.
Browse files Browse the repository at this point in the history
  • Loading branch information
isullivan committed Aug 6, 2024
1 parent bbab02d commit 597ed10
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 0 deletions.
3 changes: 3 additions & 0 deletions python/lsst/ip/diffim/subtractImages.py
Original file line number Diff line number Diff line change
Expand Up @@ -716,6 +716,9 @@ def _validateExposures(template, science):
"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

0 comments on commit 597ed10

Please sign in to comment.