Coverage for tests/test_util.py: 26%
45 statements
« prev ^ index » next coverage.py v7.1.0, created at 2023-02-05 19:03 -0800
« prev ^ index » next coverage.py v7.1.0, created at 2023-02-05 19:03 -0800
1# LSST Data Management System
2# Copyright 2017 LSST Corporation.
3#
4# This product includes software developed by the
5# LSST Project (http://www.lsst.org/).
6#
7# This program is free software: you can redistribute it and/or modify
8# it under the terms of the GNU General Public License as published by
9# the Free Software Foundation, either version 3 of the License, or
10# (at your option) any later version.
11#
12# This program is distributed in the hope that it will be useful,
13# but WITHOUT ANY WARRANTY; without even the implied warranty of
14# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15# GNU General Public License for more details.
16#
17# You should have received a copy of the LSST License Statement and
18# the GNU General Public License along with this program. If not,
19# see <http://www.lsstcorp.org/LegalNotices/>.
20#
23import unittest
25import lsst.utils
27from lsst.validate.drp import util
30class UtilCalculations(lsst.utils.tests.TestCase):
31 """Test utility functions."""
33 def testEllipticityHorizonalLine(self):
34 """Is util.ellipticity correct for a horizontal line."""
36 ixx, ixy, iyy = 1, 0, 0
37 exp_e, exp_e1, exp_e2 = 1+0j, 1, 0
39 obs_e, obs_e1, obs_e2 = util.ellipticity(ixx, ixy, iyy)
40 self.assertFloatsAlmostEqual(exp_e, obs_e)
41 self.assertFloatsAlmostEqual(exp_e1, obs_e1)
42 self.assertFloatsAlmostEqual(exp_e2, obs_e2)
44 def testEllipticityVerticalLine(self):
45 """Is util.ellipticity correct for a vertical line."""
47 ixx, ixy, iyy = 0, 0, 1
48 exp_e, exp_e1, exp_e2 = -1+0j, -1, 0
50 obs_e, obs_e1, obs_e2 = util.ellipticity(ixx, ixy, iyy)
51 self.assertFloatsAlmostEqual(exp_e, obs_e)
52 self.assertFloatsAlmostEqual(exp_e1, obs_e1)
53 self.assertFloatsAlmostEqual(exp_e2, obs_e2)
55 def testEllipticityDiagonalLine(self):
56 """Is util.ellipticity correct for a diagonal line."""
58 ixx, ixy, iyy = 1, 1, 1
59 exp_e, exp_e1, exp_e2 = 0+1j, 0, 1
61 obs_e, obs_e1, obs_e2 = util.ellipticity(ixx, ixy, iyy)
62 print(obs_e, obs_e1, obs_e2)
63 self.assertFloatsAlmostEqual(exp_e, obs_e)
64 self.assertFloatsAlmostEqual(exp_e1, obs_e1)
65 self.assertFloatsAlmostEqual(exp_e2, obs_e2)
67 def testEllipticityCircle(self):
68 """Is util.ellipticity correct for a circle."""
70 ixx, ixy, iyy = 1, 0, 1
71 exp_e, exp_e1, exp_e2 = 0+0j, 0, 0
73 obs_e, obs_e1, obs_e2 = util.ellipticity(ixx, ixy, iyy)
74 self.assertFloatsAlmostEqual(exp_e, obs_e)
75 self.assertFloatsAlmostEqual(exp_e1, obs_e1)
76 self.assertFloatsAlmostEqual(exp_e2, obs_e2)
78 def testEllipticityEllipse(self):
79 """Is util.ellipticity correct for an ellipse."""
81 ixx, ixy, iyy = 4, 0, 1
82 exp_e, exp_e1, exp_e2 = 0.6+0j, 0.6, 0
84 obs_e, obs_e1, obs_e2 = util.ellipticity(ixx, ixy, iyy)
85 self.assertFloatsAlmostEqual(exp_e, obs_e)
86 self.assertFloatsAlmostEqual(exp_e1, obs_e1)
87 self.assertFloatsAlmostEqual(exp_e2, obs_e2)
90def setup_module(module):
91 lsst.utils.tests.init()
94if __name__ == "__main__": 94 ↛ 95line 94 didn't jump to line 95, because the condition on line 94 was never true
95 lsst.utils.tests.init()
96 unittest.main()