LSST Applications g04c3c9f7ca+2075667efa,g1e125bf412+5f448d5fcf,g2079a07aa2+3e9fd84d81,g2305ad1205+b635cf1488,g2bbee38e9b+6c6beb4891,g337abbeb29+6c6beb4891,g33d1c0ed96+6c6beb4891,g3a166c0a6a+6c6beb4891,g50ff169b8f+96c6868917,g52b1c1532d+585e252eca,g591dd9f2cf+42f171e1e6,g5c3423f6d4+d536b04327,g607f77f49a+d536b04327,g6f43f06aed+ca1339dc19,g858d7b2824+d536b04327,g8ee334c5b4+d7f9608c2f,g9963eaa53e+b3dc1655d3,g998f4353bf+d536b04327,g99cad8db69+8ef2408349,g9ddcbc5298+9a081db1e4,ga1e77700b3+2cbb763275,gadfd92a7e4+aec2f3b930,gae0086650b+585e252eca,gb0e22166c9+0e73c8378f,gb3b7280ab2+cb5fdb229e,gbb8dafda3b+a327199e22,gc120e1dc64+88074880ea,gc28159a63d+6c6beb4891,gcdd4ae20e8+bd241b2308,gcde1bda545+903e937d91,gcf0d15dbbd+bd241b2308,gdaeeff99f8+f9a426f77a,gddc38dedce+585e252eca,ge79ae78c31+6c6beb4891,gfbcc870c63+b310236976,w.2024.23
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.calibType.IsrCalib Class Reference
Inheritance diagram for lsst.ip.isr.calibType.IsrCalib:
lsst.ip.isr.calibType.IsrProvenance lsst.ip.isr.crosstalk.CrosstalkCalib lsst.ip.isr.defects.Defects lsst.ip.isr.deferredCharge.DeferredChargeCalib lsst.ip.isr.linearize.Linearizer lsst.ip.isr.photodiode.PhotodiodeCalib lsst.ip.isr.photodiodeCorrection.PhotodiodeCorrection lsst.ip.isr.ptcDataset.PhotonTransferCurveDataset lsst.ip.isr.straylight.StrayLightData lsst.ip.isr.transmissionCurve.IntermediateTransmissionCurve

Public Member Functions

 __init__ (self, camera=None, detector=None, log=None, **kwargs)
 
 __str__ (self)
 
 __eq__ (self, other)
 
 requiredAttributes (self)
 
 requiredAttributes (self, value)
 
 getMetadata (self)
 
 setMetadata (self, metadata)
 
 updateMetadata (self, camera=None, detector=None, filterName=None, setCalibId=False, setCalibInfo=False, setDate=False, **kwargs)
 
 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)
 
 fromDict (cls, dictionary, **kwargs)
 
 toDict (self)
 
 fromTable (cls, tableList, **kwargs)
 
 toTable (self)
 
 validate (self, other=None)
 
 apply (self, target)
 

Public Attributes

 requiredAttributes
 
 log
 

Protected Attributes

 _instrument
 
 _raftName
 
 _slotName
 
 _detectorName
 
 _detectorSerial
 
 _detectorId
 
 _filter
 
 _calibId
 
 _seqfile
 
 _seqname
 
 _seqcksum
 
 _metadata
 
 _requiredAttributes
 

Static Protected Attributes

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

Detailed Description

Generic calibration type.

Subclasses must implement the toDict, fromDict, toTable, fromTable
methods that allow the calibration information to be converted
from dictionaries and afw tables.  This will allow the calibration
to be persisted using the base class read/write methods.

The validate method is intended to provide a common way to check
that the calibration is valid (internally consistent) and
appropriate (usable with the intended data).  The apply method is
intended to allow the calibration to be applied in a consistent
manner.

Parameters
----------
camera : `lsst.afw.cameraGeom.Camera`, optional
    Camera to extract metadata from.
detector : `lsst.afw.cameraGeom.Detector`, optional
    Detector to extract metadata from.
