Hide keyboard shortcuts

Hot-keys 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

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.ip.isr.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 coeffErr : `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.threshold = 4000 

68 mcConfig.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, 10): 

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.run(exposure, dataId=None) 

86 fullResult.append(result) 

87 

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

89 coeff, coeffSig, coeffNum = mct.reduce(fullResult) 

90 

91 # Needed because measureCrosstalk cannot find coefficients equal to 0.0 

92 coeff = np.nan_to_num(coeff) 

93 coeffSig = np.nan_to_num(coeffSig) 

94 

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

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

97 coeffErr = abs(coeff - expectation) <= coeffSig 

98 return coeffErr 

99 

100 def testMeasureCrosstalkTaskTrimmed(self): 

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

102 """ 

103 coeffErr = self.setup_measureCrosstalk(isTrimmed=True, nSources=8) 

104 

105 self.assertTrue(np.all(coeffErr)) 

106 

107 def testMeasureCrosstalkTaskUntrimmed(self): 

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

109 """ 

110 coeffErr = self.setup_measureCrosstalk(isTrimmed=False, nSources=8) 

111 

112 # DM-18528 This doesn't always fully converge, so be permissive 

113 # for now. 

114 self.assertTrue(np.any(coeffErr)) 

115 

116 

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

118 pass 

119 

120 

121def setup_module(module): 

122 lsst.utils.tests.init() 

123 

124 

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

126 lsst.utils.tests.init() 

127 unittest.main()