Coverage for tests/test_Chunker.py: 25%

40 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 

24import unittest 

25 

26from lsst.sphgeom import Box, Chunker 

27 

28 

29class ChunkerTestCase(unittest.TestCase): 

30 """Test Chunker.""" 

31 

32 def testConstruction(self): 

33 chunker = Chunker(85, 12) 

34 self.assertEqual(chunker.numStripes, 85) 

35 self.assertEqual(chunker.numSubStripesPerStripe, 12) 

36 

37 def testComparisonOperators(self): 

38 c = Chunker(85, 12) 

39 self.assertEqual(c, c) 

40 self.assertEqual(c, Chunker(85, 12)) 

41 self.assertNotEqual(c, Chunker(85, 10)) 

42 

43 def testIntersecting(self): 

44 b = Box.fromDegrees(273.6, 30.7, 273.7180105379097, 30.722546655347717) 

45 c = Chunker(85, 12) 

46 self.assertEqual(c.getChunksIntersecting(b), [9630, 9631, 9797]) 

47 self.assertEqual(c.getSubChunksIntersecting(b), [(9630, [770]), (9631, [759]), (9797, [11])]) 

48 

49 def testString(self): 

50 chunker = Chunker(85, 12) 

51 self.assertEqual(str(chunker), "Chunker(85, 12)") 

52 self.assertEqual(repr(chunker), "Chunker(85, 12)") 

53 self.assertEqual(chunker, eval(repr(chunker), {"Chunker": Chunker})) 

54 

55 def testPickle(self): 

56 a = Chunker(85, 12) 

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

58 self.assertEqual(a, b) 

59 

60 def testChunkBoundingBox(self): 

61 chunker = Chunker(200, 5) 

62 chunk_id = 3645 

63 stripe = chunker.getStripe(chunk_id) 

64 chunk_in_stripe = chunker.getChunk(chunk_id, stripe) 

65 bbox = chunker.getChunkBoundingBox(stripe, chunk_in_stripe) 

66 sbbox = chunker.getSubChunkBoundingBox(0, 0) 

67 self.assertEqual(stripe, 9) 

68 self.assertEqual(chunk_in_stripe, 45) 

69 b = Box.fromRadians(5.048988193233824, -1.4294246573883558, 5.1611879309330035, -1.413716694110407) 

70 self.assertAlmostEqual(bbox, b) 

71 sb = Box.fromRadians(0.0, -1.5707963267948966, 6.283185307179586, -1.5676547341363067) 

72 self.assertAlmostEqual(sbbox, sb) 

73 

74 

75if __name__ == "__main__": 

76 unittest.main()