Skip to content

Commit

Permalink
Record values of deprecated attributes when reading old PTC versions
Browse files Browse the repository at this point in the history
  • Loading branch information
Alex-Broughton committed Oct 31, 2024
1 parent 6cf0085 commit 25da546
Showing 1 changed file with 47 additions and 0 deletions.
47 changes: 47 additions & 0 deletions python/lsst/ip/isr/ptcDataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -425,6 +425,10 @@ def setAmpValuesPartialDataset(
self.finalModelVars[ampName] = np.array([np.nan])
self.finalMeans[ampName] = np.array([np.nan])

self._covariancesModelNoB[ampName] = np.array([nanMatrixFit])
self._aMatrixNoB[ampName] = nanMatrixFit
self._noiseMatrixNoB[ampName] = nanMatrixFit

def setAuxValuesPartialDataset(self, auxDict):
"""
Set a dictionary of auxiliary values for a partial dataset.
Expand Down Expand Up @@ -489,6 +493,8 @@ def fromDict(cls, dictionary):
calib.badAmps = np.array(dictionary['badAmps'], 'str').tolist()
calib.ampNames = []

calibVersion = dictionary['metadata']['PTC_VERSION']

# The cov matrices are square
covMatrixSide = calib.covMatrixSide
covMatrixSideFullCovFit = calib.covMatrixSideFullCovFit
Expand Down Expand Up @@ -543,6 +549,19 @@ def fromDict(cls, dictionary):
calib.noiseMatrix[ampName] = np.array(
dictionary['noiseMatrix'][ampName],
dtype=np.float64).reshape((covMatrixSideFullCovFit, covMatrixSideFullCovFit))

# Deprecated to be removed after v28
if calibVersion < 2.1:
calib._covariancesModelNoB[ampName] = np.array(
dictionary['covariancesModelNoB'][ampName], dtype=np.float64).reshape(
(nSignalPoints, covMatrixSideFullCovFit, covMatrixSideFullCovFit))
calib._aMatrixNoB[ampName] = np.array(
dictionary['aMatrixNoB'][ampName],
dtype=np.float64).reshape((covMatrixSideFullCovFit, covMatrixSideFullCovFit))
calib._noiseMatrixNoB[ampName] = np.array(
dictionary['noiseMatrixNoB'][ampName],
dtype=np.float64).reshape((covMatrixSideFullCovFit, covMatrixSideFullCovFit))

else:
# Empty dataset
calib.covariances[ampName] = np.array([], dtype=np.float64)
Expand Down Expand Up @@ -692,6 +711,9 @@ def fromTable(cls, tableList):
inDict['badAmps'] = []
inDict['photoCharges'] = dict()
inDict['ampOffsets'] = dict()
inDict['noiseMatrixNoB'] = dict()
inDict['covariancesModelNoB'] = dict()
inDict['aMatrixNoB'] = dict()

calibVersion = metadata['PTC_VERSION']
if calibVersion == 1.0:
Expand Down Expand Up @@ -745,8 +767,14 @@ def fromTable(cls, tableList):
if calibVersion < 1.3:
nanMatrix = np.full_like(inDict['aMatrix'][ampName], np.nan)
inDict['noiseMatrix'][ampName] = nanMatrix
inDict['noiseMatrixNoB'][ampName] = nanMatrix
elif calibVersion >= 1.3 and calibVersion < 2.1:
inDict['noiseMatrix'][ampName] = record['NOISE_MATRIX']
inDict['noiseMatrixNoB'][ampName] = record['NOISE_MATRIX_NO_B']
else:
inDict['noiseMatrix'][ampName] = record['NOISE_MATRIX']
nanMatrix = np.full_like(inDict['aMatrix'][ampName], np.nan)
inDict['noiseMatrixNoB'][ampName] = nanMatrix
if calibVersion < 1.5:
# Matched to `COV_MATRIX_SIDE`. Same for all amps.
inDict['covMatrixSideFullCovFit'] = inDict['covMatrixSide']
Expand Down Expand Up @@ -789,6 +817,15 @@ def fromTable(cls, tableList):
inDict['ampOffsets'][ampName] = record['AMP_OFFSETS']
inDict['gainUnadjusted'][ampName] = record['GAIN_UNADJUSTED']
inDict['gainList'][ampName] = record['GAIN_LIST']
if calibVersion < 2.1:
inDict['covariancesModelNoB'][ampName] = record['COVARIANCES_MODEL']
inDict['aMatrixNoB'][ampName] = record['A_MATRIX']
else:
inDict['covariancesModelNoB'][ampName] = np.full_like(
inDict['covariancesModel'][ampName],
np.nan,
)
inDict['aMatrixNoB'][ampName] = np.full_like(inDict['aMatrix'][ampName], np.nan)

inDict['auxValues'] = {}
record = ptcTable[0]
Expand Down Expand Up @@ -988,6 +1025,16 @@ def appendPartialPtc(self, partialPtc):
self.covMatrixSide,
)
)
self._covariancesModelNoB[ampName] = np.append(
self._covariancesModelNoB[ampName].ravel(),
partialPtc._covariancesModelNoB[ampName].ravel()
).reshape(
(
len(self.rawExpTimes[ampName]),
self.covMatrixSide,
self.covMatrixSide,
)
)

def sort(self, sortIndex):
"""Sort the components of the PTC by a given sort index.
Expand Down

0 comments on commit 25da546

Please sign in to comment.