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-42863: Add method to evaluate PTC model in ptcDataset #269

Merged
merged 2 commits into from
Sep 26, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 30 additions & 13 deletions tests/test_ptc.py
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ def setUp(self):
(1, self.dataset.covMatrixSide, self.dataset.covMatrixSide)
)

def notest_covAstier(self):
def test_covAstier(self):
"""Test to check getCovariancesAstier

We check that the gain is the same as the imput gain from the
Expand Down Expand Up @@ -414,6 +414,15 @@ def notest_covAstier(self):
self.assertEqual(
ptc.covariancesModelNoB[ampName].shape, covModelNoBShape
)
# Check if evalPtcModel produces expected values
nanMask = ~np.isnan(ptc.finalMeans[ampName])
means = ptc.finalMeans[ampName][nanMask]
covModel = ptc.covariancesModel[ampName][nanMask]
covariancesModel = ptc.evalPtcModel(means, setBtoZero=False)[ampName]
self.assertFloatsAlmostEqual(covariancesModel, covModel, atol=1e-13)
# Note that the PhotoTransferCurveDataset does not store the gain
# fit parameter for FULLCOVARIANCE with b=0, so we can't compare
# exactly.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is that something that we need to add?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes we do, but I want to keep this ticket small and then filed this ticket to update the ptc class https://rubinobs.atlassian.net/browse/DM-46509


# And check that this is serializable
with tempfile.NamedTemporaryFile(suffix=".fits") as f:
Expand Down Expand Up @@ -545,7 +554,15 @@ def ptcFitAndCheckPtc(
np.sqrt(self.noiseSq)
)

def notest_lsstcam_samples(self):
# Check if evalColModel produces expected values
if not doFitBootstrap:
nanMask = ~np.isnan(localDataset.finalMeans[ampName])
means = localDataset.finalMeans[ampName][nanMask]
model = localDataset.finalModelVars[ampName][nanMask]
evalVarModel = localDataset.evalPtcModel(means)[ampName]
self.assertFloatsEqual(evalVarModel, model)

def test_lsstcam_samples(self):
for dense in [False, True]:
for mode in ["normal", "upturn", "dip"]:
rawMeans, rawVars, ptcTurnoff = self._getSampleMeanAndVar(dense=dense, mode=mode)
Expand Down Expand Up @@ -592,7 +609,7 @@ def notest_lsstcam_samples(self):
msg=f"Dense: {dense}; Mode: {mode}",
)

def notest_ptcFit(self):
def test_ptcFit(self):
for doLegacy in [False, True]:
for fitType, order in [
("POLYNOMIAL", 2),
Expand All @@ -605,7 +622,7 @@ def notest_ptcFit(self):
doLegacy=doLegacy,
)

def notest_meanVarMeasurement(self):
def test_meanVarMeasurement(self):
task = self.defaultTaskExtract
im1Area, im2Area, imStatsCtrl, mu1, mu2 = task.getImageAreasMasksStats(
self.flatExp1, self.flatExp2
Expand All @@ -615,7 +632,7 @@ def notest_meanVarMeasurement(self):
self.assertLess(self.flatWidth - np.sqrt(varDiff), 1)
self.assertLess(self.flatMean - mu, 1)

def notest_meanVarMeasurementWithNans(self):
def test_meanVarMeasurementWithNans(self):
task = self.defaultTaskExtract

flatExp1 = self.flatExp1.clone()
Expand Down Expand Up @@ -653,7 +670,7 @@ def notest_meanVarMeasurementWithNans(self):
self.assertLess(np.sqrt(expectedVar) - np.sqrt(varDiff), 1)
self.assertLess(expectedMu - mu, 1)

def notest_meanVarMeasurementAllNan(self):
def test_meanVarMeasurementAllNan(self):
task = self.defaultTaskExtract
flatExp1 = self.flatExp1.clone()
flatExp2 = self.flatExp2.clone()
Expand All @@ -673,7 +690,7 @@ def notest_meanVarMeasurementAllNan(self):
self.assertTrue(covDiff is None)
self.assertTrue(np.isnan(rowMeanVariance))

def notest_meanVarMeasurementTooFewPixels(self):
def test_meanVarMeasurementTooFewPixels(self):
task = self.defaultTaskExtract
flatExp1 = self.flatExp1.clone()
flatExp2 = self.flatExp2.clone()
Expand All @@ -699,7 +716,7 @@ def notest_meanVarMeasurementTooFewPixels(self):
self.assertTrue(covDiff is None)
self.assertTrue(np.isnan(rowMeanVariance))

def notest_meanVarMeasurementTooNarrowStrip(self):
def test_meanVarMeasurementTooNarrowStrip(self):
# We need a new config to make sure the second covariance cut is
# triggered.
config = cpPipe.ptc.PhotonTransferCurveExtractTask.ConfigClass()
Expand Down Expand Up @@ -733,7 +750,7 @@ def notest_meanVarMeasurementTooNarrowStrip(self):
self.assertTrue(covDiff is None)
self.assertTrue(np.isnan(rowMeanVariance))

def notest_makeZeroSafe(self):
def test_makeZeroSafe(self):
noZerosArray = [1.0, 20, -35, 45578.98, 90.0, 897, 659.8]
someZerosArray = [1.0, 20, 0, 0, 90, 879, 0]
allZerosArray = [0.0, 0.0, 0, 0, 0.0, 0, 0]
Expand Down Expand Up @@ -768,7 +785,7 @@ def notest_makeZeroSafe(self):
for exp, meas in zip(noZerosArray, measuredNoZerosArray):
self.assertEqual(exp, meas)

def notest_getInitialGoodPoints(self):
def test_getInitialGoodPoints(self):
xs = [1, 2, 3, 4, 5, 6]
ys = [2 * x for x in xs]
points = self.defaultTaskSolve._getInitialGoodPoints(
Expand Down Expand Up @@ -846,15 +863,15 @@ def runGetGainFromFlatPair(self, correctionType="NONE"):
ptc.noiseList[ampName][i], np.sqrt(self.noiseSq) / self.gain,
)

def notest_getGainFromFlatPair(self):
def test_getGainFromFlatPair(self):
for gainCorrectionType in [
"NONE",
"SIMPLE",
"FULL",
]:
self.runGetGainFromFlatPair(gainCorrectionType)

def notest_ptcFitBootstrap(self):
def test_ptcFitBootstrap(self):
"""Test the bootstrap fit option for the PTC"""
for (fitType, order) in [('POLYNOMIAL', 2), ('POLYNOMIAL', 3), ('EXPAPPROXIMATION', None)]:
self.ptcFitAndCheckPtc(fitType=fitType, order=order, doFitBootstrap=True)
Expand Down Expand Up @@ -1666,7 +1683,7 @@ def setUp(self):
"C01": [(123, 234), (345, 456), (567, 678)],
}

def notest_generalBehaviour(self):
def test_generalBehaviour(self):
test = PhotonTransferCurveDataset(["C00", "C01"], " ")
test.inputExpIdPairs = {
"C00": [(123, 234), (345, 456), (567, 678)],
Expand Down
Loading