defdap.quat module

class defdap.quat.Quat(*args, allow_southern=False)[source]

Bases: object

Class used to define and perform operations on quaternions. These are interpreted in the passive sense.

quat_coef
classmethod from_euler_angles(ph1, phi, ph2)[source]

Create a quat object from 3 Bunge euler angles.

Parameters:
  • ph1 (float) – First Euler angle, rotation around Z in radians.

  • phi (float) – Second Euler angle, rotation around new X in radians.

  • ph2 (float) – Third Euler angle, rotation around new Z in radians.

Returns:

Initialised Quat object.

Return type:

defdap.quat.Quat

classmethod from_axis_angle(axis, angle)[source]

Create a quat object from a rotation around an axis. This creates a quaternion to represent the passive rotation (-ve axis).

Parameters:
  • axis (ndarray) – Axis that the rotation is applied around.

  • angle (float) – Magnitude of rotation in radians.

Returns:

Initialised Quat object.

Return type:

defdap.quat.Quat

euler_angles()[source]

Calculate the Euler angle representation for this rotation.

Returns:

eulers – Bunge euler angles (in radians).

Return type:

numpy.ndarray, shape 3

References

Melcher A. et al., ‘Conversion of EBSD data by a quaternion based algorithm to be used for grain structure simulations’, Technische Mechanik, 30(4)401 – 413

Rowenhorst D. et al., ‘Consistent representations of and conversions between 3D rotations’, Model. Simul. Mater. Sci. Eng., 23(8)

rot_matrix()[source]

Calculate the rotation matrix representation for this rotation.

Returns:

rot_matrix – Rotation matrix.

Return type:

numpy.ndarray, shape (3, 3)

References

Melcher A. et al., ‘Conversion of EBSD data by a quaternion based algorithm to be used for grain structure simulations’, Technische Mechanik, 30(4)401 – 413

Rowenhorst D. et al., ‘Consistent representations of and conversions between 3D rotations’, Model. Simul. Mater. Sci. Eng., 23(8)

dot(right)[source]

Calculate dot product between two quaternions.

Parameters:

right (Quat) – Right hand quaternion.

Returns:

Dot product.

Return type:

float

norm()[source]

Calculate the norm of the quaternion.

Returns:

Norm of the quaternion.

Return type:

float

normalise()[source]

Normalise the quaternion (turn it into an unit quaternion).

Returns:

Normalised quaternion.

Return type:

defdap.quat.Quat

property conjugate: Quat

Calculate the conjugate of the quaternion.

Returns:

Conjugate of quaternion.

Return type:

defdap.quat.Quat

transform_vector(vector)[source]

Transforms vector by the quaternion. For passive EBSD quaterions this is a transformation from sample space to crystal space. Perform on conjugate of quaternion for crystal to sample. For a quaternion representing a passive rotation from CS1 to CS2 and a fixed vector V defined in CS1, this gives the coordinates of V in CS2.

Parameters:

vector (numpy.ndarray, shape 3 or equivalent) – Vector to transform.

Returns:

Transformed vector.

Return type:

numpy.ndarray, shape 3

mis_ori(right, sym_group, return_quat=0)[source]

Calculate misorientation angle between 2 orientations taking into account the symmetries of the crystal structure. Angle is 2*arccos(output).

Parameters:
  • right (Quat) – Orientation to find misorientation to.

  • sym_group (str) – Crystal type (cubic, hexagonal).

  • return_quat (Optional[int, None]) – What to return: 0 for minimum misorientation, 1 for symmetric equivalent with minimum misorientation, 2 for both.

Return type:

Tuple[float, Quat]

Returns:

  • float – Minimum misorientation.

  • defdap.quat.Quat – Symmetric equivalent orientation with minimum misorientation.

mis_ori_axis(right)[source]

Calculate misorientation axis between 2 orientations. This does not consider symmetries of the crystal structure.

Parameters:

right (defdap.quat.Quat) – Orientation to find misorientation axis to.

Returns:

Axis of misorientation.

Return type:

numpy.ndarray, shape 3

plot_ipf(direction, sym_group, projection=None, plot=None, fig=None, ax=None, plot_colour_bar=False, clabel='', make_interactive=False, marker_colour=None, marker_size=40, **kwargs)[source]

Plot IPF of orientation, with relation to specified sample direction.

Parameters:
  • direction (ndarray) – Sample reference direction for IPF.

  • sym_group (str) – Crystal type (cubic, hexagonal).

  • projection (Optional[str, None]) – Projection to use. Either string (stereographic or lambert) or a function.

  • plot (Optional[ForwardRef, None]) – Defdap plot to plot on.

  • fig (Optional[ForwardRef, None]) – Figure to plot on, if not provided the current active axis is used.

  • ax (Optional[ForwardRef, None]) – Axis to plot on, if not provided the current active axis is used.

  • make_interactive (Optional[bool, None]) – If true, make the plot interactive.

  • plot_colour_bar (bool) – If true, plot a colour bar next to the map.

  • clabel (str) – Label for the colour bar.

  • marker_colour (str or list of str) – Colour of markers (only used for half and half colouring, otherwise use argument c).

  • marker_size (Optional[float, None]) – Size of markers (only used for half and half colouring, otherwise use argument s).

  • kwargs – All other arguments are passed to defdap.plotting.PolePlot.add_points().

