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 unittest 

25 

26from lsst.sphgeom import Angle, Circle, HtmPixelization, RangeSet, UnitVector3d, ConvexPolygon 

27 

28 

29class HtmPixelizationTestCase(unittest.TestCase): 

30 

31 def test_construction(self): 

32 with self.assertRaises(ValueError): 

33 HtmPixelization(-1) 

34 with self.assertRaises(ValueError): 

35 HtmPixelization(HtmPixelization.MAX_LEVEL + 1) 

36 h1 = HtmPixelization(0) 

37 self.assertEqual(h1.getLevel(), 0) 

38 h2 = HtmPixelization(1) 

39 h3 = HtmPixelization(h2) 

40 self.assertNotEqual(h1, h2) 

41 self.assertEqual(h2, h3) 

42 

43 def test_indexing(self): 

44 h = HtmPixelization(1) 

45 self.assertEqual(h.index(UnitVector3d(1, 1, 1)), 63) 

46 

47 def test_pixel(self): 

48 h = HtmPixelization(1) 

49 self.assertIsInstance(h.pixel(10), ConvexPolygon) 

50 

51 def test_level(self): 

52 for index in (0, 16 * 4**HtmPixelization.MAX_LEVEL): 

53 self.assertEqual(HtmPixelization.level(index), -1) 

54 for level in range(HtmPixelization.MAX_LEVEL + 1): 

55 for root in range(8, 16): 

56 self.assertEqual(HtmPixelization.level(root * 4**level), level) 

57 

58 def test_envelope_and_interior(self): 

59 pixelization = HtmPixelization(3) 

60 c = Circle(UnitVector3d(1, 1, 1), Angle.fromDegrees(0.1)) 

61 rs = pixelization.envelope(c) 

62 self.assertTrue(rs == RangeSet(0x3ff)) 

63 rs = pixelization.envelope(c, 1) 

64 self.assertTrue(rs == RangeSet(0x3ff)) 

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

66 rs = pixelization.interior(c) 

67 self.assertTrue(rs.empty()) 

68 

69 def test_index_to_string(self): 

70 strings = ['S0', 'S1', 'S2', 'S3', 'N0', 'N1', 'N2', 'N3'] 

71 for i in range(8, 16): 

72 s0 = strings[i - 8] 

73 self.assertEqual(HtmPixelization.asString(i), s0) 

74 self.assertEqual(HtmPixelization(0).toString(i), s0) 

75 for j in range(4): 

76 s1 = s0 + str(j) 

77 self.assertEqual(HtmPixelization.asString(i*4 + j), s1) 

78 self.assertEqual(HtmPixelization(1).asString(i*4 + j), s1) 

79 

80 def test_string(self): 

81 p = HtmPixelization(3) 

82 self.assertEqual(str(p), 'HtmPixelization(3)') 

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

84 self.assertEqual( 

85 p, eval(repr(p), dict(HtmPixelization=HtmPixelization))) 

86 

87 def test_pickle(self): 

88 a = HtmPixelization(20) 

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

90 self.assertEqual(a, b) 

91 

92 

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

94 unittest.main()