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

# 

# LSST Data Management System 

# Copyright 2008, 2009, 2010 LSST Corporation. 

# 

# This product includes software developed by the 

# LSST Project (http://www.lsst.org/). 

# 

# This program is free software: you can redistribute it and/or modify 

# it under the terms of the GNU General Public License as published by 

# the Free Software Foundation, either version 3 of the License, or 

# (at your option) any later version. 

# 

# This program is distributed in the hope that it will be useful, 

# but WITHOUT ANY WARRANTY; without even the implied warranty of 

# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 

# GNU General Public License for more details. 

# 

# You should have received a copy of the LSST License Statement and 

# the GNU General Public License along with this program. If not, 

# see <http://www.lsstcorp.org/LegalNotices/>. 

# 

"""Test DodecaSkyMap class 

""" 

import math 

import unittest 

 

import numpy 

 

import lsst.sphgeom 

import lsst.geom as geom 

import lsst.utils.tests 

 

from lsst.skymap import DodecaSkyMap 

from helper import skyMapTestCase 

 

 

# dodecahedron properties 

_Phi = (1.0 + math.sqrt(5.0)) / 2.0 

_DihedralAngle = geom.Angle(2.0 * math.atan(_Phi), geom.radians) 

 

 

class DodecaSkyMapTestCase(skyMapTestCase.SkyMapTestCase): 

 

def setUp(self): 

self.setAttributes( 

SkyMapClass=DodecaSkyMap, 

name="dodeca", 

numNeighbors=6, 

numTracts=12, 

neighborAngularSeparation=180*geom.degrees - _DihedralAngle, 

) 

 

def testSha1Compare(self): 

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

defaultSkyMap = self.getSkyMap() 

config = self.getConfig() 

config.withTractsOnPoles = True 

skyMap = self.getSkyMap(config=config) 

self.assertNotEqual(skyMap, defaultSkyMap) 

 

def testFindTract(self): 

"""Test findTract and tractInfo.findPatch 

""" 

skyMap = DodecaSkyMap() 

for tractInfo0 in skyMap: 

tractId0 = tractInfo0.getId() 

ctrCoord0 = tractInfo0.getCtrCoord() 

vector0 = numpy.array(ctrCoord0.getVector()) 

 

# make a list of all 5 nearest neighbors 

nbrTractList = [] 

for otherTractInfo in skyMap: 

otherCtrCoord = otherTractInfo.getCtrCoord() 

dist = ctrCoord0.separation(otherCtrCoord) 

if abs(dist - self.neighborAngularSeparation) < geom.Angle(0.1, geom.degrees): 

nbrTractList.append(otherTractInfo) 

self.assertEqual(len(nbrTractList), 5) 

 

for tractInfo1 in nbrTractList: 

tractId1 = tractInfo1.getId() 

ctrCoord1 = tractInfo1.getCtrCoord() 

vector1 = numpy.array(ctrCoord1.getVector()) 

for tractInfo2 in nbrTractList[tractInfo1.getId():]: 

dist = ctrCoord1.separation(tractInfo2.getCtrCoord()) 

if abs(dist - self.neighborAngularSeparation) > geom.Angle(0.1, geom.degrees): 

continue 

tractId2 = tractInfo2.getId() 

ctrCoord2 = tractInfo2.getCtrCoord() 

vector2 = numpy.array(ctrCoord2.getVector()) 

 

# sky tracts 0, 1 and 2 form a triangle of nearest neighbors 

# explore the boundary between tract 0 and tract 1 

# and also the boundary between tract 0 and tract 2 

for deltaFrac in (-0.001, 0.001): 

isNearest0 = deltaFrac > 0.0 

 

for exploreBoundary1 in (True, False): 

# if exploreBoundary1, explore boundary between tract 0 and tract 1, 

# else explore the boundary between tract 0 and tract 2 

 

if isNearest0: 

expectedTractId = tractId0 

elif exploreBoundary1: 

expectedTractId = tractId1 

else: 

expectedTractId = tractId2 

 

for farFrac in (0.0, 0.05, 0.3, (1.0/3.0) - 0.01): 

# farFrac is the fraction of the tract center vector point whose boundary 

# is not being explored; it must be less than 1/3; 

# remFrac is the remaining fraction, which is divided between tract 0 

# and the tract whose boundary is being explored 

remFrac = 1.0 - farFrac 

frac0 = (remFrac / 2.0) + deltaFrac 

boundaryFrac = (remFrac / 2.0) - deltaFrac 

 

if exploreBoundary1: 

frac2 = farFrac 

frac1 = boundaryFrac 

else: 

frac1 = farFrac 

frac2 = boundaryFrac 

 

testVector = (vector0 * frac0) + (vector1 * frac1) + (vector2 * frac2) 

vecLen = math.sqrt(numpy.sum(testVector**2)) 

testVector /= vecLen 

testCoord = geom.SpherePoint(lsst.sphgeom.Vector3d(*testVector)) 

nearestTractInfo = skyMap.findTract(testCoord) 

nearestTractId = nearestTractInfo.getId() 

 

if expectedTractId != nearestTractId: 

nearestCtrCoord = nearestTractInfo.getCtrCoord() 

nearestVector = nearestCtrCoord.getVector() 

 

print("tractId0=%s; tractId1=%s; tractId2=%s; nearestTractId=%s" % 

(tractId0, tractId1, tractId2, nearestTractId)) 

print("vector0=%s; vector1=%s; vector2=%s; nearestVector=%s" % 

(vector0, vector1, vector2, nearestVector)) 

print("frac0=%s; frac1=%s; frac2=%s" % (frac0, frac1, frac2)) 

print("testVector=", testVector) 

 

print("dist0=%s; dist1=%s; dist2=%s; nearDist=%s" % ( 

testCoord.separation(ctrCoord0).asDegrees(), 

testCoord.separation(ctrCoord1).asDegrees(), 

testCoord.separation(ctrCoord2).asDegrees(), 

testCoord.separation(nearestCtrCoord).asDegrees(), 

)) 

self.fail("Expected nearest tractId=%s; got tractId=%s" % 

(expectedTractId, nearestTractId)) 

 

patchInfo = nearestTractInfo.findPatch(testCoord) 

pixelInd = geom.Point2I( 

nearestTractInfo.getWcs().skyToPixel(testCoord)) 

self.assertTrue(patchInfo.getInnerBBox().contains(pixelInd)) 

 

 

def getCornerCoords(wcs, bbox): 

"""Return the coords of the four corners of a bounding box 

""" 

bbox = geom.Box2D(bbox) # mak 

cornerPosList = ( 

bbox.getMin(), 

geom.Point2D(bbox.getMaxX(), bbox.getMinY()), 

bbox.getMax(), 

geom.Point2D(bbox.getMinX(), bbox.getMaxY()), 

) 

return wcs.pixelToSky(cornerPosList) 

 

 

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

pass 

 

 

def setup_module(module): 

lsst.utils.tests.init() 

 

 

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

lsst.utils.tests.init() 

unittest.main()