upxo.pxtal.fm_steel_3d.steps.steps_visualization module

Visualization – Part H of the FM Steel 3D walkthrough (Viz Settings + Pole Figures), extended per hierarchy level: an interactive 3D render, a scatter pole figure, a 1st-order morphological property grid, and a misorientation distribution – for whichever of PAG/Packet/Block/Sub-block have been reached.

Bulk property queries via feature_props_3d.query_level, an interactive 3D render via GrainStructureViz3D, pole figures via upxo.viz.xphy.pole_figure.PoleFigure, and misorientation-angle distributions via upxo.xtalphy.crystal_orientation. grain_boundary_misorientation_distribution – the same classes/functions the other FM steel visualisations already use, plus one genuinely new core function this needed (geom_metrics_3d. feature_aspect_ratio_bbox – no general 3D aspect-ratio function existed outside one instance-bound method on a different pipeline’s class).

upxo.pxtal.fm_steel_3d.steps.steps_visualization.distribution_stats(fm, level)[source]

Bulk geometric property query for every feature at level (‘grain’ | ‘pag’ | ‘packet’ | ‘block’ | ‘subblock’).

Returns:

  • FeaturePropsCollection (vectorised property arrays (.vol_physical_array,)

  • .vol_equiv_diameter_array, .sphericity_array, …) plus .summary() and

  • .distribution(prop, bins=None).

upxo.pxtal.fm_steel_3d.steps.steps_visualization.compute_aspect_ratios(fm, level)[source]

Per-feature 3D bounding-box aspect ratio, in the SAME order as distribution_stats(fm, level)’s own FeaturePropsCollection (ascending active integer label order) – so it lines up element-wise with any of that collection’s own arrays, e.g. for plot_morphology_grid. FeaturePropsCollection has no aspect-ratio field of its own; this is computed separately via geom_metrics_3d.feature_aspect_ratio_bbox.

Return type:

np.ndarray, one value per feature.

upxo.pxtal.fm_steel_3d.steps.steps_visualization.plot_distribution(collection, prop='vol_equiv_diameter_array', bins=30, ax=None)[source]

Density histogram + KDE overlay of one property array from a FeaturePropsCollection (see distribution_stats).

Return type:

matplotlib.axes.Axes

upxo.pxtal.fm_steel_3d.steps.steps_visualization.plot_morphology_grid(collection, aspect_ratios, bins=20, figsize=(14, 7), suptitle=None)[source]

2x4 grid of density-histogram + KDE-overlay plots for the 7 standard 1st-order morphological properties: mean volume, surface area, surface-area-to-volume ratio, aspect ratio, junction-line segment length, triple-junction-point count, and coordination number. aspect_ratios from compute_aspect_ratios (not part of FeaturePropsCollection itself).

Return type:

(matplotlib.figure.Figure, np.ndarray of Axes)

upxo.pxtal.fm_steel_3d.steps.steps_visualization.render_3d(fm, level='grain', jupyter_backend='trame', cmap=None, cmap_seed=42, randomize_ids=True, id_seed=None)[source]

Opens an interactive PyVista render of fm at level, coloured by feature ID.

randomize_ids=True (default) relabels the feature IDs themselves before rendering (see _randomize_grid_ids, seeded by id_seed) – the data-side half of the fix; cmap/cmap_seed (below) are the colormap-side half. Doing both together is the standard convention.

cmap: None (default) auto-builds a colormap that stays distinguishable even for hundreds of features (see GrainStructureViz3D.build_distinguishable_cmap, using cmap_seed for its shuffle) – a fixed 20-color qualitative map (‘tab20’) otherwise forces many features to share an identical color once the feature count exceeds 20, which is what made a genuinely fine block hierarchy render as a handful of indistinguishable blobs instead of many thin plates. Pass any matplotlib colormap name/object to use it directly instead (bypassing the auto-build and cmap_seed both). jupyter_backend=’trame’ (default) embeds a rotatable widget directly in the notebook cell instead of a static screenshot or a separate blocking window; pass None to restore that original behaviour.

Explicitly pins the color range to the full [0, max(lgi)] ID space (clim), the same as the 2D slice previews (Normalize(vmin=0, vmax=n_ids)) – without this, PyVista auto-scales the color range to whichever subset of IDs happens to be exposed on the rendered surface (this render only ever shows the domain’s outer shell – most features don’t reach it), silently remapping which colormap entry every ID actually gets away from what cmap was built assuming.

upxo.pxtal.fm_steel_3d.steps.steps_visualization.render_3d_exploded(stages, level='block', explosion_factor=0.5, jupyter_backend='trame', cmap=None, cmap_seed=42, randomize_ids=True, id_seed=None)[source]

Interactive PyVista render of level’s features (‘block’ or ‘subblock’ only – PAG/packet have no meaningful “parent” to explode away from), each rigidly translated away from its own parent’s centroid by explosion_factor (0 = true, unexploded positions), via GrainStructureViz3D.build_exploded_block_grid/ build_exploded_subblock_grid.

