Coverage for tests/test_Q3cPixelization.py: 24%
60 statements
« prev ^ index » next coverage.py v7.5.0, created at 2024-05-02 03:12 -0700
« prev ^ index » next coverage.py v7.5.0, created at 2024-05-02 03:12 -0700
1# This file is part of sphgeom.
2#
3# Developed for the LSST Data Management System.
4# This product includes software developed by the LSST Project
5# (http://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 software is dual licensed under the GNU General Public License and also
10# under a 3-clause BSD license. Recipients may choose which of these licenses
11# to use; please see the files gpl-3.0.txt and/or bsd_license.txt,
12# respectively. If you choose the GPL option then the following text applies
13# (but note that there is still no warranty even if you opt for BSD instead):
14#
15# This program is free software: you can redistribute it and/or modify
16# it under the terms of the GNU General Public License as published by
17# the Free Software Foundation, either version 3 of the License, or
18# (at your option) any later version.
19#
20# This program is distributed in the hope that it will be useful,
21# but WITHOUT ANY WARRANTY; without even the implied warranty of
22# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23# GNU General Public License for more details.
24#
25# You should have received a copy of the GNU General Public License
26# along with this program. If not, see <http://www.gnu.org/licenses/>.
28import pickle
30try:
31 import yaml
32except ImportError:
33 yaml = None
35import unittest
37from lsst.sphgeom import Angle, Circle, ConvexPolygon, Q3cPixelization, RangeSet, UnitVector3d
40class Q3cPixelizationTestCase(unittest.TestCase):
41 """Test Q3C pixelization."""
43 def test_construction(self):
44 with self.assertRaises(ValueError):
45 Q3cPixelization(-1)
46 with self.assertRaises(ValueError):
47 Q3cPixelization(Q3cPixelization.MAX_LEVEL + 1)
48 q1 = Q3cPixelization(0)
49 self.assertEqual(q1.getLevel(), 0)
50 q2 = Q3cPixelization(1)
51 q3 = Q3cPixelization(q2)
52 self.assertNotEqual(q1, q2)
53 self.assertEqual(q2, q3)
55 def test_indexing(self):
56 pixelization = Q3cPixelization(1)
57 self.assertEqual(pixelization.index(UnitVector3d(0.5, -0.5, 1.0)), 0)
59 def test_pixel(self):
60 h = Q3cPixelization(1)
61 self.assertIsInstance(h.pixel(10), ConvexPolygon)
63 def test_envelope_and_interior(self):
64 pixelization = Q3cPixelization(1)
65 c = Circle(UnitVector3d(1.0, -0.5, -0.5), Angle.fromDegrees(0.1))
66 rs = pixelization.envelope(c)
67 self.assertTrue(rs == RangeSet(4))
68 rs = pixelization.envelope(c, 1)
69 self.assertTrue(rs == RangeSet(4))
70 self.assertTrue(rs.isWithin(pixelization.universe()))
71 rs = pixelization.interior(c)
72 self.assertTrue(rs.empty())
74 def test_index_to_string(self):
75 strings = ["+X", "+Y", "+Z", "-X", "-Y", "-Z"]
76 for i in range(6):
77 s = strings[i]
78 components = [0.0] * 3
79 components[i % 3] = 1.0 if i < 3 else -1.0
80 v = UnitVector3d(*components)
81 f = Q3cPixelization(0).index(v)
82 self.assertEqual(Q3cPixelization(0).toString(f), s)
83 for j in range(4):
84 self.assertEqual(Q3cPixelization(1).toString(f * 4 + j), s + str(j))
86 def test_string(self):
87 p = Q3cPixelization(3)
88 self.assertEqual(str(p), "Q3cPixelization(3)")
89 self.assertEqual(str(p), repr(p))
90 self.assertEqual(p, eval(repr(p), {"Q3cPixelization": Q3cPixelization}))
92 def test_pickle(self):
93 a = Q3cPixelization(20)
94 b = pickle.loads(pickle.dumps(a))
95 self.assertEqual(a, b)
97 @unittest.skipIf(not yaml, "YAML module can not be imported")
98 def test_yaml(self):
99 a = Q3cPixelization(20)
100 b = yaml.safe_load(yaml.dump(a))
101 self.assertEqual(a, b)
104if __name__ == "__main__":
105 unittest.main()