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

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

35

36

37

38

39

40

41

42

43

44

45

46

47

48

49

50

51

52

53

54

55

56

57

58

59

60

61

62

63

64

65

66

67

68

69

70

71

72

73

74

75

76

77

78

79

80

81

82

83

84

85

86

87

88

89

90

91

92

93

94

95

96

97

98

99

100

101

102

103

104

105

106

107

108

109

110

111

112

113

114

115

116

117

118

119

120

121

122

123

124

125

126

127

128

129

130

131

132

133

134

135

136

137

138

139

140

141

142

143

144

145

146

147

148

149

150

151

152

153

154

155

156

157

158

159

160

161

162

163

164

165

166

167

168

169

170

171

172

173

174

175

176

177

178

179

180

181

182

183

184

185

186

187

188

189

190

191

192

193

194

195

196

197

198

import unittest 

import math 

 

import lsst.utils.tests 

import lsst.geom 

 

from lsst.skymap.ringsSkyMap import RingsSkyMap 

from helper import skyMapTestCase 

 

 

class RingsTestCase(skyMapTestCase.SkyMapTestCase): 

 

def setUp(self): 

config = RingsSkyMap.ConfigClass() 

config.numRings = 3 

self.setAttributes( 

SkyMapClass=RingsSkyMap, 

name="rings", 

config=config, 

numTracts=26, 

neighborAngularSeparation=None, # no uniform tract separation 

numNeighbors=None, # ignored because neighborAngularSeparation=None 

) 

 

def testPoles(self): 

"""Test that findAllTracts behaves at the poles 

 

Testing fix to DM-10686. 

""" 

skymap = self.getSkyMap() 

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

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

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

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

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

 

def testSha1Compare(self): 

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

defaultSkyMap = self.getSkyMap() 

for numRings in (4, 5): 

config = self.getConfig() 

config.numRings = numRings 

skyMap = self.getSkyMap(config=config) 

self.assertNotEqual(skyMap, defaultSkyMap) 

for raStart in (60.0, 75.0): 

config = self.getConfig() 

config.raStart = raStart 

skyMap = self.getSkyMap(config=config) 

self.assertNotEqual(skyMap, defaultSkyMap) 

 

def testCorners(self): 

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

skymap = self.getSkyMap() 

for tract in skymap: 

vertices = tract.getVertexList() 

for coord in vertices: 

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

 

 

class NonzeroRaStartRingsTestCase(RingsTestCase): 

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

def getConfig(self): 

config = super().getConfig() 

config.raStart = 234 

return config 

 

 

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

def getConfig(self): 

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

config = RingsSkyMap.ConfigClass() 

config.numRings = 120 

config.projection = "TAN" 

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

config.pixelScale = 0.168 

return config 

 

def setUp(self): 

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

 

def tearDown(self): 

del self.skymap 

 

def testDm7770(self): 

"""Test that DM-7770 has been fixed 

 

These operations previously caused: 

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

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

One or more of the world coordinates were invalid' 

 

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

""" 

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

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

for coord in coordList: 

self.skymap.findAllTracts(coord) 

self.skymap.findTractPatchList(coordList) 

 

def testDm14809(self): 

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

skyMapTestCase.checkDm14809(self, self.skymap) 

 

# Check that the first tract in the last ring exists 

coord = self.getFirstTractLastRingCoord() 

tract = self.skymap.findTract(coord) 

self.assertTrue(tract.contains(coord)) 

 

def testWraparound(self): 

"""Check wrapping at RA=0 

 

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

""" 

tractId = 9712 

deviation = 10 / 3600.0 # 10 arcsec 

tract = self.skymap[tractId] 

center = tract.getCtrCoord() 

centerRa = center.getRa().asDegrees() 

centerDec = center.getDec().asDegrees() 

for devRa in [-deviation, deviation]: 

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

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

self.assertEqual(tractId, foundTractId) 

 

def getFirstTractLastRingCoord(self): 

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

 

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

""" 

ringNum = self.skymap.config.numRings - 1 

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

firstRingStart = ringSize*0.5 - 0.5*math.pi 

dec = ringNum*ringSize + firstRingStart 

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

dec*lsst.geom.radians) 

 

 

class Version0HscRingsTestCase(HscRingsTestCase): 

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

def setUp(self): 

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

 

def testDm14809(self): 

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

 

The observed behaviour was: 

 

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

 

and 

 

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

 

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

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

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

numbering would remain unchanged. 

""" 

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

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

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

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

self.assertEqual(got, expect) 

 

# Check that the tract central coordinates are unique 

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

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

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

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

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

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

 

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

degrees = lsst.geom.degrees 

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

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

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

# The Cosmos field 

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

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

 

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

coord = self.getFirstTractLastRingCoord() 

tract = self.skymap.findTract(coord) 

self.assertFalse(tract.contains(coord)) 

 

 

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

pass 

 

 

def setup_module(module): 

lsst.utils.tests.init() 

 

 

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

lsst.utils.tests.init() 

unittest.main()