Skip to content

Commit

Permalink
Add unit test for bad PSF
Browse files Browse the repository at this point in the history
  • Loading branch information
isullivan committed Nov 8, 2024
1 parent d2e2940 commit e136d38
Showing 1 changed file with 32 additions and 1 deletion.
33 changes: 32 additions & 1 deletion tests/test_detectAndMeasure.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,12 @@
import numpy as np
import unittest

import lsst.afw.image as afwImage
import lsst.afw.math as afwMath
import lsst.geom
from lsst.ip.diffim import detectAndMeasure, subtractImages
from lsst.pipe.base import InvalidQuantumError
import lsst.meas.algorithms as measAlg
from lsst.pipe.base import InvalidQuantumError, UpstreamFailureNoWorkFound
import lsst.utils.tests

from utils import makeTestImage
Expand Down Expand Up @@ -161,6 +164,34 @@ def test_detection_xy0(self):
self.assertTrue(all(output.diaSources['id'] > 1000000000))
self.assertImagesEqual(subtractedMeasuredExposure.image, difference.image)

def test_raise_bad_psf(self):
"""Detection should raise if the PSF width is NaN
"""
# Set up the simulated images
noiseLevel = 1.
staticSeed = 1
fluxLevel = 500
kwargs = {"seed": staticSeed, "psfSize": 2.4, "fluxLevel": fluxLevel, "x0": 12345, "y0": 67890}
science, sources = makeTestImage(noiseLevel=noiseLevel, noiseSeed=6, **kwargs)
matchedTemplate, _ = makeTestImage(noiseLevel=noiseLevel/4, noiseSeed=7, **kwargs)
difference = science.clone()

psfShape = difference.getPsf().computeBBox(lsst.geom.Point2D(0, 0)).getDimensions()
psfcI = afwImage.ImageD(lsst.geom.Extent2I(psfShape[1], psfShape[0]))
psfNew = np.zeros(psfShape)
psfNew[0, :] = 1
psfcI.array = psfNew
psfcK = afwMath.FixedKernel(psfcI)
psf = measAlg.KernelPsf(psfcK)
difference.setPsf(psf)

# Configure the detection Task
detectionTask = self._setup_detection()

# Run detection and check the results
with self.assertRaises(UpstreamFailureNoWorkFound):
detectionTask.run(science, matchedTemplate, difference)

def test_measurements_finite(self):
"""Measured fluxes and centroids should always be finite.
"""
Expand Down

0 comments on commit e136d38

Please sign in to comment.