LSST Applications g04e9c324dd+8c5ae1fdc5,g134cb467dc+1b3060144d,g18429d2f64+f642bf4753,g199a45376c+0ba108daf9,g1fd858c14a+2dcf163641,g262e1987ae+7b8c96d2ca,g29ae962dfc+3bd6ecb08a,g2cef7863aa+aef1011c0b,g35bb328faa+8c5ae1fdc5,g3fd5ace14f+53e1a9e7c5,g4595892280+fef73a337f,g47891489e3+2efcf17695,g4d44eb3520+642b70b07e,g53246c7159+8c5ae1fdc5,g67b6fd64d1+2efcf17695,g67fd3c3899+b70e05ef52,g74acd417e5+317eb4c7d4,g786e29fd12+668abc6043,g87389fa792+8856018cbb,g89139ef638+2efcf17695,g8d7436a09f+3be3c13596,g8ea07a8fe4+9f5ccc88ac,g90f42f885a+a4e7b16d9b,g97be763408+ad77d7208f,g9dd6db0277+b70e05ef52,ga681d05dcb+a3f46e7fff,gabf8522325+735880ea63,gac2eed3f23+2efcf17695,gb89ab40317+2efcf17695,gbf99507273+8c5ae1fdc5,gd8ff7fe66e+b70e05ef52,gdab6d2f7ff+317eb4c7d4,gdc713202bf+b70e05ef52,gdfd2d52018+b10e285e0f,ge365c994fd+310e8507c4,ge410e46f29+2efcf17695,geaed405ab2+562b3308c0,gffca2db377+8c5ae1fdc5,w.2025.35
LSST Data Management Base Package
Loading...
Searching...
No Matches
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)
 
 requiredAttributes (self)
 
 requiredAttributes (self, value)
 
 __str__ (self)
 
 __eq__ (self, other)
 
 metadata (self)
 
 getMetadata (self)
 
 setMetadata (self, metadata)
 
 updateMetadataFromExposures (self, exposures)
 
 calibInfoFromDict (self, dictionary)
 
 determineCalibClass (cls, metadata, message)
 
 readText (cls, filename, **kwargs)
 
 writeText (self, filename, format="auto")
 
 readFits (cls, filename, **kwargs)
 
 writeFits (self, filename)
 
 apply (self, target)
 

Public Attributes

bool hasLinearity = False
 
bool override = False
 
 ampNames = list()
 
 linearityCoeffs = dict()
 
 linearityType = dict()
 
 linearityBBox = dict()
 
 inputAbscissa = dict()
 
 inputOrdinate = dict()
 
 inputMask = dict()
 
 inputGroupingIndex = dict()
 
 inputNormalization = dict()
 
 fitParams = dict()
 
 fitParamsErr = dict()
 
 fitChiSq = dict()
 
 fitResiduals = dict()
 
 fitResidualsSigmaMad = dict()
 
 fitResidualsUnmasked = dict()
 
 fitResidualsModel = dict()
 
 linearFit = dict()
 
 linearityTurnoff = dict()
 
 linearityMaxSignal = dict()
 
 tableData = None
 
str linearityUnits = 'adu'
 
 requiredAttributes = set(["_OBSTYPE", "_SCHEMA", "_VERSION"])
 
 log = log if log else logging.getLogger(__name__)
 

Protected Attributes

 _instrument = None
 
 _raftName = None
 
 _slotName = None
 
 _detectorName = None
 
 _detectorSerial = None
 
 _detectorId = None
 
 _filter = None
 
str _calibId = None
 
 _seqfile = None
 
 _seqname = None
 
 _seqcksum = None
 
 _metadata = PropertyList()
 
 _requiredAttributes
 

Static Protected Attributes

str _OBSTYPE = "generic"
 
str _SCHEMA = "NO SCHEMA"
 
int _VERSION = 0
 

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`, `np.ndarray`]
    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`, `np.ndarray`], optional
    Linearity fit parameters used to construct the correction
    coefficients, indexed as above.
fitParamsErr : `dict` [`str`, `np.ndarray`], 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`, `np.ndarray`], optional
    Residuals of the fit, indexed as above. Used for
    calculating photodiode corrections
fitResidualsSigmaMad : `dict` [`str`, `float`], optional
    Robust median-absolute-deviation of fit residuals, scaled
    by the signal level.
fitResidualsUnmasked : `dict` [`str`, `np.ndarray`], optional
    Same as fitResiduals, but all outliers are included and
    not masked as nans.
fitResidualsModel : `dict` [`str`, `np.ndarray`], optional
    The model count level for each of the fitResiduals.
linearFit : The linear fit to the low flux region of the curve.
    [intercept, slope].
tableData : `np.ndarray`, optional
    Lookup table data for the linearity correction.
inputAbscissa : `dict` [`str`, `np.ndarray`], optional
    Input abscissa used to construct linearizer (usually photodiode
    or exposure time).
inputOrdinate : `dict` [`str`, `np.ndarray`], optional
    Input ordinate used to construct linearizer (raw mean counts).
inputMask : `dict` [`str`, `np.ndarray`], optional
    Input mask used for the fitting.
inputGroupingIndex : `dict` [`str`, `np.ndarray`], optional
    Input grouping index used for fitting.
inputNormalization : `dict` [`str`, `np.ndarray`], optional
    Input normalization that was applied to the abscissa for
    each pair from the PTC used for the linearization fit.

Version 1.4 adds ``linearityTurnoff`` and ``linearityMaxSignal``.
Version 1.5 adds ``fitResidualsUnmasked``, ``inputAbscissa``,
    ``inputOrdinate``, ``inputMask``, ``inputGroupingIndex``,
    ``fitResidualsModel``, and ``inputNormalization``.

Definition at line 40 of file linearize.py.

Constructor & Destructor Documentation

◆ __init__()

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

Definition at line 133 of file linearize.py.

133 def __init__(self, table=None, **kwargs):
134 self.hasLinearity = False
135 self.override = False
136
137 self.ampNames = list()
138 self.linearityCoeffs = dict()
139 self.linearityType = dict()
140 self.linearityBBox = dict()
141 self.inputAbscissa = dict()
142 self.inputOrdinate = dict()
143 self.inputMask = dict()
144 self.inputGroupingIndex = dict()
145 self.inputNormalization = dict()
146 self.fitParams = dict()
147 self.fitParamsErr = dict()
148 self.fitChiSq = dict()
149 self.fitResiduals = dict()
150 self.fitResidualsSigmaMad = dict()
151 self.fitResidualsUnmasked = dict()
152 self.fitResidualsModel = dict()
153 self.linearFit = dict()
154 self.linearityTurnoff = dict()
155 self.linearityMaxSignal = dict()
156 self.tableData = None
157 if table is not None:
158 if len(table.shape) != 2:
159 raise RuntimeError("table shape = %s; must have two dimensions" % (table.shape,))
160 if table.shape[1] < table.shape[0]:
161 raise RuntimeError("table shape = %s; indices are switched" % (table.shape,))
162 self.tableData = np.array(table, order="C")
163
164 # The linearizer is always natively in adu because it
165 # is computed prior to computing gains.
166 self.linearityUnits = 'adu'
167
168 super().__init__(**kwargs)
169 self.requiredAttributes.update(['hasLinearity', 'override',
170 'ampNames',
171 'linearityCoeffs', 'linearityType', 'linearityBBox',
172 'fitParams', 'fitParamsErr', 'fitChiSq',
173 'fitResiduals', 'fitResidualsSigmaMad', 'linearFit', 'tableData',
174 'units', 'linearityTurnoff', 'linearityMaxSignal',
175 'fitResidualsUnmasked', 'inputAbscissa', 'inputOrdinate',
176 'inputMask', 'inputGroupingIndex', 'fitResidualsModel',
177 'inputNormalization'])
178

Member Function Documentation

◆ __eq__()

lsst.ip.isr.calibType.IsrCalib.__eq__ ( self,
other )
inherited
Calibration equivalence.

Running ``calib.log.setLevel(0)`` enables debug statements to
identify problematic fields.

Definition at line 105 of file calibType.py.

105 def __eq__(self, other):
106 """Calibration equivalence.
107
108 Running ``calib.log.setLevel(0)`` enables debug statements to
109 identify problematic fields.
110 """
111 if not isinstance(other, self.__class__):
112 self.log.debug("Incorrect class type: %s %s", self.__class__, other.__class__)
113 return False
114
115 for attr in self._requiredAttributes:
116 attrSelf = getattr(self, attr)
117 attrOther = getattr(other, attr)
118
119 if isinstance(attrSelf, dict):
120 # Dictionary of arrays.
121 if attrSelf.keys() != attrOther.keys():
122 self.log.debug("Dict Key Failure: %s %s %s", attr, attrSelf.keys(), attrOther.keys())
123 return False
124 for key in attrSelf:
125 try:
126 if not np.allclose(attrSelf[key], attrOther[key], equal_nan=True):
127 self.log.debug("Array Failure: %s %s %s", key, attrSelf[key], attrOther[key])
128 return False
129 except TypeError:
130 # If it is not something numpy can handle
131 # (it's not a number or array of numbers),
132 # then it needs to have its own equivalence
133 # operator.
134 if np.all(attrSelf[key] != attrOther[key]):
135 return False
136 elif (isinstance(attrSelf, np.ndarray) or isinstance(attrSelf, Column)
137 or isinstance(attrOther, np.ndarray) or isinstance(attrOther, Column)):
138 # Bare array.
139 if isinstance(attrSelf[0], (str, np.str_, np.bytes_)):
140 if not np.all(attrSelf == attrOther):
141 self.log.debug("Array Failure: %s %s %s", attr, attrSelf, attrOther)
142 return False
143 else:
144 if not np.allclose(attrSelf, attrOther, equal_nan=True):
145 self.log.debug("Array Failure: %s %s %s", attr, attrSelf, attrOther)
146 return False
147 elif type(attrSelf) is not type(attrOther):
148 if set([attrSelf, attrOther]) == set([None, ""]):
149 # Fits converts None to "", but None is not "".
150 continue
151 self.log.debug("Type Failure: %s %s %s %s %s", attr, type(attrSelf), type(attrOther),
152 attrSelf, attrOther)
153 return False
154 else:
155 if attrSelf != attrOther:
156 self.log.debug("Value Failure: %s %s %s", attr, attrSelf, attrOther)
157 return False
158
159 return True
160

◆ __str__()

lsst.ip.isr.calibType.IsrCalib.__str__ ( self)
inherited

Definition at line 102 of file calibType.py.

102 def __str__(self):
103 return f"{self.__class__.__name__}(obstype={self._OBSTYPE}, detector={self._detectorName}, )"
104

◆ apply()

lsst.ip.isr.calibType.IsrCalib.apply ( self,
target )
inherited
Method to apply the calibration to the target object.

Parameters
----------
target : `object`
    Thing to validate against.

Returns
-------
valid : `bool`
    Returns true if the calibration was applied correctly.

Raises
------
NotImplementedError
    Raised if not implemented.

Definition at line 704 of file calibType.py.

704 def apply(self, target):
705 """Method to apply the calibration to the target object.
706
707 Parameters
708 ----------
709 target : `object`
710 Thing to validate against.
711
712 Returns
713 -------
714 valid : `bool`
715 Returns true if the calibration was applied correctly.
716
717 Raises
718 ------
719 NotImplementedError
720 Raised if not implemented.
721 """
722 raise NotImplementedError("Must be implemented by subclass.")
723
724

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

567 def applyLinearity(self, image, detector=None, log=None, gains=None):
568 """Apply the linearity to an image.
569
570 If the linearity parameters are populated, use those,
571 otherwise use the values from the detector.
572
573 Parameters
574 ----------
575 image : `~lsst.afw.image.image`
576 Image to correct.
577 detector : `~lsst.afw.cameraGeom.detector`, optional
578 Detector to use to determine exposure trimmed state. If
579 supplied, but no other linearity information is provided
580 by the calibration, then the static solution stored in the
581 detector will be used.
582 log : `~logging.Logger`, optional
583 Log object to use for logging.
584 gains : `dict` [`str`, `float`], optional
585 Dictionary of amp name to gain. If this is provided then
586 linearity terms will be converted from adu to electrons.
587 Only used for Spline linearity corrections.
588 """
589 if log is None:
590 log = self.log
591 if detector and not self.hasLinearity:
592 self.fromDetector(detector)
593
594 self.validate(detector)
595
596 # Check if the image is trimmed.
597 isTrimmed = None
598 if detector:
599 isTrimmed = isTrimmedImage(image, detector)
600
601 numAmps = 0
602 numLinearized = 0
603 numOutOfRange = 0
604 for ampName in self.linearityType.keys():
605 linearizer = self.getLinearityTypeByName(self.linearityType[ampName])
606 numAmps += 1
607
608 if gains and self.linearityUnits == 'adu':
609 gainValue = gains[ampName]
610 else:
611 gainValue = 1.0
612
613 if linearizer is not None:
614 match isTrimmed:
615 case True:
616 bbox = detector[ampName].getBBox()
617 case False:
618 bbox = detector[ampName].getRawBBox()
619 case None:
620 bbox = self.linearityBBox[ampName]
621
622 ampView = image.Factory(image, bbox)
623 success, outOfRange = linearizer()(ampView, **{'coeffs': self.linearityCoeffs[ampName],
624 'table': self.tableData,
625 'log': self.log,
626 'gain': gainValue})
627 numOutOfRange += outOfRange
628 if success:
629 numLinearized += 1
630 elif log is not None:
631 log.warning("Amplifier %s did not linearize.",
632 ampName)
633 return Struct(
634 numAmps=numAmps,
635 numLinearized=numLinearized,
636 numOutOfRange=numOutOfRange
637 )
638
639

◆ calibInfoFromDict()

lsst.ip.isr.calibType.IsrCalib.calibInfoFromDict ( self,
dictionary )
inherited
Handle common keywords.

This isn't an ideal solution, but until all calibrations
expect to find everything in the metadata, they still need to
search through dictionaries.

Parameters
----------
dictionary : `dict` or `lsst.daf.base.PropertyList`
    Source for the common keywords.

Raises
------
RuntimeError
    Raised if the dictionary does not match the expected OBSTYPE.

Definition at line 325 of file calibType.py.

325 def calibInfoFromDict(self, dictionary):
326 """Handle common keywords.
327
328 This isn't an ideal solution, but until all calibrations
329 expect to find everything in the metadata, they still need to
330 search through dictionaries.
331
332 Parameters
333 ----------
334 dictionary : `dict` or `lsst.daf.base.PropertyList`
335 Source for the common keywords.
336
337 Raises
338 ------
339 RuntimeError
340 Raised if the dictionary does not match the expected OBSTYPE.
341 """
342
343 def search(haystack, needles):
344 """Search dictionary 'haystack' for an entry in 'needles'
345 """
346 test = [haystack.get(x) for x in needles]
347 test = set([x for x in test if x is not None])
348 if len(test) == 0:
349 if "metadata" in haystack:
350 return search(haystack["metadata"], needles)
351 else:
352 return None
353 elif len(test) == 1:
354 value = list(test)[0]
355 if value == "":
356 return None
357 else:
358 return value
359 else:
360 raise ValueError(f"Too many values found: {len(test)} {test} {needles}")
361
362 if "metadata" in dictionary:
363 metadata = dictionary["metadata"]
364
365 if self._OBSTYPE != metadata["OBSTYPE"]:
366 raise RuntimeError(f"Incorrect calibration supplied. Expected {self._OBSTYPE}, "
367 f"found {metadata['OBSTYPE']}")
368
369 if (value := search(dictionary, ["INSTRUME", "instrument"])) is not None:
370 self._instrument = value
371 if (value := search(dictionary, ["RAFTNAME"])) is not None:
372 self._slotName = value
373 if (value := search(dictionary, ["DETECTOR", "detectorId"])) is not None:
374 self._detectorId = value
375 if (value := search(dictionary, ["DET_NAME", "DETECTOR_NAME", "detectorName"])) is not None:
376 self._detectorName = value
377 if (value := search(dictionary, ["DET_SER", "DETECTOR_SERIAL", "detectorSerial"])) is not None:
378 self._detectorSerial = value
379 if (value := search(dictionary, ["FILTER", "filterName"])) is not None:
380 self._filter = value
381 if (value := search(dictionary, ["CALIB_ID"])) is not None:
382 self._calibId = value
383 if (value := search(dictionary, ["SEQFILE"])) is not None:
384 self._seqfile = value
385 if (value := search(dictionary, ["SEQNAME"])) is not None:
386 self._seqname = value
387 if (value := search(dictionary, ["SEQCKSUM"])) is not None:
388 self._seqcksum = value
389

◆ determineCalibClass()

lsst.ip.isr.calibType.IsrCalib.determineCalibClass ( cls,
metadata,
message )
inherited
Attempt to find calibration class in metadata.

Parameters
----------
metadata : `dict` or `lsst.daf.base.PropertyList`
    Metadata possibly containing a calibration class entry.
message : `str`
    Message to include in any errors.

Returns
-------
calibClass : `object`
    The class to use to read the file contents.  Should be an
    `lsst.ip.isr.IsrCalib` subclass.

Raises
------
ValueError
    Raised if the resulting calibClass is the base
    `lsst.ip.isr.IsrClass` (which does not implement the
    content methods).

Definition at line 391 of file calibType.py.

391 def determineCalibClass(cls, metadata, message):
392 """Attempt to find calibration class in metadata.
393
394 Parameters
395 ----------
396 metadata : `dict` or `lsst.daf.base.PropertyList`
397 Metadata possibly containing a calibration class entry.
398 message : `str`
399 Message to include in any errors.
400
401 Returns
402 -------
403 calibClass : `object`
404 The class to use to read the file contents. Should be an
405 `lsst.ip.isr.IsrCalib` subclass.
406
407 Raises
408 ------
409 ValueError
410 Raised if the resulting calibClass is the base
411 `lsst.ip.isr.IsrClass` (which does not implement the
412 content methods).
413 """
414 calibClassName = metadata.get("CALIBCLS")
415 if calibClassName is None:
416 calibClassName = metadata.get("fileType")
417 if calibClassName == "shutterMotionProfile":
418 calibClassName = "lsst.ip.isr.ShutterMotionProfile"
419 calibClass = doImport(calibClassName) if calibClassName is not None else cls
420 if calibClass is IsrCalib:
421 raise ValueError(f"Cannot use base class to read calibration data: {message}")
422 return calibClass
423

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

200 def fromDetector(self, detector):
201 """Read linearity parameters from a detector.
202
203 Parameters
204 ----------
205 detector : `lsst.afw.cameraGeom.detector`
206 Input detector with parameters to use.
207
208 Returns
209 -------
210 calib : `lsst.ip.isr.Linearizer`
211 The calibration constructed from the detector.
212 """
213 self._detectorName = detector.getName()
214 self._detectorSerial = detector.getSerial()
215 self._detectorId = detector.getId()
216 self.hasLinearity = True
217
218 # Do not translate Threshold, Maximum, Units.
219 for amp in detector.getAmplifiers():
220 ampName = amp.getName()
221 self.ampNames.append(ampName)
222 self.linearityType[ampName] = amp.getLinearityType()
223 self.linearityCoeffs[ampName] = amp.getLinearityCoeffs()
224 self.linearityBBox[ampName] = amp.getBBox()
225
226 # Detector linearizers (legacy) are assumed to be adu units.
227 self.linearityUnits = 'adu'
228
229 return self
230

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

232 def fromDict(cls, dictionary):
233 """Construct a calibration from a dictionary of properties
234
235 Parameters
236 ----------
237 dictionary : `dict`
238 Dictionary of properties
239
240 Returns
241 -------
242 calib : `lsst.ip.isr.Linearity`
243 Constructed calibration.
244
245 Raises
246 ------
247 RuntimeError
248 Raised if the supplied dictionary is for a different
249 calibration.
250 """
251
252 calib = cls()
253
254 if calib._OBSTYPE != dictionary['metadata']['OBSTYPE']:
255 raise RuntimeError(f"Incorrect linearity supplied. Expected {calib._OBSTYPE}, "
256 f"found {dictionary['metadata']['OBSTYPE']}")
257
258 calib.setMetadata(dictionary['metadata'])
259
260 calib.hasLinearity = dictionary.get('hasLinearity',
261 dictionary['metadata'].get('HAS_LINEARITY', False))
262 calib.override = dictionary.get('override', True)
263
264 # Old linearizers which do not have linearityUnits are
265 # assumed to be adu because that's all that has been
266 # supported.
267 calib.linearityUnits = dictionary.get('linearityUnits', 'adu')
268
269 if calib.hasLinearity:
270 for ampName in dictionary['amplifiers']:
271 amp = dictionary['amplifiers'][ampName]
272 calib.ampNames.append(ampName)
273 calib.linearityCoeffs[ampName] = np.array(amp.get('linearityCoeffs', [0.0]))
274 calib.linearityType[ampName] = amp.get('linearityType', 'None')
275 calib.linearityBBox[ampName] = amp.get('linearityBBox', None)
276
277 calib.inputAbscissa[ampName] = np.array(amp.get('inputAbscissa', [0.0]))
278 calib.inputOrdinate[ampName] = np.array(amp.get('inputOrdinate', [0.0]))
279 calib.inputMask[ampName] = np.array(amp.get('inputMask', [False]))
280 calib.inputGroupingIndex[ampName] = np.array(amp.get('inputGroupingIndex', [0.0]))
281 calib.inputNormalization[ampName] = np.array(amp.get('inputNormalization', [1.0]))
282
283 calib.fitParams[ampName] = np.array(amp.get('fitParams', [0.0]))
284 calib.fitParamsErr[ampName] = np.array(amp.get('fitParamsErr', [0.0]))
285 calib.fitChiSq[ampName] = amp.get('fitChiSq', np.nan)
286 calib.fitResiduals[ampName] = np.array(amp.get('fitResiduals', [0.0]))
287 calib.fitResidualsSigmaMad[ampName] = np.array(amp.get('fitResidualsSigmaMad', np.nan))
288 calib.fitResidualsUnmasked[ampName] = np.array(amp.get('fitResidualsUnmasked', [0.0]))
289 calib.fitResidualsModel[ampName] = np.array(amp.get('fitResidualsModel', [0.0]))
290 calib.linearFit[ampName] = np.array(amp.get('linearFit', [0.0]))
291
292 calib.linearityTurnoff[ampName] = np.array(amp.get('linearityTurnoff', np.nan))
293 calib.linearityMaxSignal[ampName] = np.array(amp.get('linearityMaxSignal', np.nan))
294
295 calib.tableData = dictionary.get('tableData', None)
296 if calib.tableData:
297 calib.tableData = np.array(calib.tableData)
298
299 return calib
300

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

345 def fromTable(cls, tableList):
346 """Read linearity from a FITS file.
347
348 This method uses the `fromDict` method to create the
349 calibration, after constructing an appropriate dictionary from
350 the input tables.
351
352 Parameters
353 ----------
354 tableList : `list` [`astropy.table.Table`]
355 afwTable read from input file name.
356
357 Returns
358 -------
359 linearity : `~lsst.ip.isr.linearize.Linearizer``
360 Linearity parameters.
361
362 Notes
363 -----
364 The method reads a FITS file with 1 or 2 extensions. The metadata is
365 read from the header of extension 1, which must exist. Then the table
366 is loaded, and the ['AMPLIFIER_NAME', 'TYPE', 'COEFFS', 'BBOX_X0',
367 'BBOX_Y0', 'BBOX_DX', 'BBOX_DY'] columns are read and used to set each
368 dictionary by looping over rows.
369 Extension 2 is then attempted to read in the try block (which only
370 exists for lookup tables). It has a column named 'LOOKUP_VALUES' that
371 contains a vector of the lookup entries in each row.
372 """
373 coeffTable = tableList[0]
374
375 metadata = coeffTable.meta
376 inDict = dict()
377 inDict['metadata'] = metadata
378 inDict['hasLinearity'] = metadata.get('HAS_LINEARITY', False)
379 inDict['amplifiers'] = dict()
380 inDict['linearityUnits'] = metadata.get('LINEARITY_UNITS', 'adu')
381
382 for record in coeffTable:
383 ampName = record['AMPLIFIER_NAME']
384
385 inputAbscissa = record['INP_ABSCISSA'] if 'INP_ABSCISSA' in record.columns else np.array([0.0])
386 inputOrdinate = record['INP_ORDINATE'] if 'INP_ORDINATE' in record.columns else np.array([0.0])
387 inputMask = record['INP_MASK'] if 'INP_MASK' in record.columns else np.array([False])
388 inputGroupingIndex = record['INP_GROUPING_INDEX'] if 'INP_GROUPING_INDEX' in record.columns \
389 else np.array([0])
390 inputNormalization = record['INP_NORMALIZATION'] if 'INP_NORMALIZATION' in record.columns \
391 else np.array([1.0])
392 fitParams = record['FIT_PARAMS'] if 'FIT_PARAMS' in record.columns else np.array([0.0])
393 fitParamsErr = record['FIT_PARAMS_ERR'] if 'FIT_PARAMS_ERR' in record.columns else np.array([0.0])
394 fitChiSq = record['RED_CHI_SQ'] if 'RED_CHI_SQ' in record.columns else np.nan
395 fitResiduals = record['FIT_RES'] if 'FIT_RES' in record.columns else np.array([0.0])
396 fitResidualsSigmaMad = record['FIT_RES_SIGMAD'] if 'FIT_RES_SIGMAD' in record.columns else np.nan
397 fitResidualsUnmasked = record['FIT_RES_UNMASKED'] \
398 if 'FIT_RES_UNMASKED' in record.columns else np.array([0.0])
399 fitResidualsModel = record['FIT_RES_MODEL'] \
400 if 'FIT_RES_MODEL' in record.columns else np.array([0.0])
401 linearFit = record['LIN_FIT'] if 'LIN_FIT' in record.columns else np.array([0.0])
402
403 linearityTurnoff = record['LINEARITY_TURNOFF'] if 'LINEARITY_TURNOFF' in record.columns \
404 else np.nan
405 linearityMaxSignal = record['LINEARITY_MAX_SIGNAL'] if 'LINEARITY_MAX_SIGNAL' in record.columns \
406 else np.nan
407
408 inDict['amplifiers'][ampName] = {
409 'linearityType': record['TYPE'],
410 'linearityCoeffs': record['COEFFS'],
411 'linearityBBox': Box2I(Point2I(record['BBOX_X0'], record['BBOX_Y0']),
412 Extent2I(record['BBOX_DX'], record['BBOX_DY'])),
413 'inputAbscissa': inputAbscissa,
414 'inputOrdinate': inputOrdinate,
415 'inputMask': inputMask,
416 'inputGroupingIndex': inputGroupingIndex,
417 'inputNormalization': inputNormalization,
418 'fitParams': fitParams,
419 'fitParamsErr': fitParamsErr,
420 'fitChiSq': fitChiSq,
421 'fitResiduals': fitResiduals,
422 'fitResidualsSigmaMad': fitResidualsSigmaMad,
423 'fitResidualsUnmasked': fitResidualsUnmasked,
424 'fitResidualsModel': fitResidualsModel,
425 'linearFit': linearFit,
426 'linearityTurnoff': linearityTurnoff,
427 'linearityMaxSignal': linearityMaxSignal,
428 }
429
430 if len(tableList) > 1:
431 tableData = tableList[1]
432 inDict['tableData'] = [record['LOOKUP_VALUES'] for record in tableData]
433
434 return cls().fromDict(inDict)
435

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

483 def getLinearityTypeByName(self, linearityTypeName):
484 """Determine the linearity class to use from the type name.
485
486 Parameters
487 ----------
488 linearityTypeName : str
489 String name of the linearity type that is needed.
490
491 Returns
492 -------
493 linearityType : `~lsst.ip.isr.linearize.LinearizeBase`
494 The appropriate linearity class to use. If no matching class
495 is found, `None` is returned.
496 """
497 for t in [LinearizeLookupTable,
498 LinearizeSquared,
499 LinearizePolynomial,
500 LinearizeProportional,
501 LinearizeSpline,
502 LinearizeNone]:
503 if t.LinearityType == linearityTypeName:
504 return t
505 return None
506

◆ getMetadata()

lsst.ip.isr.calibType.IsrCalib.getMetadata ( self)
inherited
Retrieve metadata associated with this calibration.

Returns
-------
meta : `lsst.daf.base.PropertyList`
    Metadata. The returned `~lsst.daf.base.PropertyList` can be
    modified by the caller and the changes will be written to
    external files.

Definition at line 174 of file calibType.py.

174 def getMetadata(self):
175 """Retrieve metadata associated with this calibration.
176
177 Returns
178 -------
179 meta : `lsst.daf.base.PropertyList`
180 Metadata. The returned `~lsst.daf.base.PropertyList` can be
181 modified by the caller and the changes will be written to
182 external files.
183 """
184 return self._metadata
185

◆ metadata()

lsst.ip.isr.calibType.IsrCalib.metadata ( self)
inherited

Definition at line 171 of file calibType.py.

171 def metadata(self):
172 return self._metadata
173

◆ readFits()

lsst.ip.isr.calibType.IsrCalib.readFits ( cls,
filename,
** kwargs )
inherited
Read calibration data from a FITS file.

Parameters
----------
filename : `str`
    Filename to read data from.
kwargs : `dict` or collections.abc.Mapping`, optional
    Set of key=value pairs to pass to the ``fromTable``
    method.

Returns
-------
calib : `lsst.ip.isr.IsrCalib`
    Calibration contained within the file.

Definition at line 517 of file calibType.py.

517 def readFits(cls, filename, **kwargs):
518 """Read calibration data from a FITS file.
519
520 Parameters
521 ----------
522 filename : `str`
523 Filename to read data from.
524 kwargs : `dict` or collections.abc.Mapping`, optional
525 Set of key=value pairs to pass to the ``fromTable``
526 method.
527
528 Returns
529 -------
530 calib : `lsst.ip.isr.IsrCalib`
531 Calibration contained within the file.
532 """
533 tableList = []
534 tableList.append(Table.read(filename, hdu=1, mask_invalid=False))
535 extNum = 2 # Fits indices start at 1, we've read one already.
536 keepTrying = True
537
538 while keepTrying:
539 with warnings.catch_warnings():
540 warnings.simplefilter("error")
541 try:
542 newTable = Table.read(filename, hdu=extNum, mask_invalid=False)
543 tableList.append(newTable)
544 extNum += 1
545 except Exception:
546 keepTrying = False
547
548 for table in tableList:
549 for k, v in table.meta.items():
550 if isinstance(v, fits.card.Undefined):
551 table.meta[k] = None
552
553 calibClass = cls.determineCalibClass(tableList[0].meta, "readFits")
554 if calibClass._OBSTYPE in ("PHOTODIODE", ):
555 # Merge primary header, as these types store information
556 # there.
557 with fits.open(filename) as hdul:
558 primaryHeader = hdul[0].header
559 tableList[0].meta = merge_headers([tableList[0].meta, primaryHeader], mode="first")
560
561 return calibClass.fromTable(tableList, **kwargs)
562

◆ readText()

lsst.ip.isr.calibType.IsrCalib.readText ( cls,
filename,
** kwargs )
inherited
Read calibration representation from a yaml/ecsv file.

Parameters
----------
filename : `str`
    Name of the file containing the calibration definition.
kwargs : `dict` or collections.abc.Mapping`, optional
    Set of key=value pairs to pass to the ``fromDict`` or
    ``fromTable`` methods.

