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.

quatCoef
classmethod fromEulerAngles(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 fromAxisAngle(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

eulerAngles()[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)

rotMatrix()[source]

Calculate the rotation matrix representation for this rotation.

Returns

rotMatrix – 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

Calculate the conjugate of the quaternion.

Returns

Conjugate of quaternion.

Return type

defdap.quat.Quat

transformVector(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

misOri(right, symGroup, returnQuat=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.

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

  • returnQuat (Optional[int]) – 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.

misOriAxis(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

plotIPF(direction, symGroup, projection=None, plot=None, fig=None, ax=None, plotColourBar=False, clabel='', makeInteractive=False, markerColour=None, markerSize=40, **kwargs)[source]

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

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

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

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

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

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

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

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

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

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

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

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

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

Return type

plotting.PolePlot

plotUnitCell(crystalStructure, OI=True, plot=None, fig=None, ax=None, makeInteractive=False, **kwargs)[source]

Plots a unit cell.

Parameters
Return type

plotting.CrystalPlot

static createManyQuats(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 multiplyManyQuats(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.

Returns

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 calcSymEqvs(quats, symGroup, dtype=<class 'float'>)[source]

Calculate all symmetrically equivalent quaternions of given quaternions.

Parameters
Returns

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

Return type

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

static calcAverageOri(quatComps)[source]

Calculate the average orientation of given quats.

Parameters

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

Returns

avOri – Average orientation of input quaternions.

Return type

defdap.quat.Quat

static calcMisOri(quatComps, refOri)[source]

Calculate the misorientation between the quaternions and a reference quaternion.

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

  • refOri (Quat) – Reference orientation.

Return type

Tuple[ndarray, Quat]

Returns

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

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

static polarAngles(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 calcIPFcolours(quats, direction, symGroup, 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, numQuats)

References

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

static calcFundDirs(quats, direction, symGroup, 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.

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

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

Returns

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

Return type

float, float

static symEqv(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