LSST Applications g0000d66e7c+ce78115f25,g0485b4d2cb+c8d56b10d4,g0fba68d861+fcbc158cd0,g1ec0fe41b4+3e153770da,g1fd858c14a+57ee4e1624,g2440f9efcc+8c5ae1fdc5,g35bb328faa+8c5ae1fdc5,g4d2262a081+1e04cc5a47,g53246c7159+8c5ae1fdc5,g55585698de+7a33f081c8,g56a49b3a55+b9d5cac73f,g60b5630c4e+7a33f081c8,g67b6fd64d1+035c836e50,g78460c75b0+7e33a9eb6d,g786e29fd12+668abc6043,g7ac00fbb6c+b938379438,g8352419a5c+8c5ae1fdc5,g8852436030+5ba78a36c9,g89139ef638+035c836e50,g94187f82dc+7a33f081c8,g989de1cb63+035c836e50,g9d31334357+7a33f081c8,g9f33ca652e+e34120223a,ga815be3f0b+911242149a,gabe3b4be73+8856018cbb,gabf8522325+21619da9f3,gb1101e3267+0b44b44611,gb89ab40317+035c836e50,gc91f06edcd+e59fb3c9bc,gcf25f946ba+5ba78a36c9,gd6cbbdb0b4+958adf5c1f,gde0f65d7ad+6c98dcc924,ge278dab8ac+83c63f4893,ge410e46f29+035c836e50,gf35d7ec915+97dd712d81,gf5e32f922b+8c5ae1fdc5,gf67bdafdda+035c836e50,gf6800124b1+1714c04baa,w.2025.19
LSST Data Management Base Package
Loading...
Searching...
No Matches
lsst.ip.isr.transmissionCurve.IntermediateOpticsTransmissionCurve Class Reference
Inheritance diagram for lsst.ip.isr.transmissionCurve.IntermediateOpticsTransmissionCurve:
lsst.ip.isr.transmissionCurve.IntermediateTransmissionCurve lsst.ip.isr.calibType.IsrCalib

Public Member Functions

 setMetadata (self, metadata)
 
 fromTable (cls, tableList)
 
 setTransmissionCurveRepresentation (self)
 
 getTransmissionCurve (self)
 
 writeFits (self, outputFilename)
 
 requiredAttributes (self)
 
 requiredAttributes (self, value)
 
 __str__ (self)
 
 __eq__ (self, other)
 
 metadata (self)
 
 getMetadata (self)
 
 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)
 
 fromDetector (self, detector)
 
 fromDict (cls, dictionary, **kwargs)
 
 toDict (self)
 
 toTable (self)
 
 validate (self, other=None)
 
 apply (self, target)
 

Public Attributes

 data = None
 
 transmissionCurve = None
 
bool isSpatiallyConstant = True
 
 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

Definition at line 210 of file transmissionCurve.py.

Member Function Documentation

◆ __eq__()

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

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

Definition at line 103 of file calibType.py.

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

◆ __str__()

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

Definition at line 100 of file calibType.py.

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

◆ apply()

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

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

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

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

Definition at line 685 of file calibType.py.

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

◆ calibInfoFromDict()

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

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

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

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

Definition at line 322 of file calibType.py.

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

◆ determineCalibClass()

lsst.ip.isr.calibType.IsrCalib.determineCalibClass ( cls,
metadata,
message )
inherited
Attempt to find calibration class in metadata.

Parameters
----------
metadata : `dict` or `lsst.daf.base.PropertyList`
    Metadata possibly containing a calibration class entry.
message : `str`
    Message to include in any errors.

Returns
-------
calibClass : `object`
    The class to use to read the file contents.  Should be an
    `lsst.ip.isr.IsrCalib` subclass.

Raises
------
ValueError
    Raised if the resulting calibClass is the base
    `lsst.ip.isr.IsrClass` (which does not implement the
    content methods).

Definition at line 388 of file calibType.py.

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

◆ fromDetector()

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

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

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

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

Definition at line 567 of file calibType.py.

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

◆ fromDict()

lsst.ip.isr.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.

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

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

◆ fromTable()

lsst.ip.isr.transmissionCurve.IntermediateTransmissionCurve.fromTable ( cls,
tableList )
inherited
Construct intermediate transmission curve from a list of input
tables.  Only the first table is used.

Parameters
----------
tableList : `list` [`astropy.table.Table`]
    List containing input tables.

Returns
-------
calib : `lsst.ip.isr.IntermediateTransmissionCurve`
    The final calibration.

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

Definition at line 66 of file transmissionCurve.py.

66 def fromTable(cls, tableList):
67 """Construct intermediate transmission curve from a list of input
68 tables. Only the first table is used.
69
70 Parameters
71 ----------
72 tableList : `list` [`astropy.table.Table`]
73 List containing input tables.
74
75 Returns
76 -------
77 calib : `lsst.ip.isr.IntermediateTransmissionCurve`
78 The final calibration.
79 """
80 calib = cls()
81
82 metadata = tableList[0].meta
83 calib.setMetadata(metadata)
84 calib.updateMetadata()
85
86 calib.data = tableList[0]
87 calib.setTransmissionCurveRepresentation()
88 return calib
89

◆ getMetadata()

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

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

Definition at line 171 of file calibType.py.

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

◆ getTransmissionCurve()

lsst.ip.isr.transmissionCurve.IntermediateTransmissionCurve.getTransmissionCurve ( self)
inherited

Definition at line 165 of file transmissionCurve.py.

165 def getTransmissionCurve(self):
166 if self.transmissionCurve is None and self.data is None:
167 raise RuntimeError("No transmission curve data found.")
168 if self.transmissionCurve is None:
169 self.setTransmissionCurveRepresentation()
170 return self.transmissionCurve
171

◆ metadata()

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

Definition at line 168 of file calibType.py.

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

◆ readFits()

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

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

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

Definition at line 505 of file calibType.py.

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

◆ readText()

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

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

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

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

Definition at line 418 of file calibType.py.

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

◆ requiredAttributes() [1/2]

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

Definition at line 159 of file calibType.py.

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

◆ requiredAttributes() [2/2]

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

Definition at line 163 of file calibType.py.

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

◆ setMetadata()

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

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

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

Definition at line 61 of file transmissionCurve.py.

61 def setMetadata(self, metadata):
62 # Inherits from lsst.ip.isr.IsrCalib.setMetadata.
63 super().setMetadata(metadata)
64

◆ setTransmissionCurveRepresentation()

lsst.ip.isr.transmissionCurve.IntermediateTransmissionCurve.setTransmissionCurveRepresentation ( self)
inherited
Construct transmission curve representation from the data that was
read.

Raises
------
RuntimeError
    This is raised if no table data exists in the calibration,
    if there are array length mismatches, or if the wavelength
    sampling for multi-amp tables differ.

Definition at line 90 of file transmissionCurve.py.

90 def setTransmissionCurveRepresentation(self):
91 """Construct transmission curve representation from the data that was
92 read.
93
94 Raises
95 ------
96 RuntimeError
97 This is raised if no table data exists in the calibration,
98 if there are array length mismatches, or if the wavelength
99 sampling for multi-amp tables differ.
100 """
101 if self.data is None:
102 raise RuntimeError("No table data was found to convert to a transmission curve!")
103
104 throughputKey = None
105 if 'wavelength' not in self.data.columns:
106 raise RuntimeError("Expected column [wavelength] not found.")
107 if 'efficiency' in self.data.columns:
108 throughputKey = 'efficiency'
109 elif 'throughput' in self.data.columns:
110 throughputKey = 'throughput'
111 else:
112 raise RuntimeError("Expected columns [throughput|efficiency] not found.")
113
114 doAverageCurves = False
115 if 'amp_name' in self.data.columns:
116 doAverageCurves = True
117
118 # These will be used to construct the
119 # ``lsst.afw.image.TransmissionCurve`` object.
120 wavelengths = None
121 throughput = None
122
123 if doAverageCurves:
124 curveStack = None
125 amplifierNames = set(self.data['amp_name'])
126 comparisonIndices = np.where(self.data['amp_name'] == next(iter(amplifierNames)))
127 wavelengths = self.data[comparisonIndices]['wavelength']
128
129 for amplifier in amplifierNames:
130 indices = np.where(self.data['amp_name'] == amplifier)
131 if len(self.data[indices]) != len(self.data[comparisonIndices]):
132 raise RuntimeError("Incompatible lengths in average.")
133 if not np.array_equal(self.data[indices]['wavelength'], wavelengths):
134 raise RuntimeError("Mismatch in wavelength samples.")
135
136 if curveStack is not None:
137 curveStack = np.column_stack((curveStack, self.data[indices][throughputKey]))
138 else:
139 curveStack = self.data[indices][throughputKey]
140 throughput = np.mean(curveStack, 1)
141
142 # This averaging operation has stripped units.
143 throughput = throughput * self.data[throughputKey].unit
144 else:
145 wavelengths = self.data['wavelength']
146 throughput = self.data[throughputKey]
147
148 # Convert units:
149 # import pdb; pdb.set_trace()
150 with cds.enable():
151 # These need to be in Angstroms, for consistency.
152 wavelengths = wavelengths.to(u.Angstrom).to_value()
153
154 if throughput.unit != u.dimensionless_unscaled and throughput.unit != u.UnrecognizedUnit('-'):
155 # These need to be fractions, not percent.
156 throughput = throughput.to(u.dimensionless_unscaled).to_value()
157
158 self.transmissionCurve = TransmissionCurve.makeSpatiallyConstant(
159 throughput.astype(np.float64),
160 wavelengths.astype(np.float64),
161 throughputAtMin=0.0,
162 throughputAtMax=0.0
163 )
164

