Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DM-30560: Handle cases of incomputable Psfs in source injection #536

Merged
merged 1 commit into from
Jun 17, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
28 changes: 26 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,31 @@ 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:
# 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