Code reference

EBSD class: read, analyze and plot EBSD maps

class ebsdlab.ebsd.EBSD(fileName: str | Path, symmetry: str = '')

Bases: object

Class to allow for read EBSD data

addScaleBar(fileName: str = '', site: str = 'BL', barLength: float | None = None, alpha: float = 0.5) → Any

Add scale-bar to image

Parameters:
  • fileName – if given, save to file

  • site – where to put the scale bar: bottom-left “BL” (default), bottom-right “BR”, top-left “TL”, top-right “TR”

  • barLength – length of scale bar. It is calculated if not given

  • alpha – transparency of scale bar background

Returns:

matplotlib figure

addScaleBarOverlay(ax: Any, barLength: float | None = None, site: str = 'lower left') → Any

Add a scale bar to an existing map axis.

Unlike addScaleBar(), this preserves the supplied Matplotlib figure and is therefore suitable for interactive applications.

Parameters:
  • ax – Matplotlib axis containing an EBSD map in micrometres.

  • barLength – scale-bar length in micrometres; calculated if omitted.

  • site – Matplotlib anchored-artists location, e.g. "lower left".

Returns:

scale bar artist

addSymbol(x: float, y: float, fileName: str = '', scale: float = 1.0, colorCube: str = 'black') → None

TODO: use version in ebsd_Orientation Add symbol of crystal orientation (symmetry and rotation) to IPF at given location

Parameters:
  • x – x-coordinate

  • y – y-coordinate

  • fileName – export to file

  • scale – scale of symbol

  • colorCube – color of symbol

addUnitCellOverlay(ax: Any, x: float, y: float, scale: float = 1.0, colorCube: str = 'black') → int

Draw the nearest orientation’s unit cell onto an existing IPF axis.

This is the composable counterpart to addSymbol(). It is useful for applications which manage the figure themselves, such as the GUI.

Parameters:
  • ax – matplotlib axis containing the IPF map

  • x – x-coordinate in [um]

  • y – y-coordinate in [um]

  • scale – scale of unit cell

  • colorCube – color of unit cell

Returns:

index of the point whose orientation is drawn

calcGrains(tolerance: float = 5.0, minSize: int = 6, minNRows: int = 2) → None

identify grains: neighbors of one phase that are indexed and misoriented less than tolerance are linked; grains are the connected regions. grainID is 1, 2, …; 0 = unindexed or grain too small.

Parameters:
  • tolerance – maximum misorientation of neighbors in a grain in degrees

  • minSize – minimum number of points of a grain

  • minNRows – minimum number of rows and of columns a grain spans

calcKAM() → None

calculate Kernel Average Misorientation in DEGREES (because user focused) from the nearest neighbors

cropVMask(xmin: float | None = None, ymin: float | None = None, xmax: float | None = None, ymax: float | None = None) → None

crop visible area

Parameters:
  • xmin – minimum x-coordinate

  • ymin – minimum y-coordinate

  • xmax – maximum x-coordinate

  • ymax – maximum y-coordinate

grainDilation() → None

fill points without grain (grainID 0) from the neighbors, in place (reload to undo); runs calcGrains with default arguments if it has not run. A point joins the grain of the majority of its neighbors that have a grain and takes phase, orientation, CI and mask of the neighbor with the highest CI among them; this also decides ties. Repeat until nothing changes. Changed points are True in self.cleaned.

maskCI(ci: float) → None

masked all points off, which have a CI less than: good points=False, bad points=True

Parameters:

ci – critical CI

maskReset() → None

reset mask

nearestIndex(x: Any, y: Any) → ndarray

Index of the grid point closest to x, y: row from y, then column within that row from x

Parameters:
  • x – x-coordinate(s) in [um]; broadcast with y

  • y – y-coordinate(s) in [um]

Returns:

point indices, of the broadcast shape of x and y

neighbors() → ndarray

identify the nearest neighboring indexes of all points

Returns:

array of neighbors; invalid points have a value=-10

plot(vector: ndarray, widthPixel: int | None = None, vmax: float | None = None, vmin: float | None = None, cmap: Any = None, show: bool = True, cbar: bool = True) → Any

given a class-vector, plot the vector as an image

Parameters:
  • vector – vector to be plotted as a 2D image

  • widthPixel – rescale to horizontal size of the image [default: optimal pixel width]

  • vmax – rescale z-scale to maximal value

  • vmin – rescale z-scale to minimal value

  • cmap – colormap [default: Spectral with masked points in black]

  • show – show the figure

  • cbar – add a colorbar

