Coverage for tests/test_ShapeUtilities.py: 41%
35 statements
« prev ^ index » next coverage.py v6.5.0, created at 2022-10-12 09:16 +0000
« prev ^ index » next coverage.py v6.5.0, created at 2022-10-12 09:16 +0000
1# This file is part of meas_base.
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/>.
22import unittest
24import numpy as np
26import lsst.geom
27import lsst.afw.geom
28import lsst.meas.base
29import lsst.utils.tests
32class ShapeTransformMatrixTestCase(lsst.utils.tests.TestCase):
34 def testIdentity(self):
35 # A no-op coordinate transform translates to a no-op shape transform
36 a = lsst.geom.AffineTransform()
37 np.testing.assert_array_equal(a.getMatrix(), np.identity(3))
38 m = lsst.meas.base.makeShapeTransformMatrix(a.getLinear())
39 np.testing.assert_array_equal(m, np.identity(3))
41 def testVsTransform(self):
42 # Transforming an ellipse by multiplying by the matrix should be
43 # equivalent to calling its transform() method.
44 lt = lsst.geom.LinearTransform.makeRotation(lsst.geom.Angle(np.random.random()))
45 e = lsst.afw.geom.Quadrupole(np.random.random(), np.random.random(),
46 np.random.random())
47 np.testing.assert_array_almost_equal(np.dot(lsst.meas.base.makeShapeTransformMatrix(lt),
48 e.getParameterVector()),
49 e.transform(lt).getParameterVector())
51 def testVales(self):
52 # Test that the analytically-derived correct values are computed
53 lt = lsst.geom.LinearTransform(np.random.random((2, 2)))
54 m = lsst.meas.base.makeShapeTransformMatrix(lt)
56 self.assertEqual(m[0, 0], lt[0, 0]*lt[0, 0])
57 self.assertEqual(m[0, 1], lt[0, 1]*lt[0, 1])
58 self.assertEqual(m[0, 2], 2*lt[0, 0]*lt[0, 1])
60 self.assertEqual(m[1, 0], lt[1, 0]*lt[1, 0])
61 self.assertEqual(m[1, 1], lt[1, 1]*lt[1, 1])
62 self.assertEqual(m[1, 2], 2*lt[1, 0]*lt[1, 1])
64 self.assertEqual(m[2, 0], lt[0, 0]*lt[1, 0])
65 self.assertEqual(m[2, 1], lt[0, 1]*lt[1, 1])
66 self.assertAlmostEqual(m[2, 2], lt[0, 0]*lt[1, 1] + lt[0, 1]*lt[1, 0], places=14)
69class TestMemory(lsst.utils.tests.MemoryTestCase):
70 pass
73def setup_module(module):
74 lsst.utils.tests.init()
77if __name__ == "__main__": 77 ↛ 78line 77 didn't jump to line 78, because the condition on line 77 was never true
78 lsst.utils.tests.init()
79 unittest.main()