Skip to content

Commit

Permalink
Merge pull request #249 from lsst/tickets/DM-37884
Browse files Browse the repository at this point in the history
DM-37884: Include all evaluateMeanPsfFwhm in try/except blocks
  • Loading branch information
arunkannawadi committed Feb 8, 2023
2 parents 5801d47 + 091ee38 commit cc3ba21
Showing 1 changed file with 45 additions and 17 deletions.
62 changes: 45 additions & 17 deletions python/lsst/ip/diffim/makeKernel.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
import lsst.daf.base
from lsst.meas.algorithms import SourceDetectionTask, SubtractBackgroundTask
from lsst.meas.base import SingleFrameMeasurementTask
from lsst.pex.exceptions import InvalidParameterError
import lsst.pex.config
import lsst.pipe.base

Expand All @@ -38,7 +39,7 @@

from . import diffimLib
from . import diffimTools
from .utils import evaluateMeanPsfFwhm
from .utils import evaluateMeanPsfFwhm, getPsfFwhm


class MakeKernelConfig(PsfMatchConfig):
Expand Down Expand Up @@ -130,14 +131,28 @@ def run(self, template, science, kernelSources, preconvolved=False):
Spatially varying background-matching function.
"""
kernelCellSet = self._buildCellSet(template.maskedImage, science.maskedImage, kernelSources)
templateFwhmPix = evaluateMeanPsfFwhm(template,
fwhmExposureBuffer=self.config.fwhmExposureBuffer,
fwhmExposureGrid=self.config.fwhmExposureGrid
)
scienceFwhmPix = evaluateMeanPsfFwhm(science,
fwhmExposureBuffer=self.config.fwhmExposureBuffer,
fwhmExposureGrid=self.config.fwhmExposureGrid
)
# Calling getPsfFwhm on template.psf fails on some rare occasions when
# the template has no input exposures at the average position of the
# stars. So we try getPsfFwhm first on template, and if that fails we
# 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.
try:
templateFwhmPix = getPsfFwhm(template.psf)
scienceFwhmPix = getPsfFwhm(science.psf)
except InvalidParameterError:
self.log.debug("Unable to evaluate PSF at the average position. "
"Evaluting PSF on a grid of points."
)
templateFwhmPix = evaluateMeanPsfFwhm(template,
fwhmExposureBuffer=self.config.fwhmExposureBuffer,
fwhmExposureGrid=self.config.fwhmExposureGrid
)
scienceFwhmPix = evaluateMeanPsfFwhm(science,
fwhmExposureBuffer=self.config.fwhmExposureBuffer,
fwhmExposureGrid=self.config.fwhmExposureGrid
)

if preconvolved:
scienceFwhmPix *= np.sqrt(2)
basisList = self.makeKernelBasisList(templateFwhmPix, scienceFwhmPix,
Expand Down Expand Up @@ -171,14 +186,27 @@ def selectKernelSources(self, template, science, candidateList=None, preconvolve
field for the Sources deemed to be appropriate for Psf
matching.
"""
templateFwhmPix = evaluateMeanPsfFwhm(template,
fwhmExposureBuffer=self.config.fwhmExposureBuffer,
fwhmExposureGrid=self.config.fwhmExposureGrid
)
scienceFwhmPix = evaluateMeanPsfFwhm(science,
fwhmExposureBuffer=self.config.fwhmExposureBuffer,
fwhmExposureGrid=self.config.fwhmExposureGrid
)
# Calling getPsfFwhm on template.psf fails on some rare occasions when
# the template has no input exposures at the average position of the
# stars. So we try getPsfFwhm first on template, and if that fails we
# 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.
try:
templateFwhmPix = getPsfFwhm(template.psf)
scienceFwhmPix = getPsfFwhm(science.psf)
except InvalidParameterError:
self.log.debug("Unable to evaluate PSF at the average position. "
"Evaluting PSF on a grid of points."
)
templateFwhmPix = evaluateMeanPsfFwhm(template,
fwhmExposureBuffer=self.config.fwhmExposureBuffer,
fwhmExposureGrid=self.config.fwhmExposureGrid
)
scienceFwhmPix = evaluateMeanPsfFwhm(science,
fwhmExposureBuffer=self.config.fwhmExposureBuffer,
fwhmExposureGrid=self.config.fwhmExposureGrid
)
if preconvolved:
scienceFwhmPix *= np.sqrt(2)
kernelSize = self.makeKernelBasisList(templateFwhmPix, scienceFwhmPix)[0].getWidth()
Expand Down

0 comments on commit cc3ba21

Please sign in to comment.