upxo.pxtal.fm_steel_3d.slice_metrics_2d module
slice_metrics_2d.py
Fast numpy-only geometric metrics for a single 2-D labeled pixel slice (e.g. one cross-section extracted from a 3-D LGI). Mirrors the vectorised edge/vertex counting style of geom_metrics_3d.py, one dimension down.
All functions accept an integer ndarray slice2d of shape (H, W) where
each non-zero integer labels one grain, and 0 is void/background.
Return convention
All functions return 1-D ndarrays of length (max_label + 1) so that result[label] holds the value for that label (label 0 = void, always 0).
Counting conventions
area_npix : pixel count (trivial) perimeter_npix: number of pixel-edge pairs where this grain borders a
different label (both orientations)
n_neighbours : count of distinct edge-adjacent other labels n_tjp : number of pixel-corners (shared by 4 pixels) where >= 3
distinct labels meet – the 2-D analogue of a 3-D junction-point vertex, i.e. a triple junction point (TJP) in the plane of this slice. Only interior corners (all 4 neighbouring pixels exist) are considered, matching geom_metrics_3d.feature_junction_points’ convention.
- tjp_boundary_npixnumber of grain-boundary pixel-edges whose BOTH
endpoints are themselves TJP corners – i.e. boundary segments that run directly between two triple junction points, as opposed to grain-boundary length in general (see perimeter_npix for that).
Physical scaling
Caller multiplies by voxel_size^2, voxel_size, voxel_size^0 for area, perimeter/tjp_boundary length, and n_neighbours/n_tjp respectively.
- upxo.pxtal.fm_steel_3d.slice_metrics_2d.label_areas(slice2d: ndarray) ndarray[source]
Per-label pixel count. result[0] = void pixel count.
- upxo.pxtal.fm_steel_3d.slice_metrics_2d.label_aspect_ratio_bbox(slice2d: ndarray) ndarray[source]
Per-label 2-D aspect ratio from each label’s axis-aligned bounding box: max(extent) / min(extent) across the 2 in-plane pixel axes. Dimensionless (bounding-box extents scale identically on both axes for square pixels, so voxel_size cancels out) – same convention as twinned_simple_3d’s compute_aspect_ratio_bbox, one dimension down.
- upxo.pxtal.fm_steel_3d.slice_metrics_2d.label_perimeters(slice2d: ndarray) ndarray[source]
Per-label boundary-edge count (both pixel-edge orientations).
- upxo.pxtal.fm_steel_3d.slice_metrics_2d.label_neighbours(slice2d: ndarray) Dict[int, frozenset][source]
{label: frozenset(edge-adjacent neighbour labels)} – void (0) excluded from keys but may appear as a value (domain-boundary exposure).
- upxo.pxtal.fm_steel_3d.slice_metrics_2d.label_junction_points(slice2d: ndarray) ndarray[source]
Per-label triple-junction-point (TJP) count in this slice.
- upxo.pxtal.fm_steel_3d.slice_metrics_2d.label_tjp_boundary_length(slice2d: ndarray) ndarray[source]
Per-label count of grain-boundary pixel-edges whose two endpoint corners are BOTH triple junction points – i.e. boundary run directly between two TJPs, in pixel-length units.
- upxo.pxtal.fm_steel_3d.slice_metrics_2d.compute_slice_metrics(slice2d: ndarray, voxel_size: float = 1.0) Dict[str, ndarray][source]
Convenience wrapper: every per-label metric for this slice, physically scaled by voxel_size, plus derived circle-equivalent-diameter and circularity. Returns a dict of 1-D arrays, each index-aligned by label (index 0 = void, always 0/undefined).
- upxo.pxtal.fm_steel_3d.slice_metrics_2d.slice_metric_values(slice2d: ndarray, voxel_size: float = 1.0, key: str = 'circle_eq_dia') ndarray[source]
One value of metric
key(a key ofcompute_slice_metrics) for each label present in the slice, ordered by label; void is left out.
- upxo.pxtal.fm_steel_3d.slice_metrics_2d.pooled_slice_metric(lgi: ndarray, voxel_size: float, key: str, axes, n_per_axis: int) ndarray[source]
Metric
keypooled over evenly spaced slices of a 3-D label grid.- Parameters:
axes (iterable of 'X', 'Y', 'Z') – Axes the slices are normal to.
n_per_axis (int) – Slices per axis (at most the number of voxels along it); repeated indices are taken once.
- Returns:
ndarray of the values of every label present on every slice, concatenated
in the order of
axes; empty if no slice was taken.