Skip to content

Commit

Permalink
Merge pull request #374 from lsst/tickets/DM-44167
Browse files Browse the repository at this point in the history
DM-44167: Update CoaddPsf to raise lsst.afw.detection.InvalidPsfError for invalid psf positions.
  • Loading branch information
erykoff authored May 8, 2024
2 parents e6526c8 + e93766c commit 0603fd7
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 9 deletions.
5 changes: 3 additions & 2 deletions src/CoaddPsf.cc
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
#include "lsst/base.h"
#include "lsst/pex/exceptions.h"
#include "lsst/geom/Box.h"
#include "lsst/afw/detection/Psf.h"
#include "lsst/afw/image/ImageUtils.h"
#include "lsst/afw/math/Statistics.h"
#include "lsst/meas/algorithms/CoaddPsf.h"
Expand Down Expand Up @@ -229,7 +230,7 @@ geom::Box2I CoaddPsf::doComputeBBox(geom::Point2D const &ccdXY, afw::image::Colo
afw::table::ExposureCatalog subcat = _catalog.subsetContaining(ccdXY, _coaddWcs, true);
if (subcat.empty()) {
throw LSST_EXCEPT(
pex::exceptions::InvalidParameterError,
lsst::afw::detection::InvalidPsfError,
(boost::format("Cannot compute BBox at point %s; no input images at that point.") % ccdXY)
.str());
}
Expand All @@ -252,7 +253,7 @@ CoaddPsf::doComputeKernelImage(geom::Point2D const &ccdXY, afw::image::Color con
afw::table::ExposureCatalog subcat = _catalog.subsetContaining(ccdXY, _coaddWcs, true);
if (subcat.empty()) {
throw LSST_EXCEPT(
pex::exceptions::InvalidParameterError,
lsst::afw::detection::InvalidPsfError,
(boost::format("Cannot compute CoaddPsf at point %s; no input images at that point.") % ccdXY)
.str());
}
Expand Down
15 changes: 8 additions & 7 deletions tests/test_coaddPsf.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,10 @@
import lsst.meas.algorithms as measAlg
import lsst.pex.exceptions as pexExceptions
import lsst.utils.tests
from lsst.afw.detection import InvalidPsfError


def getPsfMoments(psf, point):
# import os, pdb; print "PID =", os.getpid(); pdb.set_trace()
image = psf.computeImage(point)
array = image.getArray()
sumx2 = 0.0
Expand Down Expand Up @@ -127,7 +127,6 @@ def tearDown(self):

def testCreate(self):
"""Check that we can create a CoaddPsf with 9 elements."""
print("CreatePsfTest")

# also test that the weight field name is correctly observed
schema = afwTable.ExposureTable.makeMinimalSchema()
Expand Down Expand Up @@ -174,7 +173,6 @@ def testCreate(self):

def testFractionalPixel(self):
"""Check that we can create a CoaddPsf with 10 elements."""
print("FractionalPixelTest")
cdMatrix = afwGeom.makeCdMatrix(
scale=5.55555555e-05*lsst.geom.degrees,
orientation=90*lsst.geom.degrees,
Expand Down Expand Up @@ -202,7 +200,6 @@ def testFractionalPixel(self):

def testRotatePsf(self):
"""Check that we can create a CoaddPsf with 10 elements."""
print("RotatePsfTest")
cdMatrix = afwGeom.makeCdMatrix(
scale=5.55555555e-05*lsst.geom.degrees,
orientation=90*lsst.geom.degrees,
Expand All @@ -228,7 +225,6 @@ def testRotatePsf(self):

def testDefaultSize(self):
"""Test of both default size and specified size."""
print("DefaultSizeTest")
sigma0 = 5
# set the peak of the outer guassian to 0 so this is really a single gaussian.

Expand All @@ -255,7 +251,6 @@ def testDefaultSize(self):

def testSimpleGaussian(self):
"""Check that we can measure a single Gaussian's attributes."""
print("SimpleGaussianTest")
sigma0 = 5
# set the peak of the outer guassian to 0 so this is really a single gaussian.

Expand Down Expand Up @@ -296,7 +291,6 @@ def testSimpleGaussian(self):

def testWeight(self):
"""Check that we can measure a single Gaussian's attributes."""
print("WeightTest")
sigma0 = 5
# set the peak of the outer guassian to 0 so this is really a single gaussian.

Expand Down Expand Up @@ -365,6 +359,13 @@ def testTicket2872(self):
naiveAvgPos = lsst.geom.Point2D(50, 50)
with self.assertRaises(pexExceptions.InvalidParameterError):
coaddPsf.computeKernelImage(naiveAvgPos)
with self.assertRaises(InvalidPsfError):
coaddPsf.computeKernelImage(naiveAvgPos)
with self.assertRaises(pexExceptions.InvalidParameterError):
coaddPsf.computeBBox(naiveAvgPos)
with self.assertRaises(InvalidPsfError):
coaddPsf.computeBBox(naiveAvgPos)

# important test is that this doesn't throw:
coaddPsf.computeKernelImage(coaddPsf.getAveragePosition())

Expand Down

0 comments on commit 0603fd7

Please sign in to comment.