Coverage for tests/test_discreteSkyMap.py: 96%

68 statements  

« prev     ^ index     » next       coverage.py v7.15.2, created at 2026-07-26 09:11 +0000

1import numpy as np 

2import unittest 

3 

4import lsst.utils.tests 

5 

6from lsst.skymap.discreteSkyMap import DiscreteSkyMap 

7from helper import skyMapTestCase 

8 

9 

10# These are the PS1 Medium-Deep fields 

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

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

13 (53.1, -28.1333), # CDFS 

14 (130.5917, +44.3167), # IfA-Lynx 

15 (150.0, +02.2), # COSMOS 

16 (161.9167, +58.0833), # Lockman 

17 (185.0, +47.1167), # NGC4258 

18 (213.7051, +53.0834), # DEEP2-Field1/EGS 

19 (242.7875, +54.95), # EliasN1 

20 (334.1875, +00.2833), # SA22 

21 (352.3125, -00.4333), # DEEP2-Field3 

22 (270.0, +66.56), # North Ecliptic Pole 

23 ] 

24config = DiscreteSkyMap.ConfigClass() 

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

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

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

28 

29 

30class DiscreteTestCase(skyMapTestCase.SkyMapTestCase): 

31 

32 def setUp(self): 

33 self.setAttributes( 

34 SkyMapClass=DiscreteSkyMap, 

35 name="discrete", 

36 config=config, 

37 numTracts=len(coords), 

38 neighborAngularSeparation=None, # don't test for fixed angular sep 

39 numNeighbors=None, # ignored because neighborAngularSeparation is None 

40 ) 

41 

42 def testCompare(self): 

43 """Test that DiscreteSkyMap's extra state is included in its hash.""" 

44 defaultSkyMap = self.getSkyMap() 

45 for index in (3, 5): 

46 config = self.getConfig() 

47 # delete one tract 

48 del config.raList[index] 

49 del config.decList[index] 

50 del config.radiusList[index] 

51 skyMap = self.getSkyMap(config=config) 

52 self.assertNotEqual(skyMap, defaultSkyMap) 

53 for radius in (1.8, 2.3): 

54 config = self.getConfig() 

55 config.radiusList[5] = radius 

56 skyMap = self.getSkyMap(config=config) 

57 self.assertNotEqual(skyMap, defaultSkyMap) 

58 for ra in (35.1, 72.6): 

59 config = self.getConfig() 

60 config.raList[5] = ra 

61 skyMap = self.getSkyMap(config=config) 

62 self.assertNotEqual(skyMap, defaultSkyMap) 

63 for dec in (-5.2, 1.8): 

64 config = self.getConfig() 

65 config.decList[5] = dec 

66 skyMap = self.getSkyMap(config=config) 

67 self.assertNotEqual(skyMap, defaultSkyMap) 

68 

69 def testFindTractIdPatchIdArray(self): 

70 np.random.seed(12345) 

71 

72 skymap = self.getSkyMap() 

73 

74 ras = np.random.uniform(low=0.0, high=360.0, size=1000) 

75 decs = np.random.uniform(low=-90.0, high=90.0, size=1000) 

76 

77 # Make sure we have points that are just off a tract. 

78 wcs = skymap[0].wcs 

79 ras2, decs2 = wcs.pixelToSkyArray([-0.5, 10.0], [10.0, -0.5], degrees=True) 

80 ras = np.concatenate((ras, ras2)) 

81 decs = np.concatenate((decs, decs2)) 

82 

83 coords = [lsst.geom.SpherePoint(ra*lsst.geom.degrees, dec*lsst.geom.degrees) 

84 for ra, dec in zip(ras, decs)] 

85 

86 tractIds = [skymap.findTract(coord).getId() for coord in coords] 

87 patchIds = np.zeros(len(tractIds), dtype=np.int32) 

88 for i, tractId in enumerate(tractIds): 

89 tract = skymap[tractId] 

90 try: 

91 patch = tract.findPatch(coords[i]) 

92 index = patch.sequential_index 

93 except LookupError: 

94 # Not in a tract at all. 

95 tractIds[i] = -1 

96 index = -1 

97 patchIds[i] = index 

98 

99 tractIds2, patchIds2 = skymap.findTractIdPatchIdArray(ras, decs, degrees=True) 

100 

101 np.testing.assert_array_equal(tractIds2, tractIds) 

102 np.testing.assert_array_equal(patchIds2, patchIds) 

103 

104 

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

106 pass 

107 

108 

109def setup_module(module): 

110 lsst.utils.tests.init() 

111 

112 

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

114 lsst.utils.tests.init() 

115 unittest.main()