graintrace.construct_nf_mesh#

NF HEDM reconstruction: segment .mic layers and build a hex mesh.

class graintrace.construct_nf_mesh.NearFieldMeshBuilder(*, input_folder, save_dir, exp_file_token='layer', angle_convention='bunge', angle_type='radians', symmetry='432', prefix='reconstructed', write_intermediate=True, write_vtk=True, default_mesh_filename='mesh.e', default_mapped_orientations_filename='orientations', recursive=False)[source]#

Bases: object

Reconstruct a high-resolution 3D mesh from near-field (NF) HEDM .mic layers.

Reads a folder of per-layer orientation maps, segments them into grains on a voxel grid, and generates a conformal hexahedral Exodus mesh via CUBIT/SCULPT, plus per-element MRP orientations for CPFE. See examples/demonstrate_cpfe_nfff.py and the /nf-reconstruction skill. (NF reconstruction uses multiprocessing, so call it under an if __name__ == "__main__": guard.)

Parameters:
  • input_folder (PathLike)

  • save_dir (PathLike)

  • exp_file_token (str)

  • angle_convention (str)

  • angle_type (str)

  • symmetry (str)

  • prefix (str)

  • write_intermediate (bool)

  • write_vtk (bool)

  • default_mesh_filename (str)

  • default_mapped_orientations_filename (str)

  • recursive (bool)

DEFAULT_SEGMENTATION: Dict[str, Any] = {'batch_norm': 1000, 'connectivity': 26, 'grain_threshold': 100, 'grain_threshold_final': 1000, 'misorientation_tol': 0.08726646259971647, 'stop_count': 500}#
DEFAULT_GRAPH_SEGMENTATION: Dict[str, Any] = {'downsample': None, 'gamma': None, 'gamma_sweep': (0.5, 1.0, 2.0, 4.0, 8.0), 'grain_threshold_final': 30, 'method': 'graph', 'misori_tol_deg': 5.0, 'n_jobs': 1, 'n_threads': 1, 'remerge_miso_deg': 3.0, 'workdir': None}#

Graph/Leiden defaults; all but method/downsample go to FragmentationAnalyzer.segment.

OPTIONAL_GRAPH_KEYS = ('manhattan_radius', 'reduce_topk', 'rbf_sigma_deg', 'percolation_max_frac', 'seed')#

Graph keys forwarded to FragmentationAnalyzer.segment only when given.

DEFAULT_NX = 300#
DEFAULT_NY = 900#
DEFAULT_SCULPT_OPTIONS: Sequence[str] = ('--adapt', '-A', '7', '-df', '1', '-S', '2', '-CS', '4')#
REQUIRED_SCULPT_KEYS = ('psculpt', 'epu', 'nprocs')#
reconstruct(*, dz=5.0, nx=None, ny=None, voxel_size_um=None, min_confidence=None, max_point_distance=None, segmentation=None)[source]#

Reconstruct a segmented NF voxel grid from .mic/.csv layers.

Grids the layers, segments them (flood fill, or graph/Leiden), cleans up and voids any voxel left unsegmented.

Parameters:
  • dz (float) – Layer thickness in micrometers (z spacing between stacked layers).

  • nx (int | None) – In-plane grid resolution along x; None uses DEFAULT_NX.

  • ny (int | None) – In-plane grid resolution along y; None uses DEFAULT_NY.

  • voxel_size_um (Sequence[float] | None) – (hx, hy) in-plane voxel size in micrometers, instead of nx/ny.

  • min_confidence (float | None) – Voxels whose source point has a lower .mic Confidence become void; None keeps all.

  • max_point_distance (float | None) – Solid radius (um) around the measured points, replacing the Delaunay hull test.

  • segmentation (Dict[str, Any] | None) – Flat flood dict (DEFAULT_SEGMENTATION keys, misorientation_tol in radians), or {“method”: “graph”, …} with DEFAULT_GRAPH_SEGMENTATION / OPTIONAL_GRAPH_KEYS; None uses flood defaults.

Returns:

Path to merged_segmented_fixed_grid.npy; the confidence is saved beside it as fixed_grid_confidence.npy.

Raises:

ValueError – if voxel_size_um is given together with nx or ny, or the segmentation dict is invalid.

Return type:

Path

mesh(*, sculpt_config, sculpt_options=None, merged_grid=None, spn_path=None, orientations_path=None, mesh_path=None, mapped_orientations_path=None, layer_spacing=None, quality_check='raise')[source]#

Generate an Exodus mesh via SCULPT from the merged voxel grid.

Uses merged_grid if given, else save_dir/merged_segmented_fixed_grid.npy. Writes the SCULPT .spn/orientations inputs, runs SCULPT, and maps per-element MRP orientations. Block ids come out as 1..N (row k of the orientations CSV is block k + 1) with <mesh stem>_block_map.csv.

Parameters:
  • sculpt_config (Dict[str, Any]) – SCULPT configuration dict (required keys psculpt, epu, nprocs; optional launcher, environment).

  • sculpt_options (Sequence[str] | None) – SCULPT CLI flags as a sequence of strings; None uses DEFAULT_SCULPT_OPTIONS.

  • merged_grid (str | Path | None) – Path to the merged segmented grid .npy; None uses save_dir/merged_segmented_fixed_grid.npy.

  • spn_path (str | Path | None) – Override for the SCULPT .spn voxel input path.

  • orientations_path (str | Path | None) – Override for the SCULPT per-voxel orientations input path.

  • mesh_path (str | Path | None) – Override for the output Exodus mesh path; None uses the configured default.

  • mapped_orientations_path (str | Path | None) – Override for the mapped per-element orientation output basename (“.csv” is appended).

  • layer_spacing (float | None) – z voxel size of a single-layer grid; None uses the last reconstruct() dz.

  • quality_check (str) – SCULPT path: after meshing, check each hex’s scaled Jacobian (report in <mesh stem>_quality.json); “raise” (default) raises on inverted elements (they abort CPFE), “warn” only warns, “off” skips.

Returns:

Path to the written Exodus mesh.

Return type:

Path