Coverage for tests/test_Q3cPixelization.py: 22%
60 statements
« prev ^ index » next coverage.py v7.2.7, created at 2023-07-12 10:50 -0700
« prev ^ index » next coverage.py v7.2.7, created at 2023-07-12 10:50 -0700
1#
2# LSST Data Management System
3# See COPYRIGHT file at the top of the source tree.
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 <https://www.lsstcorp.org/LegalNotices/>.
21#
23import pickle
25try:
26 import yaml
27except ImportError:
28 yaml = None
30import unittest
32from lsst.sphgeom import Angle, Circle, ConvexPolygon, Q3cPixelization, RangeSet, UnitVector3d
35class Q3cPixelizationTestCase(unittest.TestCase):
36 """Test Q3C pixelization."""
38 def test_construction(self):
39 with self.assertRaises(ValueError):
40 Q3cPixelization(-1)
41 with self.assertRaises(ValueError):
42 Q3cPixelization(Q3cPixelization.MAX_LEVEL + 1)
43 q1 = Q3cPixelization(0)
44 self.assertEqual(q1.getLevel(), 0)
45 q2 = Q3cPixelization(1)
46 q3 = Q3cPixelization(q2)
47 self.assertNotEqual(q1, q2)
48 self.assertEqual(q2, q3)
50 def test_indexing(self):
51 pixelization = Q3cPixelization(1)
52 self.assertEqual(pixelization.index(UnitVector3d(0.5, -0.5, 1.0)), 0)
54 def test_pixel(self):
55 h = Q3cPixelization(1)
56 self.assertIsInstance(h.pixel(10), ConvexPolygon)
58 def test_envelope_and_interior(self):
59 pixelization = Q3cPixelization(1)
60 c = Circle(UnitVector3d(1.0, -0.5, -0.5), Angle.fromDegrees(0.1))
61 rs = pixelization.envelope(c)
62 self.assertTrue(rs == RangeSet(4))
63 rs = pixelization.envelope(c, 1)
64 self.assertTrue(rs == RangeSet(4))
65 self.assertTrue(rs.isWithin(pixelization.universe()))
66 rs = pixelization.interior(c)
67 self.assertTrue(rs.empty())
69 def test_index_to_string(self):
70 strings = ["+X", "+Y", "+Z", "-X", "-Y", "-Z"]
71 for i in range(6):
72 s = strings[i]
73 components = [0.0] * 3
74 components[i % 3] = 1.0 if i < 3 else -1.0
75 v = UnitVector3d(*components)
76 f = Q3cPixelization(0).index(v)
77 self.assertEqual(Q3cPixelization(0).toString(f), s)
78 for j in range(4):
79 self.assertEqual(Q3cPixelization(1).toString(f * 4 + j), s + str(j))
81 def test_string(self):
82 p = Q3cPixelization(3)
83 self.assertEqual(str(p), "Q3cPixelization(3)")
84 self.assertEqual(str(p), repr(p))
85 self.assertEqual(p, eval(repr(p), {"Q3cPixelization": Q3cPixelization}))
87 def test_pickle(self):
88 a = Q3cPixelization(20)
89 b = pickle.loads(pickle.dumps(a))
90 self.assertEqual(a, b)
92 @unittest.skipIf(not yaml, "YAML module can not be imported")
93 def test_yaml(self):
94 a = Q3cPixelization(20)
95 b = yaml.safe_load(yaml.dump(a))
96 self.assertEqual(a, b)
99if __name__ == "__main__":
100 unittest.main()