Coverage for tests/test_installGaussianPsf.py: 19%

64 statements  

« prev     ^ index     » next       coverage.py v6.5.0, created at 2024-01-17 19:18 +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 

24 

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 

29 

30 

31class CandidateMaskingTestCase(lsst.utils.tests.TestCase): 

32 """Test InstallGaussianPsfTask.""" 

33 

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) 

51 

52 def testMatchDoubleGaussianPsf(self): 

53 """Test InstallGaussianPsfTask when the input exposure has a DoubleGaussian PSF.""" 

54 config = InstallGaussianPsfTask.ConfigClass() 

55 task = InstallGaussianPsfTask(config=config) 

56 

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) 

74 

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) 

79 

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( 

94 psf.computeShape(psf.getAveragePosition()).getDeterminantRadius(), 

95 desSigma, 

96 delta=1e-3 

97 ) 

98 

99 def testBadDim(self): 

100 for width in (8, 10, 20): 

101 config = InstallGaussianPsfTask.ConfigClass() 

102 config.width = width 

103 with self.assertRaises(Exception): 

104 config.validate() 

105 

106 

107class TestMemory(lsst.utils.tests.MemoryTestCase): 

108 pass 

109 

110 

111def setup_module(module): 

112 lsst.utils.tests.init() 

113 

114 

115if __name__ == "__main__": 115 ↛ 116line 115 didn't jump to line 116, because the condition on line 115 was never true

116 lsst.utils.tests.init() 

117 unittest.main()