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.ptcDataset.PhotonTransferCurveDataset Class Reference
Inheritance diagram for lsst.ip.isr.ptcDataset.PhotonTransferCurveDataset:
lsst.ip.isr.calibType.IsrCalib

Public Member Functions

def __init__ (self, ampNames=[], ptcFitType=None, covMatrixSide=1, **kwargs)
 
def __eq__ (self, other)
 
def setAmpValues (self, ampName, inputExpIdPair=[(np.nan, np.nan)], expIdMask=[np.nan], rawExpTime=[np.nan], rawMean=[np.nan], rawVar=[np.nan], photoCharge=[np.nan], gain=np.nan, gainErr=np.nan, noise=np.nan, noiseErr=np.nan, ptcFitPars=[np.nan], ptcFitParsError=[np.nan], ptcFitChiSq=np.nan, covArray=[], covArrayModel=[], covSqrtWeights=[], aMatrix=[], bMatrix=[], covArrayModelNoB=[], aMatrixNoB=[], finalVar=[np.nan], finalModelVar=[np.nan], finalMean=[np.nan])
 
def updateMetadata (self, setDate=False, **kwargs)
 
def fromDict (cls, dictionary)
 
def toDict (self)
 
def fromTable (cls, tableList)
 
def toTable (self)
 
def getExpIdsUsed (self, ampName)
 
def getGoodAmps (self)
 
def requiredAttributes (self)
 
def requiredAttributes (self, value)
 
def __str__ (self)
 
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

 ptcFitType
 
 ampNames
 
 covMatrixSide
 
 badAmps
 
 inputExpIdPairs
 
 expIdMask
 
 rawExpTimes
 
 rawMeans
 
 rawVars
 
 photoCharge
 
 gain
 
 gainErr
 
 noise
 
 noiseErr
 
 ptcFitPars
 
 ptcFitParsError
 
 ptcFitChiSq
 
 covariances
 
 covariancesModel
 
 covariancesSqrtWeights
 
 aMatrix
 
 bMatrix
 
 covariancesModelNoB
 
 aMatrixNoB
 
 finalVars
 
 finalModelVars
 
 finalMeans
 
 requiredAttributes
 
 log
 

Detailed Description

A simple class to hold the output data from the PTC task.
The dataset is made up of a dictionary for each item, keyed by the
amplifiers' names, which much be supplied at construction time.
New items cannot be added to the class to save accidentally saving to the
wrong property, and the class can be frozen if desired.
inputExpIdPairs records the exposures used to produce the data.
When fitPtc() or fitCovariancesAstier() is run, a mask is built up, which
is by definition always the same length as inputExpIdPairs, rawExpTimes,
rawMeans and rawVars, and is a list of bools, which are incrementally set
to False as points are discarded from the fits.
PTC fit parameters for polynomials are stored in a list in ascending order
of polynomial term, i.e. par[0]*x^0 + par[1]*x + par[2]*x^2 etc
with the length of the list corresponding to the order of the polynomial
plus one.

Parameters
----------
ampNames : `list`
    List with the names of the amplifiers of the detector at hand.

ptcFitType : `str`
    Type of model fitted to the PTC: "POLYNOMIAL", "EXPAPPROXIMATION",
    or "FULLCOVARIANCE".

covMatrixSide : `int`
    Maximum lag of covariances (size of square covariance matrices).

kwargs : `dict`, optional
    Other keyword arguments to pass to the parent init.

Notes
-----
The stored attributes are:
badAmps : `list`
    List with bad amplifiers names.
inputExpIdPairs : `dict`, [`str`, `list`]
    Dictionary keyed by amp names containing the input exposures IDs.
expIdMask : `dict`, [`str`, `list`]
    Dictionary keyed by amp names containing the mask produced after
    outlier rejection. The mask produced by the "FULLCOVARIANCE"
    option may differ from the one produced in the other two PTC
    fit types.
rawExpTimes : `dict`, [`str`, `list`]
    Dictionary keyed by amp names containing the unmasked exposure times.
rawMeans : `dict`, [`str`, `list`]
    Dictionary keyed by amp namescontaining the unmasked average of the
    means of the exposures in each flat pair.
rawVars : `dict`, [`str`, `list`]
    Dictionary keyed by amp names containing the variance of the
    difference image of the exposures in each flat pair.
gain : `dict`, [`str`, `list`]
    Dictionary keyed by amp names containing the fitted gains.
gainErr : `dict`, [`str`, `list`]
    Dictionary keyed by amp names containing the errors on the
    fitted gains.
noise : `dict`, [`str`, `list`]
    Dictionary keyed by amp names containing the fitted noise.
noiseErr : `dict`, [`str`, `list`]
    Dictionary keyed by amp names containing the errors on the fitted noise.
ptcFitPars : `dict`, [`str`, `list`]
    Dictionary keyed by amp names containing the fitted parameters of the
    PTC model for ptcFitTye in ["POLYNOMIAL", "EXPAPPROXIMATION"].
