Coverage for tests/test_patchInfo.py: 22%

68 statements  

« prev     ^ index     » next       coverage.py v6.5.0, created at 2023-04-09 02:14 -0700

1import unittest 

2 

3import lsst.utils.tests 

4import lsst.geom 

5import lsst.sphgeom 

6 

7from lsst.skymap.discreteSkyMap import DiscreteSkyMap 

8from lsst.skymap import Index2D 

9 

10 

11class PatchInfoTestCase(lsst.utils.tests.TestCase): 

12 def setUp(self): 

13 # These are from the PS1 Medium-Deep fields 

14 coords = [(10.6750, 41.2667), # M31 

15 (36.2074, -04.5833), # XMM-LSS 

16 ] 

17 config = DiscreteSkyMap.ConfigClass() 

18 config.raList = [c[0] for c in coords] 

19 config.decList = [c[1] for c in coords] 

20 config.radiusList = [2] * len(coords) 

21 config.validate() 

22 

23 self.skymap = DiscreteSkyMap(config=config) 

24 

25 def testProperties(self): 

26 """Test accessing via properties.""" 

27 tractInfo = self.skymap[0] 

28 patchInfo = tractInfo[0] 

29 

30 self.assertEqual(patchInfo.index, patchInfo.getIndex()) 

31 self.assertEqual(patchInfo.inner_bbox, patchInfo.getInnerBBox()) 

32 self.assertEqual(patchInfo.outer_bbox, patchInfo.getOuterBBox()) 

33 self.assertEqual(patchInfo.num_cells, patchInfo.getNumCells()) 

34 self.assertEqual(patchInfo.cell_border, patchInfo.getCellBorder()) 

35 self.assertEqual(patchInfo.cell_inner_dimensions, patchInfo.getCellInnerDimensions()) 

36 self.assertEqual(patchInfo.wcs, patchInfo.getWcs()) 

37 self.assertEqual(patchInfo.wcs, tractInfo.wcs) 

38 self.assertEqual(patchInfo.sequential_index, patchInfo.getSequentialIndex()) 

39 self.assertEqual(patchInfo.inner_sky_polygon, 

40 patchInfo.getInnerSkyPolygon(tractWcs=tractInfo.wcs)) 

41 self.assertEqual(patchInfo.outer_sky_polygon, 

42 patchInfo.getOuterSkyPolygon(tractWcs=tractInfo.wcs)) 

43 

44 def testIndexes(self): 

45 """Test accessing by index via tuple and Index2D""" 

46 tractInfo = self.skymap[0] 

47 

48 index = Index2D(x=2, y=5) 

49 sequential_index = tractInfo.getSequentialPatchIndexFromPair(index) 

50 patchInfo = tractInfo[index] 

51 

52 self.assertEqual(tractInfo.getSequentialPatchIndexFromPair((2, 5)), sequential_index) 

53 self.assertEqual(tractInfo.getPatchInfo(index), patchInfo) 

54 self.assertEqual(tractInfo.getPatchInfo((2, 5)), patchInfo) 

55 self.assertEqual(tractInfo[index], patchInfo) 

56 self.assertEqual(tractInfo[sequential_index], patchInfo) 

57 self.assertEqual(tractInfo[(2, 5)], patchInfo) 

58 

59 for patchInfo in tractInfo: 

60 self.assertEqual(tractInfo[patchInfo.index], patchInfo) 

61 

62 def testSequentialIndex(self): 

63 """Test patch sequential indices.""" 

64 tractInfo = self.skymap[0] 

65 

66 for patchInfo in tractInfo: 

67 self.assertEqual(patchInfo.sequential_index, 

68 tractInfo.getSequentialPatchIndex(patchInfo)) 

69 

70 def testSkyPolygons(self): 

71 """Test sky polygons.""" 

72 tractInfo = self.skymap[0] 

73 patchInfo = tractInfo[0] 

74 

75 wcs = tractInfo.wcs 

76 

77 inner_bbox = patchInfo.inner_bbox 

78 points = wcs.pixelToSky(lsst.geom.Box2D(inner_bbox).getCorners()) 

79 poly = lsst.sphgeom.ConvexPolygon([p.getVector() for p in points]) 

80 

81 self.assertEqual(patchInfo.inner_sky_polygon, poly) 

82 

83 def testNoCells(self): 

84 """Test retrieving cells for a legacy tract builder.""" 

85 tractInfo = self.skymap[0] 

86 patchInfo = tractInfo[0] 

87 

88 self.assertRaises(IndexError, patchInfo.__getitem__, 0) 

89 self.assertRaises(IndexError, patchInfo.__getitem__, 10) 

90 

91 self.assertRaises(IndexError, patchInfo.getCellIndexPair, 0) 

92 self.assertRaises(IndexError, patchInfo.getCellIndexPair, 10) 

93 

94 

95class MemoryTester(lsst.utils.tests.MemoryTestCase): 

96 pass 

97 

98 

99def setup_module(module): 

100 lsst.utils.tests.init() 

101 

102 

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

104 lsst.utils.tests.init() 

105 unittest.main()