Coverage for tests/test_photodiode.py: 24%
70 statements
« prev ^ index » next coverage.py v7.3.2, created at 2023-12-12 13:11 +0000
« prev ^ index » next coverage.py v7.3.2, created at 2023-12-12 13:11 +0000
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/>.
22import unittest
23import tempfile
25import numpy as np
27import lsst.afw.cameraGeom as cameraGeom
28import lsst.geom as geom
29import lsst.utils.tests
31from lsst.ip.isr import PhotodiodeCalib
34class PhotodiodeTestCase(lsst.utils.tests.TestCase):
35 def setUp(self):
37 self.timeSeries = [0.0, 0.08496094, 0.1689453, 0.2529297,
38 0.3378906, 0.421875, 0.5068359, 0.5908203, 0.6757813,
39 0.7597656, 0.84375, 0.9287109, 1.012695, 1.097656, 1.181641,
40 1.266602]
41 self.currentSeries = [-1.350031E-12, 1.598721E-13, -1.456613E-13,
42 -1.385558E-13, -3.517187E-13, -3.375078E-13, 3.597549E-10,
43 3.591616E-10, 3.599823E-10, 3.597158E-10, 3.606893E-10,
44 3.602736E-10, 3.582272E-10, 3.59293E-10, 3.602878E-10,
45 3.588703E-10]
47 camBuilder = cameraGeom.Camera.Builder("fakeCam")
48 detBuilder = camBuilder.add('det_a', 1)
49 detBuilder.setSerial("123")
51 bbox = geom.Box2I(geom.Point2I(0, 0), geom.Extent2I(100, 100))
52 orientation = cameraGeom.Orientation()
53 pixelSize = lsst.geom.Extent2D(1, 1)
54 detBuilder.setBBox(bbox)
55 detBuilder.setOrientation(orientation)
56 detBuilder.setPixelSize(pixelSize)
58 self.camera = camBuilder
59 self.detector = detBuilder
61 def testDataOnly(self):
62 calib = PhotodiodeCalib(timeSamples=self.timeSeries,
63 currentSamples=self.currentSeries)
65 self.assertFloatsAlmostEqual(calib.integrate(), 2.88414e-10, rtol=1e-14)
66 self.assertFloatsAlmostEqual(calib.integrateDirectSum(), 2.88414e-10, rtol=1e-14)
67 self.assertFloatsAlmostEqual(calib.integrateTrimmedSum(), 2.88720e-10, rtol=1e-14)
68 self.assertFloatsAlmostEqual(calib.integrateChargeSum(), 3.5960649e-09, rtol=1e-14)
70 self.assertEqual(calib.timeSamples.shape, (16, ))
71 self.assertEqual(calib.currentSamples.shape, (16, ))
73 outPath = tempfile.mktemp() + '.yaml'
74 calib.writeText(outPath)
75 newPhotodiode = PhotodiodeCalib().readText(outPath)
76 self.assertEqual(calib, newPhotodiode)
78 outPath = tempfile.mktemp() + '.fits'
79 calib.writeFits(outPath)
80 newPhotodiode = PhotodiodeCalib().readFits(outPath)
81 self.assertEqual(calib, newPhotodiode)
83 def testFullyPopulated(self):
84 calib = PhotodiodeCalib(timeSamples=self.timeSeries,
85 currentSamples=self.currentSeries,
86 detector=self.detector,
87 camera=self.camera)
89 self.assertFloatsAlmostEqual(calib.integrate(), 2.88414e-10, rtol=1e-14)
90 self.assertFloatsAlmostEqual(calib.integrateDirectSum(), 2.88414e-10, rtol=1e-14)
91 self.assertFloatsAlmostEqual(calib.integrateTrimmedSum(), 2.88720e-10, rtol=1e-14)
92 self.assertFloatsAlmostEqual(calib.integrateChargeSum(), 3.5960649e-09, rtol=1e-14)
94 self.assertEqual(calib.timeSamples.shape, (16, ))
95 self.assertEqual(calib.currentSamples.shape, (16, ))
97 outPath = tempfile.mktemp() + '.yaml'
98 calib.writeText(outPath)
99 newPhotodiode = PhotodiodeCalib().readText(outPath)
100 self.assertEqual(calib, newPhotodiode)
102 outPath = tempfile.mktemp() + '.fits'
103 calib.writeFits(outPath)
104 newPhotodiode = PhotodiodeCalib().readFits(outPath)
105 self.assertEqual(calib, newPhotodiode)
107 def testIntegrateChargeSum(self):
108 """
109 This tests the .integrateChargeSum method in the presence of
110 an above-baseline point which is still below the initial
111 threshold for identifying points to exclude in the baseline
112 current estimate.
113 """
114 # Compute a value to insert at time 0.47.
115 test_time = 0.47
116 test_current = ((max(self.currentSeries) - min(self.currentSeries))/40.
117 + min(self.currentSeries))
118 new_times = np.array(self.timeSeries + [test_time])
119 new_currents = np.array(self.currentSeries + [test_current])
120 # Put these arrays in time order, though this isn't strictly needed.
121 index = np.argsort(new_times)
122 calib = PhotodiodeCalib(timeSamples=new_times[index],
123 currentSamples=new_currents[index])
124 self.assertFloatsAlmostEqual(calib.integrateChargeSum(), 3.6049277e-09, rtol=1e-14)
127class MemoryTester(lsst.utils.tests.MemoryTestCase):
128 pass
131def setup_module(module):
132 lsst.utils.tests.init()
135if __name__ == "__main__": 135 ↛ 136line 135 didn't jump to line 136, because the condition on line 135 was never true
136 import sys
137 setup_module(sys.modules[__name__])
138 unittest.main()