Coverage for tests/test_Mq3cPixelization.py: 20%

69 statements  

« 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/>. 

27 

28import pickle 

29 

30try: 

31 import yaml 

32except ImportError: 

33 yaml = None 

34 

35import unittest 

36 

37from lsst.sphgeom import Angle, Circle, Mq3cPixelization, RangeSet, UnitVector3d 

38 

39 

40class Mq3cPixelizationTestCase(unittest.TestCase): 

41 """Test MQ3C pixelization.""" 

42 

43 def test_construction(self): 

44 with self.assertRaises(ValueError): 

45 Mq3cPixelization(-1) 

46 with self.assertRaises(ValueError): 

47 Mq3cPixelization(Mq3cPixelization.MAX_LEVEL + 1) 

48 m1 = Mq3cPixelization(0) 

49 self.assertEqual(m1.getLevel(), 0) 

50 m2 = Mq3cPixelization(1) 

51 m3 = Mq3cPixelization(m2) 

52 self.assertNotEqual(m1, m2) 

53 self.assertEqual(m2, m3) 

54 

55 def test_indexing(self): 

56 pixelization = Mq3cPixelization(1) 

57 self.assertEqual(pixelization.index(UnitVector3d(0.5, -0.5, 1.0)), 53) 

58 

59 def test_level(self): 

60 self.assertEqual(Mq3cPixelization.level(0), -1) 

61 for level in range(Mq3cPixelization.MAX_LEVEL + 1): 

62 for root in range(8, 10): 

63 index = root * 4**level 

64 self.assertEqual(Mq3cPixelization.level(index), -1) 

65 for root in range(10, 16): 

66 index = root * 4**level 

67 self.assertEqual(Mq3cPixelization.level(index), level) 

68 

69 def test_envelope_and_interior(self): 

70 pixelization = Mq3cPixelization(1) 

71 c = Circle(UnitVector3d(1.0, -0.5, -0.5), Angle.fromDegrees(0.1)) 

72 rs = pixelization.envelope(c) 

73 self.assertTrue(rs == RangeSet(44)) 

74 rs = pixelization.envelope(c, 1) 

75 self.assertTrue(rs == RangeSet(44)) 

76 self.assertTrue(rs.isWithin(pixelization.universe())) 

77 rs = pixelization.interior(c) 

78 self.assertTrue(rs.empty()) 

79 

80 def test_index_to_string(self): 

81 strings = ["+X", "+Y", "+Z", "-X", "-Y", "-Z"] 

82 for i in range(6): 

83 s0 = strings[i] 

84 components = [0.0] * 3 

85 components[i % 3] = 1.0 if i < 3 else -1.0 

86 v = UnitVector3d(*components) 

87 f = Mq3cPixelization(0).index(v) 

88 self.assertEqual(Mq3cPixelization.asString(f), s0) 

89 self.assertEqual(Mq3cPixelization(0).toString(f), s0) 

90 for j in range(4): 

91 s1 = s0 + str(j) 

92 self.assertEqual(Mq3cPixelization.asString(f * 4 + j), s1) 

93 self.assertEqual(Mq3cPixelization(1).toString(f * 4 + j), s1) 

94 

95 def test_string(self): 

96 p = Mq3cPixelization(3) 

97 self.assertEqual(str(p), "Mq3cPixelization(3)") 

98 self.assertEqual(str(p), repr(p)) 

99 self.assertEqual(p, eval(repr(p), {"Mq3cPixelization": Mq3cPixelization})) 

100 

101 def test_pickle(self): 

102 a = Mq3cPixelization(20) 

103 b = pickle.loads(pickle.dumps(a)) 

104 self.assertEqual(a, b) 

105 

106 @unittest.skipIf(not yaml, "YAML module can not be imported") 

107 def test_yaml(self): 

108 a = Mq3cPixelization(20) 

109 b = yaml.safe_load(yaml.dump(a)) 

110 self.assertEqual(a, b) 

111 

112 

113if __name__ == "__main__": 

114 unittest.main()