Coverage for tests/test_isrMockLSST.py: 23%

65 statements  

« prev     ^ index     » next       coverage.py v7.5.0, created at 2024-05-01 04:11 -0700

1# 

2# LSST Data Management System 

3# Copyright 2008-2017 AURA/LSST. 

4# 

5# This product includes software developed by the 

6# LSST Project (http://www.lsst.org/). 

7# 

8# This program is free software: you can redistribute it and/or modify 

9# it under the terms of the GNU General Public License as published by 

10# the Free Software Foundation, either version 3 of the License, or 

11# (at your option) any later version. 

12# 

13# This program is distributed in the hope that it will be useful, 

14# but WITHOUT ANY WARRANTY; without even the implied warranty of 

15# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 

16# GNU General Public License for more details. 

17# 

18# You should have received a copy of the LSST License Statement and 

19# the GNU General Public License along with this program. If not, 

20# see <https://www.lsstcorp.org/LegalNotices/>. 

21# 

22 

23import unittest 

24import numpy as np 

25 

26import lsst.utils.tests 

27 

28import lsst.afw.image as afwImage 

29import lsst.ip.isr.isrMockLSST as isrMockLSST 

30 

31 

32class IsrMockLSSTCases(lsst.utils.tests.TestCase): 

33 """Test the generation of IsrMockLSST data. 

34 """ 

35 def setUp(self): 

36 self.inputExp = isrMockLSST.TrimmedRawMockLSST().run() 

37 self.mi = self.inputExp.getMaskedImage() 

38 

39 def test_simple(self): 

40 """Check trimmed raw data are generated as expected, 

41 taking the same approach as in test_isrMock. 

42 """ 

43 

44 initialMean = np.median(self.mi.getImage().getArray()[:]) 

45 initialStd = np.std(self.mi.getImage().getArray()[:]) 

46 

47 # Build and subtract a bias calibration 

48 bias = isrMockLSST.BiasMockLSST().run() 

49 self.mi.getImage().getArray()[:] = (self.mi.getImage().getArray()[:] 

50 - bias.getMaskedImage().getImage().getArray()[:]) 

51 newMean = np.median(self.mi.getImage().getArray()[:]) 

52 newStd = np.std(self.mi.getImage().getArray()[:]) 

53 

54 self.assertLess(newMean, initialMean) 

55 

56 initialMean = newMean 

57 initialStd = newStd 

58 

59 dark = isrMockLSST.DarkMockLSST().run() 

60 self.mi.getImage().getArray()[:] = (self.mi.getImage().getArray()[:] 

61 - dark.getMaskedImage().getImage().getArray()[:]) 

62 newMean = np.median(self.mi.getImage().getArray()[:]) 

63 newStd = np.std(self.mi.getImage().getArray()[:]) 

64 

65 self.assertLess(newMean, initialMean) 

66 

67 initialMean = newMean 

68 initialStd = newStd 

69 

70 flat = isrMockLSST.FlatMockLSST().run() 

71 self.mi.getImage().getArray()[:] = (self.mi.getImage().getArray()[:] 

72 - flat.getMaskedImage().getImage().getArray()[:]) 

73 newMean = np.median(self.mi.getImage().getArray()[:]) 

74 newStd = np.std(self.mi.getImage().getArray()[:]) 

75 

76 self.assertAlmostEqual(newMean, initialMean, -2) 

77 self.assertLess(newStd, initialStd) 

78 

79 initialMean = newMean 

80 initialStd = newStd 

81 

82 fringe = isrMockLSST.FringeMockLSST().run() 

83 self.mi.getImage().getArray()[:] = (self.mi.getImage().getArray()[:] 

84 - fringe.getMaskedImage().getImage().getArray()[:]) 

85 newMean = np.median(self.mi.getImage().getArray()[:]) 

86 newStd = np.std(self.mi.getImage().getArray()[:]) 

87 

88 self.assertLess(newMean, initialMean) 

89 

90 def test_untrimmedSimple(self): 

91 """Test untrimmed mocks are genetared. 

92 """ 

93 exposureLowNoise = isrMockLSST.RawMockLSST().run() 

94 

95 rawMock = isrMockLSST.RawMockLSST() 

96 rawMock.config.readNoise = 100. 

97 exposureHighNoise = rawMock.run() 

98 

99 lowNoiseStd = np.std(exposureLowNoise.getMaskedImage().getImage().getArray()[:]) 

100 highNoiseStd = np.std(exposureHighNoise.getMaskedImage().getImage().getArray()[:]) 

101 

102 self.assertLess(lowNoiseStd, highNoiseStd) 

103 

104 def test_productTypes(self): 

105 """Tests non-image data are returned as the expected type, 

106 taking the same approach as in test_isrMock. 

107 """ 

108 self.assertIsInstance(isrMockLSST.BfKernelMockLSST().run(), np.ndarray) 

109 self.assertIsInstance(isrMockLSST.CrosstalkCoeffMockLSST().run(), np.ndarray) 

110 

111 self.assertIsInstance(isrMockLSST.DefectMockLSST().run()[0], lsst.meas.algorithms.Defect) 

112 self.assertIsInstance(isrMockLSST.TransmissionMockLSST().run(), afwImage.TransmissionCurve) 

113 

114 def test_edgeCases(self): 

115 """Tests that improperly specified configurations do not return data, 

116 taking the same approach as in test_isrMock 

117 """ 

118 config = isrMockLSST.IsrMockLSSTConfig() 

119 self.assertIsNone(isrMockLSST.IsrMockLSST(config=config).run()) 

120 

121 with self.assertRaises(RuntimeError): 

122 config.doGenerateData = True 

123 isrMockLSST.IsrMockLSST(config=config).run() 

124 

125 

126class MemoryTester(lsst.utils.tests.MemoryTestCase): 

127 pass 

128 

129 

130def setup_module(module): 

131 lsst.utils.tests.init() 

132 

133 

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

135 lsst.utils.tests.init() 

136 unittest.main()