upxo.xtalphy.gb_disorientation_map module

Disorientation along the grain boundaries of a 2D orientation map.

The pixel grain map is converted to smooth boundary lines (UPXO’s geometrification, then smoothing of the boundary segments), and every line between two grains gets the disorientation angle of that pair, so a map can be drawn with the lines coloured by angle while the grains stay uncoloured.

Two steps, so the slow one is done once and the picture can be redrawn freely:

  1. compute_gb_disorientation() – geometrify, smooth, and find the disorientation of every boundary pair. Reports progress through upxo._sup.progress.

  2. upxo.viz.ebsd_maps.gb_disorientation_figure() – draw the result.

class upxo.xtalphy.gb_disorientation_map.GBDisorientation(segments: List[ndarray], angles: ndarray, pairs: ndarray, shape: tuple, n_grains: int, smooth_passes: int, max_smooth_levels: tuple, original_ids: ndarray = None)[source]

Bases: object

Smoothed boundary lines with their disorientation.

segments list of (n, 2) arrays of (x, y) in pixel units; pixel

centres are at integer coordinates (x = column, y = row).

angles disorientation of each segment in degrees; NaN for a line that

lies on the edge of the map and so separates one grain only.

pairs (n, 2) grain ids on either side (0 where there is no neighbour).

Ids refer to grain_ids after the 4-connected relabelling.

segments: List[ndarray]
angles: ndarray
pairs: ndarray
shape: tuple
n_grains: int
smooth_passes: int
max_smooth_levels: tuple
original_ids: ndarray = None
upxo.xtalphy.gb_disorientation_map.compute_gb_disorientation(lfi, quat, smooth_passes: int = 2, max_smooth_levels=(3, 3)) → GBDisorientation[source]
Parameters:
  • lfi ((ny, nx) int) – Grain label map with every pixel labelled (> 0).

  • quat ((ny, nx, 4)) – Per-pixel unit quaternions [w, x, y, z].

  • smooth_passes (int) – Smoothing passes over the boundary segments (1 or 2).

  • max_smooth_levels (sequence of int) – Smoothing level for each pass.

upxo.xtalphy.gb_disorientation_map.pair_disorientation_deg(R_all, index_a, index_b, chunk=1500)[source]

Disorientation (degrees, cubic symmetry) between grain index_a[k] and index_b[k] for every k, from rotation matrices R_all.

Works through the pairs in chunks of chunk to bound memory, and reports progress.

upxo.xtalphy.gb_disorientation_map.classify_boundaries(result: GBDisorientation, twin_ids) → ndarray[source]

Kind of every boundary segment: EDGE (lies on the map edge), GRAIN_GRAIN, TWIN_GRAIN or TWIN_TWIN.

twin_ids are labels of the input map that are twins; the relabelled pieces of a twin grain count as twins too.

upxo.xtalphy.gb_disorientation_map.segments_and_pairs_from_rings(rings)[source]

(segments, pairs) from a {gid: ring} dict, where each ring has a .segments list of smoothed boundary-segment objects produced by polygonised_grain_structure.smooth_gbsegs – an interior boundary’s segment is the SAME Python object on both owning grains’ rings, so grouping by id(segment) (object identity, not geometry) recovers exactly which grain(s) own each segment without any coordinate comparison. This is the numerically exact way to recover a shared grain boundary: unlike intersecting two independently-built polygon boundaries (which only coincide up to floating-point precision and so routinely fragments into scattered sub-pixel pieces, see ebsd_smoothing.disorientation_from_polygons’s own docstring), this never compares coordinates at all.

Returns:

  • segments (list of (n, 2) float arrays)

  • pairs ((n, 2) int array) – (gid_a, gid_b) for an interior boundary shared by two grains, (gid, 0) for one lying on the map edge (only one owner).