LSST Applications g1653933729+a8ce1bb630,g171997e3ee+76e92115be,g1a997c3884+a8ce1bb630,g28da252d5a+4013ff5194,g2bbee38e9b+d6d0f9f6ae,g2bc492864f+d6d0f9f6ae,g2cdde0e794+ccb74358b7,g3156d2b45e+07302053f8,g347aa1857d+d6d0f9f6ae,g35bb328faa+a8ce1bb630,g3a166c0a6a+d6d0f9f6ae,g3e281a1b8c+130fae20e3,g4005a62e65+17cd334064,g414038480c+c9f68e2a12,g41af890bb2+3e1f62f438,g4e1a3235cc+9db7d56ad0,g7b55021d1b+7b623691d5,g80478fca09+334cc8d2bd,g82479be7b0+b568f6b267,g858d7b2824+37b39d8760,g9125e01d80+a8ce1bb630,ga5288a1d22+11cb34fefe,gae0086650b+a8ce1bb630,gb4ec7eb0ab+37b39d8760,gb58c049af0+d64f4d3760,gc081298178+284e133171,gc28159a63d+d6d0f9f6ae,gcf0d15dbbd+00fe2e0b07,gd6b7c0dfd1+8b62435e69,gda3e153d99+37b39d8760,gda6a2b7d83+00fe2e0b07,gdaeeff99f8+1711a396fd,gdd5a9049c5+23f3b3239a,ge2409df99d+5d9f551a54,ge33fd446bb+37b39d8760,ge79ae78c31+d6d0f9f6ae,gf0baf85859+2dea8344a2,gf5289d68f6+3777f3df5e,w.2024.41
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
 
 tableData
 
 linearityUnits
 
 log
 

Protected Attributes

 _detectorName
 
 _detectorSerial
 
 _detectorId
 

Static Protected Attributes

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

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.

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 111 of file linearize.py.

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

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 471 of file linearize.py.

471 def applyLinearity(self, image, detector=None, log=None, gains=None):
472 """Apply the linearity to an image.
473
474 If the linearity parameters are populated, use those,
475 otherwise use the values from the detector.
476
477 Parameters
478 ----------
479 image : `~lsst.afw.image.image`
480 Image to correct.
481 detector : `~lsst.afw.cameraGeom.detector`, optional
482 Detector to use to determine exposure trimmed state. If
483 supplied, but no other linearity information is provided
484 by the calibration, then the static solution stored in the
485 detector will be used.
486 log : `~logging.Logger`, optional
487 Log object to use for logging.
488 gains : `dict` [`str`, `float`], optional
489 Dictionary of amp name to gain. If this is provided then
490 linearity terms will be converted from adu to electrons.
491 Only used for Spline linearity corrections.
492 """
493 if log is None:
494 log = self.log
495 if detector and not self.hasLinearity:
496 self.fromDetector(detector)
497
498 self.validate(detector)
499
500 # Check if the image is trimmed.
501 isTrimmed = None
502 if detector:
503 isTrimmed = isTrimmedImage(image, detector)
504
505 numAmps = 0
506 numLinearized = 0
507 numOutOfRange = 0
508 for ampName in self.linearityType.keys():
509 linearizer = self.getLinearityTypeByName(self.linearityType[ampName])
510 numAmps += 1
511
512 if gains and self.linearityUnits == 'adu':
513 gainValue = gains[ampName]
514 else:
515 gainValue = 1.0
516
517 if linearizer is not None:
518 match isTrimmed:
519 case True:
520 bbox = detector[ampName].getBBox()
521 case False:
522 bbox = detector[ampName].getRawBBox()
523 case None:
524 bbox = self.linearityBBox[ampName]
525
526 ampView = image.Factory(image, bbox)
527 success, outOfRange = linearizer()(ampView, **{'coeffs': self.linearityCoeffs[ampName],
528 'table': self.tableData,
529 'log': self.log,
530 'gain': gainValue})
531 numOutOfRange += outOfRange
532 if success:
533 numLinearized += 1
534 elif log is not None:
535 log.warning("Amplifier %s did not linearize.",
536 ampName)
537 return Struct(
538 numAmps=numAmps,
539 numLinearized=numLinearized,
540 numOutOfRange=numOutOfRange
541 )
542
543

