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

# 

# 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 EquatSkyMap class 

""" 

import unittest 

 

import numpy 

 

import lsst.afw.geom as afwGeom 

import lsst.utils.tests 

 

from lsst.skymap import EquatSkyMap 

from helper import skyMapTestCase 

 

 

class EquatSkyMapTestCase(skyMapTestCase.SkyMapTestCase): 

def setUp(self): 

self.setAttributes( 

SkyMapClass=EquatSkyMap, 

name="equat", 

numTracts=4, 

neighborAngularSeparation=90*afwGeom.degrees, 

numNeighbors=2, 

) 

 

def getNeighborTracts(self, skyMap, tractId): 

"""Return previous and next tractInfo 

""" 

if not 0 <= tractId < len(skyMap): 

raise RuntimeError("Invalid tractId=%s" % (tractId,)) 

if tractId > 0: 

prevTract = skyMap[tractId - 1] 

else: 

prevTract = skyMap[-1] 

if tractId + 1 < len(skyMap): 

nextTract = skyMap[tractId + 1] 

else: 

nextTract = skyMap[0] 

return (prevTract, nextTract) 

 

def testDefaults(self): 

"""Test important default values 

""" 

config = EquatSkyMap.ConfigClass() 

skyMap = EquatSkyMap(config) 

self.assertEqual(skyMap.config.projection, "CEA") 

 

def testSymmetry(self): 

"""Verify that the projection is symmetrical about the equator 

""" 

for minDec in (-5.0, -1.0, 0.5): 

maxDec = minDec + 2.0 

config = EquatSkyMap.ConfigClass() 

config.decRange = minDec, maxDec 

skyMap = EquatSkyMap(config) 

for tractInfo in skyMap[0:1]: 

numPatches = tractInfo.getNumPatches() 

midXIndex = numPatches[0]//2 

minPixelPosList = [] 

maxPixelPosList = [] 

maxYInd = numPatches[1] - 1 

for xInd in (0, midXIndex, numPatches[0] - 1): 

minDecPatchInfo = tractInfo.getPatchInfo((xInd, 0)) 

minDecPosBox = afwGeom.Box2D(minDecPatchInfo.getOuterBBox()) 

minPixelPosList += [ 

minDecPosBox.getMin(), 

afwGeom.Point2D(minDecPosBox.getMaxX(), minDecPosBox.getMinY()), 

] 

 

maxDecPatchInfo = tractInfo.getPatchInfo((xInd, maxYInd)) 

maxDecPosBox = afwGeom.Box2D(maxDecPatchInfo.getOuterBBox()) 

maxPixelPosList += [ 

maxDecPosBox.getMax(), 

afwGeom.Point2D(maxDecPosBox.getMinX(), maxDecPosBox.getMaxY()), 

] 

wcs = tractInfo.getWcs() 

minDecList = [wcs.pixelToSky(pos).getPosition(afwGeom.degrees)[1] for pos in minPixelPosList] 

maxDecList = [wcs.pixelToSky(pos).getPosition(afwGeom.degrees)[1] for pos in maxPixelPosList] 

self.assertTrue(numpy.allclose(minDecList, minDecList[0])) 

self.assertTrue(numpy.allclose(maxDecList, maxDecList[0])) 

self.assertTrue(minDecList[0] <= minDec) 

self.assertTrue(maxDecList[0] >= maxDec) 

 

def testMoreBasicAttributes(self): 

"""Confirm that constructor attributes are available. 

""" 

defaultSkyMap = self.getSkyMap() 

for numTracts in (1, 2, 4, 25): 

config = EquatSkyMap.ConfigClass() 

config.numTracts = numTracts 

skyMap = EquatSkyMap(config) 

self.assertEqual(len(skyMap), numTracts) 

if numTracts == defaultSkyMap.config.numTracts: 

self.assertEqual(skyMap, defaultSkyMap) 

else: 

self.assertNotEqual(skyMap, defaultSkyMap) 

 

for decRange in ([-1.3, 0.5], [6.1, 6.8]): 

config = EquatSkyMap.ConfigClass() 

config.decRange = decRange 

skyMap = EquatSkyMap(config) 

self.assertNotEqual(skyMap, defaultSkyMap) 

 

def testFindTract(self): 

"""Test the SkyMap.findTract method 

""" 

for numTracts in (2, 4): 

config = EquatSkyMap.ConfigClass() 

config.numTracts = numTracts 

skyMap = EquatSkyMap(config) 

decRange = skyMap.config.decRange 

decList = ( 

(decRange[0] * 0.999) + (decRange[1] * 0.901), 

(decRange[0] * 0.500) + (decRange[1] * 0.500), 

(decRange[0] * 0.091) + (decRange[1] * 0.999), 

) 

for tractInfo0 in skyMap: 

tractId0 = tractInfo0.getId() 

ctrCoord0 = tractInfo0.getCtrCoord() 

 

for tractInfo1 in self.getNeighborTracts(skyMap, tractId0): 

 

tractId1 = tractInfo1.getId() 

ctrCoord1 = tractInfo1.getCtrCoord() 

 

for deltaFrac in (-0.001, 0.001): 

v0 = ctrCoord0.getVector() * (0.5 + deltaFrac) 

v1 = ctrCoord1.getVector() * (0.5 - deltaFrac) 

testVec = v0 + v1 

testRa = afwGeom.SpherePoint(testVec).getRa() 

 

if deltaFrac > 0.0: 

expectedTractId = tractId0 

else: 

expectedTractId = tractId1 

 

for testDecDeg in decList: 

testDec = afwGeom.Angle(testDecDeg, afwGeom.degrees) 

testCoord = afwGeom.SpherePoint(testRa, testDec) 

 

nearestTractInfo = skyMap.findTract(testCoord) 

nearestTractId = nearestTractInfo.getId() 

 

self.assertEqual(nearestTractId, expectedTractId) 

 

patchInfo = nearestTractInfo.findPatch(testCoord) 

pixelInd = afwGeom.Point2I(nearestTractInfo.getWcs().skyToPixel(testCoord)) 

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

 

# find a point outside the tract and make sure it fails 

tractInfo = tractInfo0 

wcs = tractInfo.getWcs() 

bbox = afwGeom.Box2D(tractInfo.getBBox()) 

outerPixPosList = [ 

bbox.getMin() - afwGeom.Extent2D(1, 1), 

afwGeom.Point2D(bbox.getMaxX(), bbox.getMinY()) - afwGeom.Extent2D(1, 1), 

bbox.getMax() + afwGeom.Extent2D(1, 1), 

afwGeom.Point2D(bbox.getMinX(), bbox.getMaxY()) + afwGeom.Extent2D(1, 1), 

] 

for outerPixPos in outerPixPosList: 

testCoord = wcs.pixelToSky(outerPixPos) 

self.assertRaises(LookupError, tractInfo.findPatch, testCoord) 

 

 

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

pass 

 

 

def setup_module(module): 

lsst.utils.tests.init() 

 

 

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

lsst.utils.tests.init() 

unittest.main()