upxo.viz.ebsd_smoothing module
Smoothed grain-polygon construction for the pixellated/smoothed display of
EBSD maps – two independently-selectable
techniques. Both return {gid: shapely Polygon/MultiPolygon} and
grains, the integer label array the returned gids index into (NOT
necessarily the caller’s original lfi – Technique A relabels
disconnected pieces of the same crystallographic grain via
connected-components first, same as gb_disorientation_map.
compute_gb_disorientation already does internally; Technique B does not
relabel, so its grains is the input lfi unchanged). A caller that
needs a per-grain summary value (e.g. mean Euler angle for a smoothed
map) always computes it from this SAME returned grains array, so the
label spaces never need reconciling by hand.
Technique A: UPXO’s existing segment-based geometrification + boundary smoothing (
polygonised_grain_structure.smooth_gbsegs) – the exact computationgb_disorientation_map.compute_gb_disorientationalready does internally for its own boundary lines. Also returns the smoothed GB-segment data itself (gb_rings, a 3rd return value) so a caller building a GBDisorientation from these polygons can reuse the exact segment geometry instead of reconstructing it from the polygons.Technique B: Voronoi-tessellation-based smoothing (
geometrification.GrainManifold2D) – scatter seed points, Voronoi-tessellate, sample the label field at each seed, union same-label cells into one polygon per grain. Also returns the raw Voronoi ridge data between individual cells of different grain labels (gb_ridges, a 3rd return value, fromGrainManifold2D.grain_boundary_ridges()), captured BEFORE same- label cells are unioned together and any shared-edge precision is lost – numerically exact for the same reason Technique A’s gb_rings is, just one level earlier (at the raw Voronoi cell, not the smoothed boundary segment).
disorientation_from_polygons builds a GBDisorientation-compatible
result from either technique’s polygons, instead of
compute_gb_disorientation’s own from-scratch pixel-grid smoothing –
which lets a disorientation map reuse an already-computed smoothed
structure when the same technique was chosen for both, instead of
recomputing it. Pass
the matching technique’s own exact data (gb_rings= for Technique A,
gb_ridges= for Technique B) when available – otherwise it falls back
to polygon-boundary intersection, which is numerically fragile (see its
own docstring).
- upxo.viz.ebsd_smoothing.smooth_technique_a(lfi, smooth_passes=2, max_smooth_levels=(3, 3))[source]
({gid: shapely Polygon/MultiPolygon}, grains, gb_rings) via segment-based geometrification + boundary smoothing (Technique A) – mirrors gb_disorientation_map.compute_gb_disorientation’s own construction exactly, stopping short of the disorientation-angle step it doesn’t need here.
gb_rings is geom.smoothed[…][“GB”] – the SAME smoothed-boundary- segment data compute_gb_disorientation itself builds its exact (numerically precise, shared-by-object-identity) GBDisorientation segments from. Returned alongside the per-grain polygons so a caller building a GBDisorientation from this technique’s output (e.g. disorientation_from_polygons) can reuse that exact data too, instead of reconstructing each shared edge via polygon-boundary intersection – see disorientation_from_polygons’s own docstring for why that reconstruction is numerically fragile.
- upxo.viz.ebsd_smoothing.smooth_technique_b(lfi, seeds_per_grain=20, rng_seed=None)[source]
({gid: shapely Polygon/MultiPolygon}, grains, gb_ridges) via Voronoi tessellation + label-sampling + same-label union (Technique B).
grainshere islfiitself, unchanged – no relabelling.seeds_per_grain : average seed density, scaled by the grain count – total seeds = n_grains * seeds_per_grain, scattered uniformly at random over the whole map. More seeds per grain gives a closer approximation to the true pixel boundary; fewer gives a coarser, smoother one.
gb_ridges is manifold.grain_boundary_ridges() – the exact per-grain- pair boundary data from the raw Voronoi ridges, BEFORE same-label cells are unioned together and any shared-edge precision is lost. Returned alongside the per-grain polygons so a caller building a GBDisorientation from this technique’s output (e.g. disorientation_from_polygons) can reuse it instead of reconstructing each pair’s shared edge via polygon-boundary intersection – see disorientation_from_polygons’s own docstring for why that reconstruction is numerically fragile for Technique B specifically (no equivalent shared-segment data existed for it before this).
- upxo.viz.ebsd_smoothing.disorientation_from_polygons(polygons_by_gid, grains, quat, smooth_passes=0, max_smooth_levels=(), original_lfi=None, gb_rings=None, gb_ridges=None)[source]
A gb_disorientation_map.GBDisorientation built from a
{gid: polygon}dict (either smoothing technique) instead of compute_gb_disorientation’s own from-scratch pixel-grid smoothing, avoiding rebuilding the smoothed structure a second time.gb_rings : Technique A’s own smoothed GB-segment data (smooth_technique_a’s 3rd return value), when available. Used directly via gb_disorientation_map.segments_and_pairs_from_rings – numerically exact, since it groups the ALREADY-shared segment objects by identity rather than comparing coordinates.
gb_ridges : Technique B’s own exact per-grain-pair boundary data (smooth_technique_b’s 3rd return value, from GrainManifold2D.grain_boundary_ridges()), when available. Built from the raw Voronoi ridges between individual cells of different grain labels, BEFORE same-label cells are unioned together – numerically exact for the same reason gb_rings is: the two cells sharing a ridge index the SAME underlying Voronoi vertex array, so no coordinate comparison is needed to recover it.
When neither is supplied, falls back to reconstructing each pair’s shared edge via polygon-boundary intersection – one boundary segment per adjacent grain pair, coarser than gb_rings/gb_ridges’ own multi- segment boundaries, and (see _line_coords’s own docstring) numerically fragile; kept only for a caller with neither available.
grains : the SAME label array polygons_by_gid’s gids index into (smooth_technique_a/b’s second return value) – quat must be on that same (ny, nx, 4) grid.
original_lfi : the map’s ORIGINAL grain labels (Technique B: identical to grains, since it doesn’t relabel; Technique A: grains is a connected-components relabelling of this), needed so the result’s
original_ids– and therefore classify_boundaries/twin-vs-grain matching against original label ids – is correct for Technique A too, not just an identity passthrough. Omit only when the caller has no need to translate back to original ids.