Skip to content

Commit

Permalink
Merge pull request #323 from lsst/tickets/DM-44507
Browse files Browse the repository at this point in the history
DM-44507: Investigate unexpectedly large transform passed to WarpedPsf in diffim
  • Loading branch information
enourbakhsh authored Jun 7, 2024
2 parents 5d17e6b + 9ca000c commit 04c3c9f
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 9 deletions.
4 changes: 2 additions & 2 deletions python/lsst/ip/diffim/computeSpatiallySampledMetrics.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@

from lsst.ip.diffim.utils import getPsfFwhm, angleMean, evaluateMaskFraction
from lsst.meas.algorithms import SkyObjectsTask
from lsst.pex.exceptions import InvalidParameterError
from lsst.pex.exceptions import InvalidParameterError, RangeError
from lsst.utils.timer import timeMethod

import lsst.utils
Expand Down Expand Up @@ -235,7 +235,7 @@ def _evaluateLocalMetric(self, src, science, matchedTemplate, template, differen
src.set('science_psfSize', getPsfFwhm(science.psf, position=pix))
try:
src.set('template_psfSize', getPsfFwhm(template.psf, position=pix))
except InvalidParameterError:
except (InvalidParameterError, RangeError):
src.set('template_psfSize', np.nan)

metricRegionSize = 100
Expand Down
6 changes: 3 additions & 3 deletions python/lsst/ip/diffim/makeKernel.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
import lsst.geom
from lsst.meas.algorithms import SourceDetectionTask, SubtractBackgroundTask
from lsst.meas.base import SingleFrameMeasurementTask
from lsst.pex.exceptions import InvalidParameterError
from lsst.pex.exceptions import InvalidParameterError, RangeError
import lsst.pex.config
import lsst.pipe.base

Expand Down Expand Up @@ -140,7 +140,7 @@ def run(self, template, science, kernelSources, preconvolved=False):
try:
templateFwhmPix = getPsfFwhm(template.psf)
scienceFwhmPix = getPsfFwhm(science.psf)
except InvalidParameterError:
except (InvalidParameterError, RangeError):
self.log.debug("Unable to evaluate PSF at the average position. "
"Evaluting PSF on a grid of points."
)
Expand Down Expand Up @@ -191,7 +191,7 @@ def selectKernelSources(self, template, science, candidateList=None, preconvolve
try:
templateFwhmPix = getPsfFwhm(template.psf)
scienceFwhmPix = getPsfFwhm(science.psf)
except InvalidParameterError:
except (InvalidParameterError, RangeError):
self.log.debug("Unable to evaluate PSF at the average position. "
"Evaluting PSF on a grid of points."
)
Expand Down
9 changes: 7 additions & 2 deletions python/lsst/ip/diffim/subtractImages.py
Original file line number Diff line number Diff line change
Expand Up @@ -389,10 +389,15 @@ def run(self, template, science, sources, finalizedPsfApCorrCatalog=None,
# evaluate the PSF on a grid specified by fwhmExposure* fields.
# To keep consistent definitions for PSF size on the template and
# science images, we use the same method for both.
# In the try block below, we catch two exceptions:
# 1. InvalidParameterError, in case the point where we are evaluating
# the PSF lands in a gap in the template.
# 2. RangeError, in case the template coverage is so poor that we end
# up near a region with no data.
try:
templatePsfSize = getPsfFwhm(template.psf)
sciencePsfSize = getPsfFwhm(science.psf)
except lsst.pex.exceptions.InvalidParameterError:
except (lsst.pex.exceptions.InvalidParameterError, lsst.pex.exceptions.RangeError):
self.log.info("Unable to evaluate PSF at the average position. "
"Evaluting PSF on a grid of points."
)
Expand Down Expand Up @@ -1218,7 +1223,7 @@ def _shapeTest(exp1, exp2, fwhmExposureBuffer, fwhmExposureGrid):
try:
shape1 = getPsfFwhm(exp1.psf, average=False)
shape2 = getPsfFwhm(exp2.psf, average=False)
except lsst.pex.exceptions.InvalidParameterError:
except (lsst.pex.exceptions.InvalidParameterError, lsst.pex.exceptions.RangeError):
shape1 = evaluateMeanPsfFwhm(exp1,
fwhmExposureBuffer=fwhmExposureBuffer,
fwhmExposureGrid=fwhmExposureGrid
Expand Down
4 changes: 2 additions & 2 deletions python/lsst/ip/diffim/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
import lsst.meas.algorithms as measAlg
import lsst.meas.base as measBase
from lsst.meas.algorithms.testUtils import plantSources
from lsst.pex.exceptions import InvalidParameterError
from lsst.pex.exceptions import InvalidParameterError, RangeError
from lsst.utils.logging import getLogger
from .dipoleFitTask import DipoleFitAlgorithm
from . import diffimLib
Expand Down Expand Up @@ -937,7 +937,7 @@ def evaluateMeanPsfFwhm(exposure: afwImage.Exposure,
pos = geom.Point2D(x, y)
try:
fwhm = getPsfFwhm(psf, average=True, position=pos)
except InvalidParameterError:
except (InvalidParameterError, RangeError):
_LOG.debug("Unable to compute PSF FWHM at position (%f, %f).", x, y)
continue

Expand Down

0 comments on commit 04c3c9f

Please sign in to comment.