upxo.pxtal.fm_steel_3d.transform_shared module
Shared grain-ID relabel/randomize and clean-structure construction helpers.
Used by the transformation steps (steps.steps_transformations): every
transform or round-trip ends with the same “clean, contiguous, randomized ID
set, optionally with tiny grains dissolved into their largest neighbour”
guarantee, implemented once here.
- upxo.pxtal.fm_steel_3d.transform_shared.relabel_and_randomize(lgi)[source]
Relabel grain IDs to a contiguous 1..N range, then shuffle them.
Nearest-neighbour or majority-vote resampling can drop small grains entirely, leaving gaps in the surviving grain-ID sequence (for example {1, 2, 4, 7, …} if grains 3, 5 and 6 did not survive). A freshly simulated Monte Carlo structure is always relabelled (cc3d) and shuffled (
gid_ops.shuffleLFIIDs); a raw resampled or round-tripped structure is neither. This applies the same two-step convention.
- upxo.pxtal.fm_steel_3d.transform_shared.build_clean_structure(raw_lgi, voxel_size, physical_dimensions, units, connectivity, seed, cleanup_threshold)[source]
Common final-construction step for a transformed structure.
Relabels and randomizes
raw_lgi’s grain IDs to a contiguous, shuffled range, then, ifcleanup_threshold> 0, dissolves any grain below that many voxels into its largest neighbour (FMSteel3DBase.from_lfi’s ownmin_grain_nvoxelscleanup) and relabels AGAIN, since the cleanup can itself reopen gaps in the ID sequence. Returns the final FMSteel3DBase.