Return type:

plotting.PolePlot

plot_unit_cell(crystal_structure, OI=True, plot=None, fig=None, ax=None, make_interactive=False, **kwargs)[source]

Plots a unit cell.

Parameters:
Return type:

plotting.CrystalPlot

static create_many_quats(eulerArray)[source]

Create a an array of quats from an array of Euler angles.

Parameters:

eulerArray (ndarray) – Array of Bunge Euler angles of shape 3 x n x … x m.

Returns:

quats – Array of quat objects of shape n x … x m.

Return type:

numpy.ndarray(defdap.quat.Quat)

static multiply_many_quats(quats, right)[source]

Multiply all quats in a list of quats, by a single quat.

Parameters:
  • quats (List[Quat]) – List of quats to be operated on.

  • right (Quat) – Single quaternion to multiply with the list of quats.

Return type:

list(defdap.quat.Quat)

static extract_quat_comps(quats)[source]

Return a NumPy array of the provided quaternion components

Input quaternions may be given as a list of Quat objects or any iterable whose items have 4 components which map to the quaternion.

Parameters:

quats (numpy.ndarray(defdap.quat.Quat)) – A list of Quat objects to return the components of

Returns:

Array of quaternion components, shape (4, ..)

Return type:

numpy.ndarray

static calc_sym_eqvs(quats, sym_group, dtype=<class 'float'>)[source]

Calculate all symmetrically equivalent quaternions of given quaternions.

Parameters:
Returns:

quat_comps – Array containing all symmetrically equivalent quaternion components of input quaternions.

Return type:

numpy.ndarray, shape: (numSym x 4 x numQuats)

static calc_average_ori(quat_comps)[source]

Calculate the average orientation of given quats.

Parameters:

quat_comps (numpy.ndarray) – Array containing all symmetrically equivalent quaternion components of given quaternions (shape: numSym x 4 x numQuats), can be calculated with Quat.calc_sym_eqvs().

Returns:

av_ori – Average orientation of input quaternions.

Return type:

defdap.quat.Quat

static calcMisOri(quat_comps, ref_ori)[source]

Calculate the misorientation between the quaternions and a reference quaternion.

Parameters:
  • quat_comps (ndarray) – Array containing all symmetrically equivalent quaternion components of given quaternions (shape: numSym x 4 x numQuats), can be calculated from quats with Quat.calc_sym_eqvs() .

  • ref_ori (Quat) – Reference orientation.

Return type:

Tuple[ndarray, Quat]

Returns:

  • min_mis_oris (numpy.ndarray, len numQuats) – Minimum misorientation between quats and reference orientation.

  • min_quat_comps (defdap.quat.Quat) – Quaternion components describing minimum misorientation between quats and reference orientation.

static polar_angles(x, y, z)[source]

Convert Cartesian coordinates to polar coordinates, for an unit vector.

Parameters:
Returns:

inclination angle and azimuthal angle (around z axis from x in anticlockwise as per ISO).

Return type:

float, float

static calc_ipf_colours(quats, direction, sym_group, dtype=<class 'numpy.float32'>)[source]

Calculate the RGB colours, based on the location of the given quats on the fundamental region of the IPF for the sample direction specified.

Parameters:
Returns:

Array of rgb colours for each quat.

Return type:

numpy.ndarray, shape (3, num_quats)

References

Stephen Cluff (BYU) - IPF_rgbcalc.m subroutine in OpenXY https://github.com/BYU-MicrostructureOfMaterials/OpenXY/blob/master/Code/PlotIPF.m

static calc_fund_dirs(quats, direction, sym_group, dtype=<class 'float'>)[source]

Transform the sample direction to crystal coords based on the quats and find the ones in the fundamental sector of the IPF.

Parameters:
  • quats (array_like(defdap.quat.Quat)) – Array of quat objects.

  • direction (ndarray) – Direction in sample space.

  • sym_group (str) – Crystal type (cubic, hexagonal).

  • dtype (Optional[type, None]) – Data type to use for calculation.

Returns:

inclination angle and azimuthal angle (around z axis from x in anticlockwise).

Return type:

float, float

static sym_eqv(symGroup)[source]

Returns all symmetric equivalents for a given crystal type. LEGACY: move to use symmetries defined in crystal structures

Parameters:

symGroup (str) – Crystal type (cubic, hexagonal).

Returns:

Symmetrically equivalent quats.

Return type:

list of defdap.quat.Quat