Skip to content

Commit

Permalink
Merge pull request #225 from lsst/tickets/DM-44996
Browse files Browse the repository at this point in the history
DM-44996: Add error handling to PSF cutouts
  • Loading branch information
isullivan committed Jun 26, 2024
2 parents 50259f2 + 22e17ce commit 0491626
Showing 1 changed file with 28 additions and 19 deletions.
47 changes: 28 additions & 19 deletions python/lsst/ap/association/packageAlerts.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
confluent_kafka = None

import lsst.alert.packet as alertPack
from lsst.afw.detection import InvalidPsfError
import lsst.afw.geom as afwGeom
import lsst.geom as geom
import lsst.pex.config as pexConfig
Expand Down Expand Up @@ -400,29 +401,37 @@ def createCcdDataCutout(self, image, skyCenter, pixelCenter, extent, photoCalib,
CCDData object storing the calibrate information from the input
difference or template image.
"""

imBBox = image.getBBox()
if not geom.Box2D(image.getBBox()).contains(pixelCenter):
self.log.warning(
"DiaSource id=%i centroid lies at pixel (%.2f, %.2f) "
"which is outside the Exposure with bounding box "
"((%i, %i), (%i, %i)). Returning None for cutout...",
srcId, pixelCenter.x, pixelCenter.y,
imBBox.minX, imBBox.maxX, imBBox.minY, imBBox.maxY)
return None
# Catch errors in retrieving the cutout.
try:
cutout = image.getCutout(pixelCenter, extent)
except InvalidParameterError:
imBBox = image.getBBox()
if not geom.Box2D(image.getBBox()).contains(pixelCenter):
self.log.warning(
"DiaSource id=%i centroid lies at pixel (%.2f, %.2f) "
"which is outside the Exposure with bounding box "
"((%i, %i), (%i, %i)). Returning None for cutout...",
srcId, pixelCenter.x, pixelCenter.y,
imBBox.minX, imBBox.maxX, imBBox.minY, imBBox.maxY)
else:
raise InvalidParameterError(
"Failed to retrieve cutout from image for DiaSource with "
"id=%i. InvalidParameterError thrown during cutout "
"creation. Exiting."
% srcId)
return None

# use image.psf.computeKernelImage to provide PSF centered in the array
cutoutPsf = image.psf.computeKernelImage(pixelCenter).array
raise InvalidParameterError(
"Failed to retrieve cutout from image for DiaSource with "
"id=%i. InvalidParameterError thrown during cutout "
"creation. Returning None for cutout..."
% srcId)
try:
# use image.psf.computeKernelImage to provide PSF centered in the array
cutoutPsf = image.psf.computeKernelImage(pixelCenter).array
except InvalidParameterError:
self.log.warning("Could not calculate PSF for DiaSource with "
"id=%i. InvalidParameterError encountered. Exiting."
% srcId)
cutoutPsf = None
except InvalidPsfError:
self.log.warning("Could not calculate PSF for DiaSource with "
"id=%i. InvalidPsfError encountered. Exiting."
% srcId)
cutoutPsf = None

# Find the value of the bottom corner of our cutout's BBox and
# subtract 1 so that the CCDData cutout position value will be
Expand Down

0 comments on commit 0491626

Please sign in to comment.