LSST Applications g0fba68d861+bb7a7cfa1f,g1ec0fe41b4+f536777771,g1fd858c14a+470a99fdf4,g216c3ac8a7+0d4d80193f,g35bb328faa+fcb1d3bbc8,g4d2262a081+23bd310d1b,g53246c7159+fcb1d3bbc8,g56a49b3a55+369644a549,g5a012ec0e7+3632fc3ff3,g60b5630c4e+3bfb9058a5,g67b6fd64d1+ed4b5058f4,g78460c75b0+2f9a1b4bcd,g786e29fd12+cf7ec2a62a,g8180f54f50+60bd39f3b6,g8352419a5c+fcb1d3bbc8,g87d29937c9+57a68d035f,g8852436030+4699110379,g89139ef638+ed4b5058f4,g9125e01d80+fcb1d3bbc8,g94187f82dc+3bfb9058a5,g989de1cb63+ed4b5058f4,g9ccd5d7f00+b7cae620c0,g9d31334357+3bfb9058a5,g9f33ca652e+00883ace41,gabe3b4be73+1e0a283bba,gabf8522325+fa80ff7197,gb1101e3267+27b24065a3,gb58c049af0+f03b321e39,gb89ab40317+ed4b5058f4,gc0af124501+708fe67c54,gcf25f946ba+4699110379,gd6cbbdb0b4+bb83cc51f8,gde0f65d7ad+acd5afb0eb,ge1ad929117+3bfb9058a5,ge278dab8ac+d65b3c2b70,ge410e46f29+ed4b5058f4,gf5e32f922b+fcb1d3bbc8,gf67bdafdda+ed4b5058f4,w.2025.17
LSST Data Management Base Package
Loading...
Searching...
No Matches
lsst.ip.isr.photodiodeCorrection.PhotodiodeCorrection Class Reference
Inheritance diagram for lsst.ip.isr.photodiodeCorrection.PhotodiodeCorrection:
lsst.ip.isr.calibType.IsrCalib

Public Member Functions

 __init__ (self, table=None, **kwargs)
 
 updateMetadata (self, setDate=False, **kwargs)
 
 fromDict (cls, dictionary)
 
 toDict (self)
 
 fromTable (cls, tableList)
 
 toTable (self)
 
 validate (self)
 
 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)
 
 fromDetector (self, detector)
 
 apply (self, target)
 

Public Attributes

 abscissaCorrections = dict()
 
 tableData = None
 
 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 photodiode correction.

These parameters are included in 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)
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 photodiode correction attributes stored are:
abscissaCorrections : `dict` : [`str`, `float`]
Correction value indexed by exposure pair

Definition at line 32 of file photodiodeCorrection.py.

Constructor & Destructor Documentation

◆ __init__()

lsst.ip.isr.photodiodeCorrection.PhotodiodeCorrection.__init__ ( self,
table = None,
** kwargs )

Definition at line 69 of file photodiodeCorrection.py.

69 def __init__(self, table=None, **kwargs):
70 self.abscissaCorrections = dict()
71 self.tableData = None
72 if table is not None:
73 if len(table.shape) != 2:
74 raise RuntimeError("table shape = %s; must have two dimensions" % (table.shape,))
75 if table.shape[1] < table.shape[0]:
76 raise RuntimeError("table shape = %s; indices are switched" % (table.shape,))
77 self.tableData = np.array(table, order="C")
78
79 super().__init__(**kwargs)
80 self.requiredAttributes.update(['abscissaCorrections'])
81

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 103 of file calibType.py.

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

◆ __str__()

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

Definition at line 100 of file calibType.py.

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

◆ 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 685 of file calibType.py.

685 def apply(self, target):
686 """Method to apply the calibration to the target object.
687
688 Parameters
689 ----------
690 target : `object`
691 Thing to validate against.
692
693 Returns
694 -------
695 valid : `bool`
696 Returns true if the calibration was applied correctly.
697
698 Raises
699 ------
700 NotImplementedError
701 Raised if not implemented.
702 """
703 raise NotImplementedError("Must be implemented by subclass.")
704
705

