LSST Applications  21.0.0+04719a4bac,21.0.0-1-ga51b5d4+f5e6047307,21.0.0-11-g2b59f77+a9c1acf22d,21.0.0-11-ga42c5b2+86977b0b17,21.0.0-12-gf4ce030+76814010d2,21.0.0-13-g1721dae+760e7a6536,21.0.0-13-g3a573fe+768d78a30a,21.0.0-15-g5a7caf0+f21cbc5713,21.0.0-16-g0fb55c1+b60e2d390c,21.0.0-19-g4cded4ca+71a93a33c0,21.0.0-2-g103fe59+bb20972958,21.0.0-2-g45278ab+04719a4bac,21.0.0-2-g5242d73+3ad5d60fb1,21.0.0-2-g7f82c8f+8babb168e8,21.0.0-2-g8f08a60+06509c8b61,21.0.0-2-g8faa9b5+616205b9df,21.0.0-2-ga326454+8babb168e8,21.0.0-2-gde069b7+5e4aea9c2f,21.0.0-2-gecfae73+1d3a86e577,21.0.0-2-gfc62afb+3ad5d60fb1,21.0.0-25-g1d57be3cd+e73869a214,21.0.0-3-g357aad2+ed88757d29,21.0.0-3-g4a4ce7f+3ad5d60fb1,21.0.0-3-g4be5c26+3ad5d60fb1,21.0.0-3-g65f322c+e0b24896a3,21.0.0-3-g7d9da8d+616205b9df,21.0.0-3-ge02ed75+a9c1acf22d,21.0.0-4-g591bb35+a9c1acf22d,21.0.0-4-g65b4814+b60e2d390c,21.0.0-4-gccdca77+0de219a2bc,21.0.0-4-ge8a399c+6c55c39e83,21.0.0-5-gd00fb1e+05fce91b99,21.0.0-6-gc675373+3ad5d60fb1,21.0.0-64-g1122c245+4fb2b8f86e,21.0.0-7-g04766d7+cd19d05db2,21.0.0-7-gdf92d54+04719a4bac,21.0.0-8-g5674e7b+d1bd76f71f,master-gac4afde19b+a9c1acf22d,w.2021.13
LSST Data Management Base Package
Public Member Functions | Public Attributes | List of all members
lsst.ip.isr.calibType.IsrProvenance Class Reference
Inheritance diagram for lsst.ip.isr.calibType.IsrProvenance:
lsst.ip.isr.calibType.IsrCalib

Public Member Functions

def __init__ (self, calibType="unknown", **kwargs)
 
def __str__ (self)
 
def __eq__ (self, other)
 
def updateMetadata (self, setDate=False, **kwargs)
 
def fromDataIds (self, dataIdList)
 
def fromTable (cls, tableList)
 
def fromDict (cls, dictionary)
 
def toDict (self)
 
def toTable (self)
 
def requiredAttributes (self)
 
def requiredAttributes (self, value)
 
def getMetadata (self)
 
def setMetadata (self, metadata)
 
def updateMetadata (self, camera=None, detector=None, filterName=None, setCalibId=False, setCalibInfo=False, setDate=False, **kwargs)
 
def calibInfoFromDict (self, dictionary)
 
def readText (cls, filename, **kwargs)
 
def writeText (self, filename, format='auto')
 
def readFits (cls, filename, **kwargs)
 
def writeFits (self, filename)
 
def fromDetector (self, detector)
 
def fromDict (cls, dictionary, **kwargs)
 
def fromTable (cls, tableList, **kwargs)
 
def validate (self, other=None)
 
def apply (self, target)
 

Public Attributes

 calibType
 
 dimensions
 
 dataIdList
 
 requiredAttributes
 
 log
 

Detailed Description

Class for the provenance of data used to construct calibration.

Provenance is not really a calibration, but we would like to
record this when constructing the calibration, and it provides an
example of the base calibration class.

Parameters
----------
instrument : `str`, optional
    Name of the instrument the data was taken with.
calibType : `str`, optional
    Type of calibration this provenance was generated for.
detectorName : `str`, optional
    Name of the detector this calibration is for.
detectorSerial : `str`, optional
    Identifier for the detector.

Definition at line 570 of file calibType.py.

Constructor & Destructor Documentation

◆ __init__()

