Skip to content

Commit 87337ce

Browse files
committed
Update tests to use new paired ptc run task.
1 parent 43cd8d3 commit 87337ce

File tree

1 file changed

+27
-25
lines changed

1 file changed

+27
-25
lines changed

tests/test_ptc.py

+27-25
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ def test_covAstier(self):
148148
extractConfig.doExtractPhotodiodeData = True
149149
extractConfig.doKsHistMeasurement = True
150150
extractConfig.auxiliaryHeaderKeys = ["CCOBCURR", "CCDTEMP"]
151-
extractTask = cpPipe.ptc.PhotonTransferCurveExtractTask(config=extractConfig)
151+
extractPairTask = cpPipe.ptc.PhotonTransferCurveExtractPairTask(config=extractConfig)
152152

153153
# Create solve task config
154154
solveConfig = self.defaultConfigSolve
@@ -167,7 +167,7 @@ def test_covAstier(self):
167167
inputGain = self.gain
168168

169169
muStandard, varStandard = {}, {}
170-
expDict = {}
170+
expHandles = []
171171
expIds = []
172172
pdHandles = []
173173
idCounter = 0
@@ -190,7 +190,7 @@ def test_covAstier(self):
190190

191191
mockExpRef1 = PretendRef(mockExp1)
192192
mockExpRef2 = PretendRef(mockExp2)
193-
expDict[expTime] = ((mockExpRef1, idCounter), (mockExpRef2, idCounter + 1))
193+
expHandles.extend((mockExpRef1, mockExpRef2))
194194
expIds.append(idCounter)
195195
expIds.append(idCounter + 1)
196196
for ampNumber, ampName in enumerate(self.ampNames):
@@ -201,8 +201,8 @@ def test_covAstier(self):
201201
imStatsCtrl,
202202
mu1,
203203
mu2,
204-
) = extractTask.getImageAreasMasksStats(mockExp1, mockExp2)
205-
muDiff, varDiff, covAstier, rowMeanVariance = extractTask.measureMeanVarCov(
204+
) = extractPairTask.getImageAreasMasksStats(mockExp1, mockExp2)
205+
muDiff, varDiff, covAstier, rowMeanVariance = extractPairTask.measureMeanVarCov(
206206
im1Area, im2Area, imStatsCtrl, mu1, mu2
207207
)
208208
muStandard.setdefault(ampName, []).append(muDiff)
@@ -231,30 +231,33 @@ def test_covAstier(self):
231231
)
232232
idCounter += 2
233233

234-
resultsExtract = extractTask.run(
235-
inputExp=expDict,
236-
inputDims=expIds,
237-
inputPhotodiodeData=pdHandles,
238-
)
234+
# Divide out the pairs.
235+
outputCovariances = []
236+
for i in range(len(expHandles) // 2):
237+
inputExp = [expHandles[2*i], expHandles[2*i + 1]]
238+
inputDims = [expIds[2*i], expIds[2*i + 1]]
239+
inputPhotodiodeData = [pdHandles[2*i], pdHandles[2*i + 1]]
240+
results = extractPairTask.run(
241+
inputExp=inputExp,
242+
inputDims=inputDims,
243+
inputPhotodiodeData=inputPhotodiodeData,
244+
)
245+
outputCovariances.append(results.outputCovariance)
239246

240247
# Force the last PTC dataset to have a NaN, and ensure that the
241248
# task runs (DM-38029). This is a minor perturbation and does not
242-
# affect the output comparison. Note that we use index -2 because
243-
# these datasets are in pairs of [real, dummy] to match the inputs
244-
# to the extract task.
245-
resultsExtract.outputCovariances[-2].rawMeans["C:0,0"] = np.array([np.nan])
246-
resultsExtract.outputCovariances[-2].rawVars["C:0,0"] = np.array([np.nan])
249+
# affect the output comparison.
250+
outputCovariances[-1].rawMeans["C:0,0"] = np.array([np.nan])
251+
outputCovariances[-1].rawVars["C:0,0"] = np.array([np.nan])
247252

248253
# Force the next-to-last PTC dataset to have a decreased variance to
249-
# ensure that the outlier fit rejection works. Note that we use
250-
# index -4 because these datasets are in pairs of [real, dummy] to
251-
# match the inputs to the extract task.
252-
rawVar = resultsExtract.outputCovariances[-4].rawVars["C:0,0"]
253-
resultsExtract.outputCovariances[-4].rawVars["C:0,0"] = rawVar * 0.9
254+
# ensure that the outlier fit rejection works.
255+
rawVar = outputCovariances[-2].rawVars["C:0,0"]
256+
outputCovariances[-2].rawVars["C:0,0"] = rawVar * 0.9
254257

255258
# Reorganize the outputCovariances so we can confirm they come
256259
# out sorted afterwards.
257-
outputCovariancesRev = resultsExtract.outputCovariances[::-1]
260+
outputCovariancesRev = outputCovariances[::-1]
258261

259262
# Some expected values for noise matrix, just to check that
260263
# it was calculated.
@@ -299,10 +302,8 @@ def test_covAstier(self):
299302
self.assertAlmostEqual(ptc.ptcTurnoff[amp], ptc.rawMeans[amp][-1])
300303

301304
# Test that all the quantities are correctly ordered and
302-
# have not accidentally been masked. We check every other
303-
# output ([::2]) because these datasets are in pairs of
304-
# [real, dummy] to match the inputs to the extract task.
305-
for i, extractPtc in enumerate(resultsExtract.outputCovariances[::2]):
305+
# have not accidentally been masked.
306+
for i, extractPtc in enumerate(outputCovariances):
306307
self.assertFloatsAlmostEqual(
307308
extractPtc.rawExpTimes[ampName][0],
308309
ptc.rawExpTimes[ampName][i],
@@ -825,6 +826,7 @@ def runGetGainFromFlatPair(self, correctionType="NONE"):
825826
expIds.append(idCounter + 1)
826827
idCounter += 2
827828

829+
# This will test the full extract task.
828830
resultsExtract = extractTask.run(
829831
inputExp=expDict,
830832
inputDims=expIds,

0 commit comments

Comments
 (0)