Coverage for tests/test_ptcDataset.py: 14%

89 statements  

« prev     ^ index     » next       coverage.py v6.5.0, created at 2023-02-09 03:43 -0800

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/>. 

21import unittest 

22import tempfile 

23 

24import numpy as np 

25 

26import lsst.utils.tests 

27 

28from lsst.ip.isr import PhotonTransferCurveDataset 

29import lsst.ip.isr.isrMock as isrMock 

30 

31 

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

33 """Test that write/read methods of PhotonTransferCurveDataset work 

34 """ 

35 def setUp(self): 

36 

37 self.flatMean = 2000 

38 self.readNoiseAdu = 10 

39 mockImageConfig = isrMock.IsrMock.ConfigClass() 

40 

41 # flatDrop is not really relevant as we replace the data 

42 # but good to note it in case we change how this image is made 

43 mockImageConfig.flatDrop = 0.99999 

44 mockImageConfig.isTrimmed = True 

45 

46 self.flatExp1 = isrMock.FlatMock(config=mockImageConfig).run() 

47 self.flatExp2 = self.flatExp1.clone() 

48 (shapeY, shapeX) = self.flatExp1.getDimensions() 

49 

50 self.flatWidth = np.sqrt(self.flatMean) + self.readNoiseAdu 

51 

52 self.rng1 = np.random.RandomState(1984) 

53 flatData1 = self.rng1.normal(self.flatMean, self.flatWidth, (shapeX, shapeY)) 

54 self.rng2 = np.random.RandomState(666) 

55 flatData2 = self.rng2.normal(self.flatMean, self.flatWidth, (shapeX, shapeY)) 

56 

57 self.flatExp1.image.array[:] = flatData1 

58 self.flatExp2.image.array[:] = flatData2 

59 

60 self.flux = 1000. # ADU/sec 

61 self.gain = 1.5 # e-/ADU 

62 self.noiseSq = 5*self.gain # 7.5 (e-)^2 

63 self.c1 = 1./self.gain 

64 

65 self.ampNames = [amp.getName() for amp in self.flatExp1.getDetector().getAmplifiers()] 

66 

67 def test_ptcDatset(self): 

68 # Fill the set up with made up data. 

69 nSignalPoints = 5 

70 nSideCovMatrix = 2 

71 for fitType in ['POLYNOMIAL', 'EXPAPPROXIMATION', 'FULLCOVARIANCE']: 

72 localDataset = PhotonTransferCurveDataset(self.ampNames, " ", nSideCovMatrix) 

73 localDataset.ptcFitType = fitType 

74 localDataset.badAmps = [localDataset.ampNames[0], localDataset.ampNames[1]] 

75 for ampName in localDataset.ampNames: 

76 

77 localDataset.inputExpIdPairs[ampName] = np.repeat(1, nSignalPoints).tolist() 

78 localDataset.expIdMask[ampName] = [True, False, True, True, False, True, False, True, True, 

79 True, True, False, True, False, True] 

80 localDataset.rawExpTimes[ampName] = np.arange(nSignalPoints).tolist() 

81 localDataset.rawMeans[ampName] = np.array(self.flux*np.arange(nSignalPoints)).tolist() 

82 localDataset.rawVars[ampName] = np.array(self.c1*self.flux*np.arange(nSignalPoints)).tolist() 

83 localDataset.photoCharge[ampName] = np.repeat(np.nan, nSignalPoints).tolist() 

84 localDataset.gain[ampName] = self.gain 

85 localDataset.gainErr[ampName] = 0.1 

86 localDataset.noise[ampName] = self.noiseSq 

87 localDataset.noiseErr[ampName] = 2.0 

88 

89 localDataset.finalVars[ampName] = np.array(self.c1*self.flux*np.arange( 

90 nSignalPoints)).tolist() 

91 localDataset.finalModelVars[ampName] = np.repeat(100.0, nSignalPoints).tolist() 

92 localDataset.finalMeans[ampName] = np.array(self.flux*np.arange(nSignalPoints)).tolist() 