ptcFitParsError : `dict`, [`str`, `list`]
    Dictionary keyed by amp names containing the errors on the fitted
    parameters of the PTC model for ptcFitTye in
    ["POLYNOMIAL", "EXPAPPROXIMATION"].
ptcFitChiSq : `dict`, [`str`, `list`]
    Dictionary keyed by amp names containing the reduced chi squared
    of the fit for ptcFitTye in ["POLYNOMIAL", "EXPAPPROXIMATION"].
covariances : `dict`, [`str`, `list`]
    Dictionary keyed by amp names containing a list of measured
    covariances per mean flux.
covariancesModel : `dict`, [`str`, `list`]
    Dictionary keyed by amp names containinging covariances model
    (Eq. 20 of Astier+19) per mean flux.
covariancesSqrtWeights : `dict`, [`str`, `list`]
    Dictionary keyed by amp names containinging sqrt. of covariances
    weights.
aMatrix : `dict`, [`str`, `list`]
    Dictionary keyed by amp names containing the "a" parameters from
    the model in Eq. 20 of Astier+19.
bMatrix : `dict`, [`str`, `list`]
    Dictionary keyed by amp names containing the "b" parameters from
    the model in Eq. 20 of Astier+19.
covariancesModelNoB : `dict`, [`str`, `list`]
    Dictionary keyed by amp names containing covariances model
    (with 'b'=0 in Eq. 20 of Astier+19)
    per mean flux.
aMatrixNoB : `dict`, [`str`, `list`]
    Dictionary keyed by amp names containing the "a" parameters from the
    model in Eq. 20 of Astier+19
    (and 'b' = 0).
finalVars : `dict`, [`str`, `list`]
    Dictionary keyed by amp names containing the masked variance of the
    difference image of each flat
    pair. If needed, each array will be right-padded with
    np.nan to match the length of rawExpTimes.
finalModelVars : `dict`, [`str`, `list`]
    Dictionary keyed by amp names containing the masked modeled
    variance of the difference image of each flat pair. If needed, each
    array will be right-padded with np.nan to match the length of
    rawExpTimes.
finalMeans : `dict`, [`str`, `list`]
    Dictionary keyed by amp names containing the masked average of the
    means of the exposures in each flat pair. If needed, each array
    will be right-padded with np.nan to match the length of
    rawExpTimes.
photoCharge : `dict`, [`str`, `list`]
     Dictionary keyed by amp names containing the integrated photocharge
     for linearity calibration.

Returns
-------
`lsst.cp.pipe.ptc.PhotonTransferCurveDataset`
    Output dataset from MeasurePhotonTransferCurveTask.

Definition at line 33 of file ptcDataset.py.

Constructor & Destructor Documentation

◆ __init__()

def lsst.ip.isr.ptcDataset.PhotonTransferCurveDataset.__init__ (   self,
  ampNames = [],
  ptcFitType = None,
  covMatrixSide = 1,
**  kwargs 
)

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

Definition at line 155 of file ptcDataset.py.

155  def __init__(self, ampNames=[], ptcFitType=None, covMatrixSide=1, **kwargs):
156 
157  self.ptcFitType = ptcFitType
158  self.ampNames = ampNames
159  self.covMatrixSide = covMatrixSide
160 
161  self.badAmps = [np.nan]
162 
163  self.inputExpIdPairs = {ampName: [] for ampName in ampNames}
164  self.expIdMask = {ampName: [] for ampName in ampNames}
165  self.rawExpTimes = {ampName: [] for ampName in ampNames}
166  self.rawMeans = {ampName: [] for ampName in ampNames}
167  self.rawVars = {ampName: [] for ampName in ampNames}
168  self.photoCharge = {ampName: [] for ampName in ampNames}
169 
170  self.gain = {ampName: np.nan for ampName in ampNames}
171  self.gainErr = {ampName: np.nan for ampName in ampNames}
172  self.noise = {ampName: np.nan for ampName in ampNames}
173  self.noiseErr = {ampName: np.nan for ampName in ampNames}
174 
175  self.ptcFitPars = {ampName: [] for ampName in ampNames}
176  self.ptcFitParsError = {ampName: [] for ampName in ampNames}
177  self.ptcFitChiSq = {ampName: np.nan for ampName in ampNames}
178 
179  self.covariances = {ampName: [] for ampName in ampNames}
180  self.covariancesModel = {ampName: [] for ampName in ampNames}
181  self.covariancesSqrtWeights = {ampName: [] for ampName in ampNames}
182  self.aMatrix = {ampName: np.nan for ampName in ampNames}
183  self.bMatrix = {ampName: np.nan for ampName in ampNames}
184  self.covariancesModelNoB = {ampName: [] for ampName in ampNames}
185  self.aMatrixNoB = {ampName: np.nan for ampName in ampNames}
186 
187  self.finalVars = {ampName: [] for ampName in ampNames}
188  self.finalModelVars = {ampName: [] for ampName in ampNames}
189  self.finalMeans = {ampName: [] for ampName in ampNames}
190 
191  super().__init__(**kwargs)
192  self.requiredAttributes.update(['badAmps', 'inputExpIdPairs', 'expIdMask', 'rawExpTimes',
193  'rawMeans', 'rawVars', 'gain', 'gainErr', 'noise', 'noiseErr',
194  'ptcFitPars', 'ptcFitParsError', 'ptcFitChiSq', 'aMatrixNoB',
195  'covariances', 'covariancesModel', 'covariancesSqrtWeights',
196  'covariancesModelNoB',
197  'aMatrix', 'bMatrix', 'finalVars', 'finalModelVars', 'finalMeans',
198  'photoCharge'])
199 

