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)