Coverage for tests/test_orientation.py : 19%

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# 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
25@todo: test the transforms against expected
26"""
27import unittest
29import lsst.utils.tests
30import lsst.geom
31from lsst.afw.cameraGeom import Orientation
34class OrientationWrapper:
36 def __init__(self,
37 fpPosition=lsst.geom.Point2D(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)
51class OrientationTestCase(lsst.utils.tests.TestCase):
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 zeroAngle = lsst.geom.Angle(0)
61 self.assertAlmostEqual(zeroAngle, orient.getYaw())
62 self.assertAlmostEqual(zeroAngle, orient.getRoll())
63 self.assertAlmostEqual(zeroAngle, orient.getPitch())
65 fwdTransform = orient.makeFpPixelTransform(lsst.geom.Extent2D(1.0))
66 for x in (-100.1, 0.0, 230.0):
67 for y in (-45.0, 0.0, 25.1):
68 xy = lsst.geom.Point2D(x, y)
69 fwdXY = fwdTransform.applyForward(xy)
70 for i in range(2):
71 self.assertPairsAlmostEqual(xy - lsst.geom.Extent2D(0.5), fwdXY)
72 self.compareTransforms(orient)
74 def testGetNQuarter(self):
75 """Test the getNQuarter method
76 """
77 refPos = lsst.geom.Point2D(0., 0.)
78 fpPos = lsst.geom.Point2D(0., 0.)
79 angles = ((0., 0), (90., 1), (180., 2), (270., 3), (360., 4),
80 (0.1, 0), (44.9, 0), (45.1, 1), (89.9, 1), (90.1, 1),
81 (134.9, 1), (135.1, 2), (179.9, 2), (180.1, 2), (224.9, 2),
82 (225.1, 3), (269.9, 3), (270.1, 3), (314.9, 3), (315.1, 4),
83 (359.9, 4))
84 for angle in angles:
85 orient = Orientation(
86 fpPos, refPos, lsst.geom.Angle(angle[0], lsst.geom.degrees))
87 self.assertEqual(orient.getNQuarter(), angle[1])
89 def checkTransforms(self, orientWrapper, pixelSize=lsst.geom.Extent2D(0.12, 0.21)):
90 """Check that the transforms do what we expect them to
91 """
92 pixToFpTransform = orientWrapper.orient.makeFpPixelTransform(pixelSize)
93 for x in (-100.1, 0.0, 230.0):
94 for y in (-45.0, 0.0, 25.1):
95 pixPos = lsst.geom.Point2D(x, y)
96 pixToFpTransform.forwardTransform(pixPos)
98 def compareTransforms(self, orient, pixelSize=lsst.geom.Extent2D(0.12, 0.21)):
99 """Compare makeFpPixelTransform and makePixelFpTransform to each other
100 """
101 fwdTransform = orient.makeFpPixelTransform(pixelSize)
102 revTransform = orient.makePixelFpTransform(pixelSize)
103 for x in (-100.1, 0.0, 230.0):
104 for y in (-45.0, 0.0, 25.1):
105 pixPos = lsst.geom.Point2D(x, y)
106 fwdFPPos = fwdTransform.applyForward(pixPos)
107 fwdPixPos = fwdTransform.applyInverse(fwdFPPos)
108 revPixPos = revTransform.applyForward(fwdFPPos)
109 revFPPos = revTransform.applyInverse(pixPos)
111 self.assertPairsAlmostEqual(pixPos, fwdPixPos)
112 self.assertPairsAlmostEqual(pixPos, revPixPos)
113 self.assertPairsAlmostEqual(fwdFPPos, revFPPos)
115 def testGetters(self):
116 """Test getters
117 """
118 ow = OrientationWrapper(
119 fpPosition=lsst.geom.Point2D(0.1, -0.2),
120 refPoint=lsst.geom.Point2D(-5.7, 42.3),
121 yaw=lsst.geom.Angle(-0.53),
122 pitch=lsst.geom.Angle(0.234),
123 roll=lsst.geom.Angle(1.2),
124 )
125 for i in range(2):
126 self.assertAlmostEqual(
127 ow.fpPosition[i], ow.orient.getFpPosition()[i])
128 self.assertAlmostEqual(
129 ow.refPoint[i], ow.orient.getReferencePoint()[i])
130 self.assertAlmostEqual(ow.yaw, ow.orient.getYaw())
131 self.assertAlmostEqual(ow.roll, ow.orient.getRoll())
132 self.assertAlmostEqual(ow.pitch, ow.orient.getPitch())
135class MemoryTester(lsst.utils.tests.MemoryTestCase):
136 pass
139def setup_module(module):
140 lsst.utils.tests.init()
143if __name__ == "__main__": 143 ↛ 144line 143 didn't jump to line 144, because the condition on line 143 was never true
144 lsst.utils.tests.init()
145 unittest.main()