LSST Applications g0fba68d861+539c3c8198,g1ec0fe41b4+f0b7a83aa5,g1fd858c14a+78b1f303e5,g22210bfa2a+8e34e7f00e,g2440f9efcc+8c5ae1fdc5,g3533f9d6cb+f4db8b1b3b,g35bb328faa+8c5ae1fdc5,g3fc7d4f5b9+a4d3a2d8bb,g40d01f57dd+ad4ae80abb,g4178042926+abd409f097,g53246c7159+8c5ae1fdc5,g548d740b8c+47e4a7beb3,g60b5630c4e+f4db8b1b3b,g663da51e9b+e0f2ae43b2,g67b6fd64d1+c104138150,g78460c75b0+7e33a9eb6d,g786e29fd12+668abc6043,g8352419a5c+8c5ae1fdc5,g8852436030+d435302cbd,g89139ef638+c104138150,g8b40312ef5+5b6744d273,g90aefe88b0+c7f866738c,g989de1cb63+c104138150,g9f33ca652e+0b88989aa6,ga2f891cd6c+f4db8b1b3b,gabe3b4be73+8856018cbb,gabf8522325+5cb9e9d408,gb1101e3267+78d08b86ce,gb89ab40317+c104138150,gcf25f946ba+d435302cbd,gd6cbbdb0b4+be834e5da7,gde0f65d7ad+a7114e3dba,ge278dab8ac+fa35eb453c,ge410e46f29+c104138150,gf35d7ec915+97dd712d81,gf5e32f922b+8c5ae1fdc5,gf67bdafdda+c104138150,gffe7e49bb4+f4db8b1b3b,v29.1.0.rc2
LSST Data Management Base Package
Loading...
Searching...
No Matches
lsst.ip.isr.calibType.IsrCalib Class Reference
Inheritance diagram for lsst.ip.isr.calibType.IsrCalib:
lsst.ip.isr.brighterFatterKernel.BrighterFatterKernel 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 = 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

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

Constructor & Destructor Documentation

◆ __init__()

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

Definition at line 67 of file calibType.py.

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

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.

Definition at line 104 of file calibType.py.

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

◆ __str__()

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

Definition at line 101 of file calibType.py.

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

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

693 def apply(self, target):
694 """Method to apply the calibration to the target object.
695
696 Parameters
697 ----------
698 target : `object`
699 Thing to validate against.
700
701 Returns
702 -------
703 valid : `bool`
704 Returns true if the calibration was applied correctly.
705
706 Raises
707 ------
708 NotImplementedError
709 Raised if not implemented.
710 """
711 raise NotImplementedError("Must be implemented by subclass.")
712
713

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

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

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

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

◆ 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.crosstalk.CrosstalkCalib, lsst.ip.isr.deferredCharge.DeferredChargeCalib, lsst.ip.isr.linearize.Linearizer, and lsst.ip.isr.ptcDataset.PhotonTransferCurveDataset.

Definition at line 575 of file calibType.py.

575 def fromDetector(self, detector):
576 """Modify the calibration parameters to match the supplied detector.
577
578 Parameters
579 ----------
580 detector : `lsst.afw.cameraGeom.Detector`
581 Detector to use to set parameters from.
582
583 Raises
584 ------
585 NotImplementedError
586 Raised if not implemented by a subclass.
587 This needs to be implemented by subclasses for each
588 calibration type.
589 """
590 raise NotImplementedError("Must be implemented by subclass.")
591

◆ 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.brighterFatterKernel.BrighterFatterKernel, 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 593 of file calibType.py.

593 def fromDict(cls, dictionary, **kwargs):
594 """Construct a calibration from a dictionary of properties.
595
596 Must be implemented by the specific calibration subclasses.
597
598 Parameters
599 ----------
600 dictionary : `dict`
601 Dictionary of properties.
602 kwargs : `dict` or collections.abc.Mapping`, optional
603 Set of key=value options.
604
605 Returns
606 -------
607 calib : `lsst.ip.isr.CalibType`
608 Constructed calibration.
609
610 Raises
611 ------
612 NotImplementedError
613 Raised if not implemented.
614 """
615 raise NotImplementedError("Must be implemented by subclass.")
616

◆ 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.brighterFatterKernel.BrighterFatterKernel, 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, and lsst.ip.isr.transmissionCurve.IntermediateTransmissionCurve.

