upxo.pxtal.fm_steel_3d.geom_metrics_3d module
geom_metrics_3d.py
Fast numpy-only geometric metrics for 3-D labeled voxel arrays (LGI).
All functions accept an integer ndarray lgi of shape (NX, NY, NZ) where each non-zero integer labels one closed-cell feature, 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). This makes downstream indexing by label direct and branch-free.
Counting conventions
vol_nvox : voxel count (trivial) surf_nfaces : number of voxel-face pairs where this feature borders a
different label (including void=0, so domain-boundary exposure is included in surface area)
- jl_nedgesnumber of voxel-edges (one edge = one unit-length segment)
where ≥3 distinct labels meet among the 4 adjacent voxels
- jp_nvertsnumber of voxel-vertices (one vertex shared by 8 voxels)
where ≥3 distinct labels meet — each such vertex corresponds to a junction point on the real microstructure
Physical scaling
Caller multiplies by voxel_size^3, voxel_size^2, voxel_size, voxel_size^0 for vol, surf, jl, jp respectively.
- upxo.pxtal.fm_steel_3d.geom_metrics_3d.feature_volumes(lgi: ndarray) ndarray[source]
Per-feature voxel count.
- Returns:
result[label] = voxel count for that label. result[0] = number of void voxels.
- Return type:
ndarray, shape (max_label + 1,), dtype int64
- upxo.pxtal.fm_steel_3d.geom_metrics_3d.feature_surface_faces(lgi: ndarray) ndarray[source]
Per-feature boundary-face count including domain-boundary exposure.
The LGI is padded by one void (0) layer on every face before counting so that voxels at the domain boundary accumulate faces against the padding, giving the correct total surface area even for truncated features.
- Return type:
ndarray, shape (max_label + 1,), dtype int64
- upxo.pxtal.fm_steel_3d.geom_metrics_3d.feature_neighbours(lgi: ndarray) Dict[int, frozenset][source]
Face-adjacent neighbour IDs for every non-void feature.
- Returns:
dict {label – Void (0) is excluded from dict keys, but may appear as a value to signal that the feature touches the domain boundary. Callers that only want real-feature neighbours should filter
{nb for nb in nbs if nb != 0}.- Return type:
frozenset(neighbour_labels)}
- upxo.pxtal.fm_steel_3d.geom_metrics_3d.feature_junction_line_edges(lgi: ndarray) ndarray[source]
Per-feature triple-line edge count.
A triple-line edge (one voxel-edge length) has ≥3 distinct labels among its 4 adjacent voxels. The count for a feature is the number of such edges where it is one of the participating labels.
Three edge directions (x-, y-, z-parallel) are each enumerated.
- Return type:
ndarray, shape (max_label + 1,), dtype int64
- upxo.pxtal.fm_steel_3d.geom_metrics_3d.feature_junction_points(lgi: ndarray) ndarray[source]
Per-feature junction-point vertex count.
A junction-point vertex (shared by 8 voxels) has ≥3 distinct labels among those 8 voxels. Only interior vertices (all 8 neighbours exist) are considered. Each feature is counted once per vertex it participates in.
- Return type:
ndarray, shape (max_label + 1,), dtype int64
- upxo.pxtal.fm_steel_3d.geom_metrics_3d.junction_line_segments(lgi: ndarray, voxel_size: float = 1.0) Tuple[ndarray, ndarray][source]
Extract the 3-D vertex coordinates of every triple-line edge segment.
A triple-line edge (one voxel-edge in length) has ≥3 distinct labels among its 4 adjacent voxels. All 3 edge directions are enumerated.
Coordinate convention
Corner vertex (0,0,0) of voxel (i,j,k) is at world point (i,j,k)*dx. Perpendicular axes → vertex at (perp_boundary_idx + 1) * dx Edge axis → segment from edge_vox_idx * dx
to (edge_vox_idx + 1) * dx
- param lgi:
- type lgi:
(NX, NY, NZ) integer ndarray — feature labels, 0 = void
- param voxel_size:
- type voxel_size:
physical side length of one voxel (isotropic)
- returns:
starts ((n_segs, 3) float64 — start vertex of each segment)
ends ((n_segs, 3) float64 — end vertex of each segment)
- upxo.pxtal.fm_steel_3d.geom_metrics_3d.junction_point_coords(lgi: ndarray, voxel_size: float = 1.0) ndarray[source]
Extract the 3-D world coordinates of all junction point vertices.
A junction point vertex (shared by 8 voxels) has ≥3 distinct labels among those 8 voxels. Only interior vertices (all 8 neighbours exist) are considered.
Coordinate convention
An interior vertex at array position (i, j, k) (0-indexed) sits at the corner where 8 voxels meet: - voxels: (i,j,k), (i,j,k+1), (i,j+1,k), (i,j+1,k+1),
(i+1,j,k), (i+1,j,k+1), (i+1,j+1,k), (i+1,j+1,k+1)
world coordinates: ((i+1)*dx, (j+1)*dx, (k+1)*dx)
- param lgi:
- type lgi:
(NX, NY, NZ) integer ndarray — feature labels
- param voxel_size:
- type voxel_size:
physical side length of one voxel
- returns:
World coordinates (x, y, z) of each junction point vertex. If no junction points exist, returns (0, 3) empty array.
- rtype:
ndarray of shape (n_jps, 3) float64
- upxo.pxtal.fm_steel_3d.geom_metrics_3d.feature_aspect_ratio_bbox(lgi: ndarray) ndarray[source]
Per-feature 3D aspect ratio from each feature’s axis-aligned bounding box: max(extent) / min(extent) across the three voxel-count axes.
Generalizes slice_metrics_2d.label_aspect_ratio_bbox (2D, 2 axes) and twinned_simple_3d.base_3d.compute_aspect_ratio_bbox (3D, but bound to an instance) to a free function over any 3D LGI array, matching this module’s own label-indexed-array return convention. A tilted plate (e.g. a martensitic block sliced along a {111} habit plane not aligned with x/y/z) can have a large axis-aligned bounding box despite being genuinely thin along its own habit-plane normal – this metric only detects thinness aligned with the voxel grid’s own axes.
- Returns:
ndarray (max_label+1,) float64 — result[label] is that feature’s
bounding-box aspect ratio (>= 1.0); result[0] (void) is always 0.
- upxo.pxtal.fm_steel_3d.geom_metrics_3d.all_metrics(lgi: ndarray) Dict[str, object][source]
Compute all per-feature metrics in a single call.
- Returns:
‘vol’ ndarray (max_label+1,) int64 — voxel counts ‘surf’ ndarray (max_label+1,) int64 — boundary face counts ‘jl’ ndarray (max_label+1,) int64 — triple-line edge counts ‘jp’ ndarray (max_label+1,) int64 — junction-point vertex counts ‘nb_ids’ dict {label: frozenset(neighbour_labels)}
- Return type:
dict with keys
- upxo.pxtal.fm_steel_3d.geom_metrics_3d.feature_distribution(lgi: ndarray, voxel_size: float = 1.0, key: str = 'vol', metrics: Dict[str, object] = None) ndarray[source]
One morphology value per feature present in
lgi, in physical units.Keys
‘vol’ volume, voxel_size^3 ‘surf’ surface area, voxel_size^2 ‘eqdia’ diameter of the sphere of equal volume ‘sphericity’ surface area of the equal-volume sphere / surface area ‘nnb’ number of neighbouring features (void not counted) ‘jl’ triple-line length, voxel_size ‘jp’ number of junction points ‘aspect_ratio’ bounding-box aspect ratio (dimensionless)
- param metrics:
all_metrics(lgi)computed earlier; avoids recomputing the counts.- type metrics:
dict, optional
- returns:
ndarray (n_present,) float64, ordered by label. Labels that do not occur
in
lgiare left out.