Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 16 additions & 6 deletions python/lsst/ip/diffim/psfMatch.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,14 @@
from . import diffimLib


class NoKernelCandidatesError(pipeBase.AlgorithmError):
"""Raised if there are too few candidates to compute the PSF matching
kernel.
"""
def metadata(self) -> dict:
return {}


class PsfMatchConfig(pexConfig.Config):
"""Base configuration for Psf-matching

Expand Down Expand Up @@ -786,7 +794,7 @@ def _buildCellSet(self, *args):
return

@timeMethod
def _solve(self, kernelCellSet, basisList, returnOnExcept=False):
def _solve(self, kernelCellSet, basisList):
"""Solve for the PSF matching kernel

Parameters
Expand All @@ -797,8 +805,6 @@ def _solve(self, kernelCellSet, basisList, returnOnExcept=False):
basisList : `list` of `lsst.afw.math.kernel.FixedKernel`
list of Kernels to be used in the decomposition of the spatially varying kernel
(typically as provided by makeKernelBasisList)
returnOnExcept : `bool`, optional
if True then return (None, None) if an error occurs, else raise the exception

Returns
-------
Expand All @@ -809,8 +815,8 @@ def _solve(self, kernelCellSet, basisList, returnOnExcept=False):

Raises
------
RuntimeError :
If unable to determine PSF matching kernel and ``returnOnExcept==False``.
NoKernelCandidatesError :
If there are no useable kernel candidates.
"""

import lsstDebug
Expand Down Expand Up @@ -917,7 +923,7 @@ def _solve(self, kernelCellSet, basisList, returnOnExcept=False):

# If only nGoodSpatial == 0, might be other candidates in the cells
if nGoodSpatial == 0 and nRejectedSpatial == 0:
raise RuntimeError("No kernel candidates for spatial fit")
raise NoKernelCandidatesError("No kernel candidates for spatial fit")

if nRejectedSpatial == 0:
# Nothing rejected, finished with spatial fit
Expand All @@ -938,6 +944,10 @@ def _solve(self, kernelCellSet, basisList, returnOnExcept=False):
trace_loggers[2].debug("Spatial kernel built with %d candidates", spatialkv.getNCandidates())
spatialKernel, spatialBackground = spatialkv.getSolutionPair()

# Run after the final fit to use the updated kernel visitor `spatialkv`
if spatialkv.getNCandidates() < 1:
raise NoKernelCandidatesError("No kernel candidates remain after max iterations")

spatialSolution = spatialkv.getKernelSolution()

t1 = time.time()
Expand Down