upxo.pxtal.fm_steel_3d.viz package

Submodules

Module contents

fm_steel_3d.viz: Visualization subpackage for FM steel structures.

Contains three main visualization worker classes: - GrainStructureViz3D: Grain and block structure (PyVista) - OrientationViz3D: Orientation-based visualizations (PyVista + matplotlib) - DataViz3D: Statistical data plots (matplotlib)

class upxo.pxtal.fm_steel_3d.viz.GrainStructureViz3D(default_cmap: str = 'viridis', default_window_size: tuple = (1000, 1000), default_opacity: float = 0.8)[source]

Bases: object

PyVista visualizations for grain and block structures.

static build_distinguishable_cmap(n_ids: int, seed: int = 42)[source]

A qualitative colormap with n_ids + 1 (label 0 included) visually distinguishable-ish entries, for per-feature ID coloring where a fixed small palette like ‘tab20’ (only 20 colors) would force many features to share an identical color once n_ids exceeds it – exactly the failure mode that made a genuinely fine-grained, hundreds-of-features structure (e.g. martensitic blocks) render as a handful of indistinguishable blobs. Below 20 IDs, ‘tab20’ itself is returned unchanged (it’s already maximally distinguishable at that count, and shuffling it would only lose its designed-in adjacent-color contrast for no benefit). Above that, samples ‘nipy_spectral’ (already the higher-N choice for this exact problem, see FMSteel3DBase’s own 2D preview coloring) then deterministically shuffles the order so spatially/numerically adjacent labels aren’t also colormap-adjacent (adjacent-labels- similar-color is otherwise the norm for a sequential colormap, and would visually blend touching same-family features together).

Returns:

  • matplotlib.colors.Colormap or str (pass straight through to)

  • pyvista’s cmap= argument.

plot_gs_pvvox(lgi: ndarray, grain_locs: Dict[int, ndarray], alpha: float = 1.0, title: str = 'Grain Structure', cmap: str | None = None, voxel_size: float = 1.0, downsample: float = 1.0)[source]

Visualize grain structure as PyVista voxels.

plot_pag_map_pyvista(clusters_dict: Dict[int, List[int]], grain_locs: Dict[int, ndarray], voxel_size: float = 1.0, opacity: float = 1.0, title: str = 'PAG Map', **kwargs)[source]

Visualize grains colored by PAG.

visualize_block_morphology(blocks_dict: Dict[str, ndarray], title: str = 'Block Morphology', voxel_size: float = 1.0, opacity: float = 1.0, **kwargs)[source]

Visualize all blocks with random colors.

visualize_block_morphology_v1(blocks_dict: Dict[str, ndarray], title: str = 'Block Morphology', voxel_size: float = 1.0, **kwargs)[source]

Visualize blocks with scalar bar.

visualize_blocks_in_packet(blocks_dict: Dict[str, ndarray], packet_gid=None, voxel_size: float = 1.0, opacity: float = 1.0, title: str = 'Blocks in Packet', **kwargs)[source]

Visualize blocks in a packet.

viz_browse_grains(lgi, grain_locs, **kwargs)[source]

Interactive grain browser (placeholder).

viz_clip_plane(lgi, grain_locs, **kwargs)[source]

Clip plane visualization (placeholder).

viz_mesh_slice(lgi, grain_locs, **kwargs)[source]

Mesh slice visualization (placeholder).

viz_mesh_slice_ortho(lgi, grain_locs, **kwargs)[source]

Orthogonal slice visualization (placeholder).

plot_grains(lgi, grain_locs, gids, **kwargs)[source]

Visualize specific grains.

plot_grain_sets(lgi, grain_locs, data=None, **kwargs)[source]

Visualize grain sets (placeholder).

plot_single_voxel_grains(lgi, grain_locs, title='Single Voxel Grains', **kwargs)[source]

Highlight single-voxel grains.

plot_scalar_field_slice_orthogonal(lgi, **kwargs)[source]

Scalar field on orthogonal slices (placeholder).

plot_scalar_field_slice(lgi, **kwargs)[source]

Scalar field on a single slice (placeholder).

plot_gs_pvvox_subset(lgi_subset, grain_locs_subset, **kwargs)[source]

Visualize a grain structure subset.

static build_exploded_block_grid(all_blocks: Dict[str, ndarray], clusters_dict: Dict[int, List[int]], grain_locs: Dict[int, ndarray], grain_to_pag_id: Dict[int, int], grain_to_blocks_map: Dict[int, List[str]], explosion_factor: float)[source]

Build a 3D int32 label grid where each active voxel holds a 1-based block index, with every block’s full voxel set rigidly translated by explosion_factor * (its own centroid minus its parent PAG’s centroid). explosion_factor=0 reproduces the true, unexploded layout exactly – translation preserves each block’s shape, it only relocates it.

Returns (grid, n_blocks).

static build_exploded_subblock_grid(all_subblocks: Dict[str, ndarray], all_blocks: Dict[str, ndarray], block_to_subblocks_map: Dict[str, List[str]], explosion_factor: float)[source]

Same idea one level down: each sub-block’s full voxel set is rigidly translated by explosion_factor * (its own centroid minus its parent block’s centroid) – blocks/PAGs stay in their true positions.

Returns (grid, n_subblocks).