def lsst.ip.isr.calibType.IsrProvenance.__init__ (   self,
  calibType = "unknown",
**  kwargs 
)

Definition at line 591 of file calibType.py.

592  **kwargs):
593  self.calibType = calibType
594  self.dimensions = set()
595  self.dataIdList = list()
596 
597  super().__init__(**kwargs)
598 
599  self.requiredAttributes.update(['calibType', 'dimensions', 'dataIdList'])
600 
daf::base::PropertyList * list
Definition: fits.cc:913
daf::base::PropertySet * set
Definition: fits.cc:912

Member Function Documentation

◆ __eq__()

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

Subclasses will need to check specific sub-properties.  The
default is only to check common entries.

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

Definition at line 604 of file calibType.py.

604  def __eq__(self, other):
605  return super().__eq__(other)
606 

◆ __str__()

def lsst.ip.isr.calibType.IsrProvenance.__str__ (   self)

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

Definition at line 601 of file calibType.py.

601  def __str__(self):
602  return f"{self.__class__.__name__}(obstype={self._OBSTYPE}, calibType={self.calibType}, )"
603 

◆ apply()

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

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

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

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

Definition at line 549 of file calibType.py.

549  def apply(self, target):
550  """Method to apply the calibration to the target object.
551 
552  Parameters
553  ----------
554  target : `object`
555  Thing to validate against.
556 
557  Returns
558  -------
559  valid : `bool`
560  Returns true if the calibration was applied correctly.
561 
562  Raises
563  ------
564  NotImplementedError :
565  Raised if not implemented.
566  """
567  raise NotImplementedError("Must be implemented by subclass.")
568 
569 

◆ calibInfoFromDict()

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

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

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

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

Definition at line 229 of file calibType.py.

229  def calibInfoFromDict(self, dictionary):
230  """Handle common keywords.
231 
232  This isn't an ideal solution, but until all calibrations
233  expect to find everything in the metadata, they still need to
234  search through dictionaries.
235 
236  Parameters
237  ----------
238  dictionary : `dict` or `lsst.daf.base.PropertyList`
239  Source for the common keywords.
240 
241  Raises
242  ------
243  RuntimeError :
244  Raised if the dictionary does not match the expected OBSTYPE.
245 
246  """
247 
248  def search(haystack, needles):
249  """Search dictionary 'haystack' for an entry in 'needles'
250  """
251  test = [haystack.get(x) for x in needles]
252  test = set([x for x in test if x is not None])
253  if len(test) == 0:
254  if 'metadata' in haystack:
255  return search(haystack['metadata'], needles)
256  else:
257  return None
258  elif len(test) == 1:
259  value = list(test)[0]
260  if value == '':
261  return None
262  else:
263  return value
264  else:
265  raise ValueError(f"Too many values found: {len(test)} {test} {needles}")
266 
267  if 'metadata' in dictionary:
268  metadata = dictionary['metadata']
269 
270  if self._OBSTYPE != metadata['OBSTYPE']:
271  raise RuntimeError(f"Incorrect calibration supplied. Expected {self._OBSTYPE}, "
272  f"found {metadata['OBSTYPE']}")
273 
274  self._instrument = search(dictionary, ['INSTRUME', 'instrument'])
275  self._raftName = search(dictionary, ['RAFTNAME'])
276  self._slotName = search(dictionary, ['SLOTNAME'])
277  self._detectorId = search(dictionary, ['DETECTOR', 'detectorId'])
278  self._detectorName = search(dictionary, ['DET_NAME', 'DETECTOR_NAME', 'detectorName'])
279  self._detectorSerial = search(dictionary, ['DET_SER', 'DETECTOR_SERIAL', 'detectorSerial'])
280  self._filter = search(dictionary, ['FILTER', 'filterName'])
281  self._calibId = search(dictionary, ['CALIB_ID'])
282 

◆ fromDataIds()

def lsst.ip.isr.calibType.IsrProvenance.fromDataIds (   self,
  dataIdList 
)
Update provenance from dataId List.

Parameters
----------
dataIdList : `list` [`lsst.daf.butler.DataId`]
    List of dataIds used in generating this calibration.

Definition at line 621 of file calibType.py.

621  def fromDataIds(self, dataIdList):
622  """Update provenance from dataId List.
623 
624  Parameters
625  ----------
626  dataIdList : `list` [`lsst.daf.butler.DataId`]
627  List of dataIds used in generating this calibration.
628  """
629  for dataId in dataIdList:
630  for key in dataId:
631  if key not in self.dimensions:
632  self.dimensions.add(key)
633  self.dataIdList.append(dataId)
634 
std::shared_ptr< FrameSet > append(FrameSet const &first, FrameSet const &second)
Construct a FrameSet that performs two transformations in series.
Definition: functional.cc:33

◆ fromDetector()

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

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

Raises
------
NotImplementedError
    This needs to be implemented by subclasses for each
    calibration type.

Reimplemented in lsst.ip.isr.linearize.Linearizer.

Definition at line 432 of file calibType.py.

432  def fromDetector(self, detector):
433  """Modify the calibration parameters to match the supplied detector.
434 
435  Parameters
436  ----------
437  detector : `lsst.afw.cameraGeom.Detector`
438  Detector to use to set parameters from.
439 
440  Raises
441  ------
442  NotImplementedError
443  This needs to be implemented by subclasses for each
444  calibration type.
445  """
446  raise NotImplementedError("Must be implemented by subclass.")
447 

◆ fromDict() [1/2]

def lsst.ip.isr.calibType.IsrProvenance.fromDict (   cls,
  dictionary 
)
Construct provenance from a dictionary.

Parameters
----------
dictionary : `dict`
    Dictionary of provenance parameters.

Returns
-------
provenance : `lsst.ip.isr.IsrProvenance`
    The provenance defined in the tables.

Definition at line 672 of file calibType.py.

672  def fromDict(cls, dictionary):
673  """Construct provenance from a dictionary.
674 
675  Parameters
676  ----------
677  dictionary : `dict`
678  Dictionary of provenance parameters.
679 
680  Returns
681  -------
682  provenance : `lsst.ip.isr.IsrProvenance`
683  The provenance defined in the tables.
684  """
685  calib = cls()
686  if calib._OBSTYPE != dictionary['metadata']['OBSTYPE']:
687  raise RuntimeError(f"Incorrect calibration supplied. Expected {calib._OBSTYPE}, "
688  f"found {dictionary['metadata']['OBSTYPE']}")
689  calib.updateMetadata(setDate=False, setCalibInfo=True, **dictionary['metadata'])
690 
691  # These properties should be in the metadata, but occasionally
692  # are found in the dictionary itself. Check both places,
693  # ending with `None` if neither contains the information.
694  calib.calibType = dictionary['calibType']
695  calib.dimensions = set(dictionary['dimensions'])
696  calib.dataIdList = dictionary['dataIdList']
697 
698  calib.updateMetadata()
699  return calib
700 

◆ fromDict() [2/2]

def lsst.ip.isr.calibType.IsrCalib.fromDict (   cls,
  dictionary,
**  kwargs 
)
inherited
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.

Definition at line 449 of file calibType.py.

449  def fromDict(cls, dictionary, **kwargs):
450  """Construct a calibration from a dictionary of properties.
451 
452  Must be implemented by the specific calibration subclasses.
453 
454  Parameters
455  ----------
456  dictionary : `dict`
457  Dictionary of properties.
458  kwargs : `dict` or collections.abc.Mapping`, optional
459  Set of key=value options.
460 
461  Returns
462  ------
463  calib : `lsst.ip.isr.CalibType`
464  Constructed calibration.
465 
466  Raises
467  ------
468  NotImplementedError :
469  Raised if not implemented.
470  """
471  raise NotImplementedError("Must be implemented by subclass.")
472 

◆ fromTable() [1/2]

def lsst.ip.isr.calibType.IsrProvenance.fromTable (   cls,
  tableList 
)
Construct provenance from table list.

Parameters
----------
tableList : `list` [`lsst.afw.table.Table`]
    List of tables to construct the provenance from.

Returns
-------
provenance : `lsst.ip.isr.IsrProvenance`
    The provenance defined in the tables.

Definition at line 636 of file calibType.py.

