Coverage for tests/test_installGaussianPsf.py: 23%
64 statements
« prev ^ index » next coverage.py v6.4.4, created at 2022-09-03 08:48 +0000
« prev ^ index » next coverage.py v6.4.4, created at 2022-09-03 08:48 +0000
1#
2# LSST Data Management System
3#
4# Copyright 2008-2016 AURA/LSST.
5#
6# This product includes software developed by the
7# LSST Project (http://www.lsst.org/).
8#
9# This program is free software: you can redistribute it and/or modify
10# it under the terms of the GNU General Public License as published by
11# the Free Software Foundation, either version 3 of the License, or
12# (at your option) any later version.
13#
14# This program is distributed in the hope that it will be useful,
15# but WITHOUT ANY WARRANTY; without even the implied warranty of
16# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17# GNU General Public License for more details.
18#
19# You should have received a copy of the LSST License Statement and
20# the GNU General Public License along with this program. If not,
21# see <https://www.lsstcorp.org/LegalNotices/>.
22#
23import unittest
25from lsst.afw.image import ExposureF
26from lsst.meas.algorithms import SingleGaussianPsf, DoubleGaussianPsf
27from lsst.meas.algorithms.installGaussianPsf import InstallGaussianPsfTask, FwhmPerSigma
28import lsst.utils.tests
31class CandidateMaskingTestCase(lsst.utils.tests.TestCase):
32 """Test InstallGaussianPsfTask."""
34 def testNoPsf(self):
35 """Test InstallGaussianPsfTask when the input exposure has no PSF."""
36 for width in (21, 25):
37 for fwhm in (2.8, 7.1):
38 config = InstallGaussianPsfTask.ConfigClass()
39 config.width = width
40 config.fwhm = fwhm
41 task = InstallGaussianPsfTask(config=config)
42 exposure = ExposureF(100, 100)
43 task.run(exposure=exposure)
44 self.assertTrue(exposure.hasPsf())
45 psf = exposure.getPsf()
46 psfIm = psf.computeImage(psf.getAveragePosition())
47 self.assertEqual(psfIm.getWidth(), width)
48 self.assertEqual(psfIm.getHeight(), width)
49 measFwhm = psf.computeShape(psf.getAveragePosition()).getDeterminantRadius()*FwhmPerSigma
50 self.assertAlmostEqual(measFwhm, fwhm, delta=1e-3)
52 def testMatchDoubleGaussianPsf(self):
53 """Test InstallGaussianPsfTask when the input exposure has a DoubleGaussian PSF."""
54 config = InstallGaussianPsfTask.ConfigClass()
55 task = InstallGaussianPsfTask(config=config)
57 for doubleGaussParms in (
58 # width, height, inner sigma, outer sigma, outer/inner peak amplitude
59 (21, 23, 1.2, 3.5, 0.02),
60 (23, 25, 3.5, 9.0, 0.02),
61 ):
62 exposure = ExposureF(100, 100)
63 inPsf = DoubleGaussianPsf(*doubleGaussParms)
64 exposure.setPsf(inPsf)
65 desWidth, desHeight, innerSigma = doubleGaussParms[0:3]
66 task.run(exposure=exposure)
67 self.assertTrue(exposure.hasPsf())
68 psf = exposure.getPsf()
69 psfIm = psf.computeImage(psf.getAveragePosition())
70 self.assertEqual(psfIm.getWidth(), desWidth)
71 self.assertEqual(psfIm.getHeight(), desHeight)
72 self.assertAlmostEqual(psf.computeShape(psf.getAveragePosition()).getDeterminantRadius(),
73 innerSigma, delta=0.1)
75 def testMatchSingleGaussianPsf(self):
76 """Test InstallGaussianPsfTask when the input exposure has a single Gaussian PSF."""
77 config = InstallGaussianPsfTask.ConfigClass()
78 task = InstallGaussianPsfTask(config=config)
80 for desWidth, desHeight, desSigma in (
81 (21, 23, 1.2),
82 (23, 25, 3.5),
83 ):
84 exposure = ExposureF(100, 100)
85 inPsf = SingleGaussianPsf(desWidth, desHeight, desSigma)
86 exposure.setPsf(inPsf)
87 task.run(exposure=exposure)
88 self.assertTrue(exposure.hasPsf())
89 psf = exposure.getPsf()
90 psfIm = psf.computeImage(psf.getAveragePosition())
91 self.assertEqual(psfIm.getWidth(), desWidth)
92 self.assertEqual(psfIm.getHeight(), desHeight)
93 self.assertAlmostEqual(psf.computeShape().getDeterminantRadius(), desSigma, delta=1e-3)
95 def testBadDim(self):
96 for width in (8, 10, 20):
97 config = InstallGaussianPsfTask.ConfigClass()
98 config.width = width
99 with self.assertRaises(Exception):
100 config.validate()
103class TestMemory(lsst.utils.tests.MemoryTestCase):
104 pass
107def setup_module(module):
108 lsst.utils.tests.init()
111if __name__ == "__main__": 111 ↛ 112line 111 didn't jump to line 112, because the condition on line 111 was never true
112 lsst.utils.tests.init()
113 unittest.main()