Returns:

matplotlib figure

plotIPF(direction: str | int = 'ND', widthPixel: int | None = None, fileName: str = '', show: bool = True) → Any

plot Inverse Pole Figure (IPF)

Parameters:
  • direction – default..”ND”, “RD”, “TD”; a number is used as widthPixel with “ND”

  • widthPixel – horizontal size of the image [default: optimal size based on data]

  • fileName – save to file instead of showing

  • show – show the figure if no fileName is given

Returns:

matplotlib figure

plotPF(axis: Any = (1, 0, 0), points: bool = False, fileName: str = '', color: str = '#1f77b4', alpha: float = 1.0, show: bool = True, density: int = 256, size: int = 2, vmin: float = 0.0, vmax: float | None = None, width: float = 5.0) → Any

plot pole figure, oriented as the map: X right, Y down, seen from above the sample (upper hemisphere -Z)

The distribution is a pole density function in multiples of a random distribution (mrd): the poles are binned on an equal-area grid, smoothed with a von Mises-Fisher kernel on the sphere and then projected.

Parameters:
  • axis – axis to plot: default: axis=1,0,0

  • points – plot individual points, or plot distribution [default]

  • fileName – if given, save to file

  • color – plot color

  • alpha – alpha transparency

  • show – show figure [default], False for subsequent plotting

  • density – distribution: size of the image in pixels

  • size – points: point size

  • vmin – distribution: lower values [mrd] are transparent

  • vmax – distribution: maximum of the color scale [mrd]; default: maximum of the data

  • width – distribution: half width of the kernel in degrees

Returns:

matplotlib figure

plotRGB(rgb: ndarray, widthPixel: int | None = None) → Any

given a RGB vector (same size as the other class vectors) plot the vector as an image

Parameters:
  • rgb – matrix [3, classVectorSize] to be plotted as a 2D image

  • widthPixel – horizontal size of the image [default: optimal pixel width]

Returns:

matplotlib figure

removePointsOutsideMask() → None

Set points outside the mask invalid so they are read as nonexistent by OIM after export

setGrid(x: ndarray, y: ndarray) → None

Derive grid parameters from the coordinates; the coordinates themselves are not stored. If the points are unordered, partial (e.g. partition exports) or a single row, self._gridIndex is the grid position of each point; __init__ then places all per-point data onto the full grid.

Parameters:
  • x – x-coordinates of all points

  • y – y-coordinates of all points

setVMask(every: int = 1) → None

fast preview, does not influence results in any way: maps show only every k-th row and column (at any image size), pole figures use every k-th point.

Parameters:

every – use only every k-th point. Improves plotting speed. every=1 resets.

writeANG(fileName: str) → None

WRAPPER: write body of ang file

Parameters:

fileName – file name

property x: ndarray

x-coordinates of all points

Returns:

x-coordinates in [um]

xy(idx: Any = None) → tuple[ndarray, ndarray]

x- and y-coordinates of points, computed from the grid parameters

Parameters:

idx – point indices [if None: all points]

Returns:

x, y

property y: ndarray

y-coordinates of all points

Returns:

y-coordinates in [um]

Orientation class: combination of material symmetry and specific rotation.

Attribution: initial version was part of DAMASK <damask.mpie.de> (Martin Diehl, Philip Eisenlohr, Franz Roters)

class ebsdlab.orientation.Orientation(quaternion: Rotation | None = None, matrix: ndarray | None = None, eulers: ndarray | None = None, random: bool | int = False, symmetry: str = '')

Bases: object

Orientation class: combination of material symmetry and specific rotation

asEulers(degrees: bool = False, standardRange: bool = False) → ndarray

Return this orientation’s Bunge (intrinsic ZXZ) Euler angles.

Parameters:
  • degrees – return degrees instead of radians

  • standardRange – map phi1 and phi2 into [0, 2pi)

Returns:

Euler angles (phi1, Phi, phi2)

asMatrix() → ndarray

Return this orientation as a 3-by-3 rotation matrix.

Returns:

rotation matrix

classmethod average(orientations: list[Orientation], multiplicity: Any = None) → Orientation

Return the average orientation

ref: F. Landis Markley, Yang Cheng, John Lucas Crassidis, and Yaakov Oshman,

Averaging Quaternions, Journal of Guidance, Control, and Dynamics, Vol. 30, No. 4 (2007), pp. 1193-1197. doi: 10.2514/1.28949

