Coverage for tests/test_installGaussianPsf.py: 24%

Shortcuts 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

64 statements  

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() 

47 self.assertEqual(psfIm.getWidth(), width) 

48 self.assertEqual(psfIm.getHeight(), width) 

49 measFwhm = psf.computeShape().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() 

70 self.assertEqual(psfIm.getWidth(), desWidth) 

71 self.assertEqual(psfIm.getHeight(), desHeight) 

72 self.assertAlmostEqual(psf.computeShape().getDeterminantRadius(), innerSigma, delta=0.1) 

73 

74 def testMatchSingleGaussianPsf(self): 

75 """Test InstallGaussianPsfTask when the input exposure has a single Gaussian PSF.""" 

76 config = InstallGaussianPsfTask.ConfigClass() 

77 task = InstallGaussianPsfTask(config=config) 

78 

79 for desWidth, desHeight, desSigma in ( 

80 (21, 23, 1.2), 

81 (23, 25, 3.5), 

82 ): 

83 exposure = ExposureF(100, 100) 

84 inPsf = SingleGaussianPsf(desWidth, desHeight, desSigma) 

85 exposure.setPsf(inPsf) 

86 task.run(exposure=exposure) 

87 self.assertTrue(exposure.hasPsf()) 

88 psf = exposure.getPsf() 

89 psfIm = psf.computeImage() 

90 self.assertEqual(psfIm.getWidth(), desWidth) 

91 self.assertEqual(psfIm.getHeight(), desHeight) 

92 self.assertAlmostEqual(psf.computeShape().getDeterminantRadius(), desSigma, delta=1e-3) 

93 

94 def testBadDim(self): 

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

96 config = InstallGaussianPsfTask.ConfigClass() 

97 config.width = width 

98 with self.assertRaises(Exception): 

99 config.validate() 

100 

101 

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

103 pass 

104 

105 

106def setup_module(module): 

107 lsst.utils.tests.init() 

108 

109 

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

111 lsst.utils.tests.init() 

112 unittest.main()