◆ 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 164 of file linearize.py.

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

◆ 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 195 of file linearize.py.

195 def fromDict(cls, dictionary):
196 """Construct a calibration from a dictionary of properties
197
198 Parameters
199 ----------
200 dictionary : `dict`
201 Dictionary of properties
202
203 Returns
204 -------
205 calib : `lsst.ip.isr.Linearity`
206 Constructed calibration.
207
208 Raises
209 ------
210 RuntimeError
211 Raised if the supplied dictionary is for a different
212 calibration.
213 """
214
215 calib = cls()
216
217 if calib._OBSTYPE != dictionary['metadata']['OBSTYPE']:
218 raise RuntimeError(f"Incorrect linearity supplied. Expected {calib._OBSTYPE}, "
219 f"found {dictionary['metadata']['OBSTYPE']}")
220
221 calib.setMetadata(dictionary['metadata'])
222
223 calib.hasLinearity = dictionary.get('hasLinearity',
224 dictionary['metadata'].get('HAS_LINEARITY', False))
225 calib.override = dictionary.get('override', True)
226
227 calib.linearityUnits = dictionary.get('linearityUnits', 'adu')
228
229 if calib.hasLinearity:
230 for ampName in dictionary['amplifiers']:
231 amp = dictionary['amplifiers'][ampName]
232 calib.ampNames.append(ampName)
233 calib.linearityCoeffs[ampName] = np.array(amp.get('linearityCoeffs', [0.0]))
234 calib.linearityType[ampName] = amp.get('linearityType', 'None')
235 calib.linearityBBox[ampName] = amp.get('linearityBBox', None)
236
237 calib.fitParams[ampName] = np.array(amp.get('fitParams', [0.0]))
238 calib.fitParamsErr[ampName] = np.array(amp.get('fitParamsErr', [0.0]))
239 calib.fitChiSq[ampName] = amp.get('fitChiSq', np.nan)
240 calib.fitResiduals[ampName] = np.array(amp.get('fitResiduals', [0.0]))
241 calib.fitResidualsSigmaMad[ampName] = np.array(amp.get('fitResidualsSigmaMad', np.nan))
242 calib.linearFit[ampName] = np.array(amp.get('linearFit', [0.0]))
243
244 calib.tableData = dictionary.get('tableData', None)
245 if calib.tableData:
246 calib.tableData = np.array(calib.tableData)
247
248 return calib
249

◆ 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 283 of file linearize.py.

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

◆ 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 387 of file linearize.py.

387 def getLinearityTypeByName(self, linearityTypeName):
388 """Determine the linearity class to use from the type name.
389
390 Parameters
391 ----------
392 linearityTypeName : str
393 String name of the linearity type that is needed.
394
395 Returns
396 -------
397 linearityType : `~lsst.ip.isr.linearize.LinearizeBase`
398 The appropriate linearity class to use. If no matching class
399 is found, `None` is returned.
400 """
401 for t in [LinearizeLookupTable,
402 LinearizeSquared,
403 LinearizePolynomial,
404 LinearizeProportional,
405 LinearizeSpline,
406 LinearizeNone]:
407 if t.LinearityType == linearityTypeName:
408 return t
409 return None
410

◆ 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 250 of file linearize.py.