Returns
-------
calib : `~lsst.ip.isr.IsrCalibType`
    Calibration class.

Raises
------
RuntimeError
    Raised if the filename does not end in ".ecsv" or ".yaml".

Definition at line 425 of file calibType.py.

425 def readText(cls, filename, **kwargs):
426 """Read calibration representation from a yaml/ecsv file.
427
428 Parameters
429 ----------
430 filename : `str`
431 Name of the file containing the calibration definition.
432 kwargs : `dict` or collections.abc.Mapping`, optional
433 Set of key=value pairs to pass to the ``fromDict`` or
434 ``fromTable`` methods.
435
436 Returns
437 -------
438 calib : `~lsst.ip.isr.IsrCalibType`
439 Calibration class.
440
441 Raises
442 ------
443 RuntimeError
444 Raised if the filename does not end in ".ecsv" or ".yaml".
445 """
446 if filename.endswith((".ecsv", ".ECSV")):
447 data = Table.read(filename, format="ascii.ecsv")
448 calibClass = cls.determineCalibClass(data.meta, "readText/ECSV")
449 return calibClass.fromTable([data], **kwargs)
450 elif filename.endswith((".yaml", ".YAML")):
451 with open(filename, "r") as f:
452 data = yaml.load(f, Loader=yaml.CLoader)
453 calibClass = cls.determineCalibClass(data["metadata"], "readText/YAML")
454 return calibClass.fromDict(data, **kwargs)
455 elif filename.endswith((".json", ".JSON")):
456 with open(filename, "r") as f:
457 data = json.load(f)
458 calibClass = cls.determineCalibClass(data, "readText/JSON")
459 return calibClass.fromDict(data, **kwargs)
460 else:
461 raise RuntimeError(f"Unknown filename extension: {filename}")
462

◆ requiredAttributes() [1/2]

lsst.ip.isr.calibType.IsrCalib.requiredAttributes ( self)
inherited

Definition at line 162 of file calibType.py.

162 def requiredAttributes(self):
163 return self._requiredAttributes
164

◆ requiredAttributes() [2/2]

lsst.ip.isr.calibType.IsrCalib.requiredAttributes ( self,
value )
inherited

Definition at line 166 of file calibType.py.

166 def requiredAttributes(self, value):
167 self._requiredAttributes = value
168

◆ setMetadata()

lsst.ip.isr.calibType.IsrCalib.setMetadata ( self,
metadata )
inherited
Store a copy of the supplied metadata with this calibration.

Parameters
----------
metadata : `lsst.daf.base.PropertyList`
    Metadata to associate with the calibration.  Will be copied and
    overwrite existing metadata.

Reimplemented in lsst.ip.isr.transmissionCurve.IntermediateTransmissionCurve.

Definition at line 186 of file calibType.py.

186 def setMetadata(self, metadata):
187 """Store a copy of the supplied metadata with this calibration.
188
189 Parameters
190 ----------
191 metadata : `lsst.daf.base.PropertyList`
192 Metadata to associate with the calibration. Will be copied and
193 overwrite existing metadata.
194 """
195 if metadata is not None:
196 self._metadata.update(metadata)
197
198 # Ensure that we have the obs type required by calibration ingest
199 self._metadata["OBSTYPE"] = self._OBSTYPE
200 self._metadata[self._OBSTYPE + "_SCHEMA"] = self._SCHEMA
201 self._metadata[self._OBSTYPE + "_VERSION"] = self._VERSION
202
203 if isinstance(metadata, dict):
204 self.calibInfoFromDict(metadata)
205 elif isinstance(metadata, PropertyList):
206 self.calibInfoFromDict(metadata.toDict())
207

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

