Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DM-38834: Fix ptc covariance weight bug and add associated tests. #183

Merged
merged 2 commits into from
Apr 25, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion python/lsst/cp/pipe/ptc/cpSolvePtcTask.py
Original file line number Diff line number Diff line change
Expand Up @@ -281,7 +281,7 @@ def run(self, inputCovariances, camera=None, detId=0):
datasetPtc.rawVars[ampName] = datasetPtc.rawVars[ampName][index]
datasetPtc.expIdMask[ampName] = datasetPtc.expIdMask[ampName][index]
datasetPtc.covariances[ampName] = datasetPtc.covariances[ampName][index]
datasetPtc.covariancesSqrtWeights[ampName] = datasetPtc.covariances[ampName][index]
datasetPtc.covariancesSqrtWeights[ampName] = datasetPtc.covariancesSqrtWeights[ampName][index]

if self.config.ptcFitType == "FULLCOVARIANCE":
# Fit the measured covariances vs mean signal to
Expand Down
29 changes: 23 additions & 6 deletions tests/test_ptc.py
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,10 @@ def test_covAstier(self):
extractConfig = self.defaultConfigExtract
extractConfig.minNumberGoodPixelsForCovariance = 5000
extractConfig.detectorMeasurementRegion = 'FULL'
# Cut off the low-flux point which is a bad fit, and this
# also exercises this functionality and makes the tests
# run a lot faster.
extractConfig.minMeanSignal["ALL_AMPS"] = 2000.0
extractTask = cpPipe.ptc.PhotonTransferCurveExtractTask(config=extractConfig)

solveConfig = self.defaultConfigSolve
Expand Down Expand Up @@ -181,18 +185,31 @@ def test_covAstier(self):
resultsSolve = solveTask.run(resultsExtract.outputCovariances,
camera=FakeCamera([self.flatExp1.getDetector()]))

ptc = resultsSolve.outputPtcDataset

for amp in self.ampNames:
self.assertAlmostEqual(resultsSolve.outputPtcDataset.gain[amp], inputGain, places=2)
for v1, v2 in zip(varStandard[amp], resultsSolve.outputPtcDataset.finalVars[amp]):
self.assertAlmostEqual(ptc.gain[amp], inputGain, places=2)
for v1, v2 in zip(varStandard[amp], ptc.finalVars[amp]):
self.assertAlmostEqual(v1/v2, 1.0, places=1)

# Test various operations on the PTC output from the task.
ptc = resultsSolve.outputPtcDataset
mask = ptc.getGoodPoints(amp)

values = ((ptc.covariancesModel[amp][mask, 0, 0] - ptc.covariances[amp][mask, 0, 0])
/ ptc.covariancesModel[amp][mask, 0, 0])
np.testing.assert_array_less(np.abs(values), 2e-3)

values = ((ptc.covariancesModel[amp][mask, 1, 1] - ptc.covariances[amp][mask, 1, 1])
/ ptc.covariancesModel[amp][mask, 1, 1])
np.testing.assert_array_less(np.abs(values), 0.2)

values = ((ptc.covariancesModel[amp][mask, 1, 2] - ptc.covariances[amp][mask, 1, 2])
/ ptc.covariancesModel[amp][mask, 1, 2])
np.testing.assert_array_less(np.abs(values), 0.2)

expIdsUsed = ptc.getExpIdsUsed("C:0,0")
# Check that these are the same as the inputs, paired up, with the
# final two removed.
self.assertTrue(np.all(expIdsUsed == np.array(expIds).reshape(len(expIds) // 2, 2)[:-1]))
# first two (low flux) and final two (nans) removed.
self.assertTrue(np.all(expIdsUsed == np.array(expIds).reshape(len(expIds) // 2, 2)[1:-1]))
erykoff marked this conversation as resolved.
Show resolved Hide resolved

goodAmps = ptc.getGoodAmps()
self.assertEqual(goodAmps, self.ampNames)
Expand Down