636  def fromTable(cls, tableList):
637  """Construct provenance from table list.
638 
639  Parameters
640  ----------
641  tableList : `list` [`lsst.afw.table.Table`]
642  List of tables to construct the provenance from.
643 
644  Returns
645  -------
646  provenance : `lsst.ip.isr.IsrProvenance`
647  The provenance defined in the tables.
648  """
649  table = tableList[0]
650  metadata = table.meta
651  inDict = dict()
652  inDict['metadata'] = metadata
653  inDict['calibType'] = metadata['calibType']
654  inDict['dimensions'] = set()
655  inDict['dataIdList'] = list()
656 
657  schema = dict()
658  for colName in table.columns:
659  schema[colName.lower()] = colName
660  inDict['dimensions'].add(colName.lower())
661  inDict['dimensions'] = sorted(inDict['dimensions'])
662 
663  for row in table:
664  entry = dict()
665  for dim in sorted(inDict['dimensions']):
666  entry[dim] = row[schema[dim]]
667  inDict['dataIdList'].append(entry)
668 
669  return cls.fromDict(inDict)
670 

◆ fromTable() [2/2]

def lsst.ip.isr.calibType.IsrCalib.fromTable (   cls,
  tableList,
**  kwargs 
)
inherited
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.

Definition at line 492 of file calibType.py.

492  def fromTable(cls, tableList, **kwargs):
493  """Construct a calibration from a dictionary of properties.
494 
495  Must be implemented by the specific calibration subclasses.
496 
497  Parameters
498  ----------
499  tableList : `list` [`lsst.afw.table.Table`]
500  List of tables of properties.
501  kwargs : `dict` or collections.abc.Mapping`, optional
502  Set of key=value options.
503 
504  Returns
505  ------
506  calib : `lsst.ip.isr.CalibType`
507  Constructed calibration.
508 
509  Raises
510  ------
511  NotImplementedError :
512  Raised if not implemented.
513  """
514  raise NotImplementedError("Must be implemented by subclass.")
515 

◆ getMetadata()

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

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

Definition at line 114 of file calibType.py.

114  def getMetadata(self):
115  """Retrieve metadata associated with this calibration.
116 
117  Returns
118  -------
119  meta : `lsst.daf.base.PropertyList`
120  Metadata. The returned `~lsst.daf.base.PropertyList` can be
121  modified by the caller and the changes will be written to
122  external files.
123  """
124  return self._metadata
125 

◆ readFits()

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

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

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

Definition at line 370 of file calibType.py.

370  def readFits(cls, filename, **kwargs):
371  """Read calibration data from a FITS file.
372 
373  Parameters
374  ----------
375  filename : `str`
376  Filename to read data from.
377  kwargs : `dict` or collections.abc.Mapping`, optional
378  Set of key=value pairs to pass to the ``fromTable``
379  method.
380 
381  Returns
382  -------
383  calib : `lsst.ip.isr.IsrCalib`
384  Calibration contained within the file.
385  """
386  tableList = []
387  tableList.append(Table.read(filename, hdu=1))
388  extNum = 2 # Fits indices start at 1, we've read one already.
389  keepTrying = True
390 
391  while keepTrying:
392  with warnings.catch_warnings():
393  warnings.simplefilter("error")
394  try:
395  newTable = Table.read(filename, hdu=extNum)
396  tableList.append(newTable)
397  extNum += 1
398  except Exception:
399  keepTrying = False
400 
401  for table in tableList:
402  for k, v in table.meta.items():
403  if isinstance(v, fits.card.Undefined):
404  table.meta[k] = None
405 
406  return cls.fromTable(tableList, **kwargs)
407 

◆ readText()

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

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

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

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

Definition at line 284 of file calibType.py.

284  def readText(cls, filename, **kwargs):
285  """Read calibration representation from a yaml/ecsv file.
286 
287  Parameters
288  ----------
289  filename : `str`
290  Name of the file containing the calibration definition.
291  kwargs : `dict` or collections.abc.Mapping`, optional
292  Set of key=value pairs to pass to the ``fromDict`` or
293  ``fromTable`` methods.
294 
295  Returns
296  -------
297  calib : `~lsst.ip.isr.IsrCalibType`
298  Calibration class.
299 
300  Raises
301  ------
302  RuntimeError :
303  Raised if the filename does not end in ".ecsv" or ".yaml".
304  """
305  if filename.endswith((".ecsv", ".ECSV")):
306  data = Table.read(filename, format='ascii.ecsv')
307  return cls.fromTable([data], **kwargs)
308 
309  elif filename.endswith((".yaml", ".YAML")):
310  with open(filename, 'r') as f:
311  data = yaml.load(f, Loader=yaml.CLoader)
312  return cls.fromDict(data, **kwargs)
313  else:
314  raise RuntimeError(f"Unknown filename extension: {filename}")
315 

