Coverage for python/lsst/cp/verify/verifyCrosstalk.py: 21%

57 statements  

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

1# This file is part of cp_verify. 

2# 

3# Developed for the LSST Data Management System. 

4# This product includes software developed by the LSST Project 

5# (http://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 <http://www.gnu.org/licenses/>. 

21import numpy as np 

22 

23import lsst.pipe.base.connectionTypes as cT 

24from .verifyCalib import CpVerifyCalibConfig, CpVerifyCalibTask, CpVerifyCalibConnections 

25 

26 

27__all__ = ['CpVerifyCrosstalkConfig', 'CpVerifyCrosstalkTask'] 

28 

29 

30class CpVerifyCrosstalkConnections(CpVerifyCalibConnections, 

31 dimensions={"instrument", "detector"}, 

32 defaultTemplates={}): 

33 inputCalib = cT.Input( 

34 name="calib", 

35 doc="Input calib to calculate statistics for.", 

36 storageClass="CrosstalkCalib", 

37 dimensions=["instrument", "detector"], 

38 isCalibration=True 

39 ) 

40 

41 

42class CpVerifyCrosstalkConfig(CpVerifyCalibConfig, 

43 pipelineConnections=CpVerifyCrosstalkConnections): 

44 """Inherits from base CpVerifyCalibConfig.""" 

45 

46 def setDefaults(self): 

47 super().setDefaults() 

48 self.stageName = 'CROSSTALK' 

49 self.calibStatKeywords = {'SNR': ''} # noqa F841 

50 

51 

52class CpVerifyCrosstalkTask(CpVerifyCalibTask): 

53 """Crosstalk verification sub-class, implementing the verify method. 

54 """ 

55 ConfigClass = CpVerifyCrosstalkConfig 

56 _DefaultName = 'cpVerifyCrosstalk' 

57 

58 def detectorStatistics(self, inputCalib, camera=None): 

59 """Calculate detector level statistics from the calibration. 

60 

61 Parameters 

62 ---------- 

63 inputCalib : `lsst.ip.isr.IsrCalib` 

64 The calibration to verify. 

65 camera : `lsst.afw.cameraGeom.Camera`, optional 

66 Input camera. 

67 

68 Returns 

69 ------- 

70 outputStatistics : `dict` [`str`, scalar] 

71 A dictionary of the statistics measured and their values. 

72 """ 

73 outputStatistics = {} 

74 outputStatistics['N_VALID'] = int(np.sum(inputCalib.coeffValid)) 

75 outputStatistics['N_AMP'] = inputCalib.nAmp 

76 # I think this is the residual set, which isn't what we want, 

77 # but will serve as a placeholder. 

78 outputStatistics['COEFFS'] = inputCalib.coeffs.tolist() 

79 

80 return outputStatistics 

81 

82 def amplifierStatistics(self, inputCalib, camera=None): 

83 """Calculate amplifier level statistics from the calibration. 

84 

85 Parameters 

86 ---------- 

87 inputCalib : `lsst.ip.isr.IsrCalib` 

88 The calibration to verify. 

89 camera : `lsst.afw.cameraGeom.Camera`, optional 

90 Input camera. 

91 

92 Returns 

93 ------- 

94 outputStatistics : `dict` [`str`, scalar] 

95 A dictionary of the statistics measured and their values. 

96 """ 

97 

98 pass 

99 

100 def verify(self, calib, statisticsDict, camera=None): 

101 """Verify that the calibration meets the verification criteria. 

102 

103 Parameters 

104 ---------- 

105 inputCalib : `lsst.ip.isr.IsrCalib` 

106 The calibration to verify. 

107 statisticsDictionary : `dict` [`str`, `dict` [`str`, scalar]], 

108 Dictionary of measured statistics. The inner dictionary 

109 should have keys that are statistic names (`str`) with 

110 values that are some sort of scalar (`int` or `float` are 

111 the mostly likely types). 

112 camera : `lsst.afw.cameraGeom.Camera`, optional 

113 Input camera. 

114 

115 Returns 

116 ------- 

117 outputStatistics : `dict` [`str`, `dict` [`str`, `bool`]] 

118 A dictionary indexed by the amplifier name, containing 

119 dictionaries of the verification criteria. 

120 success : `bool` 

121 A boolean indicating whether all tests have passed. 

122 """ 

123 verifyStats = {} 

124 detectorStats = statisticsDict['DET'] 

125 success = True 

126 verifyStats['NO_SIGNIFICANT_DETECTION'] = True 

127 

128 if detectorStats['N_VALID'] > 0: 

129 verifyStats['NO_SIGNIFICANT_DETECTION'] = False 

130 success = False 

131 

132 return verifyStats, success 

133 

134 def repackStats(self, statisticsDict, dimensions): 

135 # docstring inherited 

136 rowList = [] 

137 matrixRowList = [] 

138 

139 if self.config.useIsrStatistics: 

140 mjd = statisticsDict["ISR"]["MJD"] 

141 else: 

142 mjd = np.nan 

143 

144 rowBase = { 

145 "instrument": dimensions["instrument"], 

146 "detector": dimensions["detector"], 

147 "mjd": mjd, 

148 "amplifier": "detector", 

149 } 

150 row = {} 

151 row.update(rowBase) 

152 

153 # Pack DET results 

154 for key, value in statisticsDict['DET'].items(): 

155 if key == 'COEFFS': 

156 matrixRowBase = { 

157 "instrument": dimensions["instrument"], 

158 "detector": dimensions["detector"], 

159 "detectorComp": dimensions["detector"], 

160 "mjd": mjd, 

161 } 

162 

163 Umax = statisticsDict['DET']['N_AMP'] 

164 Vmax = statisticsDict['DET']['N_AMP'] 

165 for u in range(Umax): 

166 for v in range(Vmax): 

167 matrixRow = matrixRowBase 

168 matrixRow["amplifierIdx"] = u 

169 matrixRow["amplifierCompIdx"] = v 

170 matrixRow["coefficient"] = value[u][v] 

171 

172 matrixRowList.append(matrixRow) 

173 else: 

174 row[f"{self.config.stageName}_{key}"] = value 

175 

176 # VERIFY results 

177 

178 for key, value in statisticsDict["VERIFY"].items(): 

179 row[f"{self.config.stageName}_VERIFY_{key}"] = value 

180 

181 # pack final list 

182 rowList.append(row) 

183 

184 return rowList, matrixRowList