Definition at line 636 of file calibType.py.

636 def fromTable(cls, tableList, **kwargs):
637 """Construct a calibration from a dictionary of properties.
638
639 Must be implemented by the specific calibration subclasses.
640
641 Parameters
642 ----------
643 tableList : `list` [`lsst.afw.table.Table`]
644 List of tables of properties.
645 kwargs : `dict` or collections.abc.Mapping`, optional
646 Set of key=value options.
647
648 Returns
649 -------
650 calib : `lsst.ip.isr.CalibType`
651 Constructed calibration.
652
653 Raises
654 ------
655 NotImplementedError
656 Raised if not implemented.
657 """
658 raise NotImplementedError("Must be implemented by subclass.")
659

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

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

◆ metadata()

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

Definition at line 169 of file calibType.py.

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

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

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

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

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

◆ requiredAttributes() [1/2]

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

Definition at line 160 of file calibType.py.

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

◆ requiredAttributes() [2/2]

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

Definition at line 164 of file calibType.py.

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

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

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

◆ 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.brighterFatterKernel.BrighterFatterKernel, 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 617 of file calibType.py.

617 def toDict(self):
618 """Return a dictionary containing the calibration properties.
619
620 The dictionary should be able to be round-tripped through
621 `fromDict`.
622
623 Returns
624 -------
625 dictionary : `dict`
626 Dictionary of properties.
627
628 Raises
629 ------
630 NotImplementedError
631 Raised if not implemented.
632 """
633 raise NotImplementedError("Must be implemented by subclass.")
634

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

660 def toTable(self):
661 """Return a list of tables containing the calibration properties.
662
663 The table list should be able to be round-tripped through
664 `fromDict`.
665
666 Returns
667 -------
668 tableList : `list` [`lsst.afw.table.Table`]
669 List of tables of properties.
670
671 Raises
672 ------
673 NotImplementedError
674 Raised if not implemented.
675 """
676 raise NotImplementedError("Must be implemented by subclass.")
677

◆ 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.brighterFatterKernel.BrighterFatterKernel, lsst.ip.isr.calibType.IsrProvenance, lsst.ip.isr.crosstalk.CrosstalkCalib, lsst.ip.isr.linearize.Linearizer, lsst.ip.isr.photodiodeCorrection.PhotodiodeCorrection, and lsst.ip.isr.ptcDataset.PhotonTransferCurveDataset.

Definition at line 206 of file calibType.py.

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

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

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

◆ 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.linearize.Linearizer, and lsst.ip.isr.photodiodeCorrection.PhotodiodeCorrection.

Definition at line 678 of file calibType.py.

678 def validate(self, other=None):
679 """Validate that this calibration is defined and can be used.
680
681 Parameters
682 ----------
683 other : `object`, optional
684 Thing to validate against.
685
686 Returns
687 -------
688 valid : `bool`
689 Returns true if the calibration is valid and appropriate.
690 """
691 return False
692

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

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

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

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

Member Data Documentation

◆ _calibId

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

Definition at line 75 of file calibType.py.

◆ _detectorId

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

Definition at line 73 of file calibType.py.

◆ _detectorName

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

Definition at line 71 of file calibType.py.

◆ _detectorSerial

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

Definition at line 72 of file calibType.py.

◆ _filter

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

Definition at line 74 of file calibType.py.

◆ _instrument

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

Definition at line 68 of file calibType.py.

◆ _metadata

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

Definition at line 79 of file calibType.py.

◆ _OBSTYPE

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

Definition at line 63 of file calibType.py.

◆ _raftName

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

Definition at line 69 of file calibType.py.

◆ _requiredAttributes

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

Definition at line 114 of file calibType.py.

◆ _SCHEMA

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

Definition at line 64 of file calibType.py.

◆ _seqcksum

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

Definition at line 78 of file calibType.py.

◆ _seqfile

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

Definition at line 76 of file calibType.py.

◆ _seqname

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

Definition at line 77 of file calibType.py.

◆ _slotName

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

Definition at line 70 of file calibType.py.

◆ _VERSION

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

Definition at line 65 of file calibType.py.

◆ log

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

Definition at line 95 of file calibType.py.

◆ requiredAttributes

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

Definition at line 89 of file calibType.py.


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