graintrace.generate_random_crystal#
Generate synthetic crystal tessellations with NEPER and simulate HEDM z-scans.
- class graintrace.generate_random_crystal.CrystalGenerator(output_dir, bounding_box, dim=3, seed=None, env=None, neper_path=None, auto_install=False)[source]#
Bases:
objectBuild NEPER Voronoi tessellations and derive HEDM-like scan CSVs from them.
- generate_tessellation(morpho_args, iterations=10, extra_neper_args=None)[source]#
Run neper -T. extra_neper_args are appended verbatim (e.g. [‘-reg’,’1’]).
- hedm_zscan(tess_file, nstep, overlap_percentage, output_hedm='hedm_scan', verbose=False, position_noise_std=0.0, orientation_noise_std=0.0, radius_noise=0.0, noise_seed=None, remove_minimum_volume=False, min_vol=0.0)[source]#
Generate overlapping z-direction tessellation cuts to simulate HEDM scans.
nstep slices span the domain z-extent; overlap_percentage (0-100) sets the overlap between adjacent scans; output_hedm is the output subfolder name.
Per-scan measurement error is forwarded to write_to_csv: position_noise_std (absolute length units), orientation_noise_std (degrees, proper misorientation), radius_noise (relative fraction); noise_seed for reproducibility.
- check_dependencies(neper_path=None, auto_install=False)[source]#
Locate NEPER (user-installed) and build its subprocess environment.
Returns
(neper_bin, env). RaisesRuntimeErrorwith install guidance when NEPER cannot be found andauto_installis False.
- static write_to_csv(stat_file, ori_file, output_csv, verbose=True, position_noise_std=0.0, orientation_noise_std=0.0, radius_noise=0.0, noise_seed=None, remove_minimum_volume=False, min_vol=0.0)[source]#
Combine Neper .stcell (geometry) and .ori (orientation) into one CSV mimicking HEDM APS output (columns X, Y, Z, GrainRadius, Eul0, Eul1, Eul2).
Measurement error is injected per property, each applied only when its value is > 0 (all-zero gives a noiseless result):
position_noise_std: additive absolute Gaussian on X, Y, Z, in the data’s physical length units (micrometers), isotropic and origin-independent.orientation_noise_std: proper random misorientation of this angular std (degrees), applied viaorientation_helper.perturb_orientation.radius_noise: relative (fractional) Gaussian std on GrainRadius.
noise_seedmakes the noise reproducible (None uses global np.random);remove_minimum_volumedrops grains belowmin_vol. Cells with zero volume are always dropped: NEPER 7 keeps cells removed by acutas empty entries (volume 0, centroid at the origin), whereas 4.x deleted them.
- static crop_tessellation(tess_name, bounding_box=None, seed=12345, zlo=0.0, zhi=1.0, dim=3, output_dir='.', out_name='tess_cropped', env=None, neper_bin='neper', verbose=True)[source]#
Crop an existing .tess file to the slab
zlo <= z <= zhi.Uses NEPER 7
-transform cut(hspace(...))(zslab_cut_arg()). RaisesRuntimeErrorif the crop leaves no cell with positive volume.
- static zslab_cut_arg(zlo, zhi)[source]#
NEPER 7
-transformargument that keeps onlyzlo <= z <= zhi.cutremoves eachhspace(d,a,b,c)region, which NEPER 7 defines asa x + b y + c z < d(NEPER 4.x used> d; graintrace requires 7.x).
- static show_morpho_options(exit_after=False)[source]#
Display available morphology configurations and supported distributions.
- Parameters:
exit_after (bool)
- Return type:
None