◆ toDict()

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

609 def toDict(self):
610 """Return a dictionary containing the calibration properties.
611
612 The dictionary should be able to be round-tripped through
613 `fromDict`.
614
615 Returns
616 -------
617 dictionary : `dict`
618 Dictionary of properties.
619
620 Raises
621 ------
622 NotImplementedError
623 Raised if not implemented.
624 """
625 raise NotImplementedError("Must be implemented by subclass.")
626

◆ toTable()

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

652 def toTable(self):
653 """Return a list of tables containing the calibration properties.
654
655 The table list should be able to be round-tripped through
656 `fromDict`.
657
658 Returns
659 -------
660 tableList : `list` [`lsst.afw.table.Table`]
661 List of tables of properties.
662
663 Raises
664 ------
665 NotImplementedError
666 Raised if not implemented.
667 """
668 raise NotImplementedError("Must be implemented by subclass.")
669

◆ updateMetadata()

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.

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 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 )
inherited
Extract and unify metadata information.

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

Definition at line 291 of file calibType.py.

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

◆ validate()

lsst.ip.isr.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.

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

Definition at line 670 of file calibType.py.

670 def validate(self, other=None):
671 """Validate that this calibration is defined and can be used.
672
673 Parameters
674 ----------
675 other : `object`, optional
676 Thing to validate against.
677
678 Returns
679 -------
680 valid : `bool`
681 Returns true if the calibration is valid and appropriate.
682 """
683 return False
684

◆ writeFits()

lsst.ip.isr.transmissionCurve.IntermediateTransmissionCurve.writeFits ( self,
outputFilename )
inherited
Write the transmission curve data to a file.

Parameters
----------
outputFilename : `str`
    Destination filename.

Returns
-------
outputFilename : `str`
    The output filename actually used.

Raises
------
RuntimeError
    Raised if no transmission curve can be created.

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

Definition at line 172 of file transmissionCurve.py.

172 def writeFits(self, outputFilename):
173 """Write the transmission curve data to a file.
174
175 Parameters
176 ----------
177 outputFilename : `str`
178 Destination filename.
179
180 Returns
181 -------
182 outputFilename : `str`
183 The output filename actually used.
184
185 Raises
186 ------
187 RuntimeError
188 Raised if no transmission curve can be created.
189 """
190 if self.transmissionCurve is None and self.data is None:
191 raise RuntimeError("No transmission curve data found.")
192 if self.transmissionCurve is None:
193 self.setTransmissionCurveRepresentation()
194
195 return self.transmissionCurve.writeFits(outputFilename)
196
197

◆ writeText()

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

Parameters
----------
filename : `str`
    Name of the file to write.
format : `str`
    Format to write the file as.  Supported values are:
        ``"auto"`` : Determine filetype from filename.
        ``"yaml"`` : Write as yaml.
        ``"ecsv"`` : Write as ecsv.

Returns
-------
used : `str`
    The name of the file used to write the data.  This may
    differ from the input if the format is explicitly chosen.

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

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

Definition at line 451 of file calibType.py.

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

Member Data Documentation

◆ _calibId

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

Definition at line 74 of file calibType.py.

◆ _detectorId

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

Definition at line 72 of file calibType.py.

◆ _detectorName

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

Definition at line 70 of file calibType.py.

◆ _detectorSerial

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

Definition at line 71 of file calibType.py.

◆ _filter

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

Definition at line 73 of file calibType.py.

◆ _instrument

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

Definition at line 67 of file calibType.py.

◆ _metadata

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

Definition at line 78 of file calibType.py.

◆ _OBSTYPE

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

Definition at line 62 of file calibType.py.

◆ _raftName

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

Definition at line 68 of file calibType.py.

◆ _requiredAttributes

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

Definition at line 113 of file calibType.py.

◆ _SCHEMA

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

Definition at line 63 of file calibType.py.

◆ _seqcksum

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

Definition at line 77 of file calibType.py.

◆ _seqfile

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

Definition at line 75 of file calibType.py.

◆ _seqname

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

Definition at line 76 of file calibType.py.

◆ _slotName

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

Definition at line 69 of file calibType.py.

◆ _VERSION

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

Definition at line 64 of file calibType.py.

◆ data

lsst.ip.isr.transmissionCurve.IntermediateTransmissionCurve.data = None
inherited

Definition at line 52 of file transmissionCurve.py.

◆ isSpatiallyConstant

bool lsst.ip.isr.transmissionCurve.IntermediateTransmissionCurve.isSpatiallyConstant = True
inherited

Definition at line 54 of file transmissionCurve.py.

◆ log

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

Definition at line 94 of file calibType.py.

◆ requiredAttributes

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

Definition at line 88 of file calibType.py.

◆ transmissionCurve

lsst.ip.isr.transmissionCurve.IntermediateTransmissionCurve.transmissionCurve = None
inherited

Definition at line 53 of file transmissionCurve.py.


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