301 def toDict(self):
302 """Return linearity parameters as a dict.
303
304 Returns
305 -------
306 outDict : `dict`:
307 """
308 self.updateMetadata()
309
310 outDict = {'metadata': self.getMetadata(),
311 'detectorName': self._detectorName,
312 'detectorSerial': self._detectorSerial,
313 'detectorId': self._detectorId,
314 'hasTable': self.tableData is not None,
315 'amplifiers': dict(),
316 'linearityUnits': self.linearityUnits,
317 }
318 for ampName in self.linearityType:
319 outDict['amplifiers'][ampName] = {
320 'linearityType': self.linearityType[ampName],
321 'linearityCoeffs': self.linearityCoeffs[ampName].tolist(),
322 'linearityBBox': self.linearityBBox[ampName],
323 'inputAbscissa': self.inputAbscissa[ampName].tolist(),
324 'inputOrdinate': self.inputOrdinate[ampName].tolist(),
325 'inputMask': self.inputMask[ampName].tolist(),
326 'inputGroupingIndex': self.inputGroupingIndex[ampName].tolist(),
327 'inputNormalization': self.inputNormalization[ampName].tolist(),
328 'fitParams': self.fitParams[ampName].tolist(),
329 'fitParamsErr': self.fitParamsErr[ampName].tolist(),
330 'fitChiSq': self.fitChiSq[ampName],
331 'fitResiduals': self.fitResiduals[ampName].tolist(),
332 'fitResidualsSigmaMad': self.fitResidualsSigmaMad[ampName],
333 'fitResidualsUnmasked': self.fitResidualsUnmasked[ampName].tolist(),
334 'fitResidualsModel': self.fitResidualsModel[ampName].tolist(),
335 'linearFit': self.linearFit[ampName].tolist(),
336 'linearityTurnoff': self.linearityTurnoff[ampName],
337 'linearityMaxSignal': self.linearityMaxSignal[ampName],
338 }
339 if self.tableData is not None:
340 outDict['tableData'] = self.tableData.tolist()
341
342 return outDict
343

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

