LSST Applications g0f08755f38+82efc23009,g12f32b3c4e+e7bdf1200e,g1653933729+a8ce1bb630,g1a0ca8cf93+50eff2b06f,g28da252d5a+52db39f6a5,g2bbee38e9b+37c5a29d61,g2bc492864f+37c5a29d61,g2cdde0e794+c05ff076ad,g3156d2b45e+41e33cbcdc,g347aa1857d+37c5a29d61,g35bb328faa+a8ce1bb630,g3a166c0a6a+37c5a29d61,g3e281a1b8c+fb992f5633,g414038480c+7f03dfc1b0,g41af890bb2+11b950c980,g5fbc88fb19+17cd334064,g6b1c1869cb+12dd639c9a,g781aacb6e4+a8ce1bb630,g80478fca09+72e9651da0,g82479be7b0+04c31367b4,g858d7b2824+82efc23009,g9125e01d80+a8ce1bb630,g9726552aa6+8047e3811d,ga5288a1d22+e532dc0a0b,gae0086650b+a8ce1bb630,gb58c049af0+d64f4d3760,gc28159a63d+37c5a29d61,gcf0d15dbbd+2acd6d4d48,gd7358e8bfb+778a810b6e,gda3e153d99+82efc23009,gda6a2b7d83+2acd6d4d48,gdaeeff99f8+1711a396fd,ge2409df99d+6b12de1076,ge79ae78c31+37c5a29d61,gf0baf85859+d0a5978c5a,gf3967379c6+4954f8c433,gfb92a5be7c+82efc23009,gfec2e1e490+2aaed99252,w.2024.46
LSST Data Management Base Package
Loading...
Searching...
No Matches
photodiodeCorrection.py
Go to the documentation of this file.
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/>.
21"""
22PhotodiodeCorrection storage class.
23"""
24
25__all__ = ["PhotodiodeCorrection"]
26
27import numpy as np
28from astropy.table import Table
29from .calibType import IsrCalib
30
31
33 """Parameter set for photodiode correction.
34
35 These parameters are included in cameraGeom.Amplifier, but
36 should be accessible externally to allow for testing.
37
38 Parameters
39 ----------
40 table : `numpy.array`, optional
41 Lookup table; a 2-dimensional array of floats:
42
43 - one row for each row index (value of coef[0] in the amplifier)
44 - one column for each image value.
45
46 To avoid copying the table the last index should vary fastest
47 (numpy default "C" order)
48 log : `logging.Logger`, optional
49 Logger to handle messages.
50 kwargs : `dict`, optional
51 Other keyword arguments to pass to the parent init.
52
53 Raises
54 ------
55 RuntimeError
56 Raised if the supplied table is not 2D, or if the table has fewer
57 columns than rows (indicating that the indices are swapped).
58
59 Notes
60 -----
61 The photodiode correction attributes stored are:
62 abscissaCorrections : `dict` : [`str`, `float`]
63 Correction value indexed by exposure pair
64 """
65 _OBSTYPE = "PHOTODIODE_CORRECTION"
66 _SCHEMA = 'PhotodiodeCorrection'
67 _VERSION = 1.1
68
69 def __init__(self, table=None, **kwargs):
70 self.abscissaCorrections = dict()
71 self.tableData = None
72 if table is not None:
73 if len(table.shape) != 2:
74 raise RuntimeError("table shape = %s; must have two dimensions" % (table.shape,))
75 if table.shape[1] < table.shape[0]:
76 raise RuntimeError("table shape = %s; indices are switched" % (table.shape,))
77 self.tableData = np.array(table, order="C")
78
79 super().__init__(**kwargs)
80 self.requiredAttributesrequiredAttributesrequiredAttributes.update(['abscissaCorrections'])
81
82 def updateMetadata(self, setDate=False, **kwargs):
83 """Update metadata keywords with new values.
84
85 This calls the base class's method after ensuring the required
86 calibration keywords will be saved.
87
88 Parameters
89 ----------
90 setDate : `bool`, optional
91 Update the CALIBDATE fields in the metadata to the current
92 time. Defaults to False.
93 kwargs :
94 Other keyword parameters to set in the metadata.
95 """
96
97 super().updateMetadata(setDate=setDate, **kwargs)
98
99 @classmethod
100 def fromDict(cls, dictionary):
101 """Construct a PhotodiodeCorrection from a dictionary of properties.
102
103 Parameters
104 ----------
105 dictionary : `dict`
106 Dictionary of properties.
107
108 Returns
109 -------
110 calib : `lsst.ip.isr.PhotodiodeCorrection`
111 Constructed photodiode data.
112
113 Raises
114 ------
115 RuntimeError
116 Raised if the supplied dictionary is for a different
117 calibration type.
118 """
119 calib = cls()
120
121 if calib._OBSTYPE != dictionary['metadata']['OBSTYPE']:
122 raise RuntimeError(f"Incorrect photodiode correction supplied. Expected {calib._OBSTYPE}, "
123 f"found {dictionary['metadata']['OBSTYPE']}")
124
125 calib.setMetadata(dictionary['metadata'])
126 for pair in dictionary['pairs']:
127 correction = dictionary['pairs'][pair]
128 calib.abscissaCorrections[pair] = correction
129
130 calib.tableData = dictionary.get('tableData', None)
131 if calib.tableData:
132 calib.tableData = np.array(calib.tableData)
133
134 return calib
135
136 def toDict(self):
137 """Return a dictionary containing the photodiode correction properties.
138
139 The dictionary should be able to be round-tripped through.
140 `fromDict`.
141
142 Returns
143 -------
144 dictionary : `dict`
145 Dictionary of properties.
146 """
148
149 outDict = dict()
150 outDict['pairs'] = dict()
151 outDict['metadata'] = self.getMetadata()
152 for pair in self.abscissaCorrections.keys():
153 outDict['pairs'][pair] = self.abscissaCorrections[pair]
154
155 if self.tableData is not None:
156 outDict['tableData'] = self.tableData.tolist()
157
158 return outDict
159
160 @classmethod
161 def fromTable(cls, tableList):
162 """Construct calibration from a list of tables.
163
164 This method uses the `fromDict` method to create the
165 calibration after constructing an appropriate dictionary from
166 the input tables.
167
168 Parameters
169 ----------
170 tableList : `list` [`astropy.table.Table`]
171 List of tables to use to construct the crosstalk
172 calibration.
173
174 Returns
175 -------
176 calib : `lsst.ip.isr.PhotodiodeCorrection`
177 The calibration defined in the tables.
178 """
179 dataTable = tableList[0]
180
181 metadata = dataTable.meta
182 inDict = dict()
183 inDict['metadata'] = metadata
184 inDict['pairs'] = dict()
185
186 for record in dataTable:
187 pair = record['PAIR']
188 inDict['pairs'][pair] = record['PD_CORR']
189
190 if len(tableList) > 1:
191 tableData = tableList[1]
192 inDict['tableData'] = [record['LOOKUP_VALUES'] for record in tableData]
193
194 return cls().fromDict(inDict)
195
196 def toTable(self):
197 """Construct a list of tables containing the information in this
198 calibration.
199
200 The list of tables should create an identical calibration
201 after being passed to this class's fromTable method.
202
203 Returns
204 -------
205 tableList : `list` [`astropy.table.Table`]
206 List of tables containing the photodiode correction
207 information.
208 """
209 tableList = []
211 catalog = Table([{'PAIR': key,
212 'PD_CORR': self.abscissaCorrections[key]}
213 for key in self.abscissaCorrections.keys()])
214 catalog.meta = self.getMetadata().toDict()
215 tableList.append(catalog)
216
217 if self.tableData is not None:
218 catalog = Table([{'LOOKUP_VALUES': value} for value in self.tableData])
219 tableList.append(catalog)
220
221 return tableList
222
223 def validate(self):
224 """Validate photodiode correction"""
225 return
updateMetadata(self, camera=None, detector=None, filterName=None, setCalibId=False, setCalibInfo=False, setDate=False, **kwargs)
Definition calibType.py:207