Coverage for tests/test_Chunker.py: 25%

40 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 

29import unittest 

30 

31from lsst.sphgeom import Box, Chunker 

32 

33 

34class ChunkerTestCase(unittest.TestCase): 

35 """Test Chunker.""" 

36 

37 def testConstruction(self): 

38 chunker = Chunker(85, 12) 

39 self.assertEqual(chunker.numStripes, 85) 

40 self.assertEqual(chunker.numSubStripesPerStripe, 12) 

41 

42 def testComparisonOperators(self): 

43 c = Chunker(85, 12) 

44 self.assertEqual(c, c) 

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

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

47 

48 def testIntersecting(self): 

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

50 c = Chunker(85, 12) 

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

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

53 

54 def testString(self): 

55 chunker = Chunker(85, 12) 

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

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

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

59 

60 def testPickle(self): 

61 a = Chunker(85, 12) 

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

63 self.assertEqual(a, b) 

64 

65 def testChunkBoundingBox(self): 

66 chunker = Chunker(200, 5) 

67 chunk_id = 3645 

68 stripe = chunker.getStripe(chunk_id) 

69 chunk_in_stripe = chunker.getChunk(chunk_id, stripe) 

70 bbox = chunker.getChunkBoundingBox(stripe, chunk_in_stripe) 

71 sbbox = chunker.getSubChunkBoundingBox(0, 0) 

72 self.assertEqual(stripe, 9) 

73 self.assertEqual(chunk_in_stripe, 45) 

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

75 self.assertAlmostEqual(bbox, b) 

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

77 self.assertAlmostEqual(sbbox, sb) 

78 

79 

80if __name__ == "__main__": 

81 unittest.main()