436 def toTable(self):
437 """Construct a list of tables containing the information in this
438 calibration.
439
440 The list of tables should create an identical calibration
441 after being passed to this class's fromTable method.
442
443 Returns
444 -------
445 tableList : `list` [`astropy.table.Table`]
446 List of tables containing the linearity calibration
447 information.
448 """
449
450 tableList = []
451 self.updateMetadata()
452 catalog = Table([{'AMPLIFIER_NAME': ampName,
453 'TYPE': self.linearityType[ampName],
454 'COEFFS': self.linearityCoeffs[ampName],
455 'BBOX_X0': self.linearityBBox[ampName].getMinX(),
456 'BBOX_Y0': self.linearityBBox[ampName].getMinY(),
457 'BBOX_DX': self.linearityBBox[ampName].getWidth(),
458 'BBOX_DY': self.linearityBBox[ampName].getHeight(),
459 'INP_ABSCISSA': self.inputAbscissa[ampName],
460 'INP_ORDINATE': self.inputOrdinate[ampName],
461 'INP_MASK': self.inputMask[ampName],
462 'INP_GROUPING_INDEX': self.inputGroupingIndex[ampName],
463 'INP_NORMALIZATION': self.inputNormalization[ampName],
464 'FIT_PARAMS': self.fitParams[ampName],
465 'FIT_PARAMS_ERR': self.fitParamsErr[ampName],
466 'RED_CHI_SQ': self.fitChiSq[ampName],
467 'FIT_RES': self.fitResiduals[ampName],
468 'FIT_RES_SIGMAD': self.fitResidualsSigmaMad[ampName],
469 'FIT_RES_UNMASKED': self.fitResidualsUnmasked[ampName],
470 'FIT_RES_MODEL': self.fitResidualsModel[ampName],
471 'LIN_FIT': self.linearFit[ampName],
472 'LINEARITY_TURNOFF': self.linearityTurnoff[ampName],
473 'LINEARITY_MAX_SIGNAL': self.linearityMaxSignal[ampName],
474 } for ampName in self.ampNames])
475 catalog.meta = self.getMetadata().toDict()
476 tableList.append(catalog)
477
478 if self.tableData is not None:
479 catalog = Table([{'LOOKUP_VALUES': value} for value in self.tableData])
480 tableList.append(catalog)
481 return tableList
482

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

179 def updateMetadata(self, setDate=False, **kwargs):
180 """Update metadata keywords with new values.
181
182 This calls the base class's method after ensuring the required
183 calibration keywords will be saved.
184
185 Parameters
186 ----------
187 setDate : `bool`, optional
188 Update the CALIBDATE fields in the metadata to the current
189 time. Defaults to False.
190 kwargs :
191 Other keyword parameters to set in the metadata.
192 """
193 kwargs['HAS_LINEARITY'] = self.hasLinearity
194 kwargs['OVERRIDE'] = self.override
195 kwargs['HAS_TABLE'] = self.tableData is not None
196 kwargs['LINEARITY_UNITS'] = self.linearityUnits
197
198 super().updateMetadata(setDate=setDate, **kwargs)
199

◆ updateMetadataFromExposures()

lsst.ip.isr.calibType.IsrCalib.updateMetadataFromExposures ( self,
exposures )
inherited
Extract and unify metadata information.

Parameters
----------
exposures : `list`
    Exposures or other calibrations to scan.

Definition at line 294 of file calibType.py.

