Coverage for tests/test_Mq3cPixelization.py: 18%

69 statements  

« 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# 

22 

23import pickle 

24 

25try: 

26 import yaml 

27except ImportError: 

28 yaml = None 

29 

30import unittest 

31 

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

33 

34 

35class Mq3cPixelizationTestCase(unittest.TestCase): 

36 """Test MQ3C pixelization.""" 

37 

38 def test_construction(self): 

39 with self.assertRaises(ValueError): 

40 Mq3cPixelization(-1) 

41 with self.assertRaises(ValueError): 

42 Mq3cPixelization(Mq3cPixelization.MAX_LEVEL + 1) 

43 m1 = Mq3cPixelization(0) 

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

45 m2 = Mq3cPixelization(1) 

46 m3 = Mq3cPixelization(m2) 

47 self.assertNotEqual(m1, m2) 

48 self.assertEqual(m2, m3) 

49 

50 def test_indexing(self): 

51 pixelization = Mq3cPixelization(1) 

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

53 

54 def test_level(self): 

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

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

57 for root in range(8, 10): 

58 index = root * 4**level 

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

60 for root in range(10, 16): 

61 index = root * 4**level 

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

63 

64 def test_envelope_and_interior(self): 

65 pixelization = Mq3cPixelization(1) 

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

67 rs = pixelization.envelope(c) 

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

69 rs = pixelization.envelope(c, 1) 

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

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

72 rs = pixelization.interior(c) 

73 self.assertTrue(rs.empty()) 

74 

75 def test_index_to_string(self): 

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

77 for i in range(6): 

78 s0 = strings[i] 

79 components = [0.0] * 3 

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

81 v = UnitVector3d(*components) 

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

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

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

85 for j in range(4): 

86 s1 = s0 + str(j) 

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

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

89 

90 def test_string(self): 

91 p = Mq3cPixelization(3) 

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

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

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

95 

96 def test_pickle(self): 

97 a = Mq3cPixelization(20) 

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

99 self.assertEqual(a, b) 

100 

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

102 def test_yaml(self): 

103 a = Mq3cPixelization(20) 

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

105 self.assertEqual(a, b) 

106 

107 

108if __name__ == "__main__": 

109 unittest.main()