Coverage for python/lsst/cp/verify/verifyCalib.py: 75%

24 statements  

« prev     ^ index     » next       coverage.py v6.5.0, created at 2022-11-06 22:17 +0000

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 lsst.pex.config as pexConfig 

22import lsst.pipe.base as pipeBase 

23import lsst.pipe.base.connectionTypes as cT 

24 

25 

26__all__ = ['CpVerifyCalibConfig', 'CpVerifyCalibTask'] 

27 

28 

29class CpVerifyCalibConnections(pipeBase.PipelineTaskConnections, 

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

31 defaultTemplates={}): 

32 inputCalib = cT.Input( 

33 name="calib", 

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

35 storageClass="IsrCalib", 

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

37 isCalibration=True 

38 ) 

39 

40 outputStats = cT.Output( 

41 name="calibStats", 

42 doc="Output statistics from cp_verify.", 

43 storageClass="StructuredDataDict", 

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

45 ) 

46 

47 

48class CpVerifyCalibConfig(pipeBase.PipelineTaskConfig, 

49 pipelineConnections=CpVerifyCalibConnections): 

50 """Configuration parameters for CpVerifyCalibTask. 

51 """ 

52 # Statistics options. 

53 useReadNoise = pexConfig.Field( 

54 dtype=bool, 

55 doc="Compare sigma against read noise?", 

56 default=True, 

57 ) 

58 numSigmaClip = pexConfig.Field( 

59 dtype=float, 

60 doc="Rejection threshold (sigma) for statistics clipping.", 

61 default=5.0, 

62 ) 

63 clipMaxIter = pexConfig.Field( 

64 dtype=int, 

65 doc="Max number of clipping iterations to apply.", 

66 default=3, 

67 ) 

68 

69 # Keywords and statistics to measure from different sources. 

70 calibStatKeywords = pexConfig.DictField( 

71 keytype=str, 

72 itemtype=str, 

73 doc="Calib statistics to run.", 

74 default={}, 

75 ) 

76 

77 

78class CpVerifyCalibTask(pipeBase.PipelineTask, pipeBase.CmdLineTask): 

79 """Main statistic measurement and validation class. 

80 

81 This operates on a generic calibration, and is designed to be 

82 subclassed so specific calibrations can apply their own validation 

83 methods. 

84 """ 

85 

86 ConfigClass = CpVerifyCalibConfig 

87 _DefaultName = 'cpVerifyCalib' 

88 

89 def run(self, inputCalib): 

90 """Calculate quality statistics and verify they meet the requirements 

91 for a calibration. 

92 

93 Parameters 

94 ---------- 

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

96 The calibration to be measured. 

97 

98 Returns 

99 ------- 

100 result : `lsst.pipe.base.Struct` 

101 Result struct with components: 

102 - ``outputStats`` : `dict` 

103 The output measured statistics. 

104 

105 Notes 

106 ----- 

107 The outputStats should have a yaml representation of the form 

108 (with STAT and TEST being the appropriate statistic and test 

109 names) 

110 

111 DET: 

112 STAT: value 

113 STAT2: value 

114 VERIFY: 

115 TEST: boolean 

116 SUCCESS: boolean 

117 

118 """ 

119 outputStats = {} 

120 

121 outputStats['DET'] = self.detectorStatistics(inputCalib) 

122 outputStats['VERIFY'], outputStats['SUCCESS'] = self.verify(inputCalib, outputStats) 

123 

124 return pipeBase.Struct( 

125 outputStats=outputStats, 

126 ) 

127 

128 # Methods that need to be implemented by the calibration-level subclasses. 

129 def detectorStatistics(self, inputCalib): 

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

131 

132 Parameters 

133 ---------- 

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

135 The calibration to verify. 

136 

137 Returns 

138 ------- 

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

140 A dictionary of the statistics measured and their values. 

141 

142 Raises 

143 ------ 

144 NotImplementedError : 

145 This method must be implemented by the calibration-type 

146 subclass. 

147 """ 

148 raise NotImplementedError("Subclasses must implement detector statistics method.") 

149 

150 def verify(self, inputCalib, statisticsDict): 

151 """Verify that the measured calibration meet the verification criteria. 

152 

153 Parameters 

154 ---------- 

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

156 The calibration to verify. 

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

158 Dictionary of measured statistics. The inner dictionary 

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

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

161 the mostly likely types). 

162 

163 Returns 

164 ------- 

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

166 A dictionary indexed by the amplifier name, containing 

167 dictionaries of the verification criteria. 

168 success : `bool` 

169 A boolean indicating whether all tests have passed. 

170 

171 Raises 

172 ------ 

173 NotImplementedError : 

174 This method must be implemented by the calibration-type 

175 subclass. 

176 """ 

177 raise NotImplementedError("Subclasses must implement verification criteria.")