Usage:
  • a = Orientation(eulers=np.radians([10, 10, 0]), symmetry=’hexagonal’)

  • b = Orientation(eulers=np.radians([20, 0, 0]), symmetry=’hexagonal’)

  • avg = Orientation.average([a,b])

Parameters:
  • cls – class method (void)

  • orientations – list of orientations

  • multiplicity –

    –

Returns:

average orientation (not rotation) in radians

disorientation(other: Orientation, sst: bool = True) → tuple[Orientation, int, int, bool]

Disorientation between myself and given other orientation.

Rotation axis falls into SST if SST == True.

(Currently requires same symmetry for both orientations. Look into A. Heinz and P. Neumann 1991 for cases with differing sym.)

Args:

other: other orientation sst: True (rotation axis falls into SST); False

Returns:

disorientation quaternion; indices of equivalent orientations; and whether the result was conjugated

eps
equivalentOrientations(who: Any = None) → list[Orientation]

Return symmetry-equivalent orientations, optionally selected by index.

Parameters:

who – indices of the symmetry operations [default: all]

Returns:

equivalent orientations

equivalentQuaternions(who: Any = None) → list[Rotation]

Return symmetry-equivalent quaternions, optionally selected by index.

Parameters:

who – indices of the symmetry operations [default: all]

Returns:

equivalent rotations

inFZ() → bool

Check whether given Rodrigues vector falls into fundamental zone of own symmetry.

Returns:

True if inside the fundamental zone

inversePole(axis: Any, proper: bool = False, sst: bool = True) → tuple[ndarray, int]

Rotate an axis into the standard stereographic triangle using symmetry.

Parameters:
  • axis – vector in crystal orientation, e.g. [100]

  • proper – consider only vectors with z >= 0 using two neighboring SSTs; this permits more positive results without changing the RGB value

  • sst – iterate through all equivalent and find the one in the SST

Returns:

vector of axis; index of the used symmetry operation

ipfColor(axis: Any, proper: bool = False) → ndarray

color of inverse pole figure for given axis

Parameters:
  • axis – axis of pole figure (ND=001)

  • proper – consider vectors with z >= 0 using two neighboring SSTs; this permits more positive results without changing the RGB value

Returns:

vector of color (rgb)

plot(poles: Any = None, unitCell: bool = True, cos: bool = True, annotate: bool = False, plot2D: str = '', scale: float = 2, fileName: str = '') → None

Plot rotated unit-cell in 3D, and possibly the pole-figure and specific poles

Projection onto 2D: cooradinate systems are given as xDirection-yDirection (z follows) - right-down: [default, as maps and pole figures] RD = x = right; TD = y = down; ND = z = intoPlane - down-right: [default in text books] RD = x = down; TD = y = right; ND = z = outOfPlane - up-left: [default in OIM] RD = x = up; TD = y = left; ND = z = outOfPlane

Parameters:
  • poles – if given (e.g. [1,0,0]), plot pole-figure and the corresponding poles

  • unitCell – plot unit cell

  • cos – plot coordinate system

  • annotate – annotate poles in pole figure (requires poles given)

  • plot2D – do a normal projection onto 2D plane: [right-down, down-right, up-left, right-up, left-down, 3D]; ‘’ keeps the current setting

  • scale – scale of pole-figure dome over crystal

  • fileName – fileName for image output (if given, image not shown)

plot2D
plotLine(ax: Any, start: Any, delta: Any, color: str = 'k', lw: float = 1, ls: str = 'solid', markerSize: float | None = None) → None

Plot one line using given projection

Parameters:
  • ax – axis to plot into

  • start – start coordinate

  • delta – delta cooradinate (end-start)

  • color – color

  • lw – line width

  • ls – line style “solid”,’dashed’

  • markerSize – size of marker (only used for non-lines: delta>0)

plotUnit(ax: Any, xlabel: str, ylabel: str, zlabel: str, x: float = 0, y: float = 0, z: float = 0, s: float = 1, view: Rotation | None = None) → None

Coordinate systems: see plotLine

Parameters:
  • ax – axis to used for plotting

  • xlabel – x-label

  • ylabel – y-label

  • zlabel – z-label

  • x – x-coordinate of origin

  • y – y-coordinate of origin

  • z – z-coordinate of origin

  • s – scale

  • view – rotation of the axes into the plotted frame [default: none]

project(x: Any, y: Any, z: Any) → tuple[ndarray, ...]

Project 3D coordinates onto the 2D plot plane given by self.plot2D

