From 474de6601dbbd50d7dd26c5459f75af3a082b592 Mon Sep 17 00:00:00 2001 From: BrunoSanchez Date: Fri, 4 Jul 2025 04:15:49 -0700 Subject: [PATCH] Replace uninformative RuntimeError for custom AlgorithmError. Verify cells are not empty in PsfMatch --- python/lsst/ip/diffim/psfMatch.py | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/python/lsst/ip/diffim/psfMatch.py b/python/lsst/ip/diffim/psfMatch.py index 42b107bae..0cf2921af 100644 --- a/python/lsst/ip/diffim/psfMatch.py +++ b/python/lsst/ip/diffim/psfMatch.py @@ -858,7 +858,20 @@ def _solve(self, kernelCellSet, basisList): ksv.resetKernelSum() ksv.setMode(diffimLib.KernelSumVisitorF.AGGREGATE) kernelCellSet.visitCandidates(ksv, nStarPerCell, ignoreExceptions=True) - ksv.processKsumDistribution() + + allCellsEmpty = True + for cell in kernelCellSet.getCellList(): + if not cell.empty(): + allCellsEmpty = False + break + if allCellsEmpty: + raise NoKernelCandidatesError("All spatial cells are emtpy of candidates") + + try: + ksv.processKsumDistribution() + except RuntimeError as e: + raise NoKernelCandidatesError("Unable to calculate the kernel sum") from e + ksv.setMode(diffimLib.KernelSumVisitorF.REJECT) kernelCellSet.visitCandidates(ksv, nStarPerCell, ignoreExceptions=True)