Hide keyboard shortcuts

Hot-keys on this page

r m x p   toggle line displays

j k   next/prev highlighted chunk

0   (zero) top of page

1   (one) first highlighted chunk

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 

24import yaml 

25import unittest 

26 

27from lsst.sphgeom import (Angle, Circle, Mq3cPixelization, RangeSet, 

28 UnitVector3d) 

29 

30 

31class Mq3cPixelizationTestCase(unittest.TestCase): 

32 

33 def test_construction(self): 

34 with self.assertRaises(ValueError): 

35 Mq3cPixelization(-1) 

36 with self.assertRaises(ValueError): 

37 Mq3cPixelization(Mq3cPixelization.MAX_LEVEL + 1) 

38 m1 = Mq3cPixelization(0) 

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

40 m2 = Mq3cPixelization(1) 

41 m3 = Mq3cPixelization(m2) 

42 self.assertNotEqual(m1, m2) 

43 self.assertEqual(m2, m3) 

44 

45 def test_indexing(self): 

46 pixelization = Mq3cPixelization(1) 

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

48 

49 def test_level(self): 

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

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

52 for root in range(8, 10): 

53 index = root * 4**level 

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

55 for root in range(10, 16): 

56 index = root * 4**level 

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

58 

59 def test_envelope_and_interior(self): 

60 pixelization = Mq3cPixelization(1) 

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

62 rs = pixelization.envelope(c) 

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

64 rs = pixelization.envelope(c, 1) 

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

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

67 rs = pixelization.interior(c) 

68 self.assertTrue(rs.empty()) 

69 

70 def test_index_to_string(self): 

71 strings = ['+X', '+Y', '+Z', '-X', '-Y', '-Z'] 

72 for i in range(6): 

73 s0 = strings[i] 

74 components = [0.0]*3 

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

76 v = UnitVector3d(*components) 

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

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

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

80 for j in range(4): 

81 s1 = s0 + str(j) 

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

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

84 

85 def test_string(self): 

86 p = Mq3cPixelization(3) 

87 self.assertEqual(str(p), 'Mq3cPixelization(3)') 

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

89 self.assertEqual( 

90 p, eval(repr(p), dict(Mq3cPixelization=Mq3cPixelization))) 

91 

92 def test_pickle(self): 

93 a = Mq3cPixelization(20) 

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

95 self.assertEqual(a, b) 

96 

97 def test_yaml(self): 

98 a = Mq3cPixelization(20) 

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

100 self.assertEqual(a, b) 

101 

102 

103if __name__ == '__main__': 103 ↛ 104line 103 didn't jump to line 104, because the condition on line 103 was never true

104 unittest.main()