Skip to content

Commit

Permalink
Update test_covAstier with new numbers
Browse files Browse the repository at this point in the history
  • Loading branch information
Alex-Broughton committed Nov 17, 2024
1 parent d8428c1 commit b7a62c3
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 34 deletions.
4 changes: 4 additions & 0 deletions pipelines/LSSTComCam/cpCti.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
description: LSSTCam cti calibration construction
instrument: lsst.obs.lsst.LsstComCam
imports:
- location: $CP_PIPE_DIR/pipelines/_ingredients/cpCtiLSST.yaml
19 changes: 9 additions & 10 deletions python/lsst/cp/pipe/ptc/cpPtcSolve.py
Original file line number Diff line number Diff line change
Expand Up @@ -613,17 +613,17 @@ def fitDataFullCovariance(self, dataset):
fitResults = {'a': [], 'c': [], 'noiseMatrix': [], 'gain': [], 'paramsErr': []}

# Pick the correct full covariance model function
model = self.funcFullCovarianceModel
ptcModel = self.funcFullCovarianceModel
if dataset.ptcFitType == "FULLCOVARIANCE_NO_B":
model = self.funcFullCovarianceModelNoB
ptcModel = self.funcFullCovarianceModelNoB
pInit = np.concatenate((a0.ravel(), noiseMatrix0.ravel(), np.array(gain0)), axis=None)

params, paramsErr, _ = fitLeastSq(
pInit,
muAtAmpMasked,
covAtAmpForFitMasked.ravel(),
model,
weightsY=covSqrtWeightsAtAmpForFitMasked.ravel(),
pInit,
muAtAmpMasked,
covAtAmpForFitMasked.ravel(),
ptcModel,
weightsY=covSqrtWeightsAtAmpForFitMasked.ravel(),
)

if dataset.ptcFitType == "FULLCOVARIANCE_NO_B":
Expand Down Expand Up @@ -662,7 +662,7 @@ def fitDataFullCovariance(self, dataset):
fitResults['c'],
fitResults['noiseMatrix'],
fitResults['gain'],
setBtoZero=dataset.ptcFitType == "FULLCOVARIANCE_NO_B",
setBtoZero=(dataset.ptcFitType == "FULLCOVARIANCE_NO_B"),
)
dataset.covariancesSqrtWeights[ampName] = covSqrtWeightsAtAmp
dataset.aMatrix[ampName] = fitResults['a']
Expand Down Expand Up @@ -782,7 +782,7 @@ def funcFullCovarianceModelNoB(self, params, x):
Parameters
----------
params : `list`
Parameters of the model: aMatrix, CMatrix, noiseMatrix,
Parameters of the model: aMatrix, noiseMatrix,
gain (e/adu).
x : `numpy.array`, (N,)
Signal mu (adu)
Expand All @@ -796,7 +796,6 @@ def funcFullCovarianceModelNoB(self, params, x):
lenParams = matrixSideFit*matrixSideFit
aMatrix = params[:lenParams].reshape((matrixSideFit, matrixSideFit))
cMatrix = np.zeros_like(aMatrix)
# params[lenParams:2*lenParams].reshape((matrixSideFit, matrixSideFit))
noiseMatrix = params[lenParams:2*lenParams].reshape((matrixSideFit, matrixSideFit))
gain = params[-1]