250 def toDict(self):
251 """Return linearity parameters as a dict.
252
253 Returns
254 -------
255 outDict : `dict`:
256 """
257 self.updateMetadata()
258
259 outDict = {'metadata': self.getMetadata(),
260 'detectorName': self._detectorName,
261 'detectorSerial': self._detectorSerial,
262 'detectorId': self._detectorId,
263 'hasTable': self.tableData is not None,
264 'amplifiers': dict(),
265 'linearityUnits': self.linearityUnits,
266 }
267 for ampName in self.linearityType:
268 outDict['amplifiers'][ampName] = {'linearityType': self.linearityType[ampName],
269 'linearityCoeffs': self.linearityCoeffs[ampName].tolist(),
270 'linearityBBox': self.linearityBBox[ampName],
271 'fitParams': self.fitParams[ampName].tolist(),
272 'fitParamsErr': self.fitParamsErr[ampName].tolist(),
273 'fitChiSq': self.fitChiSq[ampName],
274 'fitResiduals': self.fitResiduals[ampName].tolist(),
275 'fitResidualsSigmaMad': self.fitResiduals[ampName],
276 'linearFit': self.linearFit[ampName].tolist()}
277 if self.tableData is not None:
278 outDict['tableData'] = self.tableData.tolist()
279
280 return outDict
281

◆ 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 349 of file linearize.py.

349 def toTable(self):
350 """Construct a list of tables containing the information in this
351 calibration.
352
353 The list of tables should create an identical calibration
354 after being passed to this class's fromTable method.
355
356 Returns
357 -------
358 tableList : `list` [`astropy.table.Table`]
359 List of tables containing the linearity calibration
360 information.
361 """
362
363 tableList = []
364 self.updateMetadata()
365 catalog = Table([{'AMPLIFIER_NAME': ampName,
366 'TYPE': self.linearityType[ampName],
367 'COEFFS': self.linearityCoeffs[ampName],
368 'BBOX_X0': self.linearityBBox[ampName].getMinX(),
369 'BBOX_Y0': self.linearityBBox[ampName].getMinY(),
370 'BBOX_DX': self.linearityBBox[ampName].getWidth(),
371 'BBOX_DY': self.linearityBBox[ampName].getHeight(),
372 'FIT_PARAMS': self.fitParams[ampName],
373 'FIT_PARAMS_ERR': self.fitParamsErr[ampName],
374 'RED_CHI_SQ': self.fitChiSq[ampName],
375 'FIT_RES': self.fitResiduals[ampName],
376 'FIT_RES_SIGMAD': self.fitResidualsSigmaMad[ampName],
377 'LIN_FIT': self.linearFit[ampName],
378 } for ampName in self.ampNames])
379 catalog.meta = self.getMetadata().toDict()
380 tableList.append(catalog)
381
382 if self.tableData is not None:
383 catalog = Table([{'LOOKUP_VALUES': value} for value in self.tableData])
384 tableList.append(catalog)
385 return tableList
386

◆ 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 143 of file linearize.py.

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

◆ 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 411 of file linearize.py.

