Coverage for tests/test_lsf1d.py: 20%
71 statements
« prev ^ index » next coverage.py v7.2.5, created at 2023-05-12 09:40 +0000
« prev ^ index » next coverage.py v7.2.5, created at 2023-05-12 09:40 +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
24import lsst.utils.tests
25import lsst.pex.exceptions
26import lsst.meas.astrom.sip as sip
29class Lsf1dTestCase(unittest.TestCase):
31 def testBadArgs1(self):
32 """Check that code fails when order is too low"""
34 x = [630, 1000, 1205, 1427]
35 y = [.622, 1.109, 1.198, 1.429]
36 s = [1, 1, 1, 1]
38 order = 0
40 with self.assertRaises(lsst.pex.exceptions.Exception):
41 sip.LeastSqFitter1dPoly(x, y, s, order)
43 def testBadArgs2(self):
44 """Check that code fails when not len(x) != len(y)"""
46 x = [630, 1000, 1205, 1427]
47 y = [.622, 1.109, 1.198]
48 s = [1, 1, 1, 1]
50 order = 0
52 with self.assertRaises(lsst.pex.exceptions.Exception):
53 sip.LeastSqFitter1dPoly(x, y, s, order)
55 def testBadArgs3(self):
56 """Check that code fails when not len(x) != len(s)"""
58 x = [630, 1000, 1205, 1427]
59 y = [.622, 1.109, 1.198, 1.429]
60 s = [1, 1, 1, 1, 1]
62 order = 0
64 with self.assertRaises(lsst.pex.exceptions.Exception):
65 sip.LeastSqFitter1dPoly(x, y, s, order)
67 def testBadArgs4(self):
68 """Check that code fails when not order > number data points"""
70 x = [630, 1000, 1205, 1427]
71 y = [.622, 1.109, 1.198, 1.429]
72 s = [1, 1, 1, 1]
74 order = 5
76 with self.assertRaises(lsst.pex.exceptions.Exception):
77 sip.LeastSqFitter1dPoly(x, y, s, order)
79 def testConst1(self):
80 """Check that code fits a dc offset correctly (1)"""
82 x = [630, 1000, 1205, 1427]
83 y = [.622, 1.109, 1.198, 1.429]
84 s = [1, 1, 1, 1]
86 order = 1
88 lsf = sip.LeastSqFitter1dPoly(x, y, s, order)
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])
94 def testCompareToCpp1(self):
95 """Confirm that I get the same behaviour in Python as I
96 do in the C++ test fitLinear3
97 """
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.
104 x = [689.301136505, 1112.8573687, 1386.67168477]
105 y = [0.66911456573, 1.1147439759, 1.39597284177]
106 s = [1, 1, 1]
108 order = 2
109 print()
110 lsf = sip.LeastSqFitter1dPoly(x, y, s, order)
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)
116 def testCompareToCpp2(self):
117 """Confirm that I get the same behaviour in Python as I do in the C++ test fitLinear3
118 """
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.
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]
129 order = 3
130 print()
131 lsf = sip.LeastSqFitter1dPoly(x, y, s, order)
133 for i in range(len(x)):
134 f = lsf.valueAt(x[i])
135 print("%.1f %.3f %.3f" % (x[i], y[i], f))
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)
142class MemoryTester(lsst.utils.tests.MemoryTestCase):
143 pass
146def setup_module(module):
147 lsst.utils.tests.init()
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()