◆ requiredAttributes() [1/2]

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

Definition at line 107 of file calibType.py.

107  def requiredAttributes(self):
108  return self._requiredAttributes
109 

◆ requiredAttributes() [2/2]

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

Definition at line 111 of file calibType.py.

111  def requiredAttributes(self, value):
112  self._requiredAttributes = value
113 

◆ setMetadata()

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

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

Definition at line 126 of file calibType.py.

126  def setMetadata(self, metadata):
127  """Store a copy of the supplied metadata with this calibration.
128 
129  Parameters
130  ----------
131  metadata : `lsst.daf.base.PropertyList`
132  Metadata to associate with the calibration. Will be copied and
133  overwrite existing metadata.
134  """
135  if metadata is not None:
136  self._metadata.update(metadata)
137 
138  # Ensure that we have the obs type required by calibration ingest
139  self._metadata["OBSTYPE"] = self._OBSTYPE
140  self._metadata[self._OBSTYPE + "_SCHEMA"] = self._SCHEMA
141  self._metadata[self._OBSTYPE + "_VERSION"] = self._VERSION
142 
143  if isinstance(metadata, dict):
144  self.calibInfoFromDict(metadata)
145  elif isinstance(metadata, PropertyList):
146  self.calibInfoFromDict(metadata.toDict())
147 

◆ toDict()

def lsst.ip.isr.calibType.IsrProvenance.toDict (   self)
Return a dictionary containing the provenance information.

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

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

Definition at line 701 of file calibType.py.

701  def toDict(self):
702  """Return a dictionary containing the provenance information.
703 
704  Returns
705  -------
706  dictionary : `dict`
707  Dictionary of provenance.
708  """
709  self.updateMetadata()
710 
711  outDict = {}
712 
713  metadata = self.getMetadata()
714  outDict['metadata'] = metadata
715  outDict['detectorName'] = self._detectorName
716  outDict['detectorSerial'] = self._detectorSerial
717  outDict['detectorId'] = self._detectorId
718  outDict['instrument'] = self._instrument
719  outDict['calibType'] = self.calibType
720  outDict['dimensions'] = list(self.dimensions)
721  outDict['dataIdList'] = self.dataIdList
722 
723  return outDict
724 

◆ toTable()

def lsst.ip.isr.calibType.IsrProvenance.toTable (   self)
Return a list of tables containing the provenance.

This seems inefficient and slow, so this may not be the best
way to store the data.

Returns
-------
tableList : `list` [`lsst.afw.table.Table`]
    List of tables containing the provenance information

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

Definition at line 725 of file calibType.py.

725  def toTable(self):
726  """Return a list of tables containing the provenance.
727 
728  This seems inefficient and slow, so this may not be the best
729  way to store the data.
730 
731  Returns
732  -------
733  tableList : `list` [`lsst.afw.table.Table`]
734  List of tables containing the provenance information
735 
736  """
737  tableList = []
738  self.updateMetadata(setDate=True, setCalibInfo=True)
739 
740  catalog = Table(rows=self.dataIdList,
741  names=self.dimensions)
742  filteredMetadata = {k: v for k, v in self.getMetadata().toDict().items() if v is not None}
743  catalog.meta = filteredMetadata
744  tableList.append(catalog)
745  return tableList
std::vector< SchemaItem< Flag > > * items

◆ updateMetadata() [1/2]

def lsst.ip.isr.calibType.IsrCalib.updateMetadata (   self,
  camera = None,
  detector = None,
  filterName = None,
  setCalibId = False,
  setCalibInfo = False,
  setDate = False,
**  kwargs 
)
inherited
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.

Definition at line 148 of file calibType.py.

