upxo.pxtal.fm_steel_3d.feature_props_3d module
feature_props_3d.py
Slotted property class and query API for closed-cell features in the FM steel 3D hierarchy (grain → PAG → packet → block → sub-block) and any future closed-cell types (precipitates, voids, etc.).
Public API
FMID — frozen hierarchical feature identifier FeatureProps — slotted class; one instance per feature FeaturePropsCollection — iterable container with array accessors + statistics query_feature(fm, fmid) → FeatureProps query_features(fm, [fmid, …]) → FeaturePropsCollection query_level(fm, level) → FeaturePropsCollection (all features at level)
Example
from upxo.pxtal.fm_steel_3d.feature_props_3d import FMID, query_level, query_features
# All PAGs: pag_props = query_level(fm_ori, ‘pag’) print(pag_props.summary())
# Specific blocks: ids = [FMID.block(‘B_1_3_0’), FMID.block(‘B_1_3_1’)] blk_props = query_features(fm_ori, ids) for fp in blk_props:
print(fp)
Level strings
‘grain’ — grains in the base LFI (FMSteel3DBase) ‘pag’ — parent austenite grains ‘packet’ — slicing packets (each grain = one packet) ‘block’ — martensitic blocks (native_id is str ‘B_…’) ‘subblock’ — lath sub-blocks (native_id is str ‘SB_…’)
- class upxo.pxtal.fm_steel_3d.feature_props_3d.FMID(level: str, native_id: Any)[source]
Bases:
objectImmutable identifier for one feature in the FM steel hierarchy.
- level
- Type:
str — ‘grain’ | ‘pag’ | ‘packet’ | ‘block’ | ‘subblock’
- native_id
int for grain / pag / packet levels (matches the integer label in the corresponding LGI). str for block / subblock levels (e.g. ‘B_1_3_0’, ‘SB_B_1_3_0_1’).
- Convenience constructors
- ------------------------
- class upxo.pxtal.fm_steel_3d.feature_props_3d.FeatureProps(name: str, feature_type: str, feature_id: Any, level: int, vol_nvox: int, surf_nfaces: int, jl_nedges: int, jp_nverts: int, n_neighbours: int, neighbour_ids: tuple, units: str, voxel_size: float)[source]
Bases:
objectAll geometric properties of one closed-cell feature.
Slot variables (stored directly)
name str human-readable label / ID feature_type str ‘grain’ | ‘pag’ | ‘packet’ | ‘block’ | ‘subblock’ feature_id int|str native feature ID (int for grain/pag/packet, str for block/sb) level int hierarchy depth (grain=0 … subblock=4)
vol_nvox int voxel count surf_nfaces int boundary voxel-face count (surface area proxy) jl_nedges int triple-line voxel-edge count (junction line length proxy) jp_nverts int junction-point vertex count (≥3 labels meet at vertex) n_neighbours int number of distinct face-adjacent real features (void excluded) neighbour_ids tuple native IDs of those neighbours
units str ‘microns’ | ‘mm’ | ‘m’ voxel_size float physical length of one voxel edge in units
Property methods (computed, never stored)
vol_physical voxel_size^3 × vol_nvox [units^3] surf_physical voxel_size^2 × surf_nfaces [units^2] jl_physical voxel_size × jl_nedges [units] vol_equiv_diameter diameter of equal-volume sphere [units] vol_equiv_radius radius of equal-volume sphere [units] sa_vol_ratio surf_physical / vol_physical [units^-1] sphericity Wadell sphericity ∈ (0, 1] isoperimetric_quotient 36π V² / S³ ∈ (0, 1] (= 1 for sphere)
- name
- feature_type
- feature_id
- level
- vol_nvox
- surf_nfaces
- jl_nedges
- jp_nverts
- n_neighbours
- neighbour_ids
- units
- voxel_size
- class upxo.pxtal.fm_steel_3d.feature_props_3d.FeaturePropsCollection(items: Sequence[FeatureProps])[source]
Bases:
objectOrdered, iterable container of FeatureProps instances with vectorised array accessors and statistical summary.
Access
len(c) number of features c[i] FeatureProps at index i for fp in c iterate
Voxel-space arrays (dtype int64)
.vol_nvox_array .surf_nfaces_array .jl_nedges_array .jp_nverts_array .n_neighbours_array
Physical arrays (dtype float64)
.vol_physical_array .surf_physical_array .jl_physical_array .vol_equiv_diameter_array
Shape descriptor arrays (dtype float64)
.sphericity_array .sa_vol_ratio_array .isoperimetric_quotient_array
- .summary() → dict of {prop: {mean, std, min, q25, q50, q75, max, n}}
- .distribution(prop, bins=None) → (hist_counts, bin_edges)
- .feature_ids() → list of native IDs in collection order
- summary() Dict[str, Dict[str, float]][source]
Return per-property descriptive statistics.
- Returns:
dict {prop_name – Non-finite values (inf, nan) are excluded before computing statistics. Properties with no finite values are omitted.
- Return type:
{‘mean’, ‘std’, ‘min’, ‘q25’, ‘q50’, ‘q75’, ‘max’, ‘n’}}
- upxo.pxtal.fm_steel_3d.feature_props_3d.compute_boundary_mask_2d(label_slice: ndarray, background_val: int = 0, mode: str = 'sharp') ndarray[source]
Return a boundary mask for a 2D integer label image.
A pixel is True (or >0 for smooth/subpixel modes) when it neighbours at least one pixel with a different label value. Pixels whose label equals background_val are always False/0, suppressing RVE-edge artefacts.
- Parameters:
label_slice (ndarray, shape (H, W), dtype int) – 2D label image — one slice of a 3D LGI, already transposed to image orientation (rows = Y axis, cols = X axis).
background_val (int, optional) – Label value treated as background; boundary pixels carrying this label are zeroed out. Default 0.
mode (str, optional) –
Boundary detection mode: - “sharp”: Pixel-aligned boundaries via find_boundaries(mode=’inner’).
Returns boolean mask, same shape as input. Fastest.
”smooth” (under dev.): Upsamples label grid 2x, finds boundaries, then downscales. Returns float [0,1] smoothed boundaries.
”subpixel”: Pure sub-pixel via find_boundaries(mode=’subpixel’). Uses scikit-image’s mathematical sub-pixel algorithm. Returns float [0,1] downscaled to original shape. Smoothest.
Default “sharp”.
- Returns:
Boolean mask for “sharp” mode; float array [0, 1] for smooth/subpixel.
- Return type:
- upxo.pxtal.fm_steel_3d.feature_props_3d.query_feature(fm, fmid: FMID) FeatureProps[source]
Query all geometric properties of a single feature.
- Parameters:
fm (any FMSteel3D* state object)
fmid (FMID)
- Return type:
- upxo.pxtal.fm_steel_3d.feature_props_3d.query_features(fm, fmids: Sequence[FMID]) FeaturePropsCollection[source]
Query properties for a list of features at the same hierarchy level.
All FMIDs must have the same .level.
- Parameters:
fm (any FMSteel3D* state object)
fmids (sequence of FMID (all at same level))
- Return type:
FeaturePropsCollection (same order as fmids)
- upxo.pxtal.fm_steel_3d.feature_props_3d.query_level(fm, level: str) FeaturePropsCollection[source]
Query properties for ALL features at a given hierarchy level.
This is the most efficient bulk query — it builds the LGI and computes all metrics exactly once, then constructs FeatureProps for every non-void label present in the LGI.
- Parameters:
fm (any FMSteel3D* state object)
level (str — 'grain' | 'pag' | 'packet' | 'block' | 'subblock')
- Return type: