Coverage for tests/test_orientation.py: 16%

81 statements  

« prev     ^ index     » next       coverage.py v6.5.0, created at 2023-02-22 03:22 -0800

1# 

2# LSST Data Management System 

3# Copyright 2014 LSST Corporation. 

4# 

5# This product includes software developed by the 

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

7# 

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

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

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

11# (at your option) any later version. 

12# 

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

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

15# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 

16# GNU General Public License for more details. 

17# 

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

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

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

21# 

22""" 

23Tests for lsst.afw.cameraGeom.Orientation 

24 

25@todo: test the transforms against expected 

26""" 

27import unittest 

28 

29import lsst.utils.tests 

30import lsst.geom 

31from lsst.afw.cameraGeom import Orientation 

32 

33 

34class OrientationWrapper: 

35 

36 def __init__(self, 

37 fpPosition=lsst.geom.Point3D(0, 0, 0), 

38 refPoint=lsst.geom.Point2D(-0.5, -0.5), 

39 yaw=lsst.geom.Angle(0), 

40 pitch=lsst.geom.Angle(0), 

41 roll=lsst.geom.Angle(0), 

42 ): 

43 self.fpPosition = fpPosition 

44 self.refPoint = refPoint 

45 self.yaw = yaw 

46 self.pitch = pitch 

47 self.roll = roll 

48 self.orient = Orientation(fpPosition, refPoint, yaw, pitch, roll) 

49 

50 

51class OrientationTestCase(lsst.utils.tests.TestCase): 

52 

53 def testDefaultConstructor(self): 

54 """Test default constructor 

55 """ 

56 orient = Orientation() 

57 for i in range(2): 

58 self.assertAlmostEqual(0, orient.getFpPosition()[i]) 

59 self.assertAlmostEqual(-0.5, orient.getReferencePoint()[i]) 

60 for i in range(3): 

61 self.assertAlmostEqual(0, orient.getFpPosition3()[i]) 

62 zeroAngle = lsst.geom.Angle(0) 

63 self.assertAlmostEqual(zeroAngle, orient.getYaw()) 

64 self.assertAlmostEqual(zeroAngle, orient.getRoll()) 

65 self.assertAlmostEqual(zeroAngle, orient.getPitch()) 

66 

67 fwdTransform = orient.makeFpPixelTransform(lsst.geom.Extent2D(1.0)) 

68 for x in (-100.1, 0.0, 230.0): 

69 for y in (-45.0, 0.0, 25.1): 

70 xy = lsst.geom.Point2D(x, y) 

71 fwdXY = fwdTransform.applyForward(xy) 

72 for i in range(2): 

73 self.assertPairsAlmostEqual(xy - lsst.geom.Extent2D(0.5), fwdXY) 

74 self.compareTransforms(orient) 

75 

76 def testGetNQuarter(self): 

77 """Test the getNQuarter method 

78 """ 

79 refPos = lsst.geom.Point2D(0., 0.) 

80 fpPos = lsst.geom.Point3D(0., 0., 0.) 

81 angles = ((0., 0), (90., 1), (180., 2), (270., 3), (360., 4), 

82 (0.1, 0), (44.9, 0), (45.1, 1), (89.9, 1), (90.1, 1), 

83 (134.9, 1), (135.1, 2), (179.9, 2), (180.1, 2), (224.9, 2), 

84 (225.1, 3), (269.9, 3), (270.1, 3), (314.9, 3), (315.1, 4), 

85 (359.9, 4)) 

86 for angle in angles: 

87 orient = Orientation( 

88 fpPos, refPos, lsst.geom.Angle(angle[0], lsst.geom.degrees)) 

89 self.assertEqual(orient.getNQuarter(), angle[1]) 

90 

91 def checkTransforms(self, orientWrapper, pixelSize=lsst.geom.Extent2D(0.12, 0.21)): 

92 """Check that the transforms do what we expect them to 

93 """ 

94 pixToFpTransform = orientWrapper.orient.makeFpPixelTransform(pixelSize) 

95 for x in (-100.1, 0.0, 230.0): 

96 for y in (-45.0, 0.0, 25.1): 

97 pixPos = lsst.geom.Point2D(x, y) 

98 pixToFpTransform.forwardTransform(pixPos) 

99 

100 def compareTransforms(self, orient, pixelSize=lsst.geom.Extent2D(0.12, 0.21)): 

101 """Compare makeFpPixelTransform and makePixelFpTransform to each other 

102 """ 

103 fwdTransform = orient.makeFpPixelTransform(pixelSize) 

104 revTransform = orient.makePixelFpTransform(pixelSize) 

105 for x in (-100.1, 0.0, 230.0): 

106 for y in (-45.0, 0.0, 25.1): 

107 pixPos = lsst.geom.Point2D(x, y) 

108 fwdFPPos = fwdTransform.applyForward(pixPos) 

109 fwdPixPos = fwdTransform.applyInverse(fwdFPPos) 

110 revPixPos = revTransform.applyForward(fwdFPPos) 

111 revFPPos = revTransform.applyInverse(pixPos) 

112 

113 self.assertPairsAlmostEqual(pixPos, fwdPixPos) 

114 self.assertPairsAlmostEqual(pixPos, revPixPos) 

115 self.assertPairsAlmostEqual(fwdFPPos, revFPPos) 

116 

117 def testGetters(self): 

118 """Test getters 

119 """ 

120 ow1 = OrientationWrapper( 

121 fpPosition=lsst.geom.Point3D(0.1, -0.2, 0.3), 

122 refPoint=lsst.geom.Point2D(-5.7, 42.3), 

123 yaw=lsst.geom.Angle(-0.53), 

124 pitch=lsst.geom.Angle(0.234), 

125 roll=lsst.geom.Angle(1.2), 

126 ) 

127 # Verify Point2D fpPosition ctor works too 

128 ow2 = OrientationWrapper( 

129 fpPosition=lsst.geom.Point2D(0.1, -0.2), 

130 refPoint=lsst.geom.Point2D(-5.7, 42.3), 

131 yaw=lsst.geom.Angle(-0.53), 

132 pitch=lsst.geom.Angle(0.234), 

133 roll=lsst.geom.Angle(1.2), 

134 ) 

135 for ow in [ow1, ow2]: 

136 for i in range(2): 

137 self.assertAlmostEqual( 

138 ow.fpPosition[i], ow.orient.getFpPosition()[i]) 

139 self.assertAlmostEqual( 

140 ow.refPoint[i], ow.orient.getReferencePoint()[i]) 

141 for i in range(3): 

142 if isinstance(ow.fpPosition, lsst.geom.Point3D) or i < 2: 

143 self.assertAlmostEqual( 

144 ow.fpPosition[i], ow.orient.getFpPosition3()[i]) 

145 else: 

146 self.assertEqual(0.0, ow.orient.getFpPosition3()[2]) 

147 self.assertEqual(0.0, ow.orient.getHeight()) 

148 

149 self.assertAlmostEqual(ow.yaw, ow.orient.getYaw()) 

150 self.assertAlmostEqual(ow.roll, ow.orient.getRoll()) 

151 self.assertAlmostEqual(ow.pitch, ow.orient.getPitch()) 

152 

153 

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

155 pass 

156 

157 

158def setup_module(module): 

159 lsst.utils.tests.init() 

160 

161 

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

163 lsst.utils.tests.init() 

164 unittest.main()