Coverage for tests/test_lsf1d.py: 20%

71 statements  

« prev     ^ index     » next       coverage.py v7.5.0, created at 2024-04-27 11:04 +0000

1# 

2# LSST Data Management System 

3# Copyright 2008, 2009, 2010 LSST Corporation. 

4# 

5# This product includes software developed by the 

6# LSST Project (http://www.lsst.org/). 

7# 

8# This program is free software: you can redistribute it and/or modify 

9# it under the terms of the GNU General Public License as published by 

10# the Free Software Foundation, either version 3 of the License, or 

11# (at your option) any later version. 

12# 

13# This program is distributed in the hope that it will be useful, 

14# but WITHOUT ANY WARRANTY; without even the implied warranty of 

15# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 

16# GNU General Public License for more details. 

17# 

18# You should have received a copy of the LSST License Statement and 

19# the GNU General Public License along with this program. If not, 

20# see <http://www.lsstcorp.org/LegalNotices/>. 

21# 

22import unittest 

23 

24import lsst.utils.tests 

25import lsst.pex.exceptions 

26import lsst.meas.astrom.sip as sip 

27 

28 

29class Lsf1dTestCase(unittest.TestCase): 

30 

31 def testBadArgs1(self): 

32 """Check that code fails when order is too low""" 

33 

34 x = [630, 1000, 1205, 1427] 

35 y = [.622, 1.109, 1.198, 1.429] 

36 s = [1, 1, 1, 1] 

37 

38 order = 0 

39 

40 with self.assertRaises(lsst.pex.exceptions.Exception): 

41 sip.LeastSqFitter1dPoly(x, y, s, order) 

42 

43 def testBadArgs2(self): 

44 """Check that code fails when not len(x) != len(y)""" 

45 

46 x = [630, 1000, 1205, 1427] 

47 y = [.622, 1.109, 1.198] 

48 s = [1, 1, 1, 1] 

49 

50 order = 0 

51 

52 with self.assertRaises(lsst.pex.exceptions.Exception): 

53 sip.LeastSqFitter1dPoly(x, y, s, order) 

54 

55 def testBadArgs3(self): 

56 """Check that code fails when not len(x) != len(s)""" 

57 

58 x = [630, 1000, 1205, 1427] 

59 y = [.622, 1.109, 1.198, 1.429] 

60 s = [1, 1, 1, 1, 1] 

61 

62 order = 0 

63 

64 with self.assertRaises(lsst.pex.exceptions.Exception): 

65 sip.LeastSqFitter1dPoly(x, y, s, order) 

66 

67 def testBadArgs4(self): 

68 """Check that code fails when not order > number data points""" 

69 

70 x = [630, 1000, 1205, 1427] 

71 y = [.622, 1.109, 1.198, 1.429] 

72 s = [1, 1, 1, 1] 

73 

74 order = 5 

75 

76 with self.assertRaises(lsst.pex.exceptions.Exception): 

77 sip.LeastSqFitter1dPoly(x, y, s, order) 

78 

79 def testConst1(self): 

80 """Check that code fits a dc offset correctly (1)""" 

81 

82 x = [630, 1000, 1205, 1427] 

83 y = [.622, 1.109, 1.198, 1.429] 

84 s = [1, 1, 1, 1] 

85 

86 order = 1 

87 

88 lsf = sip.LeastSqFitter1dPoly(x, y, s, order) 

89 

90 for i in range(1, len(x)): 

91 self.assertAlmostEqual(lsf.valueAt(x[0]), lsf.valueAt(x[i]), 4) 

92 # print x[i], y[i], lsf.valueAt(x[i]) 

93 

94 def testCompareToCpp1(self): 

95 """Confirm that I get the same behaviour in Python as I 

96 do in the C++ test fitLinear3 

97 """ 

98 

99 # This test arises because I was having trouble using Eigen's 

100 # svd inversion. fitLinear3 in C++ worked fine, but this test 

101 # behaved differently, and I tracked the result down to 

102 # the svd routines. 

103 

104 x = [689.301136505, 1112.8573687, 1386.67168477] 

105 y = [0.66911456573, 1.1147439759, 1.39597284177] 

106 s = [1, 1, 1] 

107 

108 order = 2 

109 print() 

110 lsf = sip.LeastSqFitter1dPoly(x, y, s, order) 

111 

112 self.assertAlmostEqual(lsf.valueAt(x[0]), 0.670187891961, 4) 

113 self.assertAlmostEqual(lsf.valueAt(x[1]), 1.11201034929, 4) 

114 self.assertAlmostEqual(lsf.valueAt(x[2]), 1.39763314215, 4) 

115 

116 def testCompareToCpp2(self): 

117 """Confirm that I get the same behaviour in Python as I do in the C++ test fitLinear3 

118 """ 

119 

120 # This test arises because I was having trouble using Eigen's 

121 # svd inversion. fitLinear3 in C++ worked fine, but this test 

122 # behaved differently, and I tracked the result down to 

123 # the svd routines. 

124 

125 x = [628.857680996, 995.008255088, 1203.39412154, 1425.1404727] 

126 y = [0.616728229875, 1.01887634344, 1.19679830465, 1.42873084062] 

127 s = [1, 1, 1, 1] 

128 

129 order = 3 

130 print() 

131 lsf = sip.LeastSqFitter1dPoly(x, y, s, order) 

132 

133 for i in range(len(x)): 

134 f = lsf.valueAt(x[i]) 

135 print("%.1f %.3f %.3f" % (x[i], y[i], f)) 

136 

137 self.assertAlmostEqual(lsf.valueAt(x[0]), y[0], 1) 

138 self.assertAlmostEqual(lsf.valueAt(x[1]), y[1], 1) 

139 self.assertAlmostEqual(lsf.valueAt(x[2]), y[2], 1) 

140 

141 

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

143 pass 

144 

145 

146def setup_module(module): 

147 lsst.utils.tests.init() 

148 

149 

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

151 lsst.utils.tests.init() 

152 unittest.main()