93 

94 if fitType in ['POLYNOMIAL', 'EXPAPPROXIMATION', ]: 

95 localDataset.ptcFitPars[ampName] = np.array([10.0, 1.5, 1e-6]).tolist() 

96 localDataset.ptcFitParsError[ampName] = np.array([1.0, 0.2, 1e-7]).tolist() 

97 localDataset.ptcFitChiSq[ampName] = 1.0 

98 localDataset.ptcTurnoff[ampName] = localDataset.rawMeans[ampName][-1] 

99 

100 localDataset.covariances[ampName] = np.full( 

101 (nSignalPoints, nSideCovMatrix, nSideCovMatrix), 105.0).tolist() 

102 localDataset.covariancesModel[ampName] = np.full( 

103 (nSignalPoints, nSideCovMatrix, nSideCovMatrix), np.nan).tolist() 

104 localDataset.covariancesSqrtWeights[ampName] = np.full((nSignalPoints, nSideCovMatrix, 

105 nSideCovMatrix), 10.0).tolist() 

106 localDataset.aMatrix[ampName] = np.full((nSideCovMatrix, nSideCovMatrix), np.nan).tolist() 

107 localDataset.bMatrix[ampName] = np.full((nSideCovMatrix, nSideCovMatrix), np.nan).tolist() 

108 localDataset.covariancesModelNoB[ampName] = np.full((nSignalPoints, nSideCovMatrix, 

109 nSideCovMatrix), np.nan).tolist() 

110 localDataset.aMatrixNoB[ampName] = np.full( 

111 (nSideCovMatrix, nSideCovMatrix), np.nan).tolist() 

112 

113 if localDataset.ptcFitType in ['FULLCOVARIANCE', ]: 

114 localDataset.ptcFitPars[ampName] = np.array([np.nan, np.nan]).tolist() 

115 localDataset.ptcFitParsError[ampName] = np.array([np.nan, np.nan]).tolist() 

116 localDataset.ptcFitChiSq[ampName] = np.array([np.nan, np.nan]).tolist() 

117 localDataset.ptcTurnoff[ampName] = np.array([np.nan, np.nan]).tolist() 

118 

119 localDataset.covariances[ampName] = np.full( 

120 (nSignalPoints, nSideCovMatrix, nSideCovMatrix), 105.0).tolist() 

121 localDataset.covariancesModel[ampName] = np.full( 

122 (nSignalPoints, nSideCovMatrix, nSideCovMatrix), 100.0).tolist() 

123 localDataset.covariancesSqrtWeights[ampName] = np.full((nSignalPoints, nSideCovMatrix, 

124 nSideCovMatrix), 10.0).tolist() 

125 localDataset.aMatrix[ampName] = np.full((nSideCovMatrix, nSideCovMatrix), 1e-6).tolist() 

126 localDataset.bMatrix[ampName] = np.full((nSideCovMatrix, nSideCovMatrix), 1e-7).tolist() 

127 localDataset.covariancesModelNoB[ampName] = np.full((nSignalPoints, nSideCovMatrix, 

128 nSideCovMatrix), 15.0).tolist() 

129 localDataset.aMatrixNoB[ampName] = np.full( 

130 (nSideCovMatrix, nSideCovMatrix), 2e-6).tolist() 

131 

132 filename = tempfile.mktemp() 

133 usedFilename = localDataset.writeText(filename + ".yaml") 

134 fromText = PhotonTransferCurveDataset.readText(usedFilename) 

135 self.assertEqual(localDataset, fromText) 

136 

137 filename = tempfile.mktemp() 

138 usedFilename = localDataset.writeFits(filename + ".fits") 

139 fromFits = PhotonTransferCurveDataset.readFits(usedFilename) 

140 self.assertEqual(localDataset, fromFits) 

141 

142 

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

144 pass 

145 

146 

147def setup_module(module): 

148 lsst.utils.tests.init() 

149 

150 

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

152 import sys 

153 setup_module(sys.modules[__name__]) 

154 unittest.main()