Expand Down
2 changes: 1 addition & 1 deletion tests/test_defects.py
Original file line number Diff line number Diff line change
Expand Up @@ -549,7 +549,7 @@ def test_maskBlocks_y_out_of_order_dm38103(self):
"""A test for maskBlocksIfIntermitentBadPixelsInColumn, y out of order.
This test is a variant of
notest_maskBlocks_every_other_pixel_bad_greater_than_threshold with
test_maskBlocks_every_other_pixel_bad_greater_than_threshold with
an extra out-of-y-order bad pixel to trigger DM-38103.
"""
expectedDefects = [Box2I(corner=Point2I(50, 110), dimensions=Extent2I(1, 31))]
Expand Down
48 changes: 25 additions & 23 deletions tests/test_ptc.py
Original file line number Diff line number Diff line change
Expand Up @@ -260,17 +260,17 @@ def test_covAstier(self):
expectedNoiseMatrix = {
"FULLCOVARIANCE": np.array(
[[8.99474598, 9.94916264, -27.90587299],
[-2.95079527, -17.11827641, -47.88156244],
[5.24915021, -3.25786165, 26.09634067]],
[-2.95079527, -17.11827641, -47.88156244],
[5.24915021, -3.25786165, 26.09634067]],
),
"FULLCOVARIANCE_NO_B": np.array(
[[8.71049338, 12.48584043, -37.06585088],
[-4.80523971, -23.29102809, -66.37815343],
[7.48654766, -4.10168337, 35.64469824]],
[-4.80523971, -23.29102809, -66.37815343],
[7.48654766, -4.10168337, 35.64469824]],
),
}

for fitType in ["FULLCOVARIANCE_NO_B"]:
for fitType in ["FULLCOVARIANCE", "FULLCOVARIANCE_NO_B"]:
solveConfig.ptcFitType = fitType
solveTask = cpPipe.ptc.PhotonTransferCurveSolveTask(config=solveConfig)

Expand All @@ -293,14 +293,14 @@ def test_covAstier(self):
# Check that the PTC turnoff is correctly computed.
# This will be different for the C:0,0 amp.
if amp == "C:0,0":
self.assertAlmostEqual(ptc.ptcTurnoff[amp], ptc.rawMeans[ampName][-3])
self.assertAlmostEqual(ptc.ptcTurnoff[amp], ptc.rawMeans[amp][-3])
else:
self.assertAlmostEqual(ptc.ptcTurnoff[amp], ptc.rawMeans[ampName][-1])
self.assertAlmostEqual(ptc.ptcTurnoff[amp], ptc.rawMeans[amp][-1])

# Test that all the quantities are correctly ordered and have
# not accidentally been masked. We check every other output ([::2])
# because these datasets are in pairs of [real, dummy] to
# match the inputs to the extract task.
# Test that all the quantities are correctly ordered and
# have not accidentally been masked. We check every other
# output ([::2]) because these datasets are in pairs of
# [real, dummy] to match the inputs to the extract task.
for i, extractPtc in enumerate(resultsExtract.outputCovariances[::2]):
self.assertFloatsAlmostEqual(
extractPtc.rawExpTimes[ampName][0],
Expand Down Expand Up @@ -353,9 +353,9 @@ def test_covAstier(self):
np.nanmedian(ptc.noiseList[ampName]) * ptc.gain[ampName],
rtol=0.05,
)
# If the noise error is greater than the noise, something
# is seriously wrong. Possibly some kind of gain application
# mismatch.
# If the noise error is greater than the noise,
# something is seriously wrong. Possibly some
# kind of gain application mismatch.
self.assertLess(
ptc.noiseErr[ampName],
ptc.noise[ampName],
Expand All @@ -368,17 +368,19 @@ def test_covAstier(self):
) / 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.3)
if ptc.ptcFitType == "FULLCOVARIANCE":
values = (
ptc.covariancesModel[amp][mask, 0, 1] - ptc.covariances[amp][mask, 0, 1]
) / ptc.covariancesModel[amp][mask, 0, 1]
np.testing.assert_array_less(np.abs(values), 0.3)

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.3)
values = (
ptc.covariancesModel[amp][mask, 1, 0] - ptc.covariances[amp][mask, 1, 0]
) / ptc.covariancesModel[amp][mask, 1, 0]
np.testing.assert_array_less(np.abs(values), 0.3)

# And test that the auxiliary values are there and correctly ordered.
# And test that the auxiliary values are there and
# correctly ordered.
self.assertIn('CCOBCURR', ptc.auxValues)
self.assertIn('CCDTEMP', ptc.auxValues)
firstExpIds = np.array([i for i, _ in ptc.inputExpIdPairs['C:0,0']], dtype=np.float64)
Expand Down

0 comments on commit b7a62c3

Please sign in to comment.