Coverage for tests/test_measureCrosstalk.py: 27%

57 statements  

« prev     ^ index     » next       coverage.py v6.4.2, created at 2022-07-19 06:01 -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 

27from lsst.cp.pipe.measureCrosstalk import MeasureCrosstalkTask, MeasureCrosstalkConfig 

28import lsst.ip.isr.isrMock as isrMock 

29 

30 

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

32 

33 def setup_measureCrosstalk(self, isTrimmed=False, nSources=8): 

34 """Generate a simulated set of exposures and test the measured 

35 crosstalk matrix. 

36 

37 Parameters 

38 ---------- 

39 isTrimmed : `bool`, optional 

40 Should the simulation use trimmed or untrimmed raw 

41 exposures? 

42 nSources : `int`, optional 

43 Number of random simulated sources to generate in the 

44 simulated exposures. 

45 

46 Returns 

47 ------- 

48 goodFitMask : `np.ndarray` 

49 Array of booleans indicating if the measured and expected 

50 crosstalk ratios are smaller than the measured uncertainty 

51 in the crosstalk ratio. 

52 """ 

53 mockTask = isrMock.CalibratedRawMock() 

54 mockTask.config.rngSeed = 12345 

55 mockTask.config.doGenerateImage = True 

56 mockTask.config.doAddSky = True 

57 mockTask.config.doAddSource = True 

58 mockTask.config.doAddCrosstalk = True 

59 mockTask.config.doAddBias = True 

60 mockTask.config.doAddFringe = False 

61 

62 mockTask.config.skyLevel = 0.0 

63 mockTask.config.biasLevel = 0.0 

64 mockTask.config.readNoise = 100.0 

65 

66 mcConfig = MeasureCrosstalkConfig() 

67 mcConfig.extract.threshold = 4000 

68 mcConfig.extract.isTrimmed = isTrimmed 

69 mct = MeasureCrosstalkTask(config=mcConfig) 

70 fullResult = [] 

71 

72 mockTask.config.isTrimmed = isTrimmed 

73 # Generate simulated set of exposures. 

74 for idx in range(0, 12): 

75 mockTask.config.rngSeed = 12345 + idx * 1000 

76 

77 # Allow each simulated exposure to have nSources random 

78 # bright sources. 

79 mockTask.config.sourceAmp = (np.random.randint(8, size=nSources)).tolist() 

80 mockTask.config.sourceFlux = ((np.random.random(size=nSources) * 25000.0 + 20000.0).tolist()) 

81 mockTask.config.sourceX = ((np.random.random(size=nSources) * 100.0).tolist()) 

82 mockTask.config.sourceY = ((np.random.random(size=nSources) * 50.0).tolist()) 

83 

84 exposure = mockTask.run() 

85 result = mct.extract.run(exposure) 

86 fullResult.append(result.outputRatios) 

87 

88 # Generate the final measured CT ratios, uncertainties, pixel counts. 

89 finalResult = mct.solver.run(fullResult) 

90 calib = finalResult.outputCrosstalk 

91 

92 # Needed because measureCrosstalk cannot find coefficients equal to 0.0 

93 coeff = np.nan_to_num(calib.coeffs) 

94 coeffSig = np.nan_to_num(calib.coeffErr) 

95 

96 # Compare result against expectation used to create the simulation. 

97 expectation = isrMock.CrosstalkCoeffMock().run() 

98 goodFitMask = abs(coeff - expectation) <= coeffSig 

99 

100 if not np.all(goodFitMask): 

101 print("Coeff: ", coeff) 

102 print("Expectation: ", expectation) 

103 print("Good Fits: ", goodFitMask) 

104 return goodFitMask 

105 

106 def testMeasureCrosstalkTaskTrimmed(self): 

107 """Measure crosstalk from a sequence of trimmed mocked images. 

108 """ 

109 goodFitMask = self.setup_measureCrosstalk(isTrimmed=True, nSources=8) 

110 

111 self.assertTrue(np.all(goodFitMask)) 

112 

113 def testMeasureCrosstalkTaskUntrimmed(self): 

114 """Measure crosstalk from a sequence of untrimmed mocked images. 

115 """ 

116 goodFitMask = self.setup_measureCrosstalk(isTrimmed=False, nSources=8) 

117 

118 self.assertTrue(np.all(goodFitMask)) 

119 

120 

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

122 pass 

123 

124 

125def setup_module(module): 

126 lsst.utils.tests.init() 

127 

128 

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

130 lsst.utils.tests.init() 

131 unittest.main()