Member Function Documentation

◆ __eq__()

def lsst.ip.isr.ptcDataset.PhotonTransferCurveDataset.__eq__ (   self,
  other 
)
Calibration equivalence

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

Definition at line 200 of file ptcDataset.py.

200  def __eq__(self, other):
201  """Calibration equivalence
202  """
203  if not isinstance(other, self.__class__):
204  return False
205 
206  for attr in self._requiredAttributes:
207  attrSelf = getattr(self, attr)
208  attrOther = getattr(other, attr)
209  if isinstance(attrSelf, dict) and isinstance(attrOther, dict):
210  for ampName in attrSelf:
211  if not np.allclose(attrSelf[ampName], attrOther[ampName], equal_nan=True):
212  return False
213  else:
214  if attrSelf != attrOther:
215  return False
216  return True
217 

◆ __str__()

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

Reimplemented in lsst.ip.isr.defects.Defects, and lsst.ip.isr.calibType.IsrProvenance.

Definition at line 88 of file calibType.py.

88  def __str__(self):
89  return f"{self.__class__.__name__}(obstype={self._OBSTYPE}, detector={self._detectorName}, )"
90 

◆ 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 
daf::base::PropertyList * list
Definition: fits.cc:913
daf::base::PropertySet * set
Definition: fits.cc:912

◆ 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.ptcDataset.PhotonTransferCurveDataset.fromDict (   cls,
  dictionary 
)
Construct a calibration from a dictionary of properties.
Must be implemented by the specific calibration subclasses.
Parameters
----------
dictionary : `dict`
    Dictionary of properties.
Returns
-------
calib : `lsst.ip.isr.CalibType`
    Constructed calibration.
Raises
------
RuntimeError :
    Raised if the supplied dictionary is for a different
    calibration.

Definition at line 290 of file ptcDataset.py.

290  def fromDict(cls, dictionary):
291  """Construct a calibration from a dictionary of properties.
292  Must be implemented by the specific calibration subclasses.
293  Parameters
294  ----------
295  dictionary : `dict`
296  Dictionary of properties.
297  Returns
298  -------
299  calib : `lsst.ip.isr.CalibType`
300  Constructed calibration.
301  Raises
302  ------
303  RuntimeError :
304  Raised if the supplied dictionary is for a different
305  calibration.
306  """
307  calib = cls()
308  if calib._OBSTYPE != dictionary['metadata']['OBSTYPE']:
309  raise RuntimeError(f"Incorrect Photon Transfer Curve dataset supplied. "
310  f"Expected {calib._OBSTYPE}, found {dictionary['metadata']['OBSTYPE']}")
311  calib.setMetadata(dictionary['metadata'])
312  calib.ptcFitType = dictionary['ptcFitType']
313  calib.covMatrixSide = dictionary['covMatrixSide']
314  calib.badAmps = np.array(dictionary['badAmps'], 'str').tolist()
315  # The cov matrices are square
316  covMatrixSide = calib.covMatrixSide
317  # Number of final signal levels
318  covDimensionsProduct = len(np.array(list(dictionary['covariances'].values())[0]).ravel())
319  nSignalPoints = int(covDimensionsProduct/(covMatrixSide*covMatrixSide))
320 
321  for ampName in dictionary['ampNames']:
322  calib.ampNames.append(ampName)
323  calib.inputExpIdPairs[ampName] = np.array(dictionary['inputExpIdPairs'][ampName]).tolist()
324  calib.expIdMask[ampName] = np.array(dictionary['expIdMask'][ampName]).tolist()
325  calib.rawExpTimes[ampName] = np.array(dictionary['rawExpTimes'][ampName]).tolist()
326  calib.rawMeans[ampName] = np.array(dictionary['rawMeans'][ampName]).tolist()
327  calib.rawVars[ampName] = np.array(dictionary['rawVars'][ampName]).tolist()
328  calib.gain[ampName] = np.array(dictionary['gain'][ampName]).tolist()
329  calib.gainErr[ampName] = np.array(dictionary['gainErr'][ampName]).tolist()
330  calib.noise[ampName] = np.array(dictionary['noise'][ampName]).tolist()
331  calib.noiseErr[ampName] = np.array(dictionary['noiseErr'][ampName]).tolist()
332  calib.ptcFitPars[ampName] = np.array(dictionary['ptcFitPars'][ampName]).tolist()
333  calib.ptcFitParsError[ampName] = np.array(dictionary['ptcFitParsError'][ampName]).tolist()
334  calib.ptcFitChiSq[ampName] = np.array(dictionary['ptcFitChiSq'][ampName]).tolist()
335  calib.covariances[ampName] = np.array(dictionary['covariances'][ampName]).reshape(
336  (nSignalPoints, covMatrixSide, covMatrixSide)).tolist()
337  calib.covariancesModel[ampName] = np.array(
338  dictionary['covariancesModel'][ampName]).reshape(
339  (nSignalPoints, covMatrixSide, covMatrixSide)).tolist()
340  calib.covariancesSqrtWeights[ampName] = np.array(
341  dictionary['covariancesSqrtWeights'][ampName]).reshape(
342  (nSignalPoints, covMatrixSide, covMatrixSide)).tolist()
343  calib.aMatrix[ampName] = np.array(dictionary['aMatrix'][ampName]).reshape(
344  (covMatrixSide, covMatrixSide)).tolist()
345  calib.bMatrix[ampName] = np.array(dictionary['bMatrix'][ampName]).reshape(
346  (covMatrixSide, covMatrixSide)).tolist()
347  calib.covariancesModelNoB[ampName] = np.array(
348  dictionary['covariancesModelNoB'][ampName]).reshape(
349  (nSignalPoints, covMatrixSide, covMatrixSide)).tolist()
350  calib.aMatrixNoB[ampName] = np.array(
351  dictionary['aMatrixNoB'][ampName]).reshape((covMatrixSide, covMatrixSide)).tolist()
352  calib.finalVars[ampName] = np.array(dictionary['finalVars'][ampName]).tolist()
353  calib.finalModelVars[ampName] = np.array(dictionary['finalModelVars'][ampName]).tolist()
354  calib.finalMeans[ampName] = np.array(dictionary['finalMeans'][ampName]).tolist()
355  calib.photoCharge[ampName] = np.array(dictionary['photoCharge'][ampName]).tolist()
356  calib.updateMetadata()
357  return calib
358 

◆ 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.ptcDataset.PhotonTransferCurveDataset.fromTable (   cls,
  tableList 
)
Construct calibration from a list of tables.
This method uses the `fromDict` method to create the
calibration, after constructing an appropriate dictionary from
the input tables.
Parameters
----------
tableList : `list` [`lsst.afw.table.Table`]
    List of tables to use to construct the datasetPtc.
Returns
-------
calib : `lsst.cp.pipe.`
    The calibration defined in the tables.

Definition at line 405 of file ptcDataset.py.

405  def fromTable(cls, tableList):
406  """Construct calibration from a list of tables.
407  This method uses the `fromDict` method to create the
408  calibration, after constructing an appropriate dictionary from
409  the input tables.
410  Parameters
411  ----------
412  tableList : `list` [`lsst.afw.table.Table`]
413  List of tables to use to construct the datasetPtc.
414  Returns
415  -------
416  calib : `lsst.cp.pipe.`
417  The calibration defined in the tables.
418  """
419  ptcTable = tableList[0]
420 
421  metadata = ptcTable.meta
422  inDict = dict()
423  inDict['metadata'] = metadata
424  inDict['ampNames'] = []
425  inDict['ptcFitType'] = []
426  inDict['covMatrixSide'] = []
427  inDict['inputExpIdPairs'] = dict()
428  inDict['expIdMask'] = dict()
429  inDict['rawExpTimes'] = dict()
430  inDict['rawMeans'] = dict()
431  inDict['rawVars'] = dict()
432  inDict['gain'] = dict()
433  inDict['gainErr'] = dict()
434  inDict['noise'] = dict()
435  inDict['noiseErr'] = dict()
436  inDict['ptcFitPars'] = dict()
437  inDict['ptcFitParsError'] = dict()
438  inDict['ptcFitChiSq'] = dict()
439  inDict['covariances'] = dict()
440  inDict['covariancesModel'] = dict()
441  inDict['covariancesSqrtWeights'] = dict()
442  inDict['aMatrix'] = dict()
443  inDict['bMatrix'] = dict()
444  inDict['covariancesModelNoB'] = dict()
445  inDict['aMatrixNoB'] = dict()
446  inDict['finalVars'] = dict()
447  inDict['finalModelVars'] = dict()
448  inDict['finalMeans'] = dict()
449  inDict['badAmps'] = []
450  inDict['photoCharge'] = dict()
451 
452  for record in ptcTable:
453  ampName = record['AMPLIFIER_NAME']
454 
455  inDict['ptcFitType'] = record['PTC_FIT_TYPE']
456  inDict['covMatrixSide'] = record['COV_MATRIX_SIDE']
457  inDict['ampNames'].append(ampName)
458  inDict['inputExpIdPairs'][ampName] = record['INPUT_EXP_ID_PAIRS']
459  inDict['expIdMask'][ampName] = record['EXP_ID_MASK']
460  inDict['rawExpTimes'][ampName] = record['RAW_EXP_TIMES']
461  inDict['rawMeans'][ampName] = record['RAW_MEANS']
462  inDict['rawVars'][ampName] = record['RAW_VARS']
463  inDict['gain'][ampName] = record['GAIN']
464  inDict['gainErr'][ampName] = record['GAIN_ERR']
465  inDict['noise'][ampName] = record['NOISE']
466  inDict['noiseErr'][ampName] = record['NOISE_ERR']
467  inDict['ptcFitPars'][ampName] = record['PTC_FIT_PARS']
468  inDict['ptcFitParsError'][ampName] = record['PTC_FIT_PARS_ERROR']
469  inDict['ptcFitChiSq'][ampName] = record['PTC_FIT_CHI_SQ']
470  inDict['covariances'][ampName] = record['COVARIANCES']
471  inDict['covariancesModel'][ampName] = record['COVARIANCES_MODEL']
472  inDict['covariancesSqrtWeights'][ampName] = record['COVARIANCES_SQRT_WEIGHTS']
473  inDict['aMatrix'][ampName] = record['A_MATRIX']
474  inDict['bMatrix'][ampName] = record['B_MATRIX']
475  inDict['covariancesModelNoB'][ampName] = record['COVARIANCES_MODEL_NO_B']
476  inDict['aMatrixNoB'][ampName] = record['A_MATRIX_NO_B']
477  inDict['finalVars'][ampName] = record['FINAL_VARS']
478  inDict['finalModelVars'][ampName] = record['FINAL_MODEL_VARS']
479  inDict['finalMeans'][ampName] = record['FINAL_MEANS']
480  inDict['badAmps'] = record['BAD_AMPS']
481  inDict['photoCharge'][ampName] = record['PHOTO_CHARGE']
482  return cls().fromDict(inDict)
483 
std::shared_ptr< FrameSet > append(FrameSet const &first, FrameSet const &second)
Construct a FrameSet that performs two transformations in series.
Definition: functional.cc:33

◆ 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 

◆ getExpIdsUsed()

def lsst.ip.isr.ptcDataset.PhotonTransferCurveDataset.getExpIdsUsed (   self,
  ampName 
)
Get the exposures used, i.e. not discarded, for a given amp.
If no mask has been created yet, all exposures are returned.

Definition at line 567 of file ptcDataset.py.

567  def getExpIdsUsed(self, ampName):
568  """Get the exposures used, i.e. not discarded, for a given amp.
569  If no mask has been created yet, all exposures are returned.
570  """
571  if len(self.expIdMask[ampName]) == 0:
572  return self.inputExpIdPairs[ampName]
573 
574  # if the mask exists it had better be the same length as the expIdPairs
575  assert len(self.expIdMask[ampName]) == len(self.inputExpIdPairs[ampName])
576 
577  pairs = self.inputExpIdPairs[ampName]
578  mask = self.expIdMask[ampName]
579  # cast to bool required because numpy
580  return [(exp1, exp2) for ((exp1, exp2), m) in zip(pairs, mask) if bool(m) is True]
581 

◆ getGoodAmps()

def lsst.ip.isr.ptcDataset.PhotonTransferCurveDataset.getGoodAmps (   self)

Definition at line 582 of file ptcDataset.py.

582  def getGoodAmps(self):
583  return [amp for amp in self.ampNames if amp not in self.badAmps]

◆ 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 

◆ setAmpValues()

def lsst.ip.isr.ptcDataset.PhotonTransferCurveDataset.setAmpValues (   self,
  ampName,
  inputExpIdPair = [(np.nan, np.nan)],
  expIdMask = [np.nan],
  rawExpTime = [np.nan],
  rawMean = [np.nan],
  rawVar = [np.nan],
  photoCharge = [np.nan],
  gain = np.nan,
  gainErr = np.nan,
  noise = np.nan,
  noiseErr = np.nan,
  ptcFitPars = [np.nan],
  ptcFitParsError = [np.nan],
  ptcFitChiSq = np.nan,
  covArray = [],
  covArrayModel = [],
  covSqrtWeights = [],
  aMatrix = [],
  bMatrix = [],
  covArrayModelNoB = [],
  aMatrixNoB = [],
  finalVar = [np.nan],
  finalModelVar = [np.nan],
  finalMean = [np.nan] 
)
Function to initialize an amp of a PhotonTransferCurveDataset.

Notes
-----
The parameters are all documented in `init`.

Definition at line 218 of file ptcDataset.py.

223  finalVar=[np.nan], finalModelVar=[np.nan], finalMean=[np.nan]):
224  """Function to initialize an amp of a PhotonTransferCurveDataset.
225 
226  Notes
227  -----
228  The parameters are all documented in `init`.
229  """
230  nanMatrix = np.full((self.covMatrixSide, self.covMatrixSide), np.nan)
231  if len(covArray) == 0:
232  covArray = [nanMatrix]
233  if len(covArrayModel) == 0:
234  covArrayModel = [nanMatrix]
235  if len(covSqrtWeights) == 0:
236  covSqrtWeights = [nanMatrix]
237  if len(covArrayModelNoB) == 0:
238  covArrayModelNoB = [nanMatrix]
239  if len(aMatrix) == 0:
240  aMatrix = nanMatrix
241  if len(bMatrix) == 0:
242  bMatrix = nanMatrix
243  if len(aMatrixNoB) == 0:
244  aMatrixNoB = nanMatrix
245 
246  self.inputExpIdPairs[ampName] = inputExpIdPair
247  self.expIdMask[ampName] = expIdMask
248  self.rawExpTimes[ampName] = rawExpTime
249  self.rawMeans[ampName] = rawMean
250  self.rawVars[ampName] = rawVar
251  self.photoCharge[ampName] = photoCharge
252  self.gain[ampName] = gain
253  self.gainErr[ampName] = gainErr
254  self.noise[ampName] = noise
255  self.noiseErr[ampName] = noiseErr
256  self.ptcFitPars[ampName] = ptcFitPars
257  self.ptcFitParsError[ampName] = ptcFitParsError
258  self.ptcFitChiSq[ampName]
259  self.covariances[ampName] = covArray
260  self.covariancesSqrtWeights[ampName] = covSqrtWeights
261  self.covariancesModel[ampName] = covArrayModel
262  self.covariancesModelNoB[ampName] = covArrayModelNoB
263  self.aMatrix[ampName] = aMatrix
264  self.bMatrix[ampName] = bMatrix
265  self.aMatrixNoB[ampName] = aMatrixNoB
266  self.ptcFitPars[ampName] = ptcFitPars
267  self.ptcFitParsError[ampName] = ptcFitParsError
268  self.ptcFitChiSq[ampName] = ptcFitChiSq
269  self.finalVars[ampName] = finalVar
270  self.finalModelVars[ampName] = finalModelVar
271  self.finalMeans[ampName] = finalMean
272 

◆ 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.ptcDataset.PhotonTransferCurveDataset.toDict (   self)
Return a dictionary containing the calibration properties.
The dictionary should be able to be round-tripped through
`fromDict`.
Returns
-------
dictionary : `dict`
    Dictionary of properties.

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

Definition at line 359 of file ptcDataset.py.

359  def toDict(self):
360  """Return a dictionary containing the calibration properties.
361  The dictionary should be able to be round-tripped through
362  `fromDict`.
363  Returns
364  -------
365  dictionary : `dict`
366  Dictionary of properties.
367  """
368  self.updateMetadata()
369 
370  outDict = dict()
371  metadata = self.getMetadata()
372  outDict['metadata'] = metadata
373 
374  outDict['ptcFitType'] = self.ptcFitType
375  outDict['covMatrixSide'] = self.covMatrixSide
376  outDict['ampNames'] = self.ampNames
377  outDict['badAmps'] = self.badAmps
378  outDict['inputExpIdPairs'] = self.inputExpIdPairs
379  outDict['expIdMask'] = self.expIdMask
380  outDict['rawExpTimes'] = self.rawExpTimes
381  outDict['rawMeans'] = self.rawMeans
382  outDict['rawVars'] = self.rawVars
383  outDict['gain'] = self.gain
384  outDict['gainErr'] = self.gainErr
385  outDict['noise'] = self.noise
386  outDict['noiseErr'] = self.noiseErr
387  outDict['ptcFitPars'] = self.ptcFitPars
388  outDict['ptcFitParsError'] = self.ptcFitParsError
389  outDict['ptcFitChiSq'] = self.ptcFitChiSq
390  outDict['covariances'] = self.covariances
391  outDict['covariancesModel'] = self.covariancesModel
392  outDict['covariancesSqrtWeights'] = self.covariancesSqrtWeights
393  outDict['aMatrix'] = self.aMatrix
394  outDict['bMatrix'] = self.bMatrix
395  outDict['covariancesModelNoB'] = self.covariancesModelNoB
396  outDict['aMatrixNoB'] = self.aMatrixNoB
397  outDict['finalVars'] = self.finalVars
398  outDict['finalModelVars'] = self.finalModelVars
399  outDict['finalMeans'] = self.finalMeans
400  outDict['photoCharge'] = self.photoCharge
401 
402  return outDict
403 

◆ toTable()

def lsst.ip.isr.ptcDataset.PhotonTransferCurveDataset.toTable (   self)
Construct a list of tables containing the information in this
calibration.

The list of tables should create an identical calibration
after being passed to this class's fromTable method.
Returns
-------
tableList : `list` [`astropy.table.Table`]
    List of tables containing the linearity calibration
    information.

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

Definition at line 484 of file ptcDataset.py.

484  def toTable(self):
485  """Construct a list of tables containing the information in this
486  calibration.
487 
488  The list of tables should create an identical calibration
489  after being passed to this class's fromTable method.
490  Returns
491  -------
492  tableList : `list` [`astropy.table.Table`]
493  List of tables containing the linearity calibration
494  information.
495  """
496  tableList = []
497  self.updateMetadata()
498  nPoints = []
499  for i, ampName in enumerate(self.ampNames):
500  nPoints.append(len(list(self.covariances.values())[i]))
501  nSignalPoints = max(nPoints)
502  nPadPoints = {}
503  for i, ampName in enumerate(self.ampNames):
504  nPadPoints[ampName] = nSignalPoints - len(list(self.covariances.values())[i])
505  covMatrixSide = self.covMatrixSide
506 
507  catalog = Table([{'AMPLIFIER_NAME': ampName,
508  'PTC_FIT_TYPE': self.ptcFitType,
509  'COV_MATRIX_SIDE': self.covMatrixSide,
510  'INPUT_EXP_ID_PAIRS': self.inputExpIdPairs[ampName]
511  if len(self.expIdMask[ampName]) else np.nan,
512  'EXP_ID_MASK': self.expIdMask[ampName]
513  if len(self.expIdMask[ampName]) else np.nan,
514  'RAW_EXP_TIMES': np.array(self.rawExpTimes[ampName]).tolist()
515  if len(self.rawExpTimes[ampName]) else np.nan,
516  'RAW_MEANS': np.array(self.rawMeans[ampName]).tolist()
517  if len(self.rawMeans[ampName]) else np.nan,
518  'RAW_VARS': np.array(self.rawVars[ampName]).tolist()
519  if len(self.rawVars[ampName]) else np.nan,
520  'GAIN': self.gain[ampName],
521  'GAIN_ERR': self.gainErr[ampName],
522  'NOISE': self.noise[ampName],
523  'NOISE_ERR': self.noiseErr[ampName],
524  'PTC_FIT_PARS': np.array(self.ptcFitPars[ampName]).tolist(),
525  'PTC_FIT_PARS_ERROR': np.array(self.ptcFitParsError[ampName]).tolist(),
526  'PTC_FIT_CHI_SQ': self.ptcFitChiSq[ampName],
527  'COVARIANCES': np.pad(np.array(self.covariances[ampName]),
528  ((0, nPadPoints[ampName]), (0, 0), (0, 0)),
529  'constant', constant_values=np.nan).reshape(
530  nSignalPoints*covMatrixSide**2).tolist(),
531  'COVARIANCES_MODEL': np.pad(np.array(self.covariancesModel[ampName]),
532  ((0, nPadPoints[ampName]), (0, 0), (0, 0)),
533  'constant', constant_values=np.nan).reshape(
534  nSignalPoints*covMatrixSide**2).tolist(),
535  'COVARIANCES_SQRT_WEIGHTS': np.pad(np.array(self.covariancesSqrtWeights[ampName]),
536  ((0, nPadPoints[ampName]), (0, 0), (0, 0)),
537  'constant', constant_values=0.0).reshape(
538  nSignalPoints*covMatrixSide**2).tolist(),
539  'A_MATRIX': np.array(self.aMatrix[ampName]).reshape(covMatrixSide**2).tolist(),
540  'B_MATRIX': np.array(self.bMatrix[ampName]).reshape(covMatrixSide**2).tolist(),
541  'COVARIANCES_MODEL_NO_B':
542  np.pad(np.array(self.covariancesModelNoB[ampName]),
543  ((0, nPadPoints[ampName]), (0, 0), (0, 0)),
544  'constant', constant_values=np.nan).reshape(
545  nSignalPoints*covMatrixSide**2).tolist(),
546  'A_MATRIX_NO_B': np.array(self.aMatrixNoB[ampName]).reshape(
547  covMatrixSide**2).tolist(),
548  'FINAL_VARS': np.pad(np.array(self.finalVars[ampName]), (0, nPadPoints[ampName]),
549  'constant', constant_values=np.nan).tolist(),
550  'FINAL_MODEL_VARS': np.pad(np.array(self.finalModelVars[ampName]),
551  (0, nPadPoints[ampName]),
552  'constant', constant_values=np.nan).tolist(),
553  'FINAL_MEANS': np.pad(np.array(self.finalMeans[ampName]),
554  (0, nPadPoints[ampName]),
555  'constant', constant_values=np.nan).tolist(),
556  'BAD_AMPS': np.array(self.badAmps).tolist() if len(self.badAmps) else np.nan,
557  'PHOTO_CHARGE': np.array(self.photoCharge[ampName]).tolist(),
558  } for ampName in self.ampNames])
559  inMeta = self.getMetadata().toDict()
560  outMeta = {k: v for k, v in inMeta.items() if v is not None}
561  outMeta.update({k: "" for k, v in inMeta.items() if v is None})
562  catalog.meta = outMeta
563  tableList.append(catalog)
564 
565  return(tableList)
566 
int max

◆ 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.ptcDataset.PhotonTransferCurveDataset.updateMetadata (   self,
  setDate = False,
**  kwargs 
)
Update calibration metadata.
This calls the base class's method after ensuring the required
calibration keywords will be saved.
Parameters
----------
setDate : `bool`, optional
    Update the CALIBDATE fields in the metadata to the current
    time. Defaults to False.
kwargs :
    Other keyword parameters to set in the metadata.

Definition at line 273 of file ptcDataset.py.

