LSST Applications g0f08755f38+9c285cab97,g1635faa6d4+13f3999e92,g1653933729+a8ce1bb630,g1a0ca8cf93+bf6eb00ceb,g28da252d5a+0829b12dee,g29321ee8c0+5700dc9eac,g2bbee38e9b+9634bc57db,g2bc492864f+9634bc57db,g2cdde0e794+c2c89b37c4,g3156d2b45e+41e33cbcdc,g347aa1857d+9634bc57db,g35bb328faa+a8ce1bb630,g3a166c0a6a+9634bc57db,g3e281a1b8c+9f2c4e2fc3,g414038480c+077ccc18e7,g41af890bb2+fde0dd39b6,g5fbc88fb19+17cd334064,g781aacb6e4+a8ce1bb630,g80478fca09+55a9465950,g82479be7b0+d730eedb7d,g858d7b2824+9c285cab97,g9125e01d80+a8ce1bb630,g9726552aa6+10f999ec6a,ga5288a1d22+2a84bb7594,gacf8899fa4+c69c5206e8,gae0086650b+a8ce1bb630,gb58c049af0+d64f4d3760,gc28159a63d+9634bc57db,gcf0d15dbbd+4b7d09cae4,gda3e153d99+9c285cab97,gda6a2b7d83+4b7d09cae4,gdaeeff99f8+1711a396fd,ge2409df99d+5e831397f4,ge79ae78c31+9634bc57db,gf0baf85859+147a0692ba,gf3967379c6+41c94011de,gf3fb38a9a8+8f07a9901b,gfb92a5be7c+9c285cab97,w.2024.46
LSST Data Management Base Package
Loading...
Searching...
No Matches
Public Member Functions | Public Attributes | Protected Attributes | Static Protected Attributes | List of all members
lsst.ip.isr.linearize.Linearizer Class Reference
Inheritance diagram for lsst.ip.isr.linearize.Linearizer:
lsst.ip.isr.calibType.IsrCalib

Public Member Functions

 __init__ (self, table=None, **kwargs)
 
 updateMetadata (self, setDate=False, **kwargs)
 
 fromDetector (self, detector)
 
 fromDict (cls, dictionary)
 
 toDict (self)
 
 fromTable (cls, tableList)
 
 toTable (self)
 
 getLinearityTypeByName (self, linearityTypeName)
 
 validate (self, detector=None, amplifier=None)
 
 applyLinearity (self, image, detector=None, log=None, gains=None)
 

Public Attributes

 hasLinearity
 
 override
 
 ampNames
 
 linearityCoeffs
 
 linearityType
 
 linearityBBox
 
 fitParams
 
 fitParamsErr
 
 fitChiSq
 
 fitResiduals
 
 fitResidualsSigmaMad
 
 linearFit
 
 linearityTurnoff
 
 linearityMaxSignal
 
 tableData
 
 linearityUnits
 
 log
 

Protected Attributes

 _detectorName
 
 _detectorSerial
 
 _detectorId
 

Static Protected Attributes

str _OBSTYPE = "LINEARIZER"
 
str _SCHEMA = 'Gen3 Linearizer'
 
float _VERSION = 1.4
 

Detailed Description

Parameter set for linearization.

These parameters are included in `lsst.afw.cameraGeom.Amplifier`, but
should be accessible externally to allow for testing.

Parameters
----------
table : `numpy.array`, optional
    Lookup table; a 2-dimensional array of floats:

    - one row for each row index (value of coef[0] in the amplifier)
    - one column for each image value

    To avoid copying the table the last index should vary fastest
    (numpy default "C" order)
detector : `lsst.afw.cameraGeom.Detector`, optional
    Detector object.  Passed to self.fromDetector() on init.
log : `logging.Logger`, optional
    Logger to handle messages.
kwargs : `dict`, optional
    Other keyword arguments to pass to the parent init.

Raises
------
RuntimeError
    Raised if the supplied table is not 2D, or if the table has fewer
    columns than rows (indicating that the indices are swapped).

Notes
-----
The linearizer attributes stored are:

hasLinearity : `bool`
    Whether a linearity correction is defined for this detector.
override : `bool`
    Whether the detector parameters should be overridden.
ampNames : `list` [`str`]
    List of amplifier names to correct.
linearityCoeffs : `dict` [`str`, `numpy.array`]
    Coefficients to use in correction.  Indexed by amplifier
    names.  The format of the array depends on the type of
    correction to apply.
linearityType : `dict` [`str`, `str`]
    Type of correction to use, indexed by amplifier names.
linearityBBox : `dict` [`str`, `lsst.geom.Box2I`]
    Bounding box the correction is valid over, indexed by
    amplifier names.
fitParams : `dict` [`str`, `numpy.array`], optional
    Linearity fit parameters used to construct the correction
    coefficients, indexed as above.
fitParamsErr : `dict` [`str`, `numpy.array`], optional
    Uncertainty values of the linearity fit parameters used to
    construct the correction coefficients, indexed as above.
fitChiSq : `dict` [`str`, `float`], optional
    Chi-squared value of the linearity fit, indexed as above.
fitResiduals : `dict` [`str`, `numpy.array`], optional
    Residuals of the fit, indexed as above. Used for
    calculating photdiode corrections
fitResidualsSigmaMad : `dict` [`str`, `float`], optional
    Robust median-absolute-deviation of fit residuals, scaled
    by the signal level.
linearFit : The linear fit to the low flux region of the curve.
    [intercept, slope].
tableData : `numpy.array`, optional
    Lookup table data for the linearity correction.

Version 1.4 adds ``linearityTurnoff`` and ``linearityMaxSignal``.

Definition at line 40 of file linearize.py.

Constructor & Destructor Documentation

◆ __init__()

lsst.ip.isr.linearize.Linearizer.__init__ ( self,
table = None,
** kwargs )

Reimplemented from lsst.ip.isr.calibType.IsrCalib.

Definition at line 113 of file linearize.py.

113 def __init__(self, table=None, **kwargs):
114 self.hasLinearity = False
115 self.override = False
116
117 self.ampNames = list()
118 self.linearityCoeffs = dict()
119 self.linearityType = dict()
120 self.linearityBBox = dict()
121 self.fitParams = dict()
122 self.fitParamsErr = dict()
123 self.fitChiSq = dict()
124 self.fitResiduals = dict()
125 self.fitResidualsSigmaMad = dict()
126 self.linearFit = dict()
127 self.linearityTurnoff = dict()
128 self.linearityMaxSignal = dict()
129 self.tableData = None
130 if table is not None:
131 if len(table.shape) != 2:
132 raise RuntimeError("table shape = %s; must have two dimensions" % (table.shape,))
133 if table.shape[1] < table.shape[0]:
134 raise RuntimeError("table shape = %s; indices are switched" % (table.shape,))
135 self.tableData = np.array(table, order="C")
136
137 # The linearizer is always natively in adu because it
138 # is computed prior to computing gains.
139 self.linearityUnits = 'adu'
140
141 super().__init__(**kwargs)
142 self.requiredAttributes.update(['hasLinearity', 'override',
143 'ampNames',
144 'linearityCoeffs', 'linearityType', 'linearityBBox',
145 'fitParams', 'fitParamsErr', 'fitChiSq',
146 'fitResiduals', 'fitResidualsSigmaMad', 'linearFit', 'tableData',
147 'units', 'linearityTurnoff', 'linearityMaxSignal'])
148

Member Function Documentation

◆ applyLinearity()

lsst.ip.isr.linearize.Linearizer.applyLinearity ( self,
image,
detector = None,
log = None,
gains = None )
Apply the linearity to an image.

If the linearity parameters are populated, use those,
otherwise use the values from the detector.

Parameters
----------
image : `~lsst.afw.image.image`
    Image to correct.
detector : `~lsst.afw.cameraGeom.detector`, optional
    Detector to use to determine exposure trimmed state.  If
    supplied, but no other linearity information is provided
    by the calibration, then the static solution stored in the
    detector will be used.
log : `~logging.Logger`, optional
    Log object to use for logging.
gains : `dict` [`str`, `float`], optional
    Dictionary of amp name to gain. If this is provided then
    linearity terms will be converted from adu to electrons.
    Only used for Spline linearity corrections.

Definition at line 497 of file linearize.py.

497 def applyLinearity(self, image, detector=None, log=None, gains=None):
498 """Apply the linearity to an image.
499
500 If the linearity parameters are populated, use those,
501 otherwise use the values from the detector.
502
503 Parameters
504 ----------
505 image : `~lsst.afw.image.image`
506 Image to correct.
507 detector : `~lsst.afw.cameraGeom.detector`, optional
508 Detector to use to determine exposure trimmed state. If
509 supplied, but no other linearity information is provided
510 by the calibration, then the static solution stored in the
511 detector will be used.
512 log : `~logging.Logger`, optional
513 Log object to use for logging.
514 gains : `dict` [`str`, `float`], optional
515 Dictionary of amp name to gain. If this is provided then
516 linearity terms will be converted from adu to electrons.
517 Only used for Spline linearity corrections.
518 """
519 if log is None:
520 log = self.log
521 if detector and not self.hasLinearity:
522 self.fromDetector(detector)
523
524 self.validate(detector)
525
526 # Check if the image is trimmed.
527 isTrimmed = None
528 if detector:
529 isTrimmed = isTrimmedImage(image, detector)
530
531 numAmps = 0
532 numLinearized = 0
533 numOutOfRange = 0
534 for ampName in self.linearityType.keys():
535 linearizer = self.getLinearityTypeByName(self.linearityType[ampName])
536 numAmps += 1
537
538 if gains and self.linearityUnits == 'adu':
539 gainValue = gains[ampName]
540 else:
541 gainValue = 1.0
542
543 if linearizer is not None:
544 match isTrimmed:
545 case True:
546 bbox = detector[ampName].getBBox()
547 case False:
548 bbox = detector[ampName].getRawBBox()
549 case None:
550 bbox = self.linearityBBox[ampName]
551
552 ampView = image.Factory(image, bbox)
553 success, outOfRange = linearizer()(ampView, **{'coeffs': self.linearityCoeffs[ampName],
554 'table': self.tableData,
555 'log': self.log,
556 'gain': gainValue})
557 numOutOfRange += outOfRange
558 if success:
559 numLinearized += 1
560 elif log is not None:
561 log.warning("Amplifier %s did not linearize.",
562 ampName)
563 return Struct(
564 numAmps=numAmps,
565 numLinearized=numLinearized,
566 numOutOfRange=numOutOfRange
567 )
568
569

◆ fromDetector()

lsst.ip.isr.linearize.Linearizer.fromDetector ( self,
detector )
Read linearity parameters from a detector.

Parameters
----------
detector : `lsst.afw.cameraGeom.detector`
    Input detector with parameters to use.

Returns
-------
calib : `lsst.ip.isr.Linearizer`
    The calibration constructed from the detector.

Reimplemented from lsst.ip.isr.calibType.IsrCalib.

Definition at line 170 of file linearize.py.

170 def fromDetector(self, detector):
171 """Read linearity parameters from a detector.
172
173 Parameters
174 ----------
175 detector : `lsst.afw.cameraGeom.detector`
176 Input detector with parameters to use.
177
178 Returns
179 -------
180 calib : `lsst.ip.isr.Linearizer`
181 The calibration constructed from the detector.
182 """
183 self._detectorName = detector.getName()
184 self._detectorSerial = detector.getSerial()
185 self._detectorId = detector.getId()
186 self.hasLinearity = True
187
188 # Do not translate Threshold, Maximum, Units.
189 for amp in detector.getAmplifiers():
190 ampName = amp.getName()
191 self.ampNames.append(ampName)
192 self.linearityType[ampName] = amp.getLinearityType()
193 self.linearityCoeffs[ampName] = amp.getLinearityCoeffs()
194 self.linearityBBox[ampName] = amp.getBBox()
195
196 # Detector linearizers (legacy) are assumed to be adu units.
197 self.linearityUnits = 'adu'
198
199 return self
200

◆ fromDict()

lsst.ip.isr.linearize.Linearizer.fromDict ( cls,
dictionary )
Construct a calibration from a dictionary of properties

Parameters
----------
dictionary : `dict`
    Dictionary of properties

Returns
-------
calib : `lsst.ip.isr.Linearity`
    Constructed calibration.

Raises
------
RuntimeError
    Raised if the supplied dictionary is for a different
    calibration.

Reimplemented from lsst.ip.isr.calibType.IsrCalib.

Definition at line 202 of file linearize.py.

202 def fromDict(cls, dictionary):
203 """Construct a calibration from a dictionary of properties
204
205 Parameters
206 ----------
207 dictionary : `dict`
208 Dictionary of properties
209
210 Returns
211 -------
212 calib : `lsst.ip.isr.Linearity`
213 Constructed calibration.
214
215 Raises
216 ------
217 RuntimeError
218 Raised if the supplied dictionary is for a different
219 calibration.
220 """
221
222 calib = cls()
223
224 if calib._OBSTYPE != dictionary['metadata']['OBSTYPE']:
225 raise RuntimeError(f"Incorrect linearity supplied. Expected {calib._OBSTYPE}, "
226 f"found {dictionary['metadata']['OBSTYPE']}")
227
228 calib.setMetadata(dictionary['metadata'])
229
230 calib.hasLinearity = dictionary.get('hasLinearity',
231 dictionary['metadata'].get('HAS_LINEARITY', False))
232 calib.override = dictionary.get('override', True)
233
234 # Old linearizers which do not have linearityUnits are
235 # assumed to be adu because that's all that has been
236 # supported.
237 calib.linearityUnits = dictionary.get('linearityUnits', 'adu')
238
239 if calib.hasLinearity:
240 for ampName in dictionary['amplifiers']:
241 amp = dictionary['amplifiers'][ampName]
242 calib.ampNames.append(ampName)
243 calib.linearityCoeffs[ampName] = np.array(amp.get('linearityCoeffs', [0.0]))
244 calib.linearityType[ampName] = amp.get('linearityType', 'None')
245 calib.linearityBBox[ampName] = amp.get('linearityBBox', None)
246
247 calib.fitParams[ampName] = np.array(amp.get('fitParams', [0.0]))
248 calib.fitParamsErr[ampName] = np.array(amp.get('fitParamsErr', [0.0]))
249 calib.fitChiSq[ampName] = amp.get('fitChiSq', np.nan)
250 calib.fitResiduals[ampName] = np.array(amp.get('fitResiduals', [0.0]))
251 calib.fitResidualsSigmaMad[ampName] = np.array(amp.get('fitResidualsSigmaMad', np.nan))
252 calib.linearFit[ampName] = np.array(amp.get('linearFit', [0.0]))
253
254 calib.linearityTurnoff[ampName] = np.array(amp.get('linearityTurnoff', np.nan))
255 calib.linearityMaxSignal[ampName] = np.array(amp.get('linearityMaxSignal', np.nan))
256
257 calib.tableData = dictionary.get('tableData', None)
258 if calib.tableData:
259 calib.tableData = np.array(calib.tableData)
260
261 return calib
262

◆ fromTable()

lsst.ip.isr.linearize.Linearizer.fromTable ( cls,
tableList )
Read linearity from a FITS file.

This method uses the `fromDict` method to create the
calibration, after constructing an appropriate dictionary from
the input tables.

Parameters
----------
tableList : `list` [`astropy.table.Table`]
    afwTable read from input file name.

Returns
-------
linearity : `~lsst.ip.isr.linearize.Linearizer``
    Linearity parameters.

Notes
-----
The method reads a FITS file with 1 or 2 extensions. The metadata is
read from the header of extension 1, which must exist.  Then the table
is loaded, and  the ['AMPLIFIER_NAME', 'TYPE', 'COEFFS', 'BBOX_X0',
'BBOX_Y0', 'BBOX_DX', 'BBOX_DY'] columns are read and used to set each
dictionary by looping over rows.
Extension 2 is then attempted to read in the try block (which only
exists for lookup tables). It has a column named 'LOOKUP_VALUES' that
contains a vector of the lookup entries in each row.

Reimplemented from lsst.ip.isr.calibType.IsrCalib.

Definition at line 300 of file linearize.py.

300 def fromTable(cls, tableList):
301 """Read linearity from a FITS file.
302
303 This method uses the `fromDict` method to create the
304 calibration, after constructing an appropriate dictionary from
305 the input tables.
306
307 Parameters
308 ----------
309 tableList : `list` [`astropy.table.Table`]
310 afwTable read from input file name.
311
312 Returns
313 -------
314 linearity : `~lsst.ip.isr.linearize.Linearizer``
315 Linearity parameters.
316
317 Notes
318 -----
319 The method reads a FITS file with 1 or 2 extensions. The metadata is
320 read from the header of extension 1, which must exist. Then the table
321 is loaded, and the ['AMPLIFIER_NAME', 'TYPE', 'COEFFS', 'BBOX_X0',
322 'BBOX_Y0', 'BBOX_DX', 'BBOX_DY'] columns are read and used to set each
323 dictionary by looping over rows.
324 Extension 2 is then attempted to read in the try block (which only
325 exists for lookup tables). It has a column named 'LOOKUP_VALUES' that
326 contains a vector of the lookup entries in each row.
327 """
328 coeffTable = tableList[0]
329
330 metadata = coeffTable.meta
331 inDict = dict()
332 inDict['metadata'] = metadata
333 inDict['hasLinearity'] = metadata.get('HAS_LINEARITY', False)
334 inDict['amplifiers'] = dict()
335 inDict['linearityUnits'] = metadata.get('LINEARITY_UNITS', 'adu')
336
337 for record in coeffTable:
338 ampName = record['AMPLIFIER_NAME']
339
340 fitParams = record['FIT_PARAMS'] if 'FIT_PARAMS' in record.columns else np.array([0.0])
341 fitParamsErr = record['FIT_PARAMS_ERR'] if 'FIT_PARAMS_ERR' in record.columns else np.array([0.0])
342 fitChiSq = record['RED_CHI_SQ'] if 'RED_CHI_SQ' in record.columns else np.nan
343 fitResiduals = record['FIT_RES'] if 'FIT_RES' in record.columns else np.array([0.0])
344 fitResidualsSigmaMad = record['FIT_RES_SIGMAD'] if 'FIT_RES_SIGMAD' in record.columns else np.nan
345 linearFit = record['LIN_FIT'] if 'LIN_FIT' in record.columns else np.array([0.0])
346
347 linearityTurnoff = record['LINEARITY_TURNOFF'] if 'LINEARITY_TURNOFF' in record.columns \
348 else np.nan
349 linearityMaxSignal = record['LINEARITY_MAX_SIGNAL'] if 'LINEARITY_MAX_SIGNAL' in record.columns \
350 else np.nan
351
352 inDict['amplifiers'][ampName] = {
353 'linearityType': record['TYPE'],
354 'linearityCoeffs': record['COEFFS'],
355 'linearityBBox': Box2I(Point2I(record['BBOX_X0'], record['BBOX_Y0']),
356 Extent2I(record['BBOX_DX'], record['BBOX_DY'])),
357 'fitParams': fitParams,
358 'fitParamsErr': fitParamsErr,
359 'fitChiSq': fitChiSq,
360 'fitResiduals': fitResiduals,
361 'fitResidualsSigmaMad': fitResidualsSigmaMad,
362 'linearFit': linearFit,
363 'linearityTurnoff': linearityTurnoff,
364 'linearityMaxSignal': linearityMaxSignal,
365 }
366
367 if len(tableList) > 1:
368 tableData = tableList[1]
369 inDict['tableData'] = [record['LOOKUP_VALUES'] for record in tableData]
370
371 return cls().fromDict(inDict)
372

◆ getLinearityTypeByName()

lsst.ip.isr.linearize.Linearizer.getLinearityTypeByName ( self,
linearityTypeName )
Determine the linearity class to use from the type name.

Parameters
----------
linearityTypeName : str
    String name of the linearity type that is needed.

Returns
-------
linearityType : `~lsst.ip.isr.linearize.LinearizeBase`
    The appropriate linearity class to use.  If no matching class
    is found, `None` is returned.

Definition at line 413 of file linearize.py.

413 def getLinearityTypeByName(self, linearityTypeName):
414 """Determine the linearity class to use from the type name.
415
416 Parameters
417 ----------
418 linearityTypeName : str
419 String name of the linearity type that is needed.
420
421 Returns
422 -------
423 linearityType : `~lsst.ip.isr.linearize.LinearizeBase`
424 The appropriate linearity class to use. If no matching class
425 is found, `None` is returned.
426 """
427 for t in [LinearizeLookupTable,
428 LinearizeSquared,
429 LinearizePolynomial,
430 LinearizeProportional,
431 LinearizeSpline,
432 LinearizeNone]:
433 if t.LinearityType == linearityTypeName:
434 return t
435 return None
436

◆ toDict()

lsst.ip.isr.linearize.Linearizer.toDict ( self)
Return linearity parameters as a dict.

Returns
-------
outDict : `dict`:

Reimplemented from lsst.ip.isr.calibType.IsrCalib.

Definition at line 263 of file linearize.py.

263 def toDict(self):
264 """Return linearity parameters as a dict.
265
266 Returns
267 -------
268 outDict : `dict`:
269 """
270 self.updateMetadata()
271
272 outDict = {'metadata': self.getMetadata(),
273 'detectorName': self._detectorName,
274 'detectorSerial': self._detectorSerial,
275 'detectorId': self._detectorId,
276 'hasTable': self.tableData is not None,
277 'amplifiers': dict(),
278 'linearityUnits': self.linearityUnits,
279 }
280 for ampName in self.linearityType:
281 outDict['amplifiers'][ampName] = {
282 'linearityType': self.linearityType[ampName],
283 'linearityCoeffs': self.linearityCoeffs[ampName].tolist(),
284 'linearityBBox': self.linearityBBox[ampName],
285 'fitParams': self.fitParams[ampName].tolist(),
286 'fitParamsErr': self.fitParamsErr[ampName].tolist(),
287 'fitChiSq': self.fitChiSq[ampName],
288 'fitResiduals': self.fitResiduals[ampName].tolist(),
289 'fitResidualsSigmaMad': self.fitResiduals[ampName],
290 'linearFit': self.linearFit[ampName].tolist(),
291 'linearityTurnoff': self.linearityTurnoff[ampName],
292 'linearityMaxSignal': self.linearityMaxSignal[ampName],
293 }
294 if self.tableData is not None:
295 outDict['tableData'] = self.tableData.tolist()
296
297 return outDict
298

◆ toTable()

lsst.ip.isr.linearize.Linearizer.toTable ( self)
Construct a list of tables containing the information in this
calibration.

The list of tables should create an identical calibration
after being passed to this class's fromTable method.

Returns
-------
tableList : `list` [`astropy.table.Table`]
    List of tables containing the linearity calibration
    information.

Reimplemented from lsst.ip.isr.calibType.IsrCalib.

Definition at line 373 of file linearize.py.

373 def toTable(self):
374 """Construct a list of tables containing the information in this
375 calibration.
376
377 The list of tables should create an identical calibration
378 after being passed to this class's fromTable method.
379
380 Returns
381 -------
382 tableList : `list` [`astropy.table.Table`]
383 List of tables containing the linearity calibration
384 information.
385 """
386
387 tableList = []
388 self.updateMetadata()
389 catalog = Table([{'AMPLIFIER_NAME': ampName,
390 'TYPE': self.linearityType[ampName],
391 'COEFFS': self.linearityCoeffs[ampName],
392 'BBOX_X0': self.linearityBBox[ampName].getMinX(),
393 'BBOX_Y0': self.linearityBBox[ampName].getMinY(),
394 'BBOX_DX': self.linearityBBox[ampName].getWidth(),
395 'BBOX_DY': self.linearityBBox[ampName].getHeight(),
396 'FIT_PARAMS': self.fitParams[ampName],
397 'FIT_PARAMS_ERR': self.fitParamsErr[ampName],
398 'RED_CHI_SQ': self.fitChiSq[ampName],
399 'FIT_RES': self.fitResiduals[ampName],
400 'FIT_RES_SIGMAD': self.fitResidualsSigmaMad[ampName],
401 'LIN_FIT': self.linearFit[ampName],
402 'LINEARITY_TURNOFF': self.linearityTurnoff[ampName],
403 'LINEARITY_MAX_SIGNAL': self.linearityMaxSignal[ampName],
404 } for ampName in self.ampNames])
405 catalog.meta = self.getMetadata().toDict()
406 tableList.append(catalog)
407
408 if self.tableData is not None:
409 catalog = Table([{'LOOKUP_VALUES': value} for value in self.tableData])
410 tableList.append(catalog)
411 return tableList
412

◆ updateMetadata()

lsst.ip.isr.linearize.Linearizer.updateMetadata ( self,
setDate = False,
** kwargs )
Update metadata keywords with new values.

This calls the base class's method after ensuring the required
calibration keywords will be saved.

Parameters
----------
setDate : `bool`, optional
    Update the CALIBDATE fields in the metadata to the current
    time. Defaults to False.
kwargs :
    Other keyword parameters to set in the metadata.

Reimplemented from lsst.ip.isr.calibType.IsrCalib.

Definition at line 149 of file linearize.py.

149 def updateMetadata(self, setDate=False, **kwargs):
150 """Update metadata keywords with new values.
151
152 This calls the base class's method after ensuring the required
153 calibration keywords will be saved.
154
155 Parameters
156 ----------
157 setDate : `bool`, optional
158 Update the CALIBDATE fields in the metadata to the current
159 time. Defaults to False.
160 kwargs :
161 Other keyword parameters to set in the metadata.
162 """
163 kwargs['HAS_LINEARITY'] = self.hasLinearity
164 kwargs['OVERRIDE'] = self.override
165 kwargs['HAS_TABLE'] = self.tableData is not None
166 kwargs['LINEARITY_UNITS'] = self.linearityUnits
167
168 super().updateMetadata(setDate=setDate, **kwargs)
169

◆ validate()

lsst.ip.isr.linearize.Linearizer.validate ( self,
detector = None,
amplifier = None )
Validate linearity for a detector/amplifier.

Parameters
----------
detector : `lsst.afw.cameraGeom.Detector`, optional
    Detector to validate, along with its amplifiers.
amplifier : `lsst.afw.cameraGeom.Amplifier`, optional
    Single amplifier to validate.

Raises
------
RuntimeError
    Raised if there is a mismatch in linearity parameters, and
    the cameraGeom parameters are not being overridden.

Reimplemented from lsst.ip.isr.calibType.IsrCalib.

Definition at line 437 of file linearize.py.

437 def validate(self, detector=None, amplifier=None):
438 """Validate linearity for a detector/amplifier.
439
440 Parameters
441 ----------
442 detector : `lsst.afw.cameraGeom.Detector`, optional
443 Detector to validate, along with its amplifiers.
444 amplifier : `lsst.afw.cameraGeom.Amplifier`, optional
445 Single amplifier to validate.
446
447 Raises
448 ------
449 RuntimeError
450 Raised if there is a mismatch in linearity parameters, and
451 the cameraGeom parameters are not being overridden.
452 """
453 amplifiersToCheck = []
454 if detector:
455 if self._detectorName != detector.getName():
456 raise RuntimeError("Detector names don't match: %s != %s" %
457 (self._detectorName, detector.getName()))
458 if int(self._detectorId) != int(detector.getId()):
459 raise RuntimeError("Detector IDs don't match: %s != %s" %
460 (int(self._detectorId), int(detector.getId())))
461 # TODO: DM-38778: This check fails on LATISS due to an
462 # error in the camera configuration.
463 # if self._detectorSerial != detector.getSerial():
464 # raise RuntimeError(
465 # "Detector serial numbers don't match: %s != %s" %
466 # (self._detectorSerial, detector.getSerial()))
467 if len(detector.getAmplifiers()) != len(self.linearityCoeffs.keys()):
468 raise RuntimeError("Detector number of amps = %s does not match saved value %s" %
469 (len(detector.getAmplifiers()),
470 len(self.linearityCoeffs.keys())))
471 amplifiersToCheck.extend(detector.getAmplifiers())
472
473 if amplifier:
474 amplifiersToCheck.extend(amplifier)
475
476 for amp in amplifiersToCheck:
477 ampName = amp.getName()
478 if ampName not in self.linearityCoeffs.keys():
479 raise RuntimeError("Amplifier %s is not in linearity data" %
480 (ampName, ))
481 if amp.getLinearityType() != self.linearityType[ampName]:
482 if self.override:
483 self.log.debug("Overriding amplifier defined linearityType (%s) for %s",
484 self.linearityType[ampName], ampName)
485 else:
486 raise RuntimeError("Amplifier %s type %s does not match saved value %s" %
487 (ampName, amp.getLinearityType(), self.linearityType[ampName]))
488 if (amp.getLinearityCoeffs().shape != self.linearityCoeffs[ampName].shape or not
489 np.allclose(amp.getLinearityCoeffs(), self.linearityCoeffs[ampName], equal_nan=True)):
490 if self.override:
491 self.log.debug("Overriding amplifier defined linearityCoeffs (%s) for %s",
492 self.linearityCoeffs[ampName], ampName)
493 else:
494 raise RuntimeError("Amplifier %s coeffs %s does not match saved value %s" %
495 (ampName, amp.getLinearityCoeffs(), self.linearityCoeffs[ampName]))
496

Member Data Documentation

◆ _detectorId

lsst.ip.isr.linearize.Linearizer._detectorId
protected

Definition at line 185 of file linearize.py.

◆ _detectorName

lsst.ip.isr.linearize.Linearizer._detectorName
protected

Definition at line 183 of file linearize.py.

◆ _detectorSerial

lsst.ip.isr.linearize.Linearizer._detectorSerial
protected

Definition at line 184 of file linearize.py.

◆ _OBSTYPE

str lsst.ip.isr.linearize.Linearizer._OBSTYPE = "LINEARIZER"
staticprotected

Definition at line 109 of file linearize.py.

◆ _SCHEMA

str lsst.ip.isr.linearize.Linearizer._SCHEMA = 'Gen3 Linearizer'
staticprotected

Definition at line 110 of file linearize.py.

◆ _VERSION

float lsst.ip.isr.linearize.Linearizer._VERSION = 1.4
staticprotected

Definition at line 111 of file linearize.py.

◆ ampNames

lsst.ip.isr.linearize.Linearizer.ampNames

Definition at line 117 of file linearize.py.

◆ fitChiSq

lsst.ip.isr.linearize.Linearizer.fitChiSq

Definition at line 123 of file linearize.py.

◆ fitParams

lsst.ip.isr.linearize.Linearizer.fitParams

Definition at line 121 of file linearize.py.

◆ fitParamsErr

lsst.ip.isr.linearize.Linearizer.fitParamsErr

Definition at line 122 of file linearize.py.

◆ fitResiduals

lsst.ip.isr.linearize.Linearizer.fitResiduals

Definition at line 124 of file linearize.py.

◆ fitResidualsSigmaMad

lsst.ip.isr.linearize.Linearizer.fitResidualsSigmaMad

Definition at line 125 of file linearize.py.

◆ hasLinearity

lsst.ip.isr.linearize.Linearizer.hasLinearity

Definition at line 114 of file linearize.py.

◆ linearFit

lsst.ip.isr.linearize.Linearizer.linearFit

Definition at line 126 of file linearize.py.

◆ linearityBBox

lsst.ip.isr.linearize.Linearizer.linearityBBox

Definition at line 120 of file linearize.py.

◆ linearityCoeffs

lsst.ip.isr.linearize.Linearizer.linearityCoeffs

Definition at line 118 of file linearize.py.

◆ linearityMaxSignal

lsst.ip.isr.linearize.Linearizer.linearityMaxSignal

Definition at line 128 of file linearize.py.

◆ linearityTurnoff

lsst.ip.isr.linearize.Linearizer.linearityTurnoff

Definition at line 127 of file linearize.py.

◆ linearityType

lsst.ip.isr.linearize.Linearizer.linearityType

Definition at line 119 of file linearize.py.

◆ linearityUnits

lsst.ip.isr.linearize.Linearizer.linearityUnits

Definition at line 139 of file linearize.py.

◆ log

lsst.ip.isr.linearize.Linearizer.log

Definition at line 555 of file linearize.py.

◆ override

lsst.ip.isr.linearize.Linearizer.override

Definition at line 115 of file linearize.py.

◆ tableData

lsst.ip.isr.linearize.Linearizer.tableData

Definition at line 129 of file linearize.py.


The documentation for this class was generated from the following file: