LSST Applications g1653933729+a8ce1bb630,g171997e3ee+76e92115be,g1a997c3884+a8ce1bb630,g28da252d5a+4013ff5194,g2bbee38e9b+d6d0f9f6ae,g2bc492864f+d6d0f9f6ae,g2cdde0e794+ccb74358b7,g3156d2b45e+07302053f8,g347aa1857d+d6d0f9f6ae,g35bb328faa+a8ce1bb630,g3a166c0a6a+d6d0f9f6ae,g3e281a1b8c+130fae20e3,g4005a62e65+17cd334064,g414038480c+c9f68e2a12,g41af890bb2+3e1f62f438,g4e1a3235cc+9db7d56ad0,g7b55021d1b+7b623691d5,g80478fca09+334cc8d2bd,g82479be7b0+b568f6b267,g858d7b2824+37b39d8760,g9125e01d80+a8ce1bb630,ga5288a1d22+11cb34fefe,gae0086650b+a8ce1bb630,gb4ec7eb0ab+37b39d8760,gb58c049af0+d64f4d3760,gc081298178+284e133171,gc28159a63d+d6d0f9f6ae,gcf0d15dbbd+00fe2e0b07,gd6b7c0dfd1+8b62435e69,gda3e153d99+37b39d8760,gda6a2b7d83+00fe2e0b07,gdaeeff99f8+1711a396fd,gdd5a9049c5+23f3b3239a,ge2409df99d+5d9f551a54,ge33fd446bb+37b39d8760,ge79ae78c31+d6d0f9f6ae,gf0baf85859+2dea8344a2,gf5289d68f6+3777f3df5e,w.2024.41
LSST Data Management Base Package
Loading...
Searching...
No Matches
Public Member Functions | Public Attributes | Protected Attributes | Static Protected Attributes | List of all members
lsst.ip.isr.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)
 
 metadata (self)
 
 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.deferredCharge.DeferredChargeCalib, 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, and lsst.ip.isr.photodiode.PhotodiodeCalib.

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

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 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.string_)):
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)

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

675 def apply(self, target):
676 """Method to apply the calibration to the target object.
677
678 Parameters
679 ----------
680 target : `object`
681 Thing to validate against.
682
683 Returns
684 -------
685 valid : `bool`
686 Returns true if the calibration was applied correctly.
687
688 Raises
689 ------
690 NotImplementedError
691 Raised if not implemented.
692 """
693 raise NotImplementedError("Must be implemented by subclass.")
694
695

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

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

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

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

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

557 def fromDetector(self, detector):
558 """Modify the calibration parameters to match the supplied detector.
559
560 Parameters
561 ----------
562 detector : `lsst.afw.cameraGeom.Detector`
563 Detector to use to set parameters from.
564
565 Raises
566 ------
567 NotImplementedError
568 Raised if not implemented by a subclass.
569 This needs to be implemented by subclasses for each
570 calibration type.
571 """
572 raise NotImplementedError("Must be implemented by subclass.")
573

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

575 def fromDict(cls, dictionary, **kwargs):
576 """Construct a calibration from a dictionary of properties.
577
578 Must be implemented by the specific calibration subclasses.
579
580 Parameters
581 ----------
582 dictionary : `dict`
583 Dictionary of properties.
584 kwargs : `dict` or collections.abc.Mapping`, optional
585 Set of key=value options.
586
587 Returns
588 -------
589 calib : `lsst.ip.isr.CalibType`
590 Constructed calibration.
591
592 Raises
593 ------
594 NotImplementedError
595 Raised if not implemented.
596 """
597 raise NotImplementedError("Must be implemented by subclass.")
598

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

618 def fromTable(cls, tableList, **kwargs):
619 """Construct a calibration from a dictionary of properties.
620
621 Must be implemented by the specific calibration subclasses.
622
623 Parameters
624 ----------
625 tableList : `list` [`lsst.afw.table.Table`]
626 List of tables of properties.
627 kwargs : `dict` or collections.abc.Mapping`, optional
628 Set of key=value options.
629
630 Returns
631 -------
632 calib : `lsst.ip.isr.CalibType`
633 Constructed calibration.
634
635 Raises
636 ------
637 NotImplementedError
638 Raised if not implemented.
639 """
640 raise NotImplementedError("Must be implemented by subclass.")
641

◆ 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 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)

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

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

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

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

◆ requiredAttributes() [1/2]

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

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 )

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

599 def toDict(self):
600 """Return a dictionary containing the calibration properties.
601
602 The dictionary should be able to be round-tripped through
603 `fromDict`.
604
605 Returns
606 -------
607 dictionary : `dict`
608 Dictionary of properties.
609
610 Raises
611 ------
612 NotImplementedError
613 Raised if not implemented.
614 """
615 raise NotImplementedError("Must be implemented by subclass.")
616

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

642 def toTable(self):
643 """Return a list of tables containing the calibration properties.
644
645 The table list should be able to be round-tripped through
646 `fromDict`.
647
648 Returns
649 -------
650 tableList : `list` [`lsst.afw.table.Table`]
651 List of tables of properties.
652
653 Raises
654 ------
655 NotImplementedError
656 Raised if not implemented.
657 """
658 raise NotImplementedError("Must be implemented by subclass.")
659

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

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

◆ 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 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 self.updateMetadata(**metadata)
320

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

660 def validate(self, other=None):
661 """Validate that this calibration is defined and can be used.
662
663 Parameters
664 ----------
665 other : `object`, optional
666 Thing to validate against.
667
668 Returns
669 -------
670 valid : `bool`
671 Returns true if the calibration is valid and appropriate.
672 """
673 return False
674

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

534 def writeFits(self, filename):
535 """Write calibration data to a FITS file.
536
537 Parameters
538 ----------
539 filename : `str`
540 Filename to write data to.
541
542 Returns
543 -------
544 used : `str`
545 The name of the file used to write the data.
546 """
547 tableList = self.toTable()
548 with warnings.catch_warnings():
549 warnings.filterwarnings("ignore", category=Warning, module="astropy.io")
550 astropyList = [fits.table_to_hdu(table) for table in tableList]
551 astropyList.insert(0, fits.PrimaryHDU())
552
553 writer = fits.HDUList(astropyList)
554 writer.writeto(filename, overwrite=True)
555 return filename
556

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

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

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 164 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: