Skip to content

Commit

Permalink
Add rowMeanVariance to ptcDataset
Browse files Browse the repository at this point in the history
Fix bug
  • Loading branch information
plazas committed Jan 24, 2024
1 parent 535a204 commit bb39217
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 2 deletions.
26 changes: 24 additions & 2 deletions python/lsst/ip/isr/ptcDataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,10 @@ class PhotonTransferCurveDataset(IsrCalib):
rawVars : `dict`, [`str`, `np.ndarray`]
Dictionary keyed by amp names containing the variance of the
difference image of the exposures in each flat pair.
rowMeanVariance : `dict`, [`str`, `np.ndarray`]
Dictionary keyed by amp names containing the variance of the
means of the rows of the difference image of the exposures
in each flat pair.
histVars : `dict`, [`str`, `np.ndarray`]
Dictionary keyed by amp names containing the variance of the
difference image of the exposures in each flat pair estimated
Expand Down Expand Up @@ -176,11 +180,12 @@ class PhotonTransferCurveDataset(IsrCalib):
Version 1.3 adds the `noiseMatrix` and `noiseMatrixNoB` attributes.
Version 1.4 adds the `auxValues` attribute.
Version 1.5 adds the `covMatrixSideFullCovFit` attribute.
Version 1.6 adds the `rowMeanVariance` attribute.
"""

_OBSTYPE = 'PTC'
_SCHEMA = 'Gen3 Photon Transfer Curve'
_VERSION = 1.5
_VERSION = 1.6

def __init__(self, ampNames=[], ptcFitType=None, covMatrixSide=1,
covMatrixSideFullCovFit=None, **kwargs):
Expand All @@ -199,6 +204,7 @@ def __init__(self, ampNames=[], ptcFitType=None, covMatrixSide=1,
self.rawExpTimes = {ampName: np.array([]) for ampName in ampNames}
self.rawMeans = {ampName: np.array([]) for ampName in ampNames}
self.rawVars = {ampName: np.array([]) for ampName in ampNames}
self.rowMeanVariance = {ampName: np.array([]) for ampName in ampNames}
self.photoCharges = {ampName: np.array([]) for ampName in ampNames}

self.gain = {ampName: np.nan for ampName in ampNames}
Expand Down Expand Up @@ -234,7 +240,8 @@ def __init__(self, ampNames=[], ptcFitType=None, covMatrixSide=1,

super().__init__(**kwargs)
self.requiredAttributes.update(['badAmps', 'inputExpIdPairs', 'expIdMask', 'rawExpTimes',
'rawMeans', 'rawVars', 'gain', 'gainErr', 'noise', 'noiseErr',
'rawMeans', 'rawVars', 'rowMeanVariance', 'gain',
'gainErr', 'noise', 'noiseErr',
'ptcFitPars', 'ptcFitParsError', 'ptcFitChiSq', 'ptcTurnoff',
'aMatrixNoB', 'covariances', 'covariancesModel',
'covariancesSqrtWeights', 'covariancesModelNoB',
Expand All @@ -252,6 +259,7 @@ def setAmpValuesPartialDataset(
rawExpTime=np.nan,
rawMean=np.nan,
rawVar=np.nan,
rowMeanVariance=np.nan,
photoCharge=np.nan,
expIdMask=False,
covariance=None,
Expand All @@ -278,6 +286,9 @@ def setAmpValuesPartialDataset(
Average of the means of the exposures in this pair.
rawVar : `float`, optional
Variance of the difference of the exposures in this pair.
rowMeanVariance : `float`, optional
Variance of the means of the rows in the difference image
of the exposures in this pair.
photoCharge : `float`, optional
Integrated photocharge for flat pair for linearity calibration.
expIdMask : `bool`, optional
Expand Down Expand Up @@ -310,6 +321,7 @@ def setAmpValuesPartialDataset(
self.rawExpTimes[ampName] = np.array([rawExpTime])
self.rawMeans[ampName] = np.array([rawMean])
self.rawVars[ampName] = np.array([rawVar])
self.rowMeanVariance[ampName] = np.array([rowMeanVariance])
self.photoCharges[ampName] = np.array([photoCharge])
self.expIdMask[ampName] = np.array([expIdMask])
self.covariances[ampName] = np.array([covariance])
Expand Down Expand Up @@ -402,6 +414,8 @@ def fromDict(cls, dictionary):
calib.rawExpTimes[ampName] = np.array(dictionary['rawExpTimes'][ampName], dtype=np.float64)
calib.rawMeans[ampName] = np.array(dictionary['rawMeans'][ampName], dtype=np.float64)
calib.rawVars[ampName] = np.array(dictionary['rawVars'][ampName], dtype=np.float64)
calib.rowMeanVariance[ampName] = np.array(dictionary['rowMeanVariance'][ampName],
dtype=np.float64)
calib.gain[ampName] = float(dictionary['gain'][ampName])
calib.gainErr[ampName] = float(dictionary['gainErr'][ampName])
calib.noise[ampName] = float(dictionary['noise'][ampName])
Expand Down Expand Up @@ -501,6 +515,7 @@ def _dictOfArraysToDictOfLists(dictOfArrays):
outDict['rawExpTimes'] = _dictOfArraysToDictOfLists(self.rawExpTimes)
outDict['rawMeans'] = _dictOfArraysToDictOfLists(self.rawMeans)
outDict['rawVars'] = _dictOfArraysToDictOfLists(self.rawVars)
outDict['rowMeanVariance'] = _dictOfArraysToDictOfLists(self.rowMeanVariance)
outDict['gain'] = self.gain
outDict['gainErr'] = self.gainErr
outDict['noise'] = self.noise
Expand Down Expand Up @@ -560,6 +575,7 @@ def fromTable(cls, tableList):
inDict['rawExpTimes'] = dict()
inDict['rawMeans'] = dict()
inDict['rawVars'] = dict()
inDict['rowMeanVariance'] = dict()
inDict['gain'] = dict()
inDict['gainErr'] = dict()
inDict['noise'] = dict()
Expand Down Expand Up @@ -601,6 +617,7 @@ def fromTable(cls, tableList):
inDict['rawExpTimes'][ampName] = record['RAW_EXP_TIMES']
inDict['rawMeans'][ampName] = record['RAW_MEANS']
inDict['rawVars'][ampName] = record['RAW_VARS']
inDict['rowMeanVariance'][ampName] = record['ROW_MEAN_VARIANCE']
inDict['gain'][ampName] = record['GAIN']
inDict['gainErr'][ampName] = record['GAIN_ERR']
inDict['noise'][ampName] = record['NOISE']
Expand Down Expand Up @@ -649,6 +666,10 @@ def fromTable(cls, tableList):
inDict['covMatrixSideFullCovFit'] = inDict['covMatrixSide']
else:
inDict['covMatrixSideFullCovFit'] = record['COV_MATRIX_SIDE_FULL_COV_FIT']
if calibVersion < 1.6:
inDict['rowMeanVariance'][ampName] = np.array([np.nan])
else:
inDict['rowMeanVariance'][ampName] = record['ROW_MEAN_VARIANCE']

inDict['auxValues'] = {}
record = ptcTable[0]
Expand Down Expand Up @@ -689,6 +710,7 @@ def toTable(self):
'RAW_EXP_TIMES': self.rawExpTimes[ampName],
'RAW_MEANS': self.rawMeans[ampName],
'RAW_VARS': self.rawVars[ampName],
'ROW_MEAN_VARIANCE': self.rowMeanVariance[ampName],
'GAIN': self.gain[ampName],
'GAIN_ERR': self.gainErr[ampName],
'NOISE': self.noise[ampName],
Expand Down
1 change: 1 addition & 0 deletions tests/test_ptcDataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ def _checkTypes(self, ptcDataset):
self.assertEqual(ptcDataset.rawMeans[ampName].dtype, np.float64)
self.assertIsInstance(ptcDataset.rawVars[ampName], np.ndarray)
self.assertEqual(ptcDataset.rawVars[ampName].dtype, np.float64)
self.assertEqual(ptcDataset.rowMeanVariance[ampName].dtype, np.float64)
self.assertIsInstance(ptcDataset.gain[ampName], float)
self.assertIsInstance(ptcDataset.gainErr[ampName], float)
self.assertIsInstance(ptcDataset.noise[ampName], float)
Expand Down

0 comments on commit bb39217

Please sign in to comment.