Skip to content

Commit

Permalink
Merge pull request #899 from lsst/tickets/DM-43247
Browse files Browse the repository at this point in the history
DM-43247: Raise if no psf_stars match to selected stars
  • Loading branch information
parejkoj committed Mar 12, 2024
2 parents 1d79ad6 + f269371 commit 49e707b
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
6 changes: 6 additions & 0 deletions python/lsst/pipe/tasks/calibrateImage.py
Original file line number Diff line number Diff line change
Expand Up @@ -725,6 +725,12 @@ def _match_psf_stars(self, psf_stars, stars):
if n_unique != n_matches:
self.log.warning("%d psf_stars matched only %d stars; ",
n_matches, n_unique)
if n_matches == 0:
msg = (f"0 psf_stars out of {len(psf_stars)} matched {len(stars)} calib stars."
" Downstream processes probably won't have useful stars in this case."
" Is `star_source_selector` too strict?")
# TODO DM-39842: Turn this into an AlgorithmicError.
raise RuntimeError(msg)

# The indices of the IDs, so we can update the flag fields as arrays.
idx_psf_stars = np.searchsorted(psf_stars["id"], ids[0])
Expand Down
11 changes: 11 additions & 0 deletions tests/test_calibrateImage.py
Original file line number Diff line number Diff line change
Expand Up @@ -354,6 +354,17 @@ def test_match_psf_stars(self):
# Too few sources to reserve any in these tests.
self.assertEqual(stars["calib_psf_reserved"].sum(), 0)

def test_match_psf_stars_no_matches(self):
"""Check that _match_psf_stars handles the case of no cross-matches.
"""
calibrate = CalibrateImageTask(config=self.config)
# Make two catalogs that cannot have matches.
stars = self.truth_cat[2:].copy(deep=True)
psf_stars = self.truth_cat[:2].copy(deep=True)

with self.assertRaisesRegex(RuntimeError, "0 psf_stars out of 2 matched"):
calibrate._match_psf_stars(psf_stars, stars)


class CalibrateImageTaskRunQuantumTests(lsst.utils.tests.TestCase):
"""Tests of ``CalibrateImageTask.runQuantum``, which need a test butler,
Expand Down

0 comments on commit 49e707b

Please sign in to comment.