411 def validate(self, detector=None, amplifier=None):
412 """Validate linearity for a detector/amplifier.
413
414 Parameters
415 ----------
416 detector : `lsst.afw.cameraGeom.Detector`, optional
417 Detector to validate, along with its amplifiers.
418 amplifier : `lsst.afw.cameraGeom.Amplifier`, optional
419 Single amplifier to validate.
420
421 Raises
422 ------
423 RuntimeError
424 Raised if there is a mismatch in linearity parameters, and
425 the cameraGeom parameters are not being overridden.
426 """
427 amplifiersToCheck = []
428 if detector:
429 if self._detectorName != detector.getName():
430 raise RuntimeError("Detector names don't match: %s != %s" %
431 (self._detectorName, detector.getName()))
432 if int(self._detectorId) != int(detector.getId()):
433 raise RuntimeError("Detector IDs don't match: %s != %s" %
434 (int(self._detectorId), int(detector.getId())))
435 # TODO: DM-38778: This check fails on LATISS due to an
436 # error in the camera configuration.
437 # if self._detectorSerial != detector.getSerial():
438 # raise RuntimeError(
439 # "Detector serial numbers don't match: %s != %s" %
440 # (self._detectorSerial, detector.getSerial()))
441 if len(detector.getAmplifiers()) != len(self.linearityCoeffs.keys()):
442 raise RuntimeError("Detector number of amps = %s does not match saved value %s" %
443 (len(detector.getAmplifiers()),
444 len(self.linearityCoeffs.keys())))
445 amplifiersToCheck.extend(detector.getAmplifiers())
446
447 if amplifier:
448 amplifiersToCheck.extend(amplifier)
449
450 for amp in amplifiersToCheck:
451 ampName = amp.getName()
452 if ampName not in self.linearityCoeffs.keys():
453 raise RuntimeError("Amplifier %s is not in linearity data" %
454 (ampName, ))
455 if amp.getLinearityType() != self.linearityType[ampName]:
456 if self.override:
457 self.log.debug("Overriding amplifier defined linearityType (%s) for %s",
458 self.linearityType[ampName], ampName)
459 else:
460 raise RuntimeError("Amplifier %s type %s does not match saved value %s" %
461 (ampName, amp.getLinearityType(), self.linearityType[ampName]))
462 if (amp.getLinearityCoeffs().shape != self.linearityCoeffs[ampName].shape or not
463 np.allclose(amp.getLinearityCoeffs(), self.linearityCoeffs[ampName], equal_nan=True)):
464 if self.override:
465 self.log.debug("Overriding amplifier defined linearityCoeffs (%s) for %s",
466 self.linearityCoeffs[ampName], ampName)
467 else:
468 raise RuntimeError("Amplifier %s coeffs %s does not match saved value %s" %
469 (ampName, amp.getLinearityCoeffs(), self.linearityCoeffs[ampName]))
470

Member Data Documentation

◆ _detectorId

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

Definition at line 179 of file linearize.py.

◆ _detectorName

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

Definition at line 177 of file linearize.py.

◆ _detectorSerial

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

Definition at line 178 of file linearize.py.

◆ _OBSTYPE

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

Definition at line 107 of file linearize.py.

◆ _SCHEMA

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

Definition at line 108 of file linearize.py.

◆ _VERSION

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

Definition at line 109 of file linearize.py.

◆ ampNames

lsst.ip.isr.linearize.Linearizer.ampNames

Definition at line 115 of file linearize.py.

◆ fitChiSq

lsst.ip.isr.linearize.Linearizer.fitChiSq

Definition at line 121 of file linearize.py.

◆ fitParams

lsst.ip.isr.linearize.Linearizer.fitParams

Definition at line 119 of file linearize.py.

◆ fitParamsErr

lsst.ip.isr.linearize.Linearizer.fitParamsErr

Definition at line 120 of file linearize.py.

◆ fitResiduals

lsst.ip.isr.linearize.Linearizer.fitResiduals

Definition at line 122 of file linearize.py.

◆ fitResidualsSigmaMad

lsst.ip.isr.linearize.Linearizer.fitResidualsSigmaMad

Definition at line 123 of file linearize.py.

◆ hasLinearity

lsst.ip.isr.linearize.Linearizer.hasLinearity

Definition at line 112 of file linearize.py.

◆ linearFit

lsst.ip.isr.linearize.Linearizer.linearFit

Definition at line 124 of file linearize.py.

◆ linearityBBox

lsst.ip.isr.linearize.Linearizer.linearityBBox

Definition at line 118 of file linearize.py.

◆ linearityCoeffs

lsst.ip.isr.linearize.Linearizer.linearityCoeffs

Definition at line 116 of file linearize.py.

◆ linearityType

lsst.ip.isr.linearize.Linearizer.linearityType

Definition at line 117 of file linearize.py.

◆ linearityUnits

lsst.ip.isr.linearize.Linearizer.linearityUnits

Definition at line 133 of file linearize.py.

◆ log

lsst.ip.isr.linearize.Linearizer.log

Definition at line 529 of file linearize.py.

◆ override

lsst.ip.isr.linearize.Linearizer.override

Definition at line 113 of file linearize.py.

◆ tableData

lsst.ip.isr.linearize.Linearizer.tableData

Definition at line 125 of file linearize.py.


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