Coverage for tests/test_photodiode.py: 24%

70 statements  

« prev     ^ index     » next       coverage.py v7.2.7, created at 2023-08-12 09:51 +0000

1# This file is part of ip_isr. 

2# 

3# Developed for the LSST Data Management System. 

4# This product includes software developed by the LSST Project 

5# (https://www.lsst.org). 

6# See the COPYRIGHT file at the top-level directory of this distribution 

7# for details of code ownership. 

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 GNU General Public License 

20# along with this program. If not, see <https://www.gnu.org/licenses/>. 

21 

22import unittest 

23import tempfile 

24 

25import numpy as np 

26 

27import lsst.afw.cameraGeom as cameraGeom 

28import lsst.geom as geom 

29import lsst.utils.tests 

30 

31from lsst.ip.isr import PhotodiodeCalib 

32 

33 

34class PhotodiodeTestCase(lsst.utils.tests.TestCase): 

35 def setUp(self): 

36 

37 self.timeSeries = [0.0, 0.08496094, 0.1689453, 0.2529297, 

38 0.3378906, 0.421875, 0.5068359, 0.5908203, 0.6757813, 

39 0.7597656, 0.84375, 0.9287109, 1.012695, 1.097656, 1.181641, 

40 1.266602] 

41 self.currentSeries = [-1.350031E-12, 1.598721E-13, -1.456613E-13, 

42 -1.385558E-13, -3.517187E-13, -3.375078E-13, 3.597549E-10, 

43 3.591616E-10, 3.599823E-10, 3.597158E-10, 3.606893E-10, 

44 3.602736E-10, 3.582272E-10, 3.59293E-10, 3.602878E-10, 

45 3.588703E-10] 

46 

47 camBuilder = cameraGeom.Camera.Builder("fakeCam") 

48 detBuilder = camBuilder.add('det_a', 1) 

49 detBuilder.setSerial("123") 

50 

51 bbox = geom.Box2I(geom.Point2I(0, 0), geom.Extent2I(100, 100)) 

52 orientation = cameraGeom.Orientation() 

53 pixelSize = lsst.geom.Extent2D(1, 1) 

54 detBuilder.setBBox(bbox) 

55 detBuilder.setOrientation(orientation) 

56 detBuilder.setPixelSize(pixelSize) 

57 

58 self.camera = camBuilder 

59 self.detector = detBuilder 

60 

61 def testDataOnly(self): 

62 calib = PhotodiodeCalib(timeSamples=self.timeSeries, 

63 currentSamples=self.currentSeries) 

64 

65 self.assertFloatsAlmostEqual(calib.integrate(), 2.88414e-10, rtol=1e-14) 

66 self.assertFloatsAlmostEqual(calib.integrateDirectSum(), 2.88414e-10, rtol=1e-14) 

67 self.assertFloatsAlmostEqual(calib.integrateTrimmedSum(), 2.88720e-10, rtol=1e-14) 

68 self.assertFloatsAlmostEqual(calib.integrateChargeSum(), 3.5960649e-09, rtol=1e-14) 

69 

70 self.assertEqual(calib.timeSamples.shape, (16, )) 

71 self.assertEqual(calib.currentSamples.shape, (16, )) 

72 

73 outPath = tempfile.mktemp() + '.yaml' 

74 calib.writeText(outPath) 

75 newPhotodiode = PhotodiodeCalib().readText(outPath) 

76 self.assertEqual(calib, newPhotodiode) 

77 

78 outPath = tempfile.mktemp() + '.fits' 

79 calib.writeFits(outPath) 

80 newPhotodiode = PhotodiodeCalib().readFits(outPath) 

81 self.assertEqual(calib, newPhotodiode) 

82 

83 def testFullyPopulated(self): 

84 calib = PhotodiodeCalib(timeSamples=self.timeSeries, 

85 currentSamples=self.currentSeries, 

86 detector=self.detector, 

87 camera=self.camera) 

88 

89 self.assertFloatsAlmostEqual(calib.integrate(), 2.88414e-10, rtol=1e-14) 

90 self.assertFloatsAlmostEqual(calib.integrateDirectSum(), 2.88414e-10, rtol=1e-14) 

91 self.assertFloatsAlmostEqual(calib.integrateTrimmedSum(), 2.88720e-10, rtol=1e-14) 

92 self.assertFloatsAlmostEqual(calib.integrateChargeSum(), 3.5960649e-09, rtol=1e-14) 

93 

94 self.assertEqual(calib.timeSamples.shape, (16, )) 

95 self.assertEqual(calib.currentSamples.shape, (16, )) 

96 

97 outPath = tempfile.mktemp() + '.yaml' 

98 calib.writeText(outPath) 

99 newPhotodiode = PhotodiodeCalib().readText(outPath) 

100 self.assertEqual(calib, newPhotodiode) 

101 

102 outPath = tempfile.mktemp() + '.fits' 

103 calib.writeFits(outPath) 

104 newPhotodiode = PhotodiodeCalib().readFits(outPath) 

105 self.assertEqual(calib, newPhotodiode) 

106 

107 def testIntegrateChargeSum(self): 

108 """ 

109 This tests the .integrateChargeSum method in the presence of 

110 an above-baseline point which is still below the initial 

111 threshold for identifying points to exclude in the baseline 

112 current estimate. 

113 """ 

114 # Compute a value to insert at time 0.47. 

115 test_time = 0.47 

116 test_current = ((max(self.currentSeries) - min(self.currentSeries))/40. 

117 + min(self.currentSeries)) 

118 new_times = np.array(self.timeSeries + [test_time]) 

119 new_currents = np.array(self.currentSeries + [test_current]) 

120 # Put these arrays in time order, though this isn't strictly needed. 

121 index = np.argsort(new_times) 

122 calib = PhotodiodeCalib(timeSamples=new_times[index], 

123 currentSamples=new_currents[index]) 

124 self.assertFloatsAlmostEqual(calib.integrateChargeSum(), 3.6049277e-09, rtol=1e-14) 

125 

126 

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

128 pass 

129 

130 

131def setup_module(module): 

132 lsst.utils.tests.init() 

133 

134 

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

136 import sys 

137 setup_module(sys.modules[__name__]) 

138 unittest.main()