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

1import unittest 

2import math 

3 

4import lsst.utils.tests 

5import lsst.geom 

6 

7from lsst.skymap.ringsSkyMap import RingsSkyMap 

8from helper import skyMapTestCase 

9 

10 

11class RingsTestCase(skyMapTestCase.SkyMapTestCase): 

12 

13 def setUp(self): 

14 config = RingsSkyMap.ConfigClass() 

15 config.numRings = 3 

16 self.setAttributes( 

17 SkyMapClass=RingsSkyMap, 

18 name="rings", 

19 config=config, 

20 numTracts=26, 

21 neighborAngularSeparation=None, # no uniform tract separation 

22 numNeighbors=None, # ignored because neighborAngularSeparation=None 

23 ) 

24 

25 def testPoles(self): 

26 """Test that findAllTracts behaves at the poles 

27 

28 Testing fix to DM-10686. 

29 """ 

30 skymap = self.getSkyMap() 

31 for ra in (0, 123, 321, 359.9): 

32 tracts = skymap.findAllTracts(lsst.geom.SpherePoint(ra, 90, lsst.geom.degrees)) 

33 self.assertListEqual(tracts, [skymap[len(skymap) - 1]]) 

34 tracts = skymap.findAllTracts(lsst.geom.SpherePoint(ra, -90, lsst.geom.degrees)) 

35 self.assertListEqual(tracts, [skymap[0]]) 

36 

37 def testSha1Compare(self): 

38 """Test that RingsSkyMap's extra state is included in its hash.""" 

39 defaultSkyMap = self.getSkyMap() 

40 for numRings in (4, 5): 

41 config = self.getConfig() 

42 config.numRings = numRings 

43 skyMap = self.getSkyMap(config=config) 

44 self.assertNotEqual(skyMap, defaultSkyMap) 

45 for raStart in (60.0, 75.0): 

46 config = self.getConfig() 

47 config.raStart = raStart 

48 skyMap = self.getSkyMap(config=config) 

49 self.assertNotEqual(skyMap, defaultSkyMap) 

50 

51 def testCorners(self): 

52 """Test that corners of a tract can be found in the tract""" 

53 skymap = self.getSkyMap() 

54 for tract in skymap: 

55 vertices = tract.getVertexList() 

56 for coord in vertices: 

57 self.assertIn(tract.getId(), [tt.getId() for tt in skymap.findAllTracts(coord)]) 

58 

59 

60class NonzeroRaStartRingsTestCase(RingsTestCase): 

61 """Test that setting raStart != 0 works""" 

62 def getConfig(self): 

63 config = super().getConfig() 

64 config.raStart = 234 

65 return config 

66 

67 

68class HscRingsTestCase(lsst.utils.tests.TestCase): 

69 def getConfig(self): 

70 """Return a configuration matching that used for the HSC SSP""" 

71 config = RingsSkyMap.ConfigClass() 

72 config.numRings = 120 

73 config.projection = "TAN" 

74 config.tractOverlap = 1.0/60 # Overlap between tracts (degrees) 

75 config.pixelScale = 0.168 

76 return config 

77 

78 def setUp(self): 

79 self.skymap = RingsSkyMap(self.getConfig()) 

80 

81 def tearDown(self): 

82 del self.skymap 

83 

84 def testDm7770(self): 

85 """Test that DM-7770 has been fixed 

86 

87 These operations previously caused: 

88 lsst::pex::exceptions::RuntimeError: 'Error: wcslib 

89 returned a status code of 9 at sky 30.18, -3.8 deg: 

90 One or more of the world coordinates were invalid' 

91 

92 We are only testing function, and not the actual results. 

93 """ 

94 coordList = [lsst.geom.SpherePoint(ra, dec, lsst.geom.degrees) for 

95 ra, dec in [(30.18, -3.8), (31.3, -3.8), (31.3, -2.7), (30.18, -2.7)]] 

96 for coord in coordList: 

97 self.skymap.findAllTracts(coord) 

98 self.skymap.findTractPatchList(coordList) 

99 

100 def testDm14809(self): 

101 """Test that DM-14809 has been fixed""" 

102 skyMapTestCase.checkDm14809(self, self.skymap) 

103 

104 # Check that the first tract in the last ring exists 

105 coord = self.getFirstTractLastRingCoord() 

106 tract = self.skymap.findTract(coord) 

