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: object

Immutable 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’).

Type:

int or str

Convenience constructors
------------------------
grain(gid)      FMID.pag(pag_id)     FMID.packet(grain_id)[source]
block(bid_str)  FMID.subblock(sb_str)[source]
level: str
native_id: Any
classmethod grain(gid: int) → FMID[source]
classmethod pag(pag_id: int) → FMID[source]
classmethod packet(grain_id: int) → FMID[source]
classmethod block(block_id: str) → FMID[source]
classmethod subblock(sb_id: str) → FMID[source]
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: object

All 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
property vol_physical: float
property surf_physical: float
property jl_physical: float
property vol_equiv_diameter: float
property vol_equiv_radius: float
property sa_vol_ratio: float
property sphericity: float

ratio of surface area of equal-volume sphere to actual surface area.

Type:

Wadell sphericity

property isoperimetric_quotient: float

36π V² / S³ — equals 1 for a perfect sphere, <1 for everything else.

class upxo.pxtal.fm_steel_3d.feature_props_3d.FeaturePropsCollection(items: Sequence[FeatureProps])[source]

Bases: object

Ordered, 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
property vol_nvox_array: ndarray
property surf_nfaces_array: ndarray
property jl_nedges_array: ndarray
property jp_nverts_array: ndarray
property n_neighbours_array: ndarray
property vol_physical_array: ndarray
property surf_physical_array: ndarray
property jl_physical_array: ndarray
property vol_equiv_diameter_array: ndarray
property vol_equiv_radius_array: ndarray
property sa_vol_ratio_array: ndarray
property sphericity_array: ndarray
property isoperimetric_quotient_array: ndarray
feature_ids() → list[source]
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’}}

distribution(prop: str, bins: int | None = None) → Tuple[ndarray, ndarray][source]

Return (counts, bin_edges) histogram for property prop.

Parameters:
  • prop (str) – Any attribute or property name of FeatureProps (e.g. ‘vol_physical’, ‘sphericity’, ‘n_neighbours’).

  • bins (int, optional) – Number of histogram bins. Default: min(50, max(5, n//10)).

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:

ndarray, shape (H, W), dtype bool or float

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:

FeatureProps

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:

FeaturePropsCollection