Coverage for tests/test_gaussianPsf.py : 29%
Hot-keys on this page
r m x p toggle line displays
j k next/prev highlighted chunk
0 (zero) top of page
1 (one) first highlighted chunk
|
# This file is part of afw. # # Developed for the LSST Data Management System. # This product includes software developed by the LSST Project # (https://www.lsst.org). # See the COPYRIGHT file at the top-level directory of this distribution # for details of code ownership. # # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation, either version 3 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program. If not, see <https://www.gnu.org/licenses/>.
Tests for detection.GaussianPsf
Run with: python test_gaussianPsf.py or pytest test_gaussianPsf.py """
image = lsst.afw.image.ImageD(bbox) array = image.getArray() for yi, yv in enumerate(range(bbox.getBeginY(), bbox.getEndY())): for xi, xv in enumerate(range(bbox.getBeginX(), bbox.getEndX())): array[yi, xi] = np.exp(-0.5*((xv - xc)**2 + (yv - yc)**2)/sigma**2) array /= array.sum() return image
bbox = image.getBBox() array = image.getArray() s = 0.0 for yi, yv in enumerate(range(bbox.getBeginY(), bbox.getEndY())): for xi, xv in enumerate(range(bbox.getBeginX(), bbox.getEndX())): if (xv - xc)**2 + (yv - yc)**2 < radius**2: s += array[yi, xi] return s
self.kernelSize = 51 self.psf = lsst.afw.detection.GaussianPsf( self.kernelSize, self.kernelSize, 4.0)
del self.psf
image = self.psf.computeKernelImage() check = makeGaussianImage(image.getBBox(), self.psf.getSigma()) self.assertFloatsAlmostEqual(image.getArray(), check.getArray()) self.assertFloatsAlmostEqual(image.getArray().sum(), 1.0, atol=1E-14)
image = self.psf.computeImage(lsst.geom.Point2D(0.25, 0.25)) check = makeGaussianImage( image.getBBox(), self.psf.getSigma(), 0.25, 0.25) self.assertFloatsAlmostEqual(image.getArray(), check.getArray(), atol=1E-4, rtol=1E-4, plotOnFailure=True)
image = self.psf.computeKernelImage(lsst.geom.Point2D(0.0, 0.0)) # test aperture implementation is very crude; can only test to about 10% self.assertFloatsAlmostEqual(self.psf.computeApertureFlux(5.0), computeNaiveApertureFlux(image, 5.0), rtol=0.1) self.assertFloatsAlmostEqual(self.psf.computeApertureFlux(7.0), computeNaiveApertureFlux(image, 7.0), rtol=0.1)
self.assertFloatsAlmostEqual( self.psf.computeShape().getDeterminantRadius(), 4.0)
with lsst.utils.tests.getTempFilePath(".fits") as filename: self.psf.writeFits(filename) psf = lsst.afw.detection.GaussianPsf.readFits(filename) self.assertEqual(self.psf.getSigma(), psf.getSigma()) self.assertEqual(self.psf.getDimensions(), psf.getDimensions())
self.assertEqual(self.psf.computeKernelImage().getBBox(), self.psf.computeBBox())
self.assertEqual(self.psf.computeBBox().getWidth(), self.kernelSize)
# Test interface. GaussianPsf does not vary spatially self.assertEqual(self.psf.computeKernelImage(lsst.geom.Point2D(0.0, 0.0)).getBBox(), self.psf.computeBBox(lsst.geom.Point2D(0.0, 0.0)))
for pad in [0, -10, 10]: newLen = self.kernelSize - pad resizedPsf = self.psf.resized(newLen, newLen) newBBox = resizedPsf.computeBBox() self.assertEqual(newBBox.getWidth(), newLen) self.assertEqual(newBBox.getHeight(), newLen) self.assertEqual(resizedPsf.getSigma(), self.psf.getSigma())
image = resizedPsf.computeKernelImage() check = makeGaussianImage(newBBox, self.psf.getSigma()) self.assertFloatsAlmostEqual(image.getArray(), check.getArray()) # tolerance same as in self.testKernelImage self.assertFloatsAlmostEqual(image.getArray().sum(), 1.0, atol=1E-14)
lsst.utils.tests.init()
lsst.utils.tests.init() unittest.main() |