273  def updateMetadata(self, setDate=False, **kwargs):
274  """Update calibration metadata.
275  This calls the base class's method after ensuring the required
276  calibration keywords will be saved.
277  Parameters
278  ----------
279  setDate : `bool`, optional
280  Update the CALIBDATE fields in the metadata to the current
281  time. Defaults to False.
282  kwargs :
283  Other keyword parameters to set in the metadata.
284  """
285  kwargs['PTC_FIT_TYPE'] = self.ptcFitType
286 
287  super().updateMetadata(setDate=setDate, **kwargs)
288 

◆ 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

◆ aMatrix

lsst.ip.isr.ptcDataset.PhotonTransferCurveDataset.aMatrix

Definition at line 182 of file ptcDataset.py.

◆ aMatrixNoB

lsst.ip.isr.ptcDataset.PhotonTransferCurveDataset.aMatrixNoB

Definition at line 185 of file ptcDataset.py.

◆ ampNames

lsst.ip.isr.ptcDataset.PhotonTransferCurveDataset.ampNames

Definition at line 158 of file ptcDataset.py.

◆ badAmps

lsst.ip.isr.ptcDataset.PhotonTransferCurveDataset.badAmps

Definition at line 161 of file ptcDataset.py.

◆ bMatrix

lsst.ip.isr.ptcDataset.PhotonTransferCurveDataset.bMatrix

Definition at line 183 of file ptcDataset.py.

◆ covariances

lsst.ip.isr.ptcDataset.PhotonTransferCurveDataset.covariances

Definition at line 179 of file ptcDataset.py.

◆ covariancesModel

lsst.ip.isr.ptcDataset.PhotonTransferCurveDataset.covariancesModel

Definition at line 180 of file ptcDataset.py.

◆ covariancesModelNoB

lsst.ip.isr.ptcDataset.PhotonTransferCurveDataset.covariancesModelNoB

Definition at line 184 of file ptcDataset.py.

◆ covariancesSqrtWeights

lsst.ip.isr.ptcDataset.PhotonTransferCurveDataset.covariancesSqrtWeights

Definition at line 181 of file ptcDataset.py.

◆ covMatrixSide

lsst.ip.isr.ptcDataset.PhotonTransferCurveDataset.covMatrixSide

Definition at line 159 of file ptcDataset.py.

◆ expIdMask

lsst.ip.isr.ptcDataset.PhotonTransferCurveDataset.expIdMask

Definition at line 164 of file ptcDataset.py.

◆ finalMeans

lsst.ip.isr.ptcDataset.PhotonTransferCurveDataset.finalMeans

Definition at line 189 of file ptcDataset.py.

◆ finalModelVars

lsst.ip.isr.ptcDataset.PhotonTransferCurveDataset.finalModelVars

Definition at line 188 of file ptcDataset.py.

◆ finalVars

lsst.ip.isr.ptcDataset.PhotonTransferCurveDataset.finalVars

Definition at line 187 of file ptcDataset.py.

◆ gain

lsst.ip.isr.ptcDataset.PhotonTransferCurveDataset.gain

Definition at line 170 of file ptcDataset.py.

◆ gainErr

lsst.ip.isr.ptcDataset.PhotonTransferCurveDataset.gainErr

Definition at line 171 of file ptcDataset.py.

◆ inputExpIdPairs

lsst.ip.isr.ptcDataset.PhotonTransferCurveDataset.inputExpIdPairs

Definition at line 163 of file ptcDataset.py.

◆ log

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

Definition at line 82 of file calibType.py.

◆ noise

lsst.ip.isr.ptcDataset.PhotonTransferCurveDataset.noise

Definition at line 172 of file ptcDataset.py.

◆ noiseErr

lsst.ip.isr.ptcDataset.PhotonTransferCurveDataset.noiseErr

Definition at line 173 of file ptcDataset.py.

◆ photoCharge

lsst.ip.isr.ptcDataset.PhotonTransferCurveDataset.photoCharge

Definition at line 168 of file ptcDataset.py.

◆ ptcFitChiSq

lsst.ip.isr.ptcDataset.PhotonTransferCurveDataset.ptcFitChiSq

Definition at line 177 of file ptcDataset.py.

◆ ptcFitPars

lsst.ip.isr.ptcDataset.PhotonTransferCurveDataset.ptcFitPars

Definition at line 175 of file ptcDataset.py.

◆ ptcFitParsError

lsst.ip.isr.ptcDataset.PhotonTransferCurveDataset.ptcFitParsError

Definition at line 176 of file ptcDataset.py.

◆ ptcFitType

lsst.ip.isr.ptcDataset.PhotonTransferCurveDataset.ptcFitType

Definition at line 157 of file ptcDataset.py.

◆ rawExpTimes

lsst.ip.isr.ptcDataset.PhotonTransferCurveDataset.rawExpTimes

Definition at line 165 of file ptcDataset.py.

◆ rawMeans

lsst.ip.isr.ptcDataset.PhotonTransferCurveDataset.rawMeans

Definition at line 166 of file ptcDataset.py.

◆ rawVars

lsst.ip.isr.ptcDataset.PhotonTransferCurveDataset.rawVars

Definition at line 167 of file ptcDataset.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: