Skip to content

Commit

Permalink
Merge pull request #68 from lsst/tickets/DM-32701
Browse files Browse the repository at this point in the history
DM-32701: Add check and test for invalid PSF order.
  • Loading branch information
erykoff committed May 16, 2023
2 parents f0d5218 + 79d822e commit 08c5a6d
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
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

0 comments on commit 08c5a6d

Please sign in to comment.