Coverage for tests/test_ampOffset.py: 30%
53 statements
« prev ^ index » next coverage.py v7.2.3, created at 2023-04-21 10:02 +0000
« prev ^ index » next coverage.py v7.2.3, created at 2023-04-21 10:02 +0000
1#
2# LSST Data Management System
3#
4# Copyright 2008-2016 AURA/LSST.
5#
6# This product includes software developed by the
7# LSST Project (http://www.lsst.org/).
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 LSST License Statement and
20# the GNU General Public License along with this program. If not,
21# see <https://www.lsstcorp.org/LegalNotices/>.
22#
23import unittest
24import numpy as np
26import lsst.utils.tests
27import lsst.afw.image as afwImage
28from lsst.obs.subaru import HyperSuprimeCam
29from lsst.obs.subaru.ampOffset import SubaruAmpOffsetConfig, SubaruAmpOffsetTask
32class AmpOffsetTest(lsst.utils.tests.TestCase):
34 def setUp(self):
35 instrument = HyperSuprimeCam()
36 self.camera = instrument.getCamera()
38 def tearDown(self):
39 del self.camera
41 def buildExposure(self, addBackground=False):
42 exp = afwImage.ExposureF(self.camera[0].getBBox())
43 exp.setDetector(self.camera[0])
44 amps = exp.getDetector().getAmplifiers()
45 exp.image[amps[0].getBBox()] = -2.5
46 exp.image[amps[1].getBBox()] = -1.0
47 exp.image[amps[2].getBBox()] = 1.0
48 exp.image[amps[3].getBBox()] = 2.5
49 if addBackground:
50 exp.image.array += 100
51 return exp
53 def testAmpOffset(self):
54 exp = self.buildExposure(addBackground=False)
55 config = SubaruAmpOffsetConfig()
56 config.doBackground = False
57 config.doDetection = False
58 task = SubaruAmpOffsetTask(config=config)
59 task.run(exp)
60 meta = exp.getMetadata().toDict()
61 self.assertEqual(np.sum(exp.image.array), 0)
62 self.assertAlmostEqual(meta['PEDESTAL1'], -2.5, 7)
63 self.assertAlmostEqual(meta['PEDESTAL2'], -1.0, 7)
64 self.assertAlmostEqual(meta['PEDESTAL3'], 1.0, 7)
65 self.assertAlmostEqual(meta['PEDESTAL4'], 2.5, 7)
67 def testAmpOffsetWithBackground(self):
68 exp = self.buildExposure(addBackground=True)
69 config = SubaruAmpOffsetConfig()
70 config.doBackground = True
71 config.doDetection = True
72 task = SubaruAmpOffsetTask(config=config)
73 task.run(exp)
74 meta = exp.getMetadata().toDict()
75 self.assertAlmostEqual(meta['PEDESTAL1'], -meta['PEDESTAL4'], 7)
76 self.assertAlmostEqual(meta['PEDESTAL2'], -meta['PEDESTAL3'], 7)
79class TestMemory(lsst.utils.tests.MemoryTestCase):
80 pass
83def setup_module(module):
84 lsst.utils.tests.init()
87if __name__ == "__main__": 87 ↛ 88line 87 didn't jump to line 88, because the condition on line 87 was never true
88 lsst.utils.tests.init()
89 unittest.main()