Coverage for tests / test_gainCorrection.py: 38%

35 statements  

« prev     ^ index     » next       coverage.py v7.13.5, created at 2026-05-07 08:28 +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 

23 

24import numpy as np 

25 

26import lsst.utils.tests 

27 

28from lsst.ip.isr import GainCorrection 

29 

30 

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 ) 

38 

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) 

44 

45 def testRoundTrip(self): 

46 """Test persistence round-tripping.""" 

47 

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) 

52 

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) 

57 

58 def testCorrectGains(self): 

59 gains = { 

60 ampName: 1.5 

61 for ampName in self.gainCorrection.ampNames 

62 } 

63 

64 self.gainCorrection.correctGains(gains) 

65 

66 for i, ampName in enumerate(self.gainCorrection.ampNames): 

67 np.testing.assert_almost_equal(1.5*self.gainCorrection.gainAdjustments[i], gains[ampName]) 

68 

69 

70class MemoryTester(lsst.utils.tests.MemoryTestCase): 

71 pass 

72 

73 

74def setup_module(module): 

75 lsst.utils.tests.init() 

76 

77 

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()