log : `logging.Logger`, optional
    Log for messages.

Definition at line 39 of file calibType.py.

Constructor & Destructor Documentation

◆ __init__()

lsst.ip.isr.calibType.IsrCalib.__init__ ( self,
camera = None,
detector = None,
log = None,
** kwargs )

Reimplemented in lsst.ip.isr.ptcDataset.PhotonTransferCurveDataset, lsst.ip.isr.calibType.IsrProvenance, lsst.ip.isr.defects.Defects, lsst.ip.isr.crosstalk.CrosstalkCalib, lsst.ip.isr.transmissionCurve.IntermediateTransmissionCurve, lsst.ip.isr.linearize.Linearizer, lsst.ip.isr.photodiodeCorrection.PhotodiodeCorrection, lsst.ip.isr.photodiode.PhotodiodeCalib, and lsst.ip.isr.deferredCharge.DeferredChargeCalib.

Definition at line 66 of file calibType.py.

66 def __init__(self, camera=None, detector=None, log=None, **kwargs):
67 self._instrument = None
68 self._raftName = None
69 self._slotName = None
70 self._detectorName = None
71 self._detectorSerial = None
72 self._detectorId = None
73 self._filter = None
74 self._calibId = None
75 self._seqfile = None
76 self._seqname = None
77 self._seqcksum = None
78 self._metadata = PropertyList()
79 self.setMetadata(PropertyList())
80 self.calibInfoFromDict(kwargs)
81
82 # Define the required attributes for this calibration. These
83 # are entries that are automatically filled and propagated
84 # from the metadata. The existence of the attribute is
85 # required (they're checked for equivalence), but they do not
86 # necessarily need to have a value (None == None in this
87 # case).
88 self.requiredAttributes = set(["_OBSTYPE", "_SCHEMA", "_VERSION"])
89 self.requiredAttributes.update(["_instrument", "_raftName", "_slotName",
90 "_detectorName", "_detectorSerial", "_detectorId",
91 "_filter", "_calibId", "_seqfile", "_seqname", "_seqcksum",
92 "_metadata"])
93
94 self.log = log if log else logging.getLogger(__name__)
95
96 if detector:
97 self.fromDetector(detector)
98 self.updateMetadata(camera=camera, detector=detector)
99
daf::base::PropertySet * set
Definition fits.cc:931

Member Function Documentation

◆ __eq__()

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

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

Reimplemented in lsst.ip.isr.calibType.IsrProvenance, and lsst.ip.isr.defects.Defects.

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 attrSelf[key] != attrOther[key]:
133 return False
134 elif isinstance(attrSelf, np.ndarray):
135 # Bare array.
136 if not np.allclose(attrSelf, attrOther, equal_nan=True):
137 self.log.debug("Array Failure: %s %s %s", attr, attrSelf, attrOther)
138 return False
139 elif type(attrSelf) != type(attrOther):
140 if set([attrSelf, attrOther]) == set([None, ""]):
141 # Fits converts None to "", but None is not "".
142 continue
143 self.log.debug("Type Failure: %s %s %s %s %s", attr, type(attrSelf), type(attrOther),
144 attrSelf, attrOther)
145 return False
146 else:
147 if attrSelf != attrOther:
148 self.log.debug("Value Failure: %s %s %s", attr, attrSelf, attrOther)
149 return False
150
151 return True
152

◆ __str__()

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

Reimplemented in lsst.ip.isr.calibType.IsrProvenance, and lsst.ip.isr.defects.Defects.

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

665 def apply(self, target):
666 """Method to apply the calibration to the target object.
667
668 Parameters
669 ----------
670 target : `object`
671 Thing to validate against.
672
673 Returns
674 -------
675 valid : `bool`
676 Returns true if the calibration was applied correctly.
677
678 Raises
679 ------
680 NotImplementedError
681 Raised if not implemented.
682 """
683 raise NotImplementedError("Must be implemented by subclass.")
684
685

◆ calibInfoFromDict()

lsst.ip.isr.calibType.IsrCalib.calibInfoFromDict ( self,
dictionary )
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 311 of file calibType.py.

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

◆ determineCalibClass()

lsst.ip.isr.calibType.IsrCalib.determineCalibClass ( cls,
metadata,
message )
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 368 of file calibType.py.

368 def determineCalibClass(cls, metadata, message):
369 """Attempt to find calibration class in metadata.
370
371 Parameters
372 ----------
373 metadata : `dict` or `lsst.daf.base.PropertyList`
374 Metadata possibly containing a calibration class entry.
375 message : `str`
376 Message to include in any errors.
377
378 Returns
379 -------
380 calibClass : `object`
381 The class to use to read the file contents. Should be an
382 `lsst.ip.isr.IsrCalib` subclass.
383
384 Raises
385 ------
386 ValueError
387 Raised if the resulting calibClass is the base
388 `lsst.ip.isr.IsrClass` (which does not implement the
389 content methods).
390 """
391 calibClassName = metadata.get("CALIBCLS")
392 calibClass = doImport(calibClassName) if calibClassName is not None else cls
393 if calibClass is IsrCalib:
394 raise ValueError(f"Cannot use base class to read calibration data: {message}")
395 return calibClass
396

◆ fromDetector()

lsst.ip.isr.calibType.IsrCalib.fromDetector ( self,
detector )
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.deferredCharge.DeferredChargeCalib, lsst.ip.isr.linearize.Linearizer, lsst.ip.isr.ptcDataset.PhotonTransferCurveDataset, and lsst.ip.isr.crosstalk.CrosstalkCalib.

Definition at line 547 of file calibType.py.

547 def fromDetector(self, detector):
548 """Modify the calibration parameters to match the supplied detector.
549
550 Parameters
551 ----------
552 detector : `lsst.afw.cameraGeom.Detector`
553 Detector to use to set parameters from.
554
555 Raises
556 ------
557 NotImplementedError
558 Raised if not implemented by a subclass.
559 This needs to be implemented by subclasses for each
560 calibration type.
561 """
562 raise NotImplementedError("Must be implemented by subclass.")
563

◆ fromDict()

lsst.ip.isr.calibType.IsrCalib.fromDict ( cls,
dictionary,
** kwargs )
Construct a calibration from a dictionary of properties.

Must be implemented by the specific calibration subclasses.

Parameters
----------
dictionary : `dict`
    Dictionary of properties.