◆ 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 322 of file calibType.py.

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

◆ 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 388 of file calibType.py.

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

◆ fromDetector()

lsst.ip.isr.calibType.IsrCalib.fromDetector ( self,
detector )
inherited
Modify the calibration parameters to match the supplied detector.

Parameters
----------
detector : `lsst.afw.cameraGeom.Detector`
    Detector to use to set parameters from.

Raises
------
NotImplementedError
    Raised if not implemented by a subclass.
    This needs to be implemented by subclasses for each
    calibration type.

Reimplemented in lsst.ip.isr.crosstalk.CrosstalkCalib, lsst.ip.isr.deferredCharge.DeferredChargeCalib, lsst.ip.isr.linearize.Linearizer, and lsst.ip.isr.ptcDataset.PhotonTransferCurveDataset.

Definition at line 567 of file calibType.py.

567 def fromDetector(self, detector):
568 """Modify the calibration parameters to match the supplied detector.
569
570 Parameters
571 ----------
572 detector : `lsst.afw.cameraGeom.Detector`
573 Detector to use to set parameters from.
574
575 Raises
576 ------
577 NotImplementedError
578 Raised if not implemented by a subclass.
579 This needs to be implemented by subclasses for each
580 calibration type.
581 """
582 raise NotImplementedError("Must be implemented by subclass.")
583

◆ fromDict()

lsst.ip.isr.photodiodeCorrection.PhotodiodeCorrection.fromDict ( cls,
dictionary )
Construct a PhotodiodeCorrection from a dictionary of properties.

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

Returns
-------
calib : `lsst.ip.isr.PhotodiodeCorrection`
    Constructed photodiode data.

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

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

Definition at line 100 of file photodiodeCorrection.py.

100 def fromDict(cls, dictionary):
101 """Construct a PhotodiodeCorrection from a dictionary of properties.
102
103 Parameters
104 ----------
105 dictionary : `dict`
106 Dictionary of properties.
107
108 Returns
109 -------
110 calib : `lsst.ip.isr.PhotodiodeCorrection`
111 Constructed photodiode data.
112
113 Raises
114 ------
115 RuntimeError
116 Raised if the supplied dictionary is for a different
117 calibration type.
118 """
119 calib = cls()
120
121 if calib._OBSTYPE != dictionary['metadata']['OBSTYPE']:
122 raise RuntimeError(f"Incorrect photodiode correction supplied. Expected {calib._OBSTYPE}, "
123 f"found {dictionary['metadata']['OBSTYPE']}")
124
125 calib.setMetadata(dictionary['metadata'])
126 for pair in dictionary['pairs']:
127 correction = dictionary['pairs'][pair]
128 calib.abscissaCorrections[pair] = correction
129
130 calib.tableData = dictionary.get('tableData', None)
131 if calib.tableData:
132 calib.tableData = np.array(calib.tableData)
133
134 return calib
135

◆ fromTable()