lfi_to_polydata(lfi, scalar_array, voxel_size=1.0, cmap='tab20', title='', scalar_name='value', show_scalar_bar=True, threshold_min=0.5, clim=None, below_color=None, show_edges=True, jupyter_backend=None)[source]

Show a voxel grid coloured by a per-voxel scalar array.

jupyter_backend: None (default) preserves the original behaviour – a blocking native VTK window, or whatever PyVista’s global default is. Pass ‘trame’ (or any other pyvista-supported backend name) to render as an interactive, rotatable widget embedded directly in a Jupyter notebook cell’s output instead of a static screenshot or a separate window.

lfi_to_polydata_compare(lfi_left, lfi_right, scalar_array_left=None, scalar_array_right=None, voxel_size_left=1.0, voxel_size_right=1.0, cmap='tab20', title_left='', title_right='', scalar_name='value', threshold_min=0.5, show_edges=True)[source]

Two voxel grids side by side in ONE window, camera-linked so rotating either panel rotates both – the compare counterpart to lfi_to_polydata (which opens one independent full-window plot).

feature_fid_to_polydata(lgi_shape, iso_grain_map, block_fid_map, voxel_size=1.0, iso_cmap='cool', block_cmap='hot', title='Feature ID Map', show_edges=True)[source]

Show isolated grains and blocks in one window using two independent cmaps.

subblock_family_polydata(fid_map, fid_to_rgb, voxel_size=1.0, title='Sub-block Family Color Map', show_edges=True)[source]

Display sub-blocks using an explicit FID->RGB lookup table.

class upxo.pxtal.fm_steel_3d.viz.OrientationViz3D(default_sample_direction: List[float] | None = None)[source]

Bases: object

Orientation visualizations: IPF maps, pole figures, KS verification.

plot_ipf_map_pyvista_v2(grain_locs: Dict[int, ndarray], grain_orientations: Dict[int, Tuple[float, float, float]], sample_direction: List[float] | None = None, voxel_size: float = 1.0, opacity: float = 0.8, **kwargs)[source]

Create 3D IPF map using PyVista.

plot_ipf_map_pyvista_v1(grain_locs, grain_orientations, **kwargs)[source]

Create 3D IPF map (v1 = same as v2).

visualize_block_ipf_map(all_blocks: Dict[str, ndarray], block_orientations: Dict[str, Tuple[float, float, float]], voxel_size: float = 1.0, sample_direction: List[float] | None = None, **kwargs)[source]

Visualize blocks colored by IPF.

ipf_blocks_to_polydata(all_blocks: Dict[str, ndarray], block_orientations: Dict[str, Tuple[float, float, float]], lgi_shape: Tuple[int, int, int], voxel_size: float = 1.0, sample_direction: List[float] | None = None, title: str = 'Block IPF Map (Z)', grain_lgi: ndarray | None = None, show_edges: bool = True)[source]

Show a voxel grid where each block is colored by its IPF color.

plot_pag_ks_verification_v1(pag_id: int, pag_orientation: Tuple[float, float, float], grain_ids: List[int], grain_orientations: Dict[int, Tuple[float, float, float]], **kwargs)[source]

Verify KS relationship for a PAG.

static euler_to_ipf_color(euler_angles_deg: Tuple[float, float, float], sample_direction: List[float] | None = None) → Tuple[float, float, float][source]

Convert Bunge Euler angles (degrees) to an IPF RGB colour.

Delegates to upxo.xtalphy.crystal_orientation.ipf_color, mtex’s default inverse-pole-figure key for cubic crystals: the crystal direction of the sample axis, R.T @ sd, is brought into the fundamental sector [001]-[101]-[111] and coloured from there, so orientations related by a cubic symmetry operation get the same colour.

Parameters:
  • euler_angles_deg (tuple of float) – (phi1, Phi, phi2) in degrees, Bunge ZXZ convention.

  • sample_direction (list of float, optional) – Reference direction in sample frame. Default [0, 0, 1].

Returns:

(r, g, b)

Return type:

tuple of float in [0, 1]

class upxo.pxtal.fm_steel_3d.viz.DataViz3D(default_figure_size: tuple = (8, 5))[source]

Bases: object

Statistical plots for FM-steel 3D pipeline property distributions.

Histograms of scalar arrays and optional seaborn correlation matrices over morphological property dicts. Lightweight worker used by the notebook visualisation steps — not a grain-structure container.

plot_distribution(data: ndarray, title: str, xlabel: str, bins: int = 20, figsize: tuple | None = None, ylabel: str = 'Frequency', **kwargs)[source]

Plot histogram.

plot_mprop_correlations(mprop_dict: Dict, figsize: tuple | None = None)[source]

Plot correlation matrix using seaborn.

plot_pag_size_distribution(clusters_dict: Dict[int, List[int]], **kwargs)[source]

Plot distribution of grains per PAG.

plot_blocks_per_packet_distribution(grain_to_blocks_map: Dict[int, List[str]], **kwargs)[source]

Plot distribution of blocks per packet (keyed by grain_id = packet id).

plot_block_voxel_distribution(all_blocks: Dict[str, ndarray], **kwargs)[source]

Plot distribution of voxels per block.

plot_misorientation_distribution(grain_orientations: Dict, grain_neighbors: Dict, **kwargs)[source]

Plot misorientation angle distribution (placeholder).