From bd1831039cc194de1dc5149d0cf02c86a185f8e7 Mon Sep 17 00:00:00 2001 From: "Olivier J.N. Bertrand" <olivier.bertrand@uni-bielefeld.de> Date: Tue, 18 Sep 2018 06:10:41 +0200 Subject: [PATCH] Rename convention --- navipy/maths/constants.py | 8 ++-- navipy/maths/euler.py | 34 +++++++------- navipy/maths/homogeneous_transformations.py | 4 +- navipy/maths/quaternion.py | 4 +- navipy/maths/test_euler.py | 46 +++++++++---------- .../maths/test_homogeneous_transformations.py | 6 +-- navipy/maths/test_quaternion.py | 2 +- navipy/processing/test_OpticFlow.py | 4 +- navipy/trajectories/test_markers.py | 4 +- navipy/trajectories/test_trajectory.py | 6 +-- navipy/trajectories/transformations.py | 12 ++--- 11 files changed, 65 insertions(+), 65 deletions(-) diff --git a/navipy/maths/constants.py b/navipy/maths/constants.py index 6259986..57d5bad 100644 --- a/navipy/maths/constants.py +++ b/navipy/maths/constants.py @@ -10,7 +10,7 @@ _NEXT_AXIS = [1, 2, 0, 1] # map axes strings to/from tuples of inner axis, parity, repetition, frame _AXES2TUPLE = { - 'sxyz': (0, 0, 1, 2), 'sxyx': (0, 0, 1, 0), 'sxzy': (0, 0, 2, 1), - 'sxzx': (0, 0, 2, 0), 'syzx': (0, 1, 2, 0), 'syzy': (0, 1, 2, 1), - 'syxz': (0, 1, 0, 2), 'syxy': (0, 1, 0, 1), 'szxy': (0, 2, 0, 1), - 'szxz': (0, 2, 0, 2), 'szyx': (0, 2, 1, 0), 'szyz': (0, 2, 1, 2)} + 'xyz': (0, 0, 1, 2), 'xyx': (0, 0, 1, 0), 'xzy': (0, 0, 2, 1), + 'xzx': (0, 0, 2, 0), 'yzx': (0, 1, 2, 0), 'yzy': (0, 1, 2, 1), + 'yxz': (0, 1, 0, 2), 'yxy': (0, 1, 0, 1), 'zxy': (0, 2, 0, 1), + 'zxz': (0, 2, 0, 2), 'zyx': (0, 2, 1, 0), 'zyz': (0, 2, 1, 2)} diff --git a/navipy/maths/euler.py b/navipy/maths/euler.py index 01e5a22..28adefa 100644 --- a/navipy/maths/euler.py +++ b/navipy/maths/euler.py @@ -65,7 +65,7 @@ def R3(a): return R3 -def matrix(ai, aj, ak, axes='sxyz'): +def matrix(ai, aj, ak, axes='xyz'): """ rotation matrix around the three axis with the order given by the axes parameter @@ -92,7 +92,7 @@ def matrix(ai, aj, ak, axes='sxyz'): return Rijk -def from_matrix(matrix, axes='sxyz'): +def from_matrix(matrix, axes='xyz'): """Return Euler angles from rotation matrix for specified axis sequence. axes : One of 24 axis sequences as string or encoded tuple @@ -121,51 +121,51 @@ def from_matrix(matrix, axes='sxyz'): # new = list(axes) # new[0] = 's' # axes = ''.join(new) - if axes == 'sxyx': + if axes == 'xyx': u = [np.arctan2(matrix[1, 0], matrix[2, 0]), np.arccos(matrix[0, 0]), np.arctan2(matrix[0, 1], -matrix[0, 2])] - elif axes == 'sxyz': + elif axes == 'xyz': u = [np.arctan2(matrix[1, 2], matrix[2, 2]), -np.arcsin(matrix[0, 2]), np.arctan2(matrix[0, 1], matrix[0, 0])] - elif axes == 'sxzx': + elif axes == 'xzx': u = [np.arctan2(matrix[2, 0], -matrix[1, 0]), np.arccos(matrix[0, 0]), np.arctan2(matrix[0, 2], matrix[0, 1])] - elif axes == 'sxzy': + elif axes == 'xzy': u = [np.arctan2(-matrix[2, 1], matrix[1, 1]), np.arcsin(matrix[0, 1]), np.arctan2(-matrix[0, 2], matrix[0, 0])] - elif axes == 'syxy': + elif axes == 'yxy': u = [np.arctan2(matrix[0, 1], -matrix[2, 1]), np.arccos(matrix[1, 1]), np.arctan2(matrix[1, 0], matrix[1, 2])] - elif axes == 'syxz': + elif axes == 'yxz': u = [np.arctan2(-matrix[0, 2], matrix[2, 2]), np.arcsin(matrix[1, 2]), np.arctan2(-matrix[1, 0], matrix[1, 1])] - elif axes == 'syzx': + elif axes == 'yzx': u = [np.arctan2(matrix[2, 0], matrix[0, 0]), -np.arcsin(matrix[1, 0]), np.arctan2(matrix[1, 2], matrix[1, 1])] - elif axes == 'syzy': + elif axes == 'yzy': u = [np.arctan2(matrix[2, 1], matrix[0, 1]), np.arccos(matrix[1, 1]), np.arctan2(matrix[1, 2], -matrix[1, 0])] - elif axes == 'szxy': + elif axes == 'zxy': u = [np.arctan2(matrix[0, 1], matrix[1, 1]), -np.arcsin(matrix[2, 1]), np.arctan2(matrix[2, 0], matrix[2, 2])] - elif axes == 'szxz': + elif axes == 'zxz': u = [np.arctan2(matrix[0, 2], matrix[1, 2]), np.arccos(matrix[2, 2]), np.arctan2(matrix[2, 0], -matrix[2, 1])] - elif axes == 'szyx': + elif axes == 'zyx': u = [np.arctan2(-matrix[1, 0], matrix[0, 0]), np.arcsin(matrix[2, 0]), np.arctan2(-matrix[2, 1], matrix[2, 2])] - elif axes == 'szyz': + elif axes == 'zyz': u = [np.arctan2(matrix[1, 2], -matrix[0, 2]), np.arccos(matrix[2, 2]), np.arctan2(matrix[2, 1], matrix[2, 0])] @@ -176,7 +176,7 @@ def from_matrix(matrix, axes='sxyz'): return u -def from_quaternion(quaternion, axes='sxyz'): +def from_quaternion(quaternion, axes='xyz'): """Return Euler angles from quaternion for specified axis sequence. """ if not isinstance(quaternion, np.ndarray) and\ @@ -189,7 +189,7 @@ def from_quaternion(quaternion, axes='sxyz'): return from_matrix(quat.matrix(quaternion)[:3, :3], axes) -def angle_rate_matrix(ai, aj, ak, axes='sxyz'): +def angle_rate_matrix(ai, aj, ak, axes='xyz'): """ Return the Euler Angle Rates Matrix @@ -248,7 +248,7 @@ def angle_rate_matrix(ai, aj, ak, axes='sxyz'): return rotM -def angular_velocity(ai, aj, ak, dai, daj, dak, axes='sxyz'): +def angular_velocity(ai, aj, ak, dai, daj, dak, axes='xyz'): """ Return the angular velocity diff --git a/navipy/maths/homogeneous_transformations.py b/navipy/maths/homogeneous_transformations.py index 2ea6ee2..e815c53 100644 --- a/navipy/maths/homogeneous_transformations.py +++ b/navipy/maths/homogeneous_transformations.py @@ -313,7 +313,7 @@ def shear_from_matrix(matrix): return angle, direction, point, normal -def decompose_matrix(matrix, axes='sxyz'): +def decompose_matrix(matrix, axes='xyz'): """Return sequence oftransformations from transformation matrix. matrix : array_like @@ -376,7 +376,7 @@ def decompose_matrix(matrix, axes='sxyz'): def compose_matrix(scale=None, shear=None, angles=None, translate=None, - perspective=None, axes='sxyz'): + perspective=None, axes='xyz'): """Return transformation matrix from sequence oftransformations. This is the inverse of the decompose_matrix function. diff --git a/navipy/maths/quaternion.py b/navipy/maths/quaternion.py index f116a27..ef0d018 100644 --- a/navipy/maths/quaternion.py +++ b/navipy/maths/quaternion.py @@ -27,7 +27,7 @@ def qat(a, n): return tmp -def from_euler(ai, aj, ak, axes='sxyz'): +def from_euler(ai, aj, ak, axes='xyz'): """Return quaternion from Euler angles and axis sequence. ai, aj, ak : Euler's roll, pitch and yaw angles axes : One of 24 axis sequences as string or encoded tuple @@ -67,7 +67,7 @@ def about_axis(angle, axis): return q -def matrix(quaternion, axes='sxyz'): +def matrix(quaternion, axes='xyz'): """Return homogeneous rotation matrix from quaternion. :param quaternion : vector with at least 3 entrences (unit quaternion) :param axes: string that encodes the order of the axes and diff --git a/navipy/maths/test_euler.py b/navipy/maths/test_euler.py index 14b892e..c1ea966 100644 --- a/navipy/maths/test_euler.py +++ b/navipy/maths/test_euler.py @@ -50,7 +50,7 @@ class TestEuler(unittest.TestCase): """ Test orientation from one convention to another """ - refkey = 'sxyz' + refkey = 'xyz' for key in list(_AXES2TUPLE.keys()): rotation_0 = euler.matrix(1, 2, 3, refkey)[:3, :3] [ai, aj, ak] = euler.from_matrix(rotation_0, key) @@ -95,7 +95,7 @@ class TestEuler(unittest.TestCase): of wrong type, value are passed to the euler.angle_rate_matrix function """ - for a, b, c, d in [(None, 2, 6, 'rxyz'), (5.0, 4.0, None, 'sxyx')]: + for a, b, c, d in [(None, 2, 6, 'rxyz'), (5.0, 4.0, None, 'xyx')]: with self.assertRaises(TypeError): euler.angle_rate_matrix(a, b, c, d) @@ -112,12 +112,12 @@ class TestEuler(unittest.TestCase): of wrong type, value are passed to the euler.angle_rate_matrix function """ - for a, b, c, d, e, f, g in [(None, 2, 6, 8, 7, 8, 'sxyz'), - (9.0, 'er', 2, 3, 3, 5, 'sxyz'), - (5.0, 4.0, None, 8.0, 8.0, 4.0, 'sxyz'), - (np.nan, 8.0, 7.0, '0', 6.0, 9.0, 'sxyz'), - (4.0, 2.0, 1.0, 3.0, 'w', 2.0, 'sxyz'), - (1.0, 2.0, 3.0, 4.0, None, 4, 'sxyz')]: + for a, b, c, d, e, f, g in [(None, 2, 6, 8, 7, 8, 'xyz'), + (9.0, 'er', 2, 3, 3, 5, 'xyz'), + (5.0, 4.0, None, 8.0, 8.0, 4.0, 'xyz'), + (np.nan, 8.0, 7.0, '0', 6.0, 9.0, 'xyz'), + (4.0, 2.0, 1.0, 3.0, 'w', 2.0, 'xyz'), + (1.0, 2.0, 3.0, 4.0, None, 4, 'xyz')]: with self.assertRaises(TypeError): euler.angular_velocity(a, b, c, d, e, f, g) @@ -134,7 +134,7 @@ class TestEuler(unittest.TestCase): # dai = 0 # daj = 0 # dak = 1 - E = angle_rate_matrix(ai, aj, ak, 'szxz') + E = angle_rate_matrix(ai, aj, ak, 'zxz') testE = [[np.sin(aj) * np.sin(ak), np.cos(ak), 0], [-np.sin(aj) * np.cos(ak), np.sin(ak), 0], [np.cos(aj), 0, 1]] @@ -155,7 +155,7 @@ class TestEuler(unittest.TestCase): E_p = [[0, np.cos(ai), np.sin(aj) * np.sin(ai)], [0, -np.sin(ai), np.sin(aj) * np.cos(ai)], [1, 0, np.cos(aj)]] - E_fkt = angle_rate_matrix(ai, aj, ak, 'szxz') + E_fkt = angle_rate_matrix(ai, aj, ak, 'zxz') self.assertTrue(np.allclose(E, E_fkt)) w = np.dot(E, [dai, daj, dak]) w_p = np.dot(E_p, [dai, daj, dak]) @@ -169,7 +169,7 @@ class TestEuler(unittest.TestCase): -s(aj) * c(ak), c(aj)]] Rijk_test = np.dot(R3(ai), np.dot(R1(aj), R3(ak))) - Rijk_fkt = matrix(ai, aj, ak, 'szxz')[:3, :3] + Rijk_fkt = matrix(ai, aj, ak, 'zxz')[:3, :3] self.assertTrue(np.allclose(Rijk, Rijk_fkt)) self.assertTrue(np.allclose(Rijk, Rijk_test)) new_w_p = np.dot(Rijk, w) @@ -192,7 +192,7 @@ class TestEuler(unittest.TestCase): p1 = np.dot(MR3, np.dot(MR2, e1)) p2 = np.dot(MR3, e2) rotM = np.column_stack([p1, p2, e3]) - M = angle_rate_matrix(ea, eb, ec, 'sxyz') + M = angle_rate_matrix(ea, eb, ec, 'xyz') self.assertTrue(np.all(rotM == M)) # ryzx @@ -204,7 +204,7 @@ class TestEuler(unittest.TestCase): p1 = np.dot(MRk, np.dot(MRj, e2)) p2 = np.dot(MRk, e3) rotM = np.column_stack([p1, p2, e1]) - M = angle_rate_matrix(ea, eb, ec, 'syzx') + M = angle_rate_matrix(ea, eb, ec, 'yzx') self.assertTrue(np.allclose(rotM, M)) # ryxz @@ -216,7 +216,7 @@ class TestEuler(unittest.TestCase): p1 = np.dot(MRk, np.dot(MRj, e2)) p2 = np.dot(MRk, e1) rotM = np.column_stack([p1, p2, e3]) - M = angle_rate_matrix(ea, eb, ec, 'syxz') + M = angle_rate_matrix(ea, eb, ec, 'yxz') self.assertTrue(np.allclose(rotM, M)) # rxzy @@ -228,7 +228,7 @@ class TestEuler(unittest.TestCase): p1 = np.dot(MRk, np.dot(MRj, e1)) p2 = np.dot(MRk, e3) rotM = np.column_stack([p1, p2, e2]) - M = angle_rate_matrix(ea, eb, ec, 'sxzy') + M = angle_rate_matrix(ea, eb, ec, 'xzy') self.assertTrue(np.allclose(rotM, M)) # rzxy @@ -240,7 +240,7 @@ class TestEuler(unittest.TestCase): p1 = np.dot(MRk, np.dot(MRj, e3)) p2 = np.dot(MRk, e1) rotM = np.column_stack([p1, p2, e2]) - M = angle_rate_matrix(ea, eb, ec, 'szxy') + M = angle_rate_matrix(ea, eb, ec, 'zxy') self.assertTrue(np.allclose(rotM, M)) # rxzx @@ -252,7 +252,7 @@ class TestEuler(unittest.TestCase): p1 = np.dot(MRk, np.dot(MRj, e1)) p2 = np.dot(MRk, e3) rotM = np.column_stack([p1, p2, e1]) - M = angle_rate_matrix(ea, eb, ec, 'sxzx') + M = angle_rate_matrix(ea, eb, ec, 'xzx') self.assertTrue(np.allclose(rotM, M)) # rzxz @@ -273,8 +273,8 @@ class TestEuler(unittest.TestCase): # -s(ea)*s(ec)+c(ea)*c(eb)*c(ec), # c(ea)*s(eb)], # [s(eb)*s(ec), -s(eb)*c(ec), c(eb)]] - # mfunc = angle_rate_matrix(ea, eb, ec, 'szxz') - M = angle_rate_matrix(ea, eb, ec, 'szxz') + # mfunc = angle_rate_matrix(ea, eb, ec, 'zxz') + M = angle_rate_matrix(ea, eb, ec, 'zxz') self.assertTrue(np.allclose(rotM, M)) # rxyx @@ -286,7 +286,7 @@ class TestEuler(unittest.TestCase): p1 = np.dot(MRk, np.dot(MRj, e1)) p2 = np.dot(MRk, e2) rotM = np.column_stack([p1, p2, e1]) - M = angle_rate_matrix(ea, eb, ec, 'sxyx') + M = angle_rate_matrix(ea, eb, ec, 'xyx') self.assertTrue(np.allclose(rotM, M)) # ryxy @@ -298,7 +298,7 @@ class TestEuler(unittest.TestCase): p1 = np.dot(MRk, np.dot(MRj, e2)) p2 = np.dot(MRk, e1) rotM = np.column_stack([p1, p2, e2]) - M = angle_rate_matrix(ea, eb, ec, 'syxy') + M = angle_rate_matrix(ea, eb, ec, 'yxy') self.assertTrue(np.allclose(rotM, M)) # ryzy @@ -310,7 +310,7 @@ class TestEuler(unittest.TestCase): p1 = np.dot(MRk, np.dot(MRj, e2)) p2 = np.dot(MRk, e3) rotM = np.column_stack([p1, p2, e2]) - M = angle_rate_matrix(ea, eb, ec, 'syzy') + M = angle_rate_matrix(ea, eb, ec, 'yzy') self.assertTrue(np.allclose(rotM, M)) # rzyz @@ -322,7 +322,7 @@ class TestEuler(unittest.TestCase): p1 = np.dot(MRk, np.dot(MRj, e3)) p2 = np.dot(MRk, e2) rotM = np.column_stack([p1, p2, e3]) - M = angle_rate_matrix(ea, eb, ec, 'szyz') + M = angle_rate_matrix(ea, eb, ec, 'zyz') self.assertTrue(np.allclose(rotM, M)) diff --git a/navipy/maths/test_homogeneous_transformations.py b/navipy/maths/test_homogeneous_transformations.py index 2677bb4..805ca8a 100644 --- a/navipy/maths/test_homogeneous_transformations.py +++ b/navipy/maths/test_homogeneous_transformations.py @@ -220,9 +220,9 @@ class TestHT(unittest.TestCase): self.assertEqual(scale[0], factor) def test_decompose_matrix_rotation(self): - rotation_0 = euler.matrix(1, 2, 3, 'sxyz') + rotation_0 = euler.matrix(1, 2, 3, 'xyz') _, _, angles, _, _ = ht.decompose_matrix(rotation_0) - rotation_1 = euler.matrix(*angles, 'sxyz') + rotation_1 = euler.matrix(*angles, 'xyz') self.assertTrue(np.allclose(rotation_0, rotation_1)) def test_compose_matrix(self): @@ -252,7 +252,7 @@ class TestHT(unittest.TestCase): scale_o = np.random.rand(3) translation_o = [1, 2, 3] shear_o = [0, np.tan(angles_o[1]), 0] - axes = 'sxyz' + axes = 'xyz' matrix = ht.compose_matrix(scale_o, shear_o, angles_o, translation_o, axes=axes) scale, shear, angles, trans, persp = ht.decompose_matrix(matrix, axes) diff --git a/navipy/maths/test_quaternion.py b/navipy/maths/test_quaternion.py index a21cad1..e49bbe0 100644 --- a/navipy/maths/test_quaternion.py +++ b/navipy/maths/test_quaternion.py @@ -7,7 +7,7 @@ import navipy.maths.random as random class TestQuaternions(unittest.TestCase): def test_quaternion_from_euler(self): - quaternion = quat.from_euler(1, 2, 3, 'syxz') + quaternion = quat.from_euler(1, 2, 3, 'yxz') self.assertTrue(np.allclose(quaternion, [0.435953, 0.310622, -0.718287, 0.444435])) diff --git a/navipy/processing/test_OpticFlow.py b/navipy/processing/test_OpticFlow.py index 2669ad0..9ff3628 100644 --- a/navipy/processing/test_OpticFlow.py +++ b/navipy/processing/test_OpticFlow.py @@ -739,8 +739,8 @@ class TestCase(unittest.TestCase): angles=[ypr[0], ypr[1],ypr[2], -ypr[0], -ypr[1], -ypr[2]] - #for c in ['sxyz','sxyx','sxzy','sxzx','syzx','syzy','syxz','syxy', - # 'szxy','szxz','szyx','szyz','rzyx','rxyx','ryzx','rxzx', + #for c in ['xyz','xyx','xzy','xzx','yzx','yzy','yxz','yxy', + # 'zxy','zxz','zyx','zyz','rzyx','rxyx','ryzx','rxzx', # 'rxzy','ryzy','rzxy','ryxy','ryxz','rzxz','rxyz','rzyz']: for al in angles: for bl in angles: diff --git a/navipy/trajectories/test_markers.py b/navipy/trajectories/test_markers.py index d33807c..1b22758 100644 --- a/navipy/trajectories/test_markers.py +++ b/navipy/trajectories/test_markers.py @@ -88,7 +88,7 @@ class TestMarkersTransform(unittest.TestCase): apex0 = self.random_apex() apex1 = self.random_apex() apex2 = self.random_apex() - euler_axes = 'sxyz' + euler_axes = 'xyz' for triangle_mode in mtf._modes: scale, shear, angles, translate, perspective =\ mtf.markers2decompose( @@ -105,7 +105,7 @@ class TestMarkersTransform(unittest.TestCase): mark0 = pd.Series(data=0, index=['x', 'y', 'z']) for axis_alignement, euler_axes, known_angle in zip( ['x-axis', 'z-axis', 'y-axis'], - ['szyx', 'syxz', 'szxy'], + ['zyx', 'yxz', 'zxy'], [angles[2], angles[2], angles[2]]): triangle_mode = 'x-axis=median-from-0' transform = compose_matrix(angles=angles, diff --git a/navipy/trajectories/test_trajectory.py b/navipy/trajectories/test_trajectory.py index 8640151..d8f74e8 100644 --- a/navipy/trajectories/test_trajectory.py +++ b/navipy/trajectories/test_trajectory.py @@ -20,7 +20,7 @@ class TestTrajectoryTransform(unittest.TestCase): markers.index.name = None # Create a random trajectory trajectory = Trajectory(indeces=np.arange(10), - rotconv='sxyz') + rotconv='xyz') trajectory.x = 100 * (np.random.rand(trajectory.shape[0]) - 0.5) trajectory.y = 100 * (np.random.rand(trajectory.shape[0]) - 0.5) trajectory.z = 100 * (np.random.rand(trajectory.shape[0]) - 0.5) @@ -32,12 +32,12 @@ class TestTrajectoryTransform(unittest.TestCase): (np.random.rand(trajectory.shape[0]) - 0.5) # Create test trajectory traj_test = Trajectory(indeces=np.arange(10), - rotconv='sxyz') + rotconv='xyz') # Devide by two the second anle, because of gimbal lock col = (trajectory.rotation_mode, 'alpha_1') trajectory.loc[:, col] = trajectory.loc[:, col] / 2 # forward - non_tested_euler = ['sxzy', 'sxzx', 'syxy', + non_tested_euler = ['xzy', 'xzx', 'yxy', 'rxzx', 'rxzy', 'ryxy'] print('EULER NOT TESTED!!: ', non_tested_euler) for euler_axes in list(htconst._AXES2TUPLE.keys()): diff --git a/navipy/trajectories/transformations.py b/navipy/trajectories/transformations.py index 9fcb694..e3d0631 100644 --- a/navipy/trajectories/transformations.py +++ b/navipy/trajectories/transformations.py @@ -231,9 +231,9 @@ rotation convention. The temporary rotation convention used two determine the euler angles are: - * szyx, for axis alignment x-axis - * szxy, for axis alignment y-axis - * syxz, for axis alignment z-axis + * zyx, for axis alignment x-axis + * zxy, for axis alignment y-axis + * yxz, for axis alignment z-axis Note: If you know the angle in your rotation convention, then you \ can run this function through a minimisation procedure with free parameter \ @@ -243,21 +243,21 @@ known angle until you get the desired orientation (see twomarkers2euler) vector = mark1 - mark0 vector = normalise_vec(vector) if axis_alignement == 'x-axis': - axes_convention = 'szyx' + axes_convention = 'zyx' beta = np.arcsin(vector.z) alpha = np.arctan2(-vector.y / np.cos(beta), vector.x / np.cos(beta)) gamma = known_angle angles = [alpha, beta, gamma] elif axis_alignement == 'y-axis': - axes_convention = 'szxy' + axes_convention = 'zxy' gamma = np.arcsin(-vector.z) alpha = np.arctan2(vector.x / np.cos(gamma), vector.y / np.cos(gamma)) beta = known_angle angles = [alpha, gamma, beta] elif axis_alignement == 'z-axis': - axes_convention = 'syxz' + axes_convention = 'yxz' gamma = np.arcsin(vector.y) beta = np.arctan2(-vector.x / np.cos(gamma), vector.z / np.cos(gamma)) -- GitLab