150  **kwargs):
151  """Update metadata keywords with new values.
152 
153  Parameters
154  ----------
155  camera : `lsst.afw.cameraGeom.Camera`, optional
156  Reference camera to use to set _instrument field.
157  detector : `lsst.afw.cameraGeom.Detector`, optional
158  Reference detector to use to set _detector* fields.
159  filterName : `str`, optional
160  Filter name to assign to this calibration.
161  setCalibId : `bool`, optional
162  Construct the _calibId field from other fields.
163  setCalibInfo : `bool`, optional
164  Set calibration parameters from metadata.
165  setDate : `bool`, optional
166  Ensure the metadata CALIBDATE fields are set to the current datetime.
167  kwargs : `dict` or `collections.abc.Mapping`, optional
168  Set of key=value pairs to assign to the metadata.
169  """
170  mdOriginal = self.getMetadata()
171  mdSupplemental = dict()
172 
173  for k, v in kwargs.items():
174  if isinstance(v, fits.card.Undefined):
175  kwargs[k] = None
176 
177  if setCalibInfo:
178  self.calibInfoFromDict(kwargs)
179 
180  if camera:
181  self._instrument = camera.getName()
182 
183  if detector:
184  self._detectorName = detector.getName()
185  self._detectorSerial = detector.getSerial()
186  self._detectorId = detector.getId()
187  if "_" in self._detectorName:
188  (self._raftName, self._slotName) = self._detectorName.split("_")
189 
190  if filterName:
191  # TOD0 DM-28093: I think this whole comment can go away, if we
192  # always use physicalLabel everywhere in ip_isr.
193  # If set via:
194  # exposure.getInfo().getFilter().getName()
195  # then this will hold the abstract filter.
196  self._filter = filterName
197 
198  if setDate:
199  date = datetime.datetime.now()
200  mdSupplemental['CALIBDATE'] = date.isoformat()
201  mdSupplemental['CALIB_CREATION_DATE'] = date.date().isoformat()
202  mdSupplemental['CALIB_CREATION_TIME'] = date.time().isoformat()
203 
204  if setCalibId:
205  values = []
206  values.append(f"instrument={self._instrument}") if self._instrument else None
207  values.append(f"raftName={self._raftName}") if self._raftName else None
208  values.append(f"detectorName={self._detectorName}") if self._detectorName else None
209  values.append(f"detector={self._detectorId}") if self._detectorId else None
210  values.append(f"filter={self._filter}") if self._filter else None
211 
212  calibDate = mdOriginal.get('CALIBDATE', mdSupplemental.get('CALIBDATE', None))
213  values.append(f"calibDate={calibDate}") if calibDate else None
214 
215  self._calibId = " ".join(values)
216 
217  self._metadata["INSTRUME"] = self._instrument if self._instrument else None
218  self._metadata["RAFTNAME"] = self._raftName if self._raftName else None
219  self._metadata["SLOTNAME"] = self._slotName if self._slotName else None
220  self._metadata["DETECTOR"] = self._detectorId
221  self._metadata["DET_NAME"] = self._detectorName if self._detectorName else None
222  self._metadata["DET_SER"] = self._detectorSerial if self._detectorSerial else None
223  self._metadata["FILTER"] = self._filter if self._filter else None
224  self._metadata["CALIB_ID"] = self._calibId if self._calibId else None
225 
226  mdSupplemental.update(kwargs)
227  mdOriginal.update(mdSupplemental)
228 

◆ updateMetadata() [2/2]

def lsst.ip.isr.calibType.IsrProvenance.updateMetadata (   self,
  setDate = False,
**  kwargs 
)
Update calibration metadata.

Parameters
----------
setDate : `bool, optional
    Update the CALIBDATE fields in the metadata to the current
    time. Defaults to False.
kwargs : `dict` or `collections.abc.Mapping`, optional
    Other keyword parameters to set in the metadata.

Definition at line 607 of file calibType.py.

607  def updateMetadata(self, setDate=False, **kwargs):
608  """Update calibration metadata.
609 
610  Parameters
611  ----------
612  setDate : `bool, optional
613  Update the CALIBDATE fields in the metadata to the current
614  time. Defaults to False.
615  kwargs : `dict` or `collections.abc.Mapping`, optional
616  Other keyword parameters to set in the metadata.
617  """
618  kwargs['calibType'] = self.calibType
619  super().updateMetadata(setDate=setDate, **kwargs)
620 

◆ validate()

def lsst.ip.isr.calibType.IsrCalib.validate (   self,
  other = None 
)
inherited
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.

Definition at line 534 of file calibType.py.

534  def validate(self, other=None):
535  """Validate that this calibration is defined and can be used.
536 
537  Parameters
538  ----------
539  other : `object`, optional
540  Thing to validate against.
541 
542  Returns
543  -------
544  valid : `bool`
545  Returns true if the calibration is valid and appropriate.
546  """
547  return False
548 

◆ writeFits()

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

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

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

Definition at line 408 of file calibType.py.

408  def writeFits(self, filename):
409  """Write calibration data to a FITS file.
410 
411  Parameters
412  ----------
413  filename : `str`
414  Filename to write data to.
415 
416  Returns
417  -------
418  used : `str`
419  The name of the file used to write the data.
420 
421  """
422  tableList = self.toTable()
423  with warnings.catch_warnings():
424  warnings.filterwarnings("ignore", category=Warning, module="astropy.io")
425  astropyList = [fits.table_to_hdu(table) for table in tableList]
426  astropyList.insert(0, fits.PrimaryHDU())
427 
428  writer = fits.HDUList(astropyList)
429  writer.writeto(filename, overwrite=True)
430  return filename
431 
def writeFits(filename, stamp_ims, metadata, type_name, write_mask, write_variance)
Definition: stamps.py:40

◆ writeText()

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

Parameters
----------
filename : `str`
    Name of the file to write.
format : `str`
    Format to write the file as.  Supported values are:
        ``"auto"`` : Determine filetype from filename.
        ``"yaml"`` : Write as yaml.
        ``"ecsv"`` : Write as ecsv.
Returns
-------
used : `str`
    The name of the file used to write the data.  This may
    differ from the input if the format is explicitly chosen.

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

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

Definition at line 316 of file calibType.py.

316  def writeText(self, filename, format='auto'):
317  """Write the calibration data to a text file.
318 
319  Parameters
320  ----------
321  filename : `str`
322  Name of the file to write.
323  format : `str`
324  Format to write the file as. Supported values are:
325  ``"auto"`` : Determine filetype from filename.
326  ``"yaml"`` : Write as yaml.
327  ``"ecsv"`` : Write as ecsv.
328  Returns
329  -------
330  used : `str`
331  The name of the file used to write the data. This may
332  differ from the input if the format is explicitly chosen.
333 
334  Raises
335  ------
336  RuntimeError :
337  Raised if filename does not end in a known extension, or
338  if all information cannot be written.
339 
340  Notes
341  -----
342  The file is written to YAML/ECSV format and will include any
343  associated metadata.
344 
345  """
346  if format == 'yaml' or (format == 'auto' and filename.lower().endswith((".yaml", ".YAML"))):
347  outDict = self.toDict()
348  path, ext = os.path.splitext(filename)
349  filename = path + ".yaml"
350  with open(filename, 'w') as f:
351  yaml.dump(outDict, f)
352  elif format == 'ecsv' or (format == 'auto' and filename.lower().endswith((".ecsv", ".ECSV"))):
353  tableList = self.toTable()
354  if len(tableList) > 1:
355  # ECSV doesn't support multiple tables per file, so we
356  # can only write the first table.
357  raise RuntimeError(f"Unable to persist {len(tableList)}tables in ECSV format.")
358 
359  table = tableList[0]
360  path, ext = os.path.splitext(filename)
361  filename = path + ".ecsv"
362  table.write(filename, format="ascii.ecsv")
363  else:
364  raise RuntimeError(f"Attempt to write to a file {filename} "
365  "that does not end in '.yaml' or '.ecsv'")
366 
367  return filename
368 

Member Data Documentation

◆ calibType

lsst.ip.isr.calibType.IsrProvenance.calibType

Definition at line 593 of file calibType.py.

◆ dataIdList

lsst.ip.isr.calibType.IsrProvenance.dataIdList

Definition at line 595 of file calibType.py.

◆ dimensions

lsst.ip.isr.calibType.IsrProvenance.dimensions

Definition at line 594 of file calibType.py.

◆ log

lsst.ip.isr.calibType.IsrCalib.log
inherited

Definition at line 82 of file calibType.py.

◆ requiredAttributes

lsst.ip.isr.calibType.IsrCalib.requiredAttributes
inherited

Definition at line 77 of file calibType.py.


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