right-down : x, y (after the 180° turn about X in plot) down-right : y, -x up-left : -y, x right-up : x,y left-down : -x,-y 3D : x,y,z

Parameters:
  • x – x-coordinate(s)

  • y – y-coordinate(s)

  • z – z-coordinate(s)

Returns:

two arrays; three for “3D”

Return type:

projected coordinates

quaternion
reduced() → Orientation

Transform orientation to fall into fundamental zone according to symmetry

Returns:

equivalent orientation inside the fundamental zone

symmetry
toScreen(equivalent: bool = True) → None

print Euler angles and HKL /UVW

Parameters:

equivalent – print also equivalent orientations

Crystal symmetry operations and visualization helpers.

class ebsdlab.symmetry.Symmetry(symmetry: str = '')

Bases: object

Material symmetry identified by a human-readable lattice name.

equivalentQuaternions(quaternion: Rotation, who: Any = None) → list[Rotation]

Return rotations equivalent to quaternion under this symmetry.

Parameters:
  • quaternion – rotation

  • who – indices of the symmetry operations [default: all]

Returns:

equivalent rotations

foldIntoSST(vectors: ndarray) → ndarray

Map directions onto their symmetry-equivalent direction in the standard triangle.

Same result as trying all symmetryQuats() with inSST(proper=False), which includes inversion, but without the loop: the Laue group is applied directly by sign changes, sorting and an azimuthal fold.

Parameters:

vectors – directions (3, n)

Returns:

folded directions (3, n)

inDisorientationSST(rotation: Rotation) → bool

Return whether a misorientation lies in the standard triangle.

The criteria follow Heinz and Neumann, Acta Cryst. A47 (1991), 780-789.

Parameters:

rotation – misorientation to test

Returns:

True if inside the standard triangle

inFZ(rotation: Rotation) → bool

Return whether a rotation lies in the fundamental zone (FZ)

Parameters:

rotation – rotation to test

Returns:

True if inside the fundamental zone

inSST(vector: Any, proper: bool = False, color: bool = False) → Any

Test vectors against the standard triangle and optionally color them.

proper also considers the neighboring proper triangle. With color=True, return the membership flags and IPF colors as RGB values.

Parameters:
  • vector – one vector (3,) or several vectors (3, n)

  • proper – also consider the neighboring proper triangle

  • color – also return IPF colors

Returns:

(flags, RGB colors of shape (3,) or (3, n))

Return type:

membership flag(s); with color

standardTriangle(fileName: str = '', show: bool = True, stepSize: float = 0.1) → Any

Plot the colored cubic standard stereographic triangle.

Parameters:
  • fileName – if given, save to file

  • show – show the figure

  • stepSize – spacing of the colored points

Returns:

matplotlib figure; None if the lattice is not cubic

symmetryQuats(who: Any = None) → Rotation

Return the proper symmetry rotations, with identity at index zero.

Parameters:

who – indices of the operations to return [default: all]

Returns:

symmetry rotations

unitCell(*, a: float = 1.0, b: float | None = None, c: float | None = None, alpha: float | None = None, beta: float | None = None, gamma: float | None = None) → ndarray | list[list[None]]

Return centered unit-cell edges as [x1, y1, z1, x2, y2, z2].

Parameters:
  • a – lattice constant a

  • b – lattice constant b [default: from the lattice’s default ratio]

  • c – lattice constant c [default: from the lattice’s default ratio]

  • alpha – lattice angle in degrees [default: lattice default]

  • beta – lattice angle in degrees [default: lattice default]

  • gamma – lattice angle in degrees [default: lattice default]

Returns:

edges, one row per edge; [[None]] for an unknown lattice

unitCellSegments(rotation: Rotation, scale: float = 1.0) → list[tuple[ndarray, ndarray, float]]

Return the rotated unit-cell edges, split where they cross z=0.

Parameters:
  • rotation – orientation of the unit cell

  • scale – scale of the unit cell

Returns:

2 above z=0, 0.2 below

Return type:

segments as (start, end, line width)

xyToHKL(inPlane: Any) → ndarray | None

Convert cubic stereographic-plane coordinates to HKL vectors.

Parameters:

inPlane – coordinates (2,) or (2, n) in the stereographic plane

Returns:

HKL vectors (3,) or (3, n); None if the lattice is not cubic

ebsdlab.symmetry.showOrSave(fileName: str = '', show: bool = True) → None

Save the current figure to a file, or else show it.

Parameters:
  • fileName – if given, save to this file and close the figure

  • show – show the figure if no fileName is given