lsst.ip.isr.photodiodeCorrection.PhotodiodeCorrection.fromTable ( cls,
tableList )
Construct calibration from a list of tables.

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`]
    List of tables to use to construct the crosstalk
    calibration.

Returns
-------
calib : `lsst.ip.isr.PhotodiodeCorrection`
    The calibration defined in the tables.

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

Definition at line 161 of file photodiodeCorrection.py.

161 def fromTable(cls, tableList):
162 """Construct calibration from a list of tables.
163
164 This method uses the `fromDict` method to create the
165 calibration after constructing an appropriate dictionary from
166 the input tables.
167
168 Parameters
169 ----------
170 tableList : `list` [`astropy.table.Table`]
171 List of tables to use to construct the crosstalk
172 calibration.
173
174 Returns
175 -------
176 calib : `lsst.ip.isr.PhotodiodeCorrection`
177 The calibration defined in the tables.
178 """
179 dataTable = tableList[0]
180
181 metadata = dataTable.meta
182 inDict = dict()
183 inDict['metadata'] = metadata
184 inDict['pairs'] = dict()
185
186 for record in dataTable:
187 pair = record['PAIR']
188 inDict['pairs'][pair] = record['PD_CORR']
189
190 if len(tableList) > 1:
191 tableData = tableList[1]
192 inDict['tableData'] = [record['LOOKUP_VALUES'] for record in tableData]
193
194 return cls().fromDict(inDict)
195

◆ 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 171 of file calibType.py.

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

◆ metadata()

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

Definition at line 168 of file calibType.py.

168 def metadata(self):
169 return self._metadata
170

◆ 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 505 of file calibType.py.

505 def readFits(cls, filename, **kwargs):
506 """Read calibration data from a FITS file.
507
508 Parameters
509 ----------
510 filename : `str`
511 Filename to read data from.
512 kwargs : `dict` or collections.abc.Mapping`, optional
513 Set of key=value pairs to pass to the ``fromTable``
514 method.
515
516 Returns
517 -------
518 calib : `lsst.ip.isr.IsrCalib`
519 Calibration contained within the file.
520 """
521 tableList = []
522 tableList.append(Table.read(filename, hdu=1, mask_invalid=False))
523 extNum = 2 # Fits indices start at 1, we've read one already.
524 keepTrying = True
525
526 while keepTrying:
527 with warnings.catch_warnings():
528 warnings.simplefilter("error")
529 try:
530 newTable = Table.read(filename, hdu=extNum, mask_invalid=False)
531 tableList.append(newTable)
532 extNum += 1
533 except Exception:
534 keepTrying = False
535
536 for table in tableList:
537 for k, v in table.meta.items():
538 if isinstance(v, fits.card.Undefined):
539 table.meta[k] = None
540
541 calibClass = cls.determineCalibClass(tableList[0].meta, "readFits")
542 return calibClass.fromTable(tableList, **kwargs)
543

◆ 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 418 of file calibType.py.

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

◆ requiredAttributes() [1/2]

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

Definition at line 159 of file calibType.py.

159 def requiredAttributes(self):
160 return self._requiredAttributes
161

◆ requiredAttributes() [2/2]

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

Definition at line 163 of file calibType.py.

163 def requiredAttributes(self, value):
164 self._requiredAttributes = value
165

◆ 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 183 of file calibType.py.

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

◆ toDict()

lsst.ip.isr.photodiodeCorrection.PhotodiodeCorrection.toDict ( self)
Return a dictionary containing the photodiode correction properties.

The dictionary should be able to be round-tripped through.
`fromDict`.

Returns
-------
dictionary : `dict`
    Dictionary of properties.

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

Definition at line 136 of file photodiodeCorrection.py.

136 def toDict(self):
137 """Return a dictionary containing the photodiode correction properties.
138
139 The dictionary should be able to be round-tripped through.
140 `fromDict`.
141
142 Returns
143 -------
144 dictionary : `dict`
145 Dictionary of properties.
146 """
147 self.updateMetadata()
148
149 outDict = dict()
150 outDict['pairs'] = dict()
151 outDict['metadata'] = self.getMetadata()
152 for pair in self.abscissaCorrections.keys():
153 outDict['pairs'][pair] = self.abscissaCorrections[pair]
154
155 if self.tableData is not None:
156 outDict['tableData'] = self.tableData.tolist()
157
158 return outDict
159

◆ toTable()

lsst.ip.isr.photodiodeCorrection.PhotodiodeCorrection.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 photodiode correction
    information.

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

Definition at line 196 of file photodiodeCorrection.py.

196 def toTable(self):
197 """Construct a list of tables containing the information in this
198 calibration.
199
200 The list of tables should create an identical calibration
201 after being passed to this class's fromTable method.
202
203 Returns
204 -------
205 tableList : `list` [`astropy.table.Table`]
206 List of tables containing the photodiode correction
207 information.
208 """
209 tableList = []
210 self.updateMetadata()
211 catalog = Table([{'PAIR': key,
212 'PD_CORR': self.abscissaCorrections[key]}
213 for key in self.abscissaCorrections.keys()])
214 catalog.meta = self.getMetadata().toDict()
215 tableList.append(catalog)
216
217 if self.tableData is not None:
218 catalog = Table([{'LOOKUP_VALUES': value} for value in self.tableData])
219 tableList.append(catalog)
220
221 return tableList
222

◆ updateMetadata()

lsst.ip.isr.photodiodeCorrection.PhotodiodeCorrection.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 82 of file photodiodeCorrection.py.

82 def updateMetadata(self, setDate=False, **kwargs):
83 """Update metadata keywords with new values.
84
85 This calls the base class's method after ensuring the required
86 calibration keywords will be saved.
87
88 Parameters
89 ----------
90 setDate : `bool`, optional
91 Update the CALIBDATE fields in the metadata to the current
92 time. Defaults to False.
93 kwargs :
94 Other keyword parameters to set in the metadata.
95 """
96
97 super().updateMetadata(setDate=setDate, **kwargs)
98

◆ 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 291 of file calibType.py.

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

◆ validate()

lsst.ip.isr.photodiodeCorrection.PhotodiodeCorrection.validate ( self)
Validate photodiode correction

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

Definition at line 223 of file photodiodeCorrection.py.

223 def validate(self):
224 """Validate photodiode correction"""
225 return

◆ 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 544 of file calibType.py.

544 def writeFits(self, filename):
545 """Write calibration data to a FITS file.
546
547 Parameters
548 ----------
549 filename : `str`
550 Filename to write data to.
551
552 Returns
553 -------
554 used : `str`
555 The name of the file used to write the data.
556 """
557 tableList = self.toTable()
558 with warnings.catch_warnings():
559 warnings.filterwarnings("ignore", category=Warning, module="astropy.io")
560 astropyList = [fits.table_to_hdu(table) for table in tableList]
561 astropyList.insert(0, fits.PrimaryHDU())
562
563 writer = fits.HDUList(astropyList)
564 writer.writeto(filename, overwrite=True)
565 return filename
566

◆ 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 451 of file calibType.py.

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

Member Data Documentation

◆ _calibId

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

Definition at line 74 of file calibType.py.

◆ _detectorId

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

Definition at line 72 of file calibType.py.

◆ _detectorName

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

Definition at line 70 of file calibType.py.

◆ _detectorSerial

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

Definition at line 71 of file calibType.py.

◆ _filter

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

Definition at line 73 of file calibType.py.

◆ _instrument

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

Definition at line 67 of file calibType.py.

◆ _metadata

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

Definition at line 78 of file calibType.py.

◆ _OBSTYPE

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

Definition at line 62 of file calibType.py.

◆ _raftName

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

Definition at line 68 of file calibType.py.

◆ _requiredAttributes

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

Definition at line 113 of file calibType.py.

◆ _SCHEMA

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

Definition at line 63 of file calibType.py.

◆ _seqcksum

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

Definition at line 77 of file calibType.py.

◆ _seqfile

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

Definition at line 75 of file calibType.py.

◆ _seqname

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

Definition at line 76 of file calibType.py.

◆ _slotName

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

Definition at line 69 of file calibType.py.

◆ _VERSION

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

Definition at line 64 of file calibType.py.

◆ abscissaCorrections

lsst.ip.isr.photodiodeCorrection.PhotodiodeCorrection.abscissaCorrections = dict()

Definition at line 70 of file photodiodeCorrection.py.

◆ log

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

Definition at line 94 of file calibType.py.

◆ requiredAttributes

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

Definition at line 88 of file calibType.py.

◆ tableData

lsst.ip.isr.photodiodeCorrection.PhotodiodeCorrection.tableData = None

Definition at line 71 of file photodiodeCorrection.py.


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