upxo.pxtal.fm_steel_3d.pag_technique_selector_3d module
Unified Technique A/B + lever orchestration for PAG/packet formation.
Single entry point (generate_pags) wiring together everything validated in this investigation:
Technique A’s original sequential clustering (FMSteel3DBase.generate_pag_clusters), reused as-is for levers 1 and 3.
Lever 1: the same sequential clustering, fed a widened-connectivity neighbour graph (see base_3d.compute_neighbor_network).
Lever 2: pag_clustering_3d.cluster_grains_simultaneous (MIS-seeded simultaneous multi-source clustering).
Lever 3: pag_clustering_3d.repair_singleton_pags, a post-hoc rescue pass stackable on top of either lever 1’s or lever 2’s output (or the plain sequential baseline).
Technique B: upxo.pxtalops.grain_splitting_3d.split_grains_geodesic (within-grain packet splitting; each PAG is exactly one original base grain). That module is general-purpose (any 3D labeled grain structure, not FM-steel-specific), so it lives outside fm_steel_3d, in pxtalops alongside UPXO’s other reusable grain-structure operations.
Retained austenite (pag_grain_fraction < 1.0) is resequenced to run AFTER PAG formation, reclassifying whole formed PAGs (or, for technique B, whole original grains – equivalent, since PAG == grain there) as retained austenite, rather than pre-filtering individual grains before clustering. This is necessary because pre-filtering doesn’t generalise cleanly across all five lever combinations (in particular the MIS-based clustering used by levers 2/2_3 has no natural place to “set aside” grains beforehand the way the original sequential algorithm’s isolated_grain_strategy did) – see pag_clustering_3d.select_isolated_units’s docstring for the mechanism.
Retained-austenite PAGs are NOT removed from clusters_dict – they stay in it as ordinary (if untransformed) PAGs, tagged via retained_austenite_pag_ids. This matters for orientation: assign_pag_orientations() assigns FCC orientation to every PAG in clusters_dict uniformly, so a retained-austenite PAG’s grains keep exactly the orientation their (never-realised) parent PAG was given, the same way a transformed PAG’s grains do – rather than each grain in it drawing its own separate, uncorrelated orientation later via assign_isolated_grain_orientations(). generate_blocks() is what actually withholds block generation for retained_austenite_pag_ids; it never affects clusters_dict or pag_orientations. isolated_grains is kept (as the flattened union of retained-austenite PAGs’ grains) purely for backward compatibility with code that already reads it.
FMSteel3DBase.generate_pag_clusters itself is left completely unmodified – existing sessions/scripts that call it directly keep their original pre-filter retained-austenite behaviour and are unaffected by this module. This is the new, additive entry point for selecting a technique and a lever.
- upxo.pxtal.fm_steel_3d.pag_technique_selector_3d.generate_pags(fm_base: FMSteel3DBase, technique: str, pag_size_distribution: Dict[str, Sequence[float]], max_packets_per_pag: int = 4, lever: str = 'lever3', clustering_connectivity: int | None = None, repair_connectivity: int = 18, split_threshold: int = 32, pag_grain_fraction: float = 1.0, isolated_grain_strategy: str = 'near_mean', isolated_size_tol: float = 0.25, retained_austenite_tolerance: float = 0.05, retained_austenite_max_attempts: int = 10, retained_austenite_trim_step: int = 1, use_non_neigh_pag: bool = True, random_seed: int | None = None)[source]
Generate PAGs (technique A) or PAGs+packets (technique B) using the selected technique and, for technique A, lever.
- Parameters:
fm_base (FMSteel3DBase) – Already-cleaned base grain structure – agnostic to whether it came from Voronoi tessellation, Monte-Carlo grain growth, or any future base-grain method.
technique (str) – ‘A’ (grain clustering) or ‘B’ (within-grain splitting).
pag_size_distribution (dict) – {‘sizes’: […], ‘probs’: […]}. Any size above max_packets_per_pag is clipped down to it.
max_packets_per_pag (int, optional) – Hard cap on packets per PAG, independent of pag_size_distribution. Default 4 (the crystallographic upper bound from FCC austenite’s 4 {111} habit planes – see grain_splitting_3d/pag_clustering_3d module docstrings).
lever (str, optional) – Technique A only: one of ‘lever1’, ‘lever2’, ‘lever3’ (default), ‘lever1_3’, ‘lever2_3’. Ignored (and should be disabled in any UI) when technique=’B’.
clustering_connectivity (int, optional) – Technique A only. If None, defaults per lever: 18 for lever1/ lever1_3, fm_base.connectivity (the base labelling connectivity, typically 6) for lever2/lever2_3/lever3.
repair_connectivity (int, optional) – Technique A only, for levers with repair enabled (lever3, lever1_3, lever2_3). Default 18.
split_threshold (int, optional) – Technique B only: minimum voxels for a grain to be split into multiple packets; grains below this stay a single packet. Default 32.
pag_grain_fraction (float, optional) – Volume fraction that ends up in the PAG/packet hierarchy; the remainder becomes retained austenite (an independent set of whole PAGs – or, for technique B, whole original grains – selected AFTER PAG formation). Default 1.0 (no retained austenite).
isolated_grain_strategy (str, optional) – ‘smallest’, ‘largest’, ‘boundary’, ‘near_mean’ (default), or ‘random’ – passed to the retained-austenite selection.
isolated_size_tol (float, optional) – Used only by ‘near_mean’. Default 0.25.
retained_austenite_tolerance (float, optional) – Acceptable deviation of the achieved retained-austenite volume fraction from 1 - pag_grain_fraction, as a fraction (e.g. 0.05 = +/-5 percentage points). See pag_clustering_3d.select_isolated_units_with_tolerance for why overshoot and undershoot need different fixes. Default 0.05.
retained_austenite_max_attempts (int, optional) – Maximum fresh random re-selection attempts when even the fullest achievable independent set undershoots the tolerance band (a hard ceiling set by the PAG-adjacency graph’s structure, not something more attempts can always overcome – see the same docstring). Default 10.
retained_austenite_trim_step (int, optional) – Number of units removed per step when trimming an overshoot back into the tolerance band. Default 1 (most precise).
use_non_neigh_pag (bool, optional) – Technique A, non-MIS levers only (lever1, lever3, lever1_3): passed through to the underlying sequential FMSteel3DBase.generate_pag_ clusters call. Measured to have negligible effect on the singleton rate either way; exposed for completeness rather than hard-coded. Default True.
random_seed (int, optional)
- Return type: