From 13aee5c6da7de078ee441a2e12b7f8acf97748bd Mon Sep 17 00:00:00 2001 From: Paul Price Date: Fri, 23 Jun 2017 17:26:37 -0400 Subject: [PATCH 1/2] CoaddPsf: add more exception info A common problem when calling CoaddPsf.computePsfImage() is that WarpedPsf.computeBBoxFromTransform throws a RangeError stating 'Unexpectedly large transform passed to WarpedPsf'. This is usually because the astrometry for an input is poor, but it would be nice to identify *which* input: so add the exposure ID to the exception message. --- src/CoaddPsf.cc | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) 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)); From 9c721e1504f1f258e397975fb1a721a82a3f2a59 Mon Sep 17 00:00:00 2001 From: Paul Price Date: Tue, 18 Jul 2017 17:16:19 -0400 Subject: [PATCH 2/2] add test of bad CoaddPsf input CoaddPsf throws a RangeError when one of the inputs has an unexpectedly large transform. This tests that behaviour. --- tests/test_coaddPsf.py | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) 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