ImageD11.forward_model.ori_converter module#

ImageD11.forward_model.ori_converter.axangle2u(axis, angle, is_normalized=False)#

Rotation matrix for rotation angle angle around axis

Parameters:
  • axis (3 element sequence) – vector specifying axis for rotation.

  • angle (scalar) – angle of rotation in radians.

  • is_normalized (bool, optional) – True if axis is already normalized (has norm of 1). Default False.

Returns:

mat – rotation matrix for specified rotation

Return type:

array shape (3,3)

Notes

From: http://en.wikipedia.org/wiki/Rotation_matrix#Axis_and_angle

ImageD11.forward_model.ori_converter.euler2quat(e)#

Convert Bunge ZXZ Euler angles to an active scalar-first quaternion. :param e: Euler triplet (phi1, Phi, phi2) in radians, as in euler2u.

Returns:

Unit quaternion (w, x, y, z) for crystal-to-sample rotation.

quat2u(q) equals euler2u(e), not its transpose.

Return type:

q

Notes

Euler angle conventions are taken from EMSoft.

ImageD11.forward_model.ori_converter.euler2u(e)#
ImageD11.forward_model.ori_converter.flip_up(q)#
ImageD11.forward_model.ori_converter.map_points_out(basis_points, basis_weights, superset, subset, map_indices)#
ImageD11.forward_model.ori_converter.multiply(r, a)#
ImageD11.forward_model.ori_converter.multiply_first_component(r, a)#
ImageD11.forward_model.ori_converter.quat2axangle(quat, identity_thresh=None)#

Convert quaternion to rotation of angle around axis

Parameters:
  • quat (4 element sequence) – w, x, y, z forming quaternion.

  • identity_thresh (None or scalar, optional) – Threshold below which the norm of the vector part of the quaternion (x, y, z) is deemed to be 0, leading to the identity rotation. None (the default) leads to a threshold estimated based on the precision of the input.

Returns:

  • theta (scalar) – angle of rotation.

  • vector (array shape (3,)) – axis around which rotation occurs.

Examples

>>> vec, theta = quat2axangle([0, 1, 0, 0])
>>> vec
array([1., 0., 0.])
>>> np.allclose(theta, np.pi)
True

If this is an identity rotation, we return a zero angle and an arbitrary vector:

>>> quat2axangle([1, 0, 0, 0])
(array([1., 0., 0.]), 0.0)

If any of the quaternion values are not finite, we return a NaN in the angle, and an arbitrary vector:

>>> quat2axangle([1, np.inf, 0, 0])
(array([1., 0., 0.]), nan)

Notes

A quaternion for which x, y, z are all equal to 0, is an identity rotation. In this case we return a 0 angle and an arbitrary vector, here [1, 0, 0].

The algorithm allows for quaternions that have not been normalized.

ImageD11.forward_model.ori_converter.quat2euler(q)#
ImageD11.forward_model.ori_converter.quat2rod(q)#
ImageD11.forward_model.ori_converter.quat2u(q)#
ImageD11.forward_model.ori_converter.random_quaternions(n)#
ImageD11.forward_model.ori_converter.rod2quat(r)#
ImageD11.forward_model.ori_converter.rotate_into_fundamental_zone(q, generators)#
ImageD11.forward_model.ori_converter.u2euler(mat, axes='rzxz')#

Return Euler angles from rotation matrix for specified axis sequence in [0, 360] degrees.

Note that many Euler angle triplets can describe one matrix.

Parameters:
  • mat (array-like shape (3, 3) or (4, 4)) – Rotation matrix or affine.

  • axes (str, optional) – Axis specification; one of 24 axis sequences as string or encoded tuple - e.g. sxyz (the default).

Returns:

  • ai (float) – First rotation angle (according to axes).

  • aj (float) – Second rotation angle (according to axes).

  • ak (float) – Third rotation angle (according to axes).

Examples

>>> R0 = euler2mat(1, 2, 3, 'syxz')
>>> al, be, ga = mat2euler(R0, 'syxz')
>>> R1 = euler2mat(al, be, ga, 'syxz')
>>> np.allclose(R0, R1)
True
ImageD11.forward_model.ori_converter.u2quat(u)#