Coverage for tests/test_lsf2d.py: 23%

52 statements  

« prev     ^ index     » next       coverage.py v6.5.0, created at 2023-03-29 02:51 -0700

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 Lsf2dTestCase(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 = [535, 929, 623, 602] 

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 = [535, 929, 623] 

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

49 

50 order = 2 

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 = [535, 929, 623, 602] 

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 = [535, 929, 623, 602] 

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 testFitLinearXSurface2(self): 

80 """Python equivalent of C++ test case""" 

81 

82 x = [599.59899999999993, 1172.7726619709097, 512.51199999999994, 1083.6078436082901] 

83 y = [512.0, 539.77214401699996, 541.0, 562.09371856300004] 

84 z = [0.5989999999999327, 1.1716010609097793, 0.51199999999994361, 1.0825253182899814] 

85 s = [.1, .1, .1, .1] 

86 

87 print(" ") 

88 lsf = sip.LeastSqFitter2dPoly(x, y, z, s, 2) 

89 print(lsf.getParams()) 

90 

91 print("Output:") 

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

93 print(x[i], y[i], z[i], lsf.valueAt(x[i], y[i])) 

94 self.assertAlmostEqual(z[i], lsf.valueAt(x[i], y[i])) 

95 

96 

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

98 pass 

99 

100 

101def setup_module(module): 

102 lsst.utils.tests.init() 

103 

104 

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

106 lsst.utils.tests.init() 

107 unittest.main()