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:
compute_gb_disorientation()– geometrify, smooth, and find the disorientation of every boundary pair. Reports progress throughupxo._sup.progress.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:
objectSmoothed 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_idsafter the 4-connected relabelling.
- segments list of (n, 2) arrays of
- upxo.xtalphy.gb_disorientation_map.compute_gb_disorientation(lfi, quat, smooth_passes: int = 2, max_smooth_levels=(3, 3)) GBDisorientation[source]
- 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]andindex_b[k]for every k, from rotation matricesR_all.Works through the pairs in chunks of
chunkto 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_GRAINorTWIN_TWIN.twin_idsare 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.segmentslist of smoothed boundary-segment objects produced bypolygonised_grain_structure.smooth_gbsegs– an interior boundary’s segment is the SAME Python object on both owning grains’ rings, so grouping byid(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, seeebsd_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).