kwargs : `dict` or collections.abc.Mapping`, optional
    Set of key=value options.

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

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

Reimplemented in lsst.ip.isr.calibType.IsrProvenance, lsst.ip.isr.crosstalk.CrosstalkCalib, lsst.ip.isr.defects.Defects, lsst.ip.isr.deferredCharge.DeferredChargeCalib, lsst.ip.isr.linearize.Linearizer, lsst.ip.isr.photodiode.PhotodiodeCalib, lsst.ip.isr.photodiodeCorrection.PhotodiodeCorrection, and lsst.ip.isr.ptcDataset.PhotonTransferCurveDataset.

Definition at line 565 of file calibType.py.

565 def fromDict(cls, dictionary, **kwargs):
566 """Construct a calibration from a dictionary of properties.
567
568 Must be implemented by the specific calibration subclasses.
569
570 Parameters
571 ----------
572 dictionary : `dict`
573 Dictionary of properties.
574 kwargs : `dict` or collections.abc.Mapping`, optional
575 Set of key=value options.
576
577 Returns
578 -------
579 calib : `lsst.ip.isr.CalibType`
580 Constructed calibration.
581
582 Raises
583 ------
584 NotImplementedError
585 Raised if not implemented.
586 """
587 raise NotImplementedError("Must be implemented by subclass.")
588

◆ fromTable()

lsst.ip.isr.calibType.IsrCalib.fromTable ( cls,
tableList,
** kwargs )
Construct a calibration from a dictionary of properties.

Must be implemented by the specific calibration subclasses.

Parameters
----------
tableList : `list` [`lsst.afw.table.Table`]
    List of tables of properties.
kwargs : `dict` or collections.abc.Mapping`, optional
    Set of key=value options.

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

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

Reimplemented in lsst.ip.isr.calibType.IsrProvenance, lsst.ip.isr.crosstalk.CrosstalkCalib, lsst.ip.isr.deferredCharge.DeferredChargeCalib, lsst.ip.isr.linearize.Linearizer, lsst.ip.isr.photodiode.PhotodiodeCalib, lsst.ip.isr.photodiodeCorrection.PhotodiodeCorrection, lsst.ip.isr.ptcDataset.PhotonTransferCurveDataset, lsst.ip.isr.transmissionCurve.IntermediateTransmissionCurve, and lsst.ip.isr.defects.Defects.

Definition at line 608 of file calibType.py.

608 def fromTable(cls, tableList, **kwargs):
609 """Construct a calibration from a dictionary of properties.
610
611 Must be implemented by the specific calibration subclasses.
612
613 Parameters
614 ----------
615 tableList : `list` [`lsst.afw.table.Table`]
616 List of tables of properties.
617 kwargs : `dict` or collections.abc.Mapping`, optional
618 Set of key=value options.
619
620 Returns
621 -------
622 calib : `lsst.ip.isr.CalibType`
623 Constructed calibration.
624
625 Raises
626 ------
627 NotImplementedError
628 Raised if not implemented.
629 """
630 raise NotImplementedError("Must be implemented by subclass.")
631

◆ getMetadata()

lsst.ip.isr.calibType.IsrCalib.getMetadata ( self)
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 161 of file calibType.py.

161 def getMetadata(self):
162 """Retrieve metadata associated with this calibration.
163
164 Returns
165 -------
166 meta : `lsst.daf.base.PropertyList`
167 Metadata. The returned `~lsst.daf.base.PropertyList` can be
168 modified by the caller and the changes will be written to
169 external files.
170 """
171 return self._metadata
172

◆ readFits()

lsst.ip.isr.calibType.IsrCalib.readFits ( cls,
filename,
** kwargs )
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 485 of file calibType.py.

485 def readFits(cls, filename, **kwargs):
486 """Read calibration data from a FITS file.
487
488 Parameters
489 ----------
490 filename : `str`
491 Filename to read data from.
492 kwargs : `dict` or collections.abc.Mapping`, optional
493 Set of key=value pairs to pass to the ``fromTable``
494 method.
495
496 Returns
497 -------
498 calib : `lsst.ip.isr.IsrCalib`
499 Calibration contained within the file.
500 """
501 tableList = []
502 tableList.append(Table.read(filename, hdu=1, mask_invalid=False))
503 extNum = 2 # Fits indices start at 1, we've read one already.
504 keepTrying = True
505
506 while keepTrying:
507 with warnings.catch_warnings():
508 warnings.simplefilter("error")
509 try:
510 newTable = Table.read(filename, hdu=extNum, mask_invalid=False)
511 tableList.append(newTable)
512 extNum += 1
513 except Exception:
514 keepTrying = False
515
516 for table in tableList:
517 for k, v in table.meta.items():
518 if isinstance(v, fits.card.Undefined):
519 table.meta[k] = None
520
521 calibClass = cls.determineCalibClass(tableList[0].meta, "readFits")
522 return calibClass.fromTable(tableList, **kwargs)
523

◆ readText()

lsst.ip.isr.calibType.IsrCalib.readText ( cls,
filename,
** kwargs )
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 398 of file calibType.py.

398 def readText(cls, filename, **kwargs):
399 """Read calibration representation from a yaml/ecsv file.
400
401 Parameters
402 ----------
403 filename : `str`
404 Name of the file containing the calibration definition.
405 kwargs : `dict` or collections.abc.Mapping`, optional
406 Set of key=value pairs to pass to the ``fromDict`` or
407 ``fromTable`` methods.
408
409 Returns
410 -------
411 calib : `~lsst.ip.isr.IsrCalibType`
412 Calibration class.
413
414 Raises
415 ------
416 RuntimeError
417 Raised if the filename does not end in ".ecsv" or ".yaml".
418 """
419 if filename.endswith((".ecsv", ".ECSV")):
420 data = Table.read(filename, format="ascii.ecsv")
421 calibClass = cls.determineCalibClass(data.meta, "readText/ECSV")
422 return calibClass.fromTable([data], **kwargs)
423 elif filename.endswith((".yaml", ".YAML")):
424 with open(filename, "r") as f:
425 data = yaml.load(f, Loader=yaml.CLoader)
426 calibClass = cls.determineCalibClass(data["metadata"], "readText/YAML")
427 return calibClass.fromDict(data, **kwargs)
428 else:
429 raise RuntimeError(f"Unknown filename extension: {filename}")
430

◆ requiredAttributes() [1/2]

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

Definition at line 154 of file calibType.py.

154 def requiredAttributes(self):
155 return self._requiredAttributes
156

◆ requiredAttributes() [2/2]

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

Definition at line 158 of file calibType.py.

158 def requiredAttributes(self, value):
159 self._requiredAttributes = value
160

◆ setMetadata()

lsst.ip.isr.calibType.IsrCalib.setMetadata ( self,
metadata )
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 173 of file calibType.py.

173 def setMetadata(self, metadata):
174 """Store a copy of the supplied metadata with this calibration.
175
176 Parameters
177 ----------
178 metadata : `lsst.daf.base.PropertyList`
179 Metadata to associate with the calibration. Will be copied and
180 overwrite existing metadata.
181 """
182 if metadata is not None:
183 self._metadata.update(metadata)
184
185 # Ensure that we have the obs type required by calibration ingest
186 self._metadata["OBSTYPE"] = self._OBSTYPE
187 self._metadata[self._OBSTYPE + "_SCHEMA"] = self._SCHEMA
188 self._metadata[self._OBSTYPE + "_VERSION"] = self._VERSION
189
190 if isinstance(metadata, dict):
191 self.calibInfoFromDict(metadata)
192 elif isinstance(metadata, PropertyList):
193 self.calibInfoFromDict(metadata.toDict())
194

◆ toDict()

lsst.ip.isr.calibType.IsrCalib.toDict ( self)
Return a dictionary containing the calibration properties.

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

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

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

Reimplemented in lsst.ip.isr.calibType.IsrProvenance, lsst.ip.isr.crosstalk.CrosstalkCalib, lsst.ip.isr.defects.Defects, lsst.ip.isr.deferredCharge.DeferredChargeCalib, lsst.ip.isr.linearize.Linearizer, lsst.ip.isr.photodiode.PhotodiodeCalib, lsst.ip.isr.photodiodeCorrection.PhotodiodeCorrection, and lsst.ip.isr.ptcDataset.PhotonTransferCurveDataset.

Definition at line 589 of file calibType.py.

589 def toDict(self):
590 """Return a dictionary containing the calibration properties.
591
592 The dictionary should be able to be round-tripped through
593 `fromDict`.
594
595 Returns
596 -------
597 dictionary : `dict`
598 Dictionary of properties.
599
600 Raises
601 ------
602 NotImplementedError
603 Raised if not implemented.
604 """
605 raise NotImplementedError("Must be implemented by subclass.")
606

◆ toTable()

lsst.ip.isr.calibType.IsrCalib.toTable ( self)
Return a list of tables containing the calibration properties.

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

Returns
-------
tableList : `list` [`lsst.afw.table.Table`]
    List of tables of properties.

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

Reimplemented in lsst.ip.isr.calibType.IsrProvenance, lsst.ip.isr.crosstalk.CrosstalkCalib, lsst.ip.isr.defects.Defects, lsst.ip.isr.deferredCharge.DeferredChargeCalib, lsst.ip.isr.linearize.Linearizer, lsst.ip.isr.photodiode.PhotodiodeCalib, lsst.ip.isr.photodiodeCorrection.PhotodiodeCorrection, and lsst.ip.isr.ptcDataset.PhotonTransferCurveDataset.

Definition at line 632 of file calibType.py.

632 def toTable(self):
633 """Return a list of tables containing the calibration properties.
634
635 The table list should be able to be round-tripped through
636 `fromDict`.
637
638 Returns
639 -------
640 tableList : `list` [`lsst.afw.table.Table`]
641 List of tables of properties.
642
643 Raises
644 ------
645 NotImplementedError
646 Raised if not implemented.
647 """
648 raise NotImplementedError("Must be implemented by subclass.")
649

◆ updateMetadata()

lsst.ip.isr.calibType.IsrCalib.updateMetadata ( self,
camera = None,
detector = None,
filterName = None,
setCalibId = False,
setCalibInfo = False,
setDate = False,
** kwargs )
Update metadata keywords with new values.

Parameters
----------
camera : `lsst.afw.cameraGeom.Camera`, optional
    Reference camera to use to set ``_instrument`` field.
detector : `lsst.afw.cameraGeom.Detector`, optional
    Reference detector to use to set ``_detector*`` fields.
filterName : `str`, optional
    Filter name to assign to this calibration.
setCalibId : `bool`, optional
    Construct the ``_calibId`` field from other fields.
setCalibInfo : `bool`, optional
    Set calibration parameters from metadata.
setDate : `bool`, optional
    Ensure the metadata ``CALIBDATE`` fields are set to the current
    datetime.
kwargs : `dict` or `collections.abc.Mapping`, optional
    Set of ``key=value`` pairs to assign to the metadata.

Reimplemented in lsst.ip.isr.ptcDataset.PhotonTransferCurveDataset, lsst.ip.isr.calibType.IsrProvenance, lsst.ip.isr.crosstalk.CrosstalkCalib, lsst.ip.isr.linearize.Linearizer, and lsst.ip.isr.photodiodeCorrection.PhotodiodeCorrection.

Definition at line 195 of file calibType.py.

197 **kwargs):
198 """Update metadata keywords with new values.
199
200 Parameters
201 ----------
202 camera : `lsst.afw.cameraGeom.Camera`, optional
203 Reference camera to use to set ``_instrument`` field.
204 detector : `lsst.afw.cameraGeom.Detector`, optional
205 Reference detector to use to set ``_detector*`` fields.
206 filterName : `str`, optional
207 Filter name to assign to this calibration.
208 setCalibId : `bool`, optional
209 Construct the ``_calibId`` field from other fields.
210 setCalibInfo : `bool`, optional
211 Set calibration parameters from metadata.
212 setDate : `bool`, optional
213 Ensure the metadata ``CALIBDATE`` fields are set to the current
214 datetime.
215 kwargs : `dict` or `collections.abc.Mapping`, optional
216 Set of ``key=value`` pairs to assign to the metadata.
217 """
218 mdOriginal = self.getMetadata()
219 mdSupplemental = dict()
220
221 for k, v in kwargs.items():
222 if isinstance(v, fits.card.Undefined):
223 kwargs[k] = None
224
225 if setCalibInfo:
226 self.calibInfoFromDict(kwargs)
227
228 if camera:
229 self._instrument = camera.getName()
230
231 if detector:
232 self._detectorName = detector.getName()
233 self._detectorSerial = detector.getSerial()
234 self._detectorId = detector.getId()
235 if "_" in self._detectorName:
236 (self._raftName, self._slotName) = self._detectorName.split("_")
237
238 if filterName:
239 # TOD0 DM-28093: I think this whole comment can go away, if we
240 # always use physicalLabel everywhere in ip_isr.
241 # If set via:
242 # exposure.getInfo().getFilter().getName()
243 # then this will hold the abstract filter.
244 self._filter = filterName
245
246 if setDate:
247 date = datetime.datetime.now()
248 mdSupplemental["CALIBDATE"] = date.isoformat()
249 mdSupplemental["CALIB_CREATION_DATE"] = date.date().isoformat()
250 mdSupplemental["CALIB_CREATION_TIME"] = date.time().isoformat()
251
252 if setCalibId:
253 values = []
254 values.append(f"instrument={self._instrument}") if self._instrument else None
255 values.append(f"raftName={self._raftName}") if self._raftName else None
256 values.append(f"detectorName={self._detectorName}") if self._detectorName else None
257 values.append(f"detector={self._detectorId}") if self._detectorId else None
258 values.append(f"filter={self._filter}") if self._filter else None
259
260 calibDate = mdOriginal.get("CALIBDATE", mdSupplemental.get("CALIBDATE", None))
261 values.append(f"calibDate={calibDate}") if calibDate else None
262
263 self._calibId = " ".join(values)
264
265 self._metadata["INSTRUME"] = self._instrument if self._instrument else None
266 self._metadata["RAFTNAME"] = self._raftName if self._raftName else None
267 self._metadata["SLOTNAME"] = self._slotName if self._slotName else None
268 self._metadata["DETECTOR"] = self._detectorId
269 self._metadata["DET_NAME"] = self._detectorName if self._detectorName else None
270 self._metadata["DET_SER"] = self._detectorSerial if self._detectorSerial else None
271 self._metadata["FILTER"] = self._filter if self._filter else None
272 self._metadata["CALIB_ID"] = self._calibId if self._calibId else None
273 self._metadata["SEQFILE"] = self._seqfile if self._seqfile else None
274 self._metadata["SEQNAME"] = self._seqname if self._seqname else None
275 self._metadata["SEQCKSUM"] = self._seqcksum if self._seqcksum else None
276 self._metadata["CALIBCLS"] = get_full_type_name(self)
277
278 mdSupplemental.update(kwargs)
279 mdOriginal.update(mdSupplemental)
280

◆ updateMetadataFromExposures()

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

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

Definition at line 281 of file calibType.py.

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

◆ validate()

lsst.ip.isr.calibType.IsrCalib.validate ( self,
other = None )
Validate that this calibration is defined and can be used.

Parameters
----------
other : `object`, optional
    Thing to validate against.

Returns
-------
valid : `bool`
    Returns true if the calibration is valid and appropriate.

Reimplemented in lsst.ip.isr.photodiodeCorrection.PhotodiodeCorrection, and lsst.ip.isr.linearize.Linearizer.

Definition at line 650 of file calibType.py.

650 def validate(self, other=None):
651 """Validate that this calibration is defined and can be used.
652
653 Parameters
654 ----------
655 other : `object`, optional
656 Thing to validate against.
657
658 Returns
659 -------
660 valid : `bool`
661 Returns true if the calibration is valid and appropriate.
662 """
663 return False
664

◆ writeFits()

lsst.ip.isr.calibType.IsrCalib.writeFits ( self,
filename )
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 524 of file calibType.py.

524 def writeFits(self, filename):
525 """Write calibration data to a FITS file.
526
527 Parameters
528 ----------
529 filename : `str`
530 Filename to write data to.
531
532 Returns
533 -------
534 used : `str`
535 The name of the file used to write the data.
536 """
537 tableList = self.toTable()
538 with warnings.catch_warnings():
539 warnings.filterwarnings("ignore", category=Warning, module="astropy.io")
540 astropyList = [fits.table_to_hdu(table) for table in tableList]
541 astropyList.insert(0, fits.PrimaryHDU())
542
543 writer = fits.HDUList(astropyList)
544 writer.writeto(filename, overwrite=True)
545 return filename
546

◆ writeText()

lsst.ip.isr.calibType.IsrCalib.writeText ( self,
filename,
format = "auto" )
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 431 of file calibType.py.

431 def writeText(self, filename, format="auto"):
432 """Write the calibration data to a text file.
433
434 Parameters
435 ----------
436 filename : `str`
437 Name of the file to write.
438 format : `str`
439 Format to write the file as. Supported values are:
440 ``"auto"`` : Determine filetype from filename.
441 ``"yaml"`` : Write as yaml.
442 ``"ecsv"`` : Write as ecsv.
443
444 Returns
445 -------
446 used : `str`
447 The name of the file used to write the data. This may
448 differ from the input if the format is explicitly chosen.
449
450 Raises
451 ------
452 RuntimeError
453 Raised if filename does not end in a known extension, or
454 if all information cannot be written.
455
456 Notes
457 -----
458 The file is written to YAML/ECSV format and will include any
459 associated metadata.
460 """
461 if format == "yaml" or (format == "auto" and filename.lower().endswith((".yaml", ".YAML"))):
462 outDict = self.toDict()
463 path, ext = os.path.splitext(filename)
464 filename = path + ".yaml"
465 with open(filename, "w") as f:
466 yaml.dump(outDict, f)
467 elif format == "ecsv" or (format == "auto" and filename.lower().endswith((".ecsv", ".ECSV"))):
468 tableList = self.toTable()
469 if len(tableList) > 1:
470 # ECSV doesn't support multiple tables per file, so we
471 # can only write the first table.
472 raise RuntimeError(f"Unable to persist {len(tableList)}tables in ECSV format.")
473
474 table = tableList[0]
475 path, ext = os.path.splitext(filename)
476 filename = path + ".ecsv"
477 table.write(filename, format="ascii.ecsv")
478 else:
479 raise RuntimeError(f"Attempt to write to a file {filename} "
480 "that does not end in '.yaml' or '.ecsv'")
481
482 return filename
483

Member Data Documentation

◆ _calibId

lsst.ip.isr.calibType.IsrCalib._calibId
protected

Definition at line 74 of file calibType.py.

◆ _detectorId

lsst.ip.isr.calibType.IsrCalib._detectorId
protected

Definition at line 72 of file calibType.py.

◆ _detectorName

lsst.ip.isr.calibType.IsrCalib._detectorName
protected

Definition at line 70 of file calibType.py.

◆ _detectorSerial

lsst.ip.isr.calibType.IsrCalib._detectorSerial
protected

Definition at line 71 of file calibType.py.

◆ _filter

lsst.ip.isr.calibType.IsrCalib._filter
protected

Definition at line 73 of file calibType.py.

◆ _instrument

lsst.ip.isr.calibType.IsrCalib._instrument
protected

Definition at line 67 of file calibType.py.

◆ _metadata

lsst.ip.isr.calibType.IsrCalib._metadata
protected

Definition at line 78 of file calibType.py.

◆ _OBSTYPE

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

Definition at line 62 of file calibType.py.

◆ _raftName

lsst.ip.isr.calibType.IsrCalib._raftName
protected

Definition at line 68 of file calibType.py.

◆ _requiredAttributes

lsst.ip.isr.calibType.IsrCalib._requiredAttributes
protected

Definition at line 159 of file calibType.py.

◆ _SCHEMA

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

Definition at line 63 of file calibType.py.

◆ _seqcksum

lsst.ip.isr.calibType.IsrCalib._seqcksum
protected

Definition at line 77 of file calibType.py.

◆ _seqfile

lsst.ip.isr.calibType.IsrCalib._seqfile
protected

Definition at line 75 of file calibType.py.

◆ _seqname

lsst.ip.isr.calibType.IsrCalib._seqname
protected

Definition at line 76 of file calibType.py.

◆ _slotName

lsst.ip.isr.calibType.IsrCalib._slotName
protected

Definition at line 69 of file calibType.py.

◆ _VERSION

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

Definition at line 64 of file calibType.py.

◆ log

lsst.ip.isr.calibType.IsrCalib.log

Definition at line 94 of file calibType.py.

◆ requiredAttributes

lsst.ip.isr.calibType.IsrCalib.requiredAttributes

Definition at line 88 of file calibType.py.


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