Coverage for tests/test_transmissionCurve.py: 44%

37 statements  

« prev     ^ index     » next       coverage.py v6.5.0, created at 2023-02-22 12:23 +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 os 

23import numpy as np 

24import tempfile 

25 

26import lsst.geom 

27import lsst.utils.tests 

28 

29from lsst.afw.image import TransmissionCurve 

30from lsst.ip.isr import IntermediateTransmissionCurve 

31 

32 

33TESTDIR = os.path.abspath(os.path.dirname(__file__)) 

34 

35 

36class TransmissionCurveCases(lsst.utils.tests.TestCase): 

37 """Test intermediate transmission curve calibration type. 

38 """ 

39 def setUp(self): 

40 self.points = [lsst.geom.Point2D(np.random.rand(), np.random.rand()) for i in range(5)] 

41 

42 self.curve1 = IntermediateTransmissionCurve.readText( 

43 os.path.join(TESTDIR, "data", "test_curve1.ecsv")) 

44 self.curve2 = IntermediateTransmissionCurve.readText( 

45 os.path.join(TESTDIR, "data", "test_curve2.ecsv")) 

46 self.curve3 = IntermediateTransmissionCurve.readText( 

47 os.path.join(TESTDIR, "data", "test_curve3.ecsv")) 

48 

49 def assertTransmissionCurvesEqual(self, a, b, rtol=1e-6, atol=0.0): 

50 """Test whether two TransimssionCurves are equivalent. 

51 From afw/tests/test_transmissionCurve.py 

52 """ 

53 self.assertEqual(a.getWavelengthBounds(), b.getWavelengthBounds()) 

54 self.assertEqual(a.getThroughputAtBounds(), b.getThroughputAtBounds()) 

55 wavelengths = np.linspace(*(a.getWavelengthBounds() + (100,))) 

56 for point in self.points: 

57 self.assertFloatsAlmostEqual( 

58 a.sampleAt(point, wavelengths), 

59 b.sampleAt(point, wavelengths), 

60 rtol=rtol, atol=atol 

61 ) 

62 

63 def test_construction(self): 

64 self.assertTransmissionCurvesEqual(self.curve1.transmissionCurve, 

65 self.curve2.transmissionCurve) 

66 self.assertTransmissionCurvesEqual(self.curve1.transmissionCurve, 

67 self.curve3.transmissionCurve) 

68 

69 def test_output(self): 

70 filename1 = tempfile.mktemp() 

71 self.curve1.writeFits(filename1) 

72 

73 reread = TransmissionCurve.readFits(filename1) 

74 self.assertTransmissionCurvesEqual(reread, self.curve1.transmissionCurve) 

75 

76 

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

78 pass 

79 

80 

81def setup_module(module): 

82 lsst.utils.tests.init() 

83 

84 

85if __name__ == "__main__": 85 ↛ 86line 85 didn't jump to line 86, because the condition on line 85 was never true

86 import sys 

87 setup_module(sys.modules[__name__]) 

88 unittest.main()