From b7d96e4ef1fc6fc4842ab7dc79d7dc9ea6317f06 Mon Sep 17 00:00:00 2001
From: Ian Sullivan <sullii@uw.edu>
Date: Mon, 4 Nov 2024 20:42:27 -0800
Subject: [PATCH] Return None for the PSF if the computed shape is NAN

---
 python/lsst/pipe/tasks/finalizeCharacterization.py | 7 +++++++
 1 file changed, 7 insertions(+)

diff --git a/python/lsst/pipe/tasks/finalizeCharacterization.py b/python/lsst/pipe/tasks/finalizeCharacterization.py
index 1900ca300..16213bad4 100644
--- a/python/lsst/pipe/tasks/finalizeCharacterization.py
+++ b/python/lsst/pipe/tasks/finalizeCharacterization.py
@@ -690,6 +690,13 @@ def compute_psf_and_ap_corr_map(self, visit, detector, exposure, src, isolated_s
             self.log.warning('Failed to determine psf for visit %d, detector %d: %s',
                              visit, detector, e)
             return None, None, measured_src
+        # Verify that the PSF is usable by downstream tasks
+        sigma = psf.computeShape(psf.getAveragePosition()).getDeterminantRadius()
+        if np.isnan(sigma):
+            self.log.warning('Failed to determine psf for visit %d, detector %d: '
+                             'Computed final PSF size is NAN.',
+                             visit, detector)
+            return None, None, measured_src
 
         # Set the psf in the exposure for measurement/aperture corrections.
         exposure.setPsf(psf)