Skip to content

Commit

Permalink
Handle cases of incomputable Psfs in source injection
Browse files Browse the repository at this point in the history
Above error occassionally encountered when evaluating a
CoaddPsf in a region with no underlying exposures.
  • Loading branch information
jmeyers314 committed Jun 16, 2021
1 parent 32084cb commit e765a16
Showing 1 changed file with 27 additions and 2 deletions.
29 changes: 27 additions & 2 deletions python/lsst/pipe/tasks/insertFakes.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
import lsst.pipe.base.connectionTypes as cT
from lsst.pex.exceptions import LogicError, InvalidParameterError
from lsst.coadd.utils.coaddDataIdContainer import ExistingCoaddDataIdContainer
from lsst.geom import SpherePoint, radians, Box2D
from lsst.geom import SpherePoint, radians, Box2D, Point2D

__all__ = ["InsertFakesConfig", "InsertFakesTask"]

Expand Down Expand Up @@ -81,7 +81,32 @@ def _add_fake_sources(exposure, objects, calibFluxRadius=12.0, logger=None):
mat = wcs.linearizePixelToSky(spt, geom.arcseconds).getMatrix()
gsWCS = galsim.JacobianWCS(mat[0, 0], mat[0, 1], mat[1, 0], mat[1, 1])

psfArr = psf.computeKernelImage(pt).array
try:
psfArr = psf.computeKernelImage(pt).array
except InvalidParameterError:
logger.infof("Cannot compute Psf for object at {}; skipping", pt)
# Try mapping to nearest point contained in bbox.
contained_pt = Point2D(
np.clip(pt.x, bbox.minX, bbox.maxX),
np.clip(pt.y, bbox.minY, bbox.maxY)
)
if pt == contained_pt: # no difference, so skip immediately
if logger:
logger.infof(
"Cannot compute Psf for object at {}; skipping",
pt
)
continue
# otherwise, try again with new point
try:
psfArr = psf.computeKernelImage(contained_pt).array
except InvalidParameterError:
if logger:
logger.infof(
"Cannot compute Psf for object at {}; skipping",
pt
)
continue
apCorr = psf.computeApertureFlux(calibFluxRadius)
psfArr /= apCorr
gsPSF = galsim.InterpolatedImage(galsim.Image(psfArr), wcs=gsWCS)
Expand Down

0 comments on commit e765a16

Please sign in to comment.