LSST Applications g00d0e8bbd7+edbf708997,g199a45376c+5137f08352,g1fd858c14a+48cd4dd530,g228ff663f5+2051e4e242,g262e1987ae+9c6f24d2e3,g29ae962dfc+03663621e0,g2cef7863aa+73c82f25e4,g35bb328faa+edbf708997,g3fd5ace14f+8c4d25a1ce,g47891489e3+27ba970c8a,g53246c7159+edbf708997,g5b326b94bb+db962c32ee,g64539dfbff+d237af7fd9,g67b6fd64d1+27ba970c8a,g74acd417e5+8234f56c0c,g786e29fd12+af89c03590,g87389fa792+a4172ec7da,g88cb488625+6878ed1c5e,g89139ef638+27ba970c8a,g8d7436a09f+f76ea57dde,g8ea07a8fe4+79658f16ab,g90f42f885a+6577634e1f,g97be763408+494f77a6c4,g98df359435+1750ea0126,g9b50b81019+d8f85438e7,ga2180abaac+edbf708997,ga9e74d7ce9+128cc68277,gad4c79568f+321c5e11c3,gbf99507273+edbf708997,gc2a301910b+d237af7fd9,gca7fc764a6+27ba970c8a,gcedae5159b+afaec0eb3d,gd7ef33dd92+27ba970c8a,gdab6d2f7ff+8234f56c0c,gdbb4c4dda9+d237af7fd9,ge410e46f29+27ba970c8a,ge41e95a9f2+d237af7fd9,geaed405ab2+062dfc8cdc,w.2025.45
LSST Data Management Base Package
Loading...
Searching...
No Matches
lsst.ip.isr.transmissionCurve.IntermediateSensorTransmissionCurve Class Reference
Inheritance diagram for lsst.ip.isr.transmissionCurve.IntermediateSensorTransmissionCurve:
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 198 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 105 of file calibType.py.

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

◆ __str__()

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

Definition at line 102 of file calibType.py.

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

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

704 def apply(self, target):
705 """Method to apply the calibration to the target object.
706
707 Parameters
708 ----------
709 target : `object`
710 Thing to validate against.
711
712 Returns
713 -------
714 valid : `bool`
715 Returns true if the calibration was applied correctly.
716
717 Raises
718 ------
719 NotImplementedError
720 Raised if not implemented.
721 """
722 raise NotImplementedError("Must be implemented by subclass.")
723
724

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

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

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

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

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

586 def fromDetector(self, detector):
587 """Modify the calibration parameters to match the supplied detector.
588
589 Parameters
590 ----------
591 detector : `lsst.afw.cameraGeom.Detector`
592 Detector to use to set parameters from.
593
594 Raises
595 ------
596 NotImplementedError
597 Raised if not implemented by a subclass.
598 This needs to be implemented by subclasses for each
599 calibration type.
600 """
601 raise NotImplementedError("Must be implemented by subclass.")
602

◆ 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.flatGradient.FlatGradient, lsst.ip.isr.linearize.Linearizer, lsst.ip.isr.photodiode.PhotodiodeCalib, lsst.ip.isr.photodiodeCorrection.PhotodiodeCorrection, lsst.ip.isr.ptcDataset.PhotonTransferCurveDataset, and lsst.ip.isr.shutterMotion.ShutterMotionProfile.

Definition at line 604 of file calibType.py.

604 def fromDict(cls, dictionary, **kwargs):
605 """Construct a calibration from a dictionary of properties.
606
607 Must be implemented by the specific calibration subclasses.
608
609 Parameters
610 ----------
611 dictionary : `dict`
612 Dictionary of properties.
613 kwargs : `dict` or collections.abc.Mapping`, optional
614 Set of key=value options.
615
616 Returns
617 -------
618 calib : `lsst.ip.isr.CalibType`
619 Constructed calibration.
620
621 Raises
622 ------
623 NotImplementedError
624 Raised if not implemented.
625 """
626 raise NotImplementedError("Must be implemented by subclass.")
627

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

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

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

171 def metadata(self):
172 return self._metadata
173

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

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

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

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

◆ requiredAttributes() [1/2]

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

Definition at line 162 of file calibType.py.

162 def requiredAttributes(self):
163 return self._requiredAttributes
164

◆ requiredAttributes() [2/2]

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

Definition at line 166 of file calibType.py.

166 def requiredAttributes(self, value):
167 self._requiredAttributes = value
168

◆ 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.flatGradient.FlatGradient, lsst.ip.isr.linearize.Linearizer, lsst.ip.isr.photodiode.PhotodiodeCalib, lsst.ip.isr.photodiodeCorrection.PhotodiodeCorrection, lsst.ip.isr.ptcDataset.PhotonTransferCurveDataset, and lsst.ip.isr.shutterMotion.ShutterMotionProfile.

Definition at line 628 of file calibType.py.

628 def toDict(self):
629 """Return a dictionary containing the calibration properties.
630
631 The dictionary should be able to be round-tripped through
632 `fromDict`.
633
634 Returns
635 -------
636 dictionary : `dict`
637 Dictionary of properties.
638
639 Raises
640 ------
641 NotImplementedError
642 Raised if not implemented.
643 """
644 raise NotImplementedError("Must be implemented by subclass.")
645

◆ 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.flatGradient.FlatGradient, lsst.ip.isr.linearize.Linearizer, lsst.ip.isr.photodiode.PhotodiodeCalib, lsst.ip.isr.photodiodeCorrection.PhotodiodeCorrection, lsst.ip.isr.ptcDataset.PhotonTransferCurveDataset, and lsst.ip.isr.shutterMotion.ShutterMotionProfile.

Definition at line 671 of file calibType.py.

671 def toTable(self):
672 """Return a list of tables containing the calibration properties.
673
674 The table list should be able to be round-tripped through
675 `fromDict`.
676
677 Returns
678 -------
679 tableList : `list` [`lsst.afw.table.Table`]
680 List of tables of properties.
681
682 Raises
683 ------
684 NotImplementedError
685 Raised if not implemented.
686 """
687 raise NotImplementedError("Must be implemented by subclass.")
688

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

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

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

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

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

689 def validate(self, other=None):
690 """Validate that this calibration is defined and can be used.
691
692 Parameters
693 ----------
694 other : `object`, optional
695 Thing to validate against.
696
697 Returns
698 -------
699 valid : `bool`
700 Returns true if the calibration is valid and appropriate.
701 """
702 return False
703

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

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

Member Data Documentation

◆ _calibId

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

Definition at line 76 of file calibType.py.

◆ _detectorId

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

Definition at line 74 of file calibType.py.

◆ _detectorName

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

Definition at line 72 of file calibType.py.

◆ _detectorSerial

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

Definition at line 73 of file calibType.py.

◆ _filter

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

Definition at line 75 of file calibType.py.

◆ _instrument

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

Definition at line 69 of file calibType.py.

◆ _metadata

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

Definition at line 80 of file calibType.py.

◆ _OBSTYPE

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

Definition at line 64 of file calibType.py.

◆ _raftName

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

Definition at line 70 of file calibType.py.

◆ _requiredAttributes

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

Definition at line 115 of file calibType.py.

◆ _SCHEMA

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

Definition at line 65 of file calibType.py.

◆ _seqcksum

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

Definition at line 79 of file calibType.py.

◆ _seqfile

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

Definition at line 77 of file calibType.py.

◆ _seqname

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

Definition at line 78 of file calibType.py.

◆ _slotName

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

Definition at line 71 of file calibType.py.

◆ _VERSION

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

Definition at line 66 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 96 of file calibType.py.

◆ requiredAttributes

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

Definition at line 90 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: