diff --git a/src/CoaddPsf.cc b/src/CoaddPsf.cc index 56ed93461..59c15f4ee 100644 --- a/src/CoaddPsf.cc +++ b/src/CoaddPsf.cc @@ -274,8 +274,15 @@ PTR(afw::detection::Psf::Image) CoaddPsf::doComputeKernelImage( PTR(afw::geom::XYTransform) xytransform( new afw::image::XYTransformFromWcsPair(_coaddWcs, exposureRecord.getWcs()) ); - WarpedPsf warpedPsf = WarpedPsf(exposureRecord.getPsf(), xytransform, _warpingControl); - PTR(afw::image::Image) componentImg = warpedPsf.computeKernelImage(ccdXY, color); + PTR(afw::image::Image) componentImg; + try { + WarpedPsf warpedPsf = WarpedPsf(exposureRecord.getPsf(), xytransform, _warpingControl); + componentImg = warpedPsf.computeKernelImage(ccdXY, color); + } catch (pex::exceptions::RangeError & exc) { + LSST_EXCEPT_ADD(exc, (boost::format("Computing WarpedPsf kernel image for id=%d") % + exposureRecord.getId()).str()); + throw exc; + } imgVector.push_back(componentImg); weightSum += exposureRecord.get(_weightKey); weightVector.push_back(exposureRecord.get(_weightKey)); diff --git a/tests/test_coaddPsf.py b/tests/test_coaddPsf.py index bbb85f890..6827cec28 100755 --- a/tests/test_coaddPsf.py +++ b/tests/test_coaddPsf.py @@ -480,6 +480,27 @@ def testBBox(self): with self.assertRaises(pexExceptions.LogicError): mypsf.resized(100, 100) + def testLargeTransform(self): + """Test that images with bad astrometry are identified""" + multiplier = 1000.0 # CD matrix multiplier for bad input + badId = 1 # ID of bad input + for ii in range(3): + record = self.mycatalog.addNew() + record.setPsf(measAlg.DoubleGaussianPsf(50, 50, 5.0, 1.00, 0.0)) + cdMatrix = [self.cd11, self.cd12, self.cd21, self.cd22] + if ii == badId: + # This image has bad astrometry: + cdMatrix = [xx*multiplier for xx in cdMatrix] + record['id'] = ii + record['weight'] = 1.0 + record.setWcs(afwImage.makeWcs(self.crval, self.crpix, *cdMatrix)) + record.setBBox(afwGeom.Box2I(afwGeom.Point2I(0, 0), afwGeom.Extent2I(2000, 2000))) + + coaddPsf = measAlg.CoaddPsf(self.mycatalog, self.wcsref) + with self.assertRaises(pexExceptions.RangeError) as cm: + coaddPsf.computeKernelImage() + self.assertIn("id=%d" % (badId,), str(cm.exception)) + class TestMemory(lsst.utils.tests.MemoryTestCase): pass