294 def updateMetadataFromExposures(self, exposures):
295 """Extract and unify metadata information.
296
297 Parameters
298 ----------
299 exposures : `list`
300 Exposures or other calibrations to scan.
301 """
302 # This list of keywords is the set of header entries that
303 # should be checked and propagated. Not having an entry is
304 # not a failure, as they may not be defined for the exposures
305 # being used.
306 keywords = ["SEQNAME", "SEQFILE", "SEQCKSUM", "ODP", "AP0_RC"]
307 metadata = {}
308
309 for exp in exposures:
310 try:
311 expMeta = exp.getMetadata()
312 except AttributeError:
313 continue
314 for key in keywords:
315 if key in expMeta:
316 if key in metadata:
317 if metadata[key] != expMeta[key]:
318 self.log.warning("Metadata mismatch! Have: %s Found %s",
319 metadata[key], expMeta[key])
320 else:
321 metadata[key] = expMeta[key]
322
323 self.updateMetadata(**metadata, setCalibInfo=True)
324

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

507 def validate(self, detector=None, amplifier=None):
508 """Validate linearity for a detector/amplifier.
509
510 Parameters
511 ----------
512 detector : `lsst.afw.cameraGeom.Detector`, optional
513 Detector to validate, along with its amplifiers.
514 amplifier : `lsst.afw.cameraGeom.Amplifier`, optional
515 Single amplifier to validate.
516
517 Raises
518 ------
519 RuntimeError
520 Raised if there is a mismatch in linearity parameters, and
521 the cameraGeom parameters are not being overridden.
522 """
523 amplifiersToCheck = []
524 if detector:
525 if self._detectorName != detector.getName():
526 raise RuntimeError("Detector names don't match: %s != %s" %
527 (self._detectorName, detector.getName()))
528 if int(self._detectorId) != int(detector.getId()):
529 raise RuntimeError("Detector IDs don't match: %s != %s" %
530 (int(self._detectorId), int(detector.getId())))
531 # TODO: DM-38778: This check fails on LATISS due to an
532 # error in the camera configuration.
533 # if self._detectorSerial != detector.getSerial():
534 # raise RuntimeError(
535 # "Detector serial numbers don't match: %s != %s" %
536 # (self._detectorSerial, detector.getSerial()))
537 if len(detector.getAmplifiers()) != len(self.linearityCoeffs.keys()):
538 raise RuntimeError("Detector number of amps = %s does not match saved value %s" %
539 (len(detector.getAmplifiers()),
540 len(self.linearityCoeffs.keys())))
541 amplifiersToCheck.extend(detector.getAmplifiers())
542
543 if amplifier:
544 amplifiersToCheck.extend(amplifier)
545
546 for amp in amplifiersToCheck:
547 ampName = amp.getName()
548 if ampName not in self.linearityCoeffs.keys():
549 raise RuntimeError("Amplifier %s is not in linearity data" %
550 (ampName, ))
551 if amp.getLinearityType() != self.linearityType[ampName]:
552 if self.override:
553 self.log.debug("Overriding amplifier defined linearityType (%s) for %s",
554 self.linearityType[ampName], ampName)
555 else:
556 raise RuntimeError("Amplifier %s type %s does not match saved value %s" %
557 (ampName, amp.getLinearityType(), self.linearityType[ampName]))
558 if (amp.getLinearityCoeffs().shape != self.linearityCoeffs[ampName].shape or not
559 np.allclose(amp.getLinearityCoeffs(), self.linearityCoeffs[ampName], equal_nan=True)):
560 if self.override:
561 self.log.debug("Overriding amplifier defined linearityCoeffs (%s) for %s",
562 self.linearityCoeffs[ampName], ampName)
563 else:
564 raise RuntimeError("Amplifier %s coeffs %s does not match saved value %s" %
565 (ampName, amp.getLinearityCoeffs(), self.linearityCoeffs[ampName]))
566

◆ writeFits()

lsst.ip.isr.calibType.IsrCalib.writeFits ( self,
filename )
inherited
Write calibration data to a FITS file.

Parameters
----------
filename : `str`
    Filename to write data to.

Returns
-------
used : `str`
    The name of the file used to write the data.

Reimplemented in lsst.ip.isr.transmissionCurve.IntermediateTransmissionCurve.

Definition at line 563 of file calibType.py.

563 def writeFits(self, filename):
564 """Write calibration data to a FITS file.
565
566 Parameters
567 ----------
568 filename : `str`
569 Filename to write data to.
570
571 Returns
572 -------
573 used : `str`
574 The name of the file used to write the data.
575 """
576 tableList = self.toTable()
577 with warnings.catch_warnings():
578 warnings.filterwarnings("ignore", category=Warning, module="astropy.io")
579 astropyList = [fits.table_to_hdu(table) for table in tableList]
580 astropyList.insert(0, fits.PrimaryHDU())
581
582 writer = fits.HDUList(astropyList)
583 writer.writeto(filename, overwrite=True)
584 return filename
585

◆ writeText()

lsst.ip.isr.calibType.IsrCalib.writeText ( self,
filename,
format = "auto" )
inherited
Write the calibration data to a text file.

Parameters
----------
filename : `str`
    Name of the file to write.
format : `str`
    Format to write the file as.  Supported values are:
        ``"auto"`` : Determine filetype from filename.
        ``"yaml"`` : Write as yaml.
        ``"ecsv"`` : Write as ecsv.

Returns
-------
used : `str`
    The name of the file used to write the data.  This may
    differ from the input if the format is explicitly chosen.

Raises
------
RuntimeError
    Raised if filename does not end in a known extension, or
    if all information cannot be written.

Notes
-----
The file is written to YAML/ECSV format and will include any
associated metadata.

Definition at line 463 of file calibType.py.

463 def writeText(self, filename, format="auto"):
464 """Write the calibration data to a text file.
465
466 Parameters
467 ----------
468 filename : `str`
469 Name of the file to write.
470 format : `str`
471 Format to write the file as. Supported values are:
472 ``"auto"`` : Determine filetype from filename.
473 ``"yaml"`` : Write as yaml.
474 ``"ecsv"`` : Write as ecsv.
475
476 Returns
477 -------
478 used : `str`
479 The name of the file used to write the data. This may
480 differ from the input if the format is explicitly chosen.
481
482 Raises
483 ------
484 RuntimeError
485 Raised if filename does not end in a known extension, or
486 if all information cannot be written.
487
488 Notes
489 -----
490 The file is written to YAML/ECSV format and will include any
491 associated metadata.
492 """
493 if format == "yaml" or (format == "auto" and filename.lower().endswith((".yaml", ".YAML"))):
494 outDict = self.toDict()
495 path, ext = os.path.splitext(filename)
496 filename = path + ".yaml"
497 with open(filename, "w") as f:
498 yaml.dump(outDict, f)
499 elif format == "ecsv" or (format == "auto" and filename.lower().endswith((".ecsv", ".ECSV"))):
500 tableList = self.toTable()
501 if len(tableList) > 1:
502 # ECSV doesn't support multiple tables per file, so we
503 # can only write the first table.
504 raise RuntimeError(f"Unable to persist {len(tableList)}tables in ECSV format.")
505
506 table = tableList[0]
507 path, ext = os.path.splitext(filename)
508 filename = path + ".ecsv"
509 table.write(filename, format="ascii.ecsv")
510 else:
511 raise RuntimeError(f"Attempt to write to a file {filename} "
512 "that does not end in '.yaml' or '.ecsv'")
513
514 return filename
515

Member Data Documentation

◆ _calibId

str lsst.ip.isr.calibType.IsrCalib._calibId = None
protectedinherited

Definition at line 76 of file calibType.py.

◆ _detectorId

lsst.ip.isr.calibType.IsrCalib._detectorId = None
protectedinherited

Definition at line 74 of file calibType.py.

◆ _detectorName

lsst.ip.isr.calibType.IsrCalib._detectorName = None
protectedinherited

Definition at line 72 of file calibType.py.

◆ _detectorSerial

lsst.ip.isr.calibType.IsrCalib._detectorSerial = None
protectedinherited

Definition at line 73 of file calibType.py.

◆ _filter

lsst.ip.isr.calibType.IsrCalib._filter = None
protectedinherited

Definition at line 75 of file calibType.py.

◆ _instrument

lsst.ip.isr.calibType.IsrCalib._instrument = None
protectedinherited

Definition at line 69 of file calibType.py.

◆ _metadata

lsst.ip.isr.calibType.IsrCalib._metadata = PropertyList()
protectedinherited

Definition at line 80 of file calibType.py.

◆ _OBSTYPE

str lsst.ip.isr.calibType.IsrCalib._OBSTYPE = "generic"
staticprotectedinherited

Definition at line 64 of file calibType.py.

◆ _raftName

lsst.ip.isr.calibType.IsrCalib._raftName = None
protectedinherited

Definition at line 70 of file calibType.py.

◆ _requiredAttributes

lsst.ip.isr.calibType.IsrCalib._requiredAttributes
protectedinherited

Definition at line 115 of file calibType.py.

◆ _SCHEMA

str lsst.ip.isr.calibType.IsrCalib._SCHEMA = "NO SCHEMA"
staticprotectedinherited

Definition at line 65 of file calibType.py.

◆ _seqcksum

lsst.ip.isr.calibType.IsrCalib._seqcksum = None
protectedinherited

Definition at line 79 of file calibType.py.

◆ _seqfile

lsst.ip.isr.calibType.IsrCalib._seqfile = None
protectedinherited

Definition at line 77 of file calibType.py.

◆ _seqname

lsst.ip.isr.calibType.IsrCalib._seqname = None
protectedinherited

Definition at line 78 of file calibType.py.

◆ _slotName

lsst.ip.isr.calibType.IsrCalib._slotName = None
protectedinherited

Definition at line 71 of file calibType.py.

◆ _VERSION

int lsst.ip.isr.calibType.IsrCalib._VERSION = 0
staticprotectedinherited

Definition at line 66 of file calibType.py.

◆ ampNames

lsst.ip.isr.linearize.Linearizer.ampNames = list()

Definition at line 137 of file linearize.py.

◆ fitChiSq

lsst.ip.isr.linearize.Linearizer.fitChiSq = dict()

Definition at line 148 of file linearize.py.

◆ fitParams

lsst.ip.isr.linearize.Linearizer.fitParams = dict()

Definition at line 146 of file linearize.py.

◆ fitParamsErr

lsst.ip.isr.linearize.Linearizer.fitParamsErr = dict()

Definition at line 147 of file linearize.py.

◆ fitResiduals

lsst.ip.isr.linearize.Linearizer.fitResiduals = dict()

Definition at line 149 of file linearize.py.

◆ fitResidualsModel

lsst.ip.isr.linearize.Linearizer.fitResidualsModel = dict()

Definition at line 152 of file linearize.py.

◆ fitResidualsSigmaMad

lsst.ip.isr.linearize.Linearizer.fitResidualsSigmaMad = dict()

Definition at line 150 of file linearize.py.

◆ fitResidualsUnmasked

lsst.ip.isr.linearize.Linearizer.fitResidualsUnmasked = dict()

Definition at line 151 of file linearize.py.

◆ hasLinearity

bool lsst.ip.isr.linearize.Linearizer.hasLinearity = False

Definition at line 134 of file linearize.py.

◆ inputAbscissa

lsst.ip.isr.linearize.Linearizer.inputAbscissa = dict()

Definition at line 141 of file linearize.py.

◆ inputGroupingIndex

lsst.ip.isr.linearize.Linearizer.inputGroupingIndex = dict()

Definition at line 144 of file linearize.py.

◆ inputMask

lsst.ip.isr.linearize.Linearizer.inputMask = dict()

Definition at line 143 of file linearize.py.

◆ inputNormalization

lsst.ip.isr.linearize.Linearizer.inputNormalization = dict()

Definition at line 145 of file linearize.py.

◆ inputOrdinate

lsst.ip.isr.linearize.Linearizer.inputOrdinate = dict()

Definition at line 142 of file linearize.py.

◆ linearFit

lsst.ip.isr.linearize.Linearizer.linearFit = dict()

Definition at line 153 of file linearize.py.

◆ linearityBBox

lsst.ip.isr.linearize.Linearizer.linearityBBox = dict()

Definition at line 140 of file linearize.py.

◆ linearityCoeffs

lsst.ip.isr.linearize.Linearizer.linearityCoeffs = dict()

Definition at line 138 of file linearize.py.

◆ linearityMaxSignal

lsst.ip.isr.linearize.Linearizer.linearityMaxSignal = dict()

Definition at line 155 of file linearize.py.

◆ linearityTurnoff

lsst.ip.isr.linearize.Linearizer.linearityTurnoff = dict()

Definition at line 154 of file linearize.py.

◆ linearityType

lsst.ip.isr.linearize.Linearizer.linearityType = dict()

Definition at line 139 of file linearize.py.

◆ linearityUnits

str lsst.ip.isr.linearize.Linearizer.linearityUnits = 'adu'

Definition at line 166 of file linearize.py.

◆ log

lsst.ip.isr.calibType.IsrCalib.log = log if log else logging.getLogger(__name__)
inherited

Definition at line 96 of file calibType.py.

◆ override

bool lsst.ip.isr.linearize.Linearizer.override = False

Definition at line 135 of file linearize.py.

◆ requiredAttributes

lsst.ip.isr.calibType.IsrCalib.requiredAttributes = set(["_OBSTYPE", "_SCHEMA", "_VERSION"])
inherited

Definition at line 90 of file calibType.py.

◆ tableData

lsst.ip.isr.linearize.Linearizer.tableData = None

Definition at line 156 of file linearize.py.


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