Coverage for tests/test_ptcDataset.py : 14%

Hot-keys on this page
r m x p toggle line displays
j k next/prev highlighted chunk
0 (zero) top of page
1 (one) first highlighted chunk
1# This file is part of ip_isr.
2#
3# Developed for the LSST Data Management System.
4# This product includes software developed by the LSST Project
5# (https://www.lsst.org).
6# See the COPYRIGHT file at the top-level directory of this distribution
7# for details of code ownership.
8#
9# This program is free software: you can redistribute it and/or modify
10# it under the terms of the GNU General Public License as published by
11# the Free Software Foundation, either version 3 of the License, or
12# (at your option) any later version.
13#
14# This program is distributed in the hope that it will be useful,
15# but WITHOUT ANY WARRANTY; without even the implied warranty of
16# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17# GNU General Public License for more details.
18#
19# You should have received a copy of the GNU General Public License
20# along with this program. If not, see <https://www.gnu.org/licenses/>.
21import unittest
22import tempfile
24import numpy as np
26import lsst.utils.tests
28from lsst.ip.isr import PhotonTransferCurveDataset
29import lsst.ip.isr.isrMock as isrMock
32class PtcDatasetCases(lsst.utils.tests.TestCase):
33 """Test that write/read methods of PhotonTransferCurveDataset work
34 """
35 def setUp(self):
37 self.flatMean = 2000
38 self.readNoiseAdu = 10
39 mockImageConfig = isrMock.IsrMock.ConfigClass()
41 # flatDrop is not really relevant as we replace the data
42 # but good to note it in case we change how this image is made
43 mockImageConfig.flatDrop = 0.99999
44 mockImageConfig.isTrimmed = True
46 self.flatExp1 = isrMock.FlatMock(config=mockImageConfig).run()
47 self.flatExp2 = self.flatExp1.clone()
48 (shapeY, shapeX) = self.flatExp1.getDimensions()
50 self.flatWidth = np.sqrt(self.flatMean) + self.readNoiseAdu
52 self.rng1 = np.random.RandomState(1984)
53 flatData1 = self.rng1.normal(self.flatMean, self.flatWidth, (shapeX, shapeY))
54 self.rng2 = np.random.RandomState(666)
55 flatData2 = self.rng2.normal(self.flatMean, self.flatWidth, (shapeX, shapeY))
57 self.flatExp1.image.array[:] = flatData1
58 self.flatExp2.image.array[:] = flatData2
60 self.flux = 1000. # ADU/sec
61 self.gain = 1.5 # e-/ADU
62 self.noiseSq = 5*self.gain # 7.5 (e-)^2
63 self.c1 = 1./self.gain
65 self.ampNames = [amp.getName() for amp in self.flatExp1.getDetector().getAmplifiers()]
67 def test_ptcDatset(self):
68 # Fill the set up with made up data.
69 nSignalPoints = 5
70 nSideCovMatrix = 2
71 for fitType in ['POLYNOMIAL', 'EXPAPPROXIMATION', 'FULLCOVARIANCE']:
72 localDataset = PhotonTransferCurveDataset(self.ampNames, " ")
73 localDataset.ptcFitType = fitType
74 localDataset.badAmps = [localDataset.ampNames[0], localDataset.ampNames[1]]
75 for ampName in localDataset.ampNames:
77 localDataset.inputExpIdPairs[ampName] = np.repeat(1, nSignalPoints).tolist()
78 localDataset.expIdMask[ampName] = [True, False, True, True, False, True, False, True, True,
79 True, True, False, True, False, True]
80 localDataset.rawExpTimes[ampName] = np.arange(nSignalPoints).tolist()
81 localDataset.rawMeans[ampName] = np.array(self.flux*np.arange(nSignalPoints)).tolist()
82 localDataset.rawVars[ampName] = np.array(self.c1*self.flux*np.arange(nSignalPoints)).tolist()
83 localDataset.photoCharge[ampName] = np.repeat(np.nan, nSignalPoints).tolist()
84 localDataset.gain[ampName] = self.gain
85 localDataset.gainErr[ampName] = 0.1
86 localDataset.noise[ampName] = self.noiseSq
87 localDataset.noiseErr[ampName] = 2.0
89 localDataset.finalVars[ampName] = np.array(self.c1*self.flux*np.arange(
90 nSignalPoints)).tolist()
91 localDataset.finalModelVars[ampName] = np.repeat(100.0, nSignalPoints).tolist()
92 localDataset.finalMeans[ampName] = np.array(self.flux*np.arange(nSignalPoints)).tolist()
94 if fitType in ['POLYNOMIAL', 'EXPAPPROXIMATION', ]:
95 localDataset.ptcFitPars[ampName] = np.array([10.0, 1.5, 1e-6]).tolist()
96 localDataset.ptcFitParsError[ampName] = np.array([1.0, 0.2, 1e-7]).tolist()
97 localDataset.ptcFitChiSq[ampName] = 1.0
98 localDataset.covariances[ampName] = np.full(
99 (nSignalPoints, nSideCovMatrix, nSideCovMatrix), np.nan).tolist()
100 localDataset.covariancesModel[ampName] = np.full(
101 (nSignalPoints, nSideCovMatrix, nSideCovMatrix), np.nan).tolist()
102 localDataset.covariancesSqrtWeights[ampName] = np.full((nSignalPoints, nSideCovMatrix,
103 nSideCovMatrix), np.nan).tolist()
104 localDataset.aMatrix[ampName] = np.full((nSideCovMatrix, nSideCovMatrix), np.nan).tolist()
105 localDataset.bMatrix[ampName] = np.full((nSideCovMatrix, nSideCovMatrix), np.nan).tolist()
106 localDataset.covariancesNoB[ampName] = np.full(
107 (nSignalPoints, nSideCovMatrix, nSideCovMatrix), np.nan).tolist()
108 localDataset.covariancesModelNoB[ampName] = np.full((nSignalPoints, nSideCovMatrix,
109 nSideCovMatrix), np.nan).tolist()
110 localDataset.covariancesSqrtWeightsNoB[ampName] = np.full((nSignalPoints, nSideCovMatrix,
111 nSideCovMatrix),
112 np.nan).tolist()
113 localDataset.aMatrixNoB[ampName] = np.full(
114 (nSideCovMatrix, nSideCovMatrix), np.nan).tolist()
116 if localDataset.ptcFitType in ['FULLCOVARIANCE', ]:
117 localDataset.ptcFitPars[ampName] = np.array([np.nan, np.nan]).tolist()
118 localDataset.ptcFitParsError[ampName] = np.array([np.nan, np.nan]).tolist()
119 localDataset.ptcFitChiSq[ampName] = np.array([np.nan, np.nan]).tolist()
121 localDataset.covariances[ampName] = np.full(
122 (nSignalPoints, nSideCovMatrix, nSideCovMatrix), 105.0).tolist()
123 localDataset.covariancesModel[ampName] = np.full(
124 (nSignalPoints, nSideCovMatrix, nSideCovMatrix), 100.0).tolist()
125 localDataset.covariancesSqrtWeights[ampName] = np.full((nSignalPoints, nSideCovMatrix,
126 nSideCovMatrix), 10.0).tolist()
127 localDataset.aMatrix[ampName] = np.full((nSideCovMatrix, nSideCovMatrix), 1e-6).tolist()
128 localDataset.bMatrix[ampName] = np.full((nSideCovMatrix, nSideCovMatrix), 1e-7).tolist()
129 localDataset.covariancesNoB[ampName] = np.full(
130 (nSignalPoints, nSideCovMatrix, nSideCovMatrix), 20.0).tolist()
131 localDataset.covariancesModelNoB[ampName] = np.full((nSignalPoints, nSideCovMatrix,
132 nSideCovMatrix), 15.0).tolist()
133 localDataset.covariancesSqrtWeightsNoB[ampName] = np.full((nSignalPoints, nSideCovMatrix,
134 nSideCovMatrix), 5.0).tolist()
135 localDataset.aMatrixNoB[ampName] = np.full(
136 (nSideCovMatrix, nSideCovMatrix), 2e-6).tolist()
138 filename = tempfile.mktemp()
139 usedFilename = localDataset.writeText(filename + ".yaml")
140 fromText = PhotonTransferCurveDataset.readText(usedFilename)
141 self.assertEqual(localDataset, fromText)
143 filename = tempfile.mktemp()
144 usedFilename = localDataset.writeFits(filename + ".fits")
145 fromFits = PhotonTransferCurveDataset.readFits(usedFilename)
146 self.assertEqual(localDataset, fromFits)
149class MemoryTester(lsst.utils.tests.MemoryTestCase):
150 pass
153def setup_module(module):
154 lsst.utils.tests.init()
157if __name__ == "__main__": 157 ↛ 158line 157 didn't jump to line 158, because the condition on line 157 was never true
158 import sys
159 setup_module(sys.modules[__name__])
160 unittest.main()