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-32701: Add check and test for invalid PSF order. #68

Merged
merged 1 commit into from
May 16, 2023
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
10 changes: 10 additions & 0 deletions python/lsst/meas/extensions/psfex/psfexPsfDeterminer.py
Original file line number Diff line number Diff line change
Expand Up @@ -376,6 +376,16 @@ def determinePsf(self, exposure, psfCandidateList, metadata=None, flagKey=None):

psf = psfex.PsfexPsf(psfs[0], geom.Point2D(avgX, avgY))

# If there are too few stars, the PSFEx psf model will reduce the order
# to 0, which the Science Pipelines code cannot handle (see
# https://github.com/lsst/meas_extensions_psfex/blob/f0d5218b5446faf5e39edc30e31d2e6f673ef294/src/PsfexPsf.cc#L118
# ). The easiest way to test for this condition is trying to compute
# the PSF kernel and checking for an InvalidParameterError.
try:
_ = psf.getKernel(psf.getAveragePosition())
except pexExcept.InvalidParameterError:
raise RuntimeError("Failed to determine psfex psf: too few good stars.")

#
# Display code for debugging
#
Expand Down
13 changes: 13 additions & 0 deletions tests/test_PsfexPsf.py
Original file line number Diff line number Diff line change
Expand Up @@ -272,6 +272,19 @@ def testPsfexDeterminer(self):
self.assertEqual(psf.computeBBox(pos), psf.computeKernelImage(pos).getBBox())
self.assertEqual(psf.computeBBox(pos), psf.getKernel(pos).getBBox())

def testPsfexDeterminerTooFewStars(self):
"""Test the (Psfex) psfDeterminer with too few stars."""
self.setupDeterminer(self.exposure)
metadata = dafBase.PropertyList()

stars = self.starSelector.run(self.catalog, exposure=self.exposure)
psfCandidateList = self.makePsfCandidates.run(stars.sourceCat, exposure=self.exposure).psfCandidates

psfCandidateListShort = psfCandidateList[0: 3]

with self.assertRaisesRegex(RuntimeError, "Failed to determine"):
psf, cellSet = self.psfDeterminer.determinePsf(self.exposure, psfCandidateListShort, metadata)


class TestMemory(lsst.utils.tests.MemoryTestCase):
pass
Expand Down