Coverage for tests / test_gainCorrection.py: 38%
35 statements
« prev ^ index » next coverage.py v7.13.5, created at 2026-04-14 23:58 +0000
« prev ^ index » next coverage.py v7.13.5, created at 2026-04-14 23:58 +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/>.
21import unittest
22import tempfile
24import numpy as np
26import lsst.utils.tests
28from lsst.ip.isr import GainCorrection
31class GainCorrectionTest(lsst.utils.tests.TestCase):
32 """Test the GainCorrection dataset."""
33 def setUp(self):
34 self.gainCorrection = GainCorrection(
35 ampNames=["C01", "C02"],
36 gainAdjustments=[1.0, 1.1],
37 )
39 def _checkEqual(self, a, b):
40 self.assertEqual(b.metadata, a.metadata)
41 np.testing.assert_array_equal(b.ampNames, a.ampNames)
42 self.assertEqual(b.gainAdjustments.dtype, a.gainAdjustments.dtype)
43 np.testing.assert_array_almost_equal(b.gainAdjustments, a.gainAdjustments)
45 def testRoundTrip(self):
46 """Test persistence round-tripping."""
48 with tempfile.NamedTemporaryFile(suffix=".yaml") as f:
49 usedFilename = self.gainCorrection.writeText(f.name)
50 fromText = GainCorrection.readText(usedFilename)
51 self._checkEqual(fromText, self.gainCorrection)
53 with tempfile.NamedTemporaryFile(suffix=".fits") as f:
54 usedFilename = self.gainCorrection.writeFits(f.name)
55 fromFits = GainCorrection.readFits(usedFilename)
56 self._checkEqual(fromFits, self.gainCorrection)
58 def testCorrectGains(self):
59 gains = {
60 ampName: 1.5
61 for ampName in self.gainCorrection.ampNames
62 }
64 self.gainCorrection.correctGains(gains)
66 for i, ampName in enumerate(self.gainCorrection.ampNames):
67 np.testing.assert_almost_equal(1.5*self.gainCorrection.gainAdjustments[i], gains[ampName])
70class MemoryTester(lsst.utils.tests.MemoryTestCase):
71 pass
74def setup_module(module):
75 lsst.utils.tests.init()
78if __name__ == "__main__": 78 ↛ 79line 78 didn't jump to line 79 because the condition on line 78 was never true
79 import sys
80 setup_module(sys.modules[__name__])
81 unittest.main()