From b7a62c33efc40c05425b71da640eb86504286467 Mon Sep 17 00:00:00 2001 From: Alex Broughton Date: Fri, 11 Oct 2024 16:54:23 -0700 Subject: [PATCH] Update test_covAstier with new numbers --- pipelines/LSSTComCam/cpCti.yaml | 4 +++ python/lsst/cp/pipe/ptc/cpPtcSolve.py | 19 +++++------ tests/test_defects.py | 2 +- tests/test_ptc.py | 48 ++++++++++++++------------- 4 files changed, 39 insertions(+), 34 deletions(-) create mode 100644 pipelines/LSSTComCam/cpCti.yaml diff --git a/pipelines/LSSTComCam/cpCti.yaml b/pipelines/LSSTComCam/cpCti.yaml new file mode 100644 index 00000000..b27bcc16 --- /dev/null +++ b/pipelines/LSSTComCam/cpCti.yaml @@ -0,0 +1,4 @@ +description: LSSTCam cti calibration construction +instrument: lsst.obs.lsst.LsstComCam +imports: + - location: $CP_PIPE_DIR/pipelines/_ingredients/cpCtiLSST.yaml diff --git a/python/lsst/cp/pipe/ptc/cpPtcSolve.py b/python/lsst/cp/pipe/ptc/cpPtcSolve.py index 0487ccf3..a253037b 100644 --- a/python/lsst/cp/pipe/ptc/cpPtcSolve.py +++ b/python/lsst/cp/pipe/ptc/cpPtcSolve.py @@ -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": @@ -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'] @@ -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) @@ -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] diff --git a/tests/test_defects.py b/tests/test_defects.py index da17243d..7de2419c 100644 --- a/tests/test_defects.py +++ b/tests/test_defects.py @@ -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))] diff --git a/tests/test_ptc.py b/tests/test_ptc.py index 75382053..305e0dc4 100644 --- a/tests/test_ptc.py +++ b/tests/test_ptc.py @@ -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) @@ -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], @@ -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], @@ -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)