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