107 self.assertTrue(tract.contains(coord)) 

108 

109 def testWraparound(self): 

110 """Check wrapping at RA=0 

111 

112 How-to-reproduce of a bug identified by Sogo Mineo. 

113 """ 

114 tractId = 9712 

115 deviation = 10 / 3600.0 # 10 arcsec 

116 tract = self.skymap[tractId] 

117 center = tract.getCtrCoord() 

118 centerRa = center.getRa().asDegrees() 

119 centerDec = center.getDec().asDegrees() 

120 for devRa in [-deviation, deviation]: 

121 coord = lsst.geom.SpherePoint(centerRa + devRa, centerDec, lsst.geom.degrees) 

122 foundTractId = self.skymap.findTract(coord).getId() 

123 self.assertEqual(tractId, foundTractId) 

124 

125 def getFirstTractLastRingCoord(self): 

126 """Return the coordinates of the first tract in the last ring 

127 

128 This tract is missing in version=0, but this is fixed in version=1.in 

129 """ 

130 ringNum = self.skymap.config.numRings - 1 

131 ringSize = math.pi/(self.skymap.config.numRings + 1) 

132 firstRingStart = ringSize*0.5 - 0.5*math.pi 

133 dec = ringNum*ringSize + firstRingStart 

134 return lsst.geom.SpherePoint(self.skymap.config.raStart*lsst.geom.degrees, 

135 dec*lsst.geom.radians) 

136 

137 

138class Version0HscRingsTestCase(HscRingsTestCase): 

139 """Testing that the version=0 RingsSkyMap works in the expected way""" 

140 def setUp(self): 

141 self.skymap = RingsSkyMap(self.getConfig(), version=0) 

142 

143 def testDm14809(self): 

144 """Test that DM-14809 has been partially fixed 

145 

146 The observed behaviour was: 

147 

148 skyMap.findTract(skyMap[9712].getCtrCoord()).getId() != 9712 

149 

150 and 

151 

152 skyMap[1].getCtrCoord() == skyMap[11].getCtrCoord() 

153 

154 Specifically for version=0, we fixed the ``findTract`` behaviour but 

155 left the tract duplication (tract 11 duplicates tract 1) and the 

156 missing tract (the first tract in the last ring) so that the tract 

157 numbering would remain unchanged. 

158 """ 

159 # Check that the tract found for central coordinate of a tract is that tract 

160 expect = [tract.getId() for tract in self.skymap] 

161 expect[self.skymap._ringNums[0] + 1] = 1 # Due to the bug 

162 got = [self.skymap.findTract(tract.getCtrCoord()).getId() for tract in self.skymap] 

163 self.assertEqual(got, expect) 

164 

165 # Check that the tract central coordinates are unique 

166 # Round to integer arcminutes so differences are relatively immune to small numerical inaccuracies 

167 centers = set([(int(coord.getRa().asArcminutes()), int(coord.getDec().asArcminutes())) for 

168 coord in (tract.getCtrCoord() for tract in self.skymap)]) 

169 self.assertEqual(len(centers), len(self.skymap) - 1) # One tract is duplicated 

170 self.assertEqual(self.skymap[1].getCtrCoord(), 

171 self.skymap[self.skymap._ringNums[0] + 1].getCtrCoord()) # This is the duplicate 

172 

173 # Check that some particular tracts we know and love haven't moved 

174 degrees = lsst.geom.degrees 

175 # 9712 is at RA=0, and was identified as problematic in DM-14809 

176 self.assertEqual(self.skymap[9712].getCtrCoord(), 

177 lsst.geom.SpherePoint(0.0*degrees, 0.7438016528925696*degrees)) 

178 # The Cosmos field 

179 self.assertEqual(self.skymap[9813].getCtrCoord(), 

180 lsst.geom.SpherePoint(150.2479338842975*degrees, 2.2314049586776834*degrees)) 

181 

182 # Check that the first tract in the last ring does NOT exist (due to the bug) 

183 coord = self.getFirstTractLastRingCoord() 

184 tract = self.skymap.findTract(coord) 

185 self.assertFalse(tract.contains(coord)) 

186 

187 

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

189 pass 

190 

191 

192def setup_module(module): 

193 lsst.utils.tests.init() 

194 

195 

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

197 lsst.utils.tests.init() 

198 unittest.main()