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

""" 

LSST Data Management System 

See COPYRIGHT file at the top of the source tree. 

 

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/>. 

""" 

import unittest 

 

from numpy.testing import assert_allclose, assert_equal 

import astshim 

 

import lsst.utils.tests 

import lsst.geom 

import lsst.afw.geom as afwGeom 

from lsst.pex.exceptions import InvalidParameterError 

from lsst.afw.geom.testUtils import TransformTestBaseClass 

 

 

class EndpointTestCase(TransformTestBaseClass): 

 

def setUp(self): 

self.longMessage = True 

 

def testSpherePointEndpoint(self): 

self.assertEqual("SpherePoint", afwGeom.SpherePointEndpoint.getClassPrefix()) 

endpoint = afwGeom.SpherePointEndpoint() 

self.checkEndpointBasics( 

endpoint=endpoint, pointType=lsst.geom.SpherePoint, nAxes=2) 

self.assertEqual(repr(endpoint), "lsst.afw.geom.SpherePointEndpoint()") 

self.assertEqual("{}".format(endpoint), "SpherePointEndpoint()") 

 

for doPermute in (False, True): 

frame = astshim.SkyFrame() 

if doPermute: 

frame.permAxes([2, 1]) 

self.assertEqual(frame.lonAxis, 2) 

self.assertEqual(frame.latAxis, 1) 

else: 

self.assertEqual(frame.lonAxis, 1) 

self.assertEqual(frame.latAxis, 2) 

endpoint.normalizeFrame(frame) 

# the normalized frame always has axis in order Lon, Lat 

self.assertEqual(frame.lonAxis, 1) 

self.assertEqual(frame.latAxis, 2) 

 

badFrame = astshim.Frame(2) 

with self.assertRaises(InvalidParameterError): 

endpoint.normalizeFrame(badFrame) 

 

newFrame = endpoint.makeFrame() 

self.assertEqual(type(newFrame), astshim.SkyFrame) 

self.assertEqual(newFrame.lonAxis, 1) 

self.assertEqual(newFrame.latAxis, 2) 

 

def testPoint2Endpoint(self): 

self.assertEqual("Point2", afwGeom.Point2Endpoint.getClassPrefix()) 

endpoint = afwGeom.Point2Endpoint() 

self.checkEndpointBasics( 

endpoint=endpoint, pointType=lsst.geom.Point2D, nAxes=2) 

self.assertEqual(repr(endpoint), "lsst.afw.geom.Point2Endpoint()") 

self.assertEqual("{}".format(endpoint), "Point2Endpoint()") 

 

# normalize does not check the # of axes 

for n in range(4): 

frame1 = astshim.Frame(n) 

try: 

endpoint.normalizeFrame(frame1) 

except Exception as e: 

self.fail( 

"endpoint.normalizeFrame(Frame({})) failed with error = {}".format(n, e)) 

badFrame = astshim.SkyFrame() 

with self.assertRaises(InvalidParameterError): 

endpoint.normalizeFrame(badFrame) 

 

def testGenericEndpoint(self): 

self.assertEqual("Generic", afwGeom.GenericEndpoint.getClassPrefix()) 

for nAxes in (1, 2, 3, 4, 5): 

endpoint = afwGeom.GenericEndpoint(nAxes) 

self.checkEndpointBasics( 

endpoint=endpoint, pointType=list, nAxes=nAxes) 

self.assertEqual( 

repr(endpoint), "lsst.afw.geom.GenericEndpoint({})".format(nAxes)) 

self.assertEqual("{}".format(endpoint), 

"GenericEndpoint({})".format(nAxes)) 

 

newFrame = endpoint.makeFrame() 

self.assertEqual(type(newFrame), astshim.Frame) 

self.assertEqual(newFrame.nAxes, nAxes) 

 

for nAxes in (-1, 0): 

with self.assertRaises(InvalidParameterError): 

afwGeom.GenericEndpoint(nAxes) 

 

def checkEndpointBasics(self, endpoint, pointType, nAxes): 

isAngle = pointType == lsst.geom.SpherePoint # point components are Angles 

 

baseMsg = "endpoint={}, pointType={}, nAxes={}".format( 

endpoint, pointType, nAxes) 

 

self.assertEqual(endpoint.nAxes, nAxes, msg=baseMsg) 

 

# generate enough points to be interesting, but no need to overdo it 

nPoints = 4 

 

rawData = self.makeRawArrayData(nPoints=nPoints, nAxes=nAxes) 

pointList = endpoint.arrayFromData(rawData) 

self.assertEqual(endpoint.getNPoints(pointList), nPoints, msg=baseMsg) 

if isinstance(endpoint, afwGeom.GenericEndpoint): 

self.assertEqual(len(pointList[0]), nPoints, msg=baseMsg) 

assert_equal(rawData, pointList) 

else: 

self.assertEqual(len(pointList), nPoints, msg=baseMsg) 

for i, point in enumerate(pointList): 

for axis in range(nAxes): 

msg = "{}, endpoint={}, i={}, point={}".format( 

baseMsg, endpoint, i, point) 

if isAngle: 

desAngle = rawData[axis, i] * lsst.geom.radians 

self.assertAnglesAlmostEqual( 

point[axis], desAngle, msg=msg) 

else: 

self.assertAlmostEqual( 

point[axis], rawData[axis, i], msg=msg) 

 

rawDataRoundTrip = endpoint.dataFromArray(pointList) 

self.assertEqual(rawData.shape, rawDataRoundTrip.shape, msg=baseMsg) 

self.assertFloatsAlmostEqual(rawData, rawDataRoundTrip, msg=baseMsg) 

 

pointData = self.makeRawPointData(nAxes=nAxes) 

point = endpoint.pointFromData(pointData) 

self.assertEqual(type(point), pointType, msg=baseMsg) 

for axis in range(nAxes): 

msg = "{}, axis={}".format(baseMsg, axis) 

if isAngle: 

desAngle = pointData[axis] * lsst.geom.radians 

self.assertAnglesAlmostEqual(point[axis], desAngle, msg=msg) 

else: 

self.assertAlmostEqual(point[axis], pointData[axis], msg=msg) 

 

pointDataRoundTrip = endpoint.dataFromPoint(point) 

assert_allclose(pointData, pointDataRoundTrip, err_msg=baseMsg) 

 

def testEndpointEquals(self): 

"""Test Endpoint == Endpoint 

""" 

for i1, point1 in enumerate(self.makeEndpoints()): 

for i2, point2 in enumerate(self.makeEndpoints()): 

if i1 == i2: 

self.assertTrue(point1 == point2) 

self.assertFalse(point1 != point2) 

else: 

self.assertFalse(point1 == point2) 

self.assertTrue(point1 != point2) 

 

 

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

pass 

 

 

def setup_module(module): 

lsst.utils.tests.init() 

 

 

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

lsst.utils.tests.init() 

unittest.main()