Pulls apart features that would otherwise be hidden inside a solid volume: render_3d’s voxel-surface technique can only ever show whichever features happen to be exposed on the domain’s outer shell (most aren’t, for a fine-grained hierarchy) – exploding relocates each feature away from its siblings so previously-buried ones become visible without needing a clip plane.

stages: a steps_raw_export.PipelineStages (or any object) exposing whichever of _fm_base/_fm_with_pags/_fm_with_blocks/ _fm_with_subblocks this level needs. randomize_ids/id_seed/ cmap/cmap_seed – see render_3d; the exploded grid’s own labelling is plain sequential dict-insertion order (same as feature_props_3d’s LGI builders), so the same data-side/colormap-side randomization applies here too.

Returns:

int

Return type:

number of features exploded (n_blocks or n_subblocks).

upxo.pxtal.fm_steel_3d.steps.steps_visualization.get_level_orientations(stages, level)[source]

The {id: (phi1, Phi, phi2)} orientation dict for one hierarchy level (‘pag’ | ‘packet’ | ‘block’ | ‘subblock’ – NOT ‘grain’, which has no orientation of its own). Reuses raw_export.collect_level_data, which already derives Packet’s orientation as the mean of its constituent blocks’ (orientation_mean_3d.compute_packet_mean_orientations) – the exact same derivation for both raw export and visualization, not a second copy of it.

stages: a steps_raw_export.PipelineStages (or anything duck-typed the same way, exposing _fm_with_pags/ _fm_with_blocks/_fm_with_orientations/_fm_with_subblocks).

Returns:

  • dict, or None if this level has no orientation data yet (not reached,

  • or – for ‘packet’ – the block orientations it depends on aren’t set).

upxo.pxtal.fm_steel_3d.steps.steps_visualization.plot_pole_figure(orientations, pole_family='100', ax=None, crystal_symmetry='cubic', apply_sample_symmetries=True, use_rd=True, use_td=True, use_nd=True)[source]

Scatter pole figure of orientations (a {id: (phi1, Phi, phi2)} dict, e.g. from get_level_orientations), in Bunge-Euler degrees.

Includes BOTH crystal and sample symmetry: - Crystal symmetry (crystal_symmetry, default ‘cubic’): handled by

PoleFigure itself – every crystallographically-equivalent pole of pole_family is plotted for each orientation, not just the one literal pole direction.

  • Sample symmetry: NOT handled by PoleFigure internally (it only ever applies crystal symmetry) – before construction, every orientation is first replicated through the closed macroscopic sample-symmetry group (180-degree rotations about the sample’s RD/ TD/ND axes, use_rd/use_td/use_nd, via pole_figure.compute_sample_symmetry_group + pole_figure.apply_sample_symmetry – the standard way already- fixed orientation data is symmetrized for a sample-symmetric pole figure). gids are tiled to match the replicated orientation count. Set apply_sample_symmetries=False to skip this and plot only the orientations as given (crystal symmetry alone).

Return type:

(matplotlib.figure.Figure, matplotlib.axes.Axes)

upxo.pxtal.fm_steel_3d.steps.steps_visualization.misorientation_distribution(orientations, collection, n_bins=36, angle_range=(0.0, 65.0))[source]

Neighbour-pair (grain-boundary) misorientation-angle distribution for one hierarchy level, using each feature’s real adjacency (collection’s own FeatureProps.neighbour_ids, from distribution_stats(fm, level)) so only physically adjacent pairs are compared – via xtalphy.crystal_orientation. grain_boundary_misorientation_distribution. A pair is skipped if either feature has no entry in orientations (e.g. an isolated grain with no PAG orientation).

Returns:

  • dict ({‘misorientation_angles’, ‘misorientation_axes’, ‘pairs’,)

  • ’hist_counts’, ‘hist_bin_edges’, ‘hist_bin_centers’, ‘mean_angle’,

  • ’median_angle’, ‘std_angle’, ‘n_pairs’}, or None if fewer than 2

  • oriented features are adjacent to each other.

upxo.pxtal.fm_steel_3d.steps.steps_visualization.plot_misorientation_distribution(mdf_result, ax=None, title=None, bins=None)[source]

Density histogram + KDE overlay of a misorientation_distribution(…) result’s raw per-pair angles (mdf_result[‘misorientation_angles’]) – same _hist_kde building block as every other distribution plot here, rather than the pre-binned hist_counts/hist_bin_edges bar plot (still available on mdf_result for callers who want the raw bin counts instead). bins defaults to the same bin count grain_boundary_misorientation_distribution used for its own hist_counts (len(mdf_result[‘hist_bin_centers’])), for a directly comparable view.

Return type:

matplotlib.axes.Axes