Coverage for python/lsst/cp/verify/verifyCrosstalk.py: 21%
57 statements
« prev ^ index » next coverage.py v7.5.1, created at 2024-05-09 04:38 -0700
« prev ^ index » next coverage.py v7.5.1, created at 2024-05-09 04:38 -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
23import lsst.pipe.base.connectionTypes as cT
24from .verifyCalib import CpVerifyCalibConfig, CpVerifyCalibTask, CpVerifyCalibConnections
27__all__ = ['CpVerifyCrosstalkConfig', 'CpVerifyCrosstalkTask']
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 )
42class CpVerifyCrosstalkConfig(CpVerifyCalibConfig,
43 pipelineConnections=CpVerifyCrosstalkConnections):
44 """Inherits from base CpVerifyCalibConfig."""
46 def setDefaults(self):
47 super().setDefaults()
48 self.stageName = 'CROSSTALK'
49 self.calibStatKeywords = {'SNR': ''} # noqa F841
52class CpVerifyCrosstalkTask(CpVerifyCalibTask):
53 """Crosstalk verification sub-class, implementing the verify method.
54 """
55 ConfigClass = CpVerifyCrosstalkConfig
56 _DefaultName = 'cpVerifyCrosstalk'
58 def detectorStatistics(self, inputCalib, camera=None):
59 """Calculate detector level statistics from the calibration.
61 Parameters
62 ----------
63 inputCalib : `lsst.ip.isr.IsrCalib`
64 The calibration to verify.
65 camera : `lsst.afw.cameraGeom.Camera`, optional
66 Input camera.
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()
80 return outputStatistics
82 def amplifierStatistics(self, inputCalib, camera=None):
83 """Calculate amplifier level statistics from the calibration.
85 Parameters
86 ----------
87 inputCalib : `lsst.ip.isr.IsrCalib`
88 The calibration to verify.
89 camera : `lsst.afw.cameraGeom.Camera`, optional
90 Input camera.
92 Returns
93 -------
94 outputStatistics : `dict` [`str`, scalar]
95 A dictionary of the statistics measured and their values.
96 """
98 pass
100 def verify(self, calib, statisticsDict, camera=None):
101 """Verify that the calibration meets the verification criteria.
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.
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
128 if detectorStats['N_VALID'] > 0:
129 verifyStats['NO_SIGNIFICANT_DETECTION'] = False
130 success = False
132 return verifyStats, success
134 def repackStats(self, statisticsDict, dimensions):
135 # docstring inherited
136 rowList = []
137 matrixRowList = []
139 if self.config.useIsrStatistics:
140 mjd = statisticsDict["ISR"]["MJD"]
141 else:
142 mjd = np.nan
144 rowBase = {
145 "instrument": dimensions["instrument"],
146 "detector": dimensions["detector"],
147 "mjd": mjd,
148 "amplifier": "detector",
149 }
150 row = {}
151 row.update(rowBase)
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 }
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]
172 matrixRowList.append(matrixRow)
173 else:
174 row[f"{self.config.stageName}_{key}"] = value
176 # VERIFY results
178 for key, value in statisticsDict["VERIFY"].items():
179 row[f"{self.config.stageName}_VERIFY_{key}"] = value
181 # pack final list
182 rowList.append(row)
184 return rowList, matrixRowList