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:
- Returns:
Initialised Quat object.
- Return type:
- 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:
- Returns:
Initialised Quat object.
- Return type:
- 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)
- normalise()[source]¶
Normalise the quaternion (turn it into an unit quaternion).
- Returns:
Normalised quaternion.
- Return type:
- property conjugate: Quat¶
Calculate the conjugate of the quaternion.
- Returns:
Conjugate of quaternion.
- Return type:
- 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:
- Return type:
- 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:
- plot_unit_cell(crystal_structure, OI=True, plot=None, fig=None, ax=None, make_interactive=False, **kwargs)[source]¶
Plots a unit cell.
- Parameters:
crystal_structure (defdap.crystal.CrystalStructure) – Crystal structure.
OI (
Optional
[bool
,None
]) – True if using oxford instruments system.plot (
Optional
[ForwardRef
,None
]) – Plot object to plot to.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
]) – True to make the plot interactive.kwargs – All other arguments are passed to
defdap.plotting.CrystalPlot.add_verts()
.
- Return type:
- 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:
- static multiply_many_quats(quats, right)[source]¶
Multiply all quats in a list of quats, by a single quat.
- Parameters:
- Return type:
- 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:
- static calc_sym_eqvs(quats, sym_group, dtype=<class 'float'>)[source]¶
Calculate all symmetrically equivalent quaternions of given quaternions.
- Parameters:
quats (numpy.ndarray(defdap.quat.Quat)) – Array of quat objects.
sym_group (
str
) – Crystal type (cubic, hexagonal).dtype (
Optional
[type
,None
]) – Datatype used for calculation, defaults to float.
- 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:
- 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 withQuat.calc_sym_eqvs()
.ref_ori (
Quat
) – Reference orientation.
- Return type:
- 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:
x (numpy.ndarray(float)) – x coordinate.
y (numpy.ndarray(float)) – y coordinate.
z (numpy.ndarray(float)) – z coordinate.
- Returns:
inclination angle and azimuthal angle (around z axis from x in anticlockwise as per ISO).
- Return type:
- 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:
quats (numpy.ndarray(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:
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:
- Returns:
inclination angle and azimuthal angle (around z axis from x in anticlockwise).
- Return type: