upxo.pxtal.twinned_simple_3d.fast_cleaning module

Optional numba kernels for the small-grain and spike removal of the MC temporal slices (TwinnedSimple3DBase.clean_temporal_slices).

They give the same labels and counts as the numpy code, in a fraction of the time. numba is optional: numba_available() says whether it is installed and resolve_backend() turns a requested backend into the one used.

upxo.pxtal.twinned_simple_3d.fast_cleaning.numba_available() → bool[source]
upxo.pxtal.twinned_simple_3d.fast_cleaning.resolve_backend(backend: str = 'auto') → str[source]

‘numba’ or ‘numpy’ for a requested backend.

'auto' is numba when it is installed, else numpy; 'numpy' is the numpy code; 'numba' raises ImportError if numba is not installed.

upxo.pxtal.twinned_simple_3d.fast_cleaning.merge_small_grains(lgi, min_grain_size, max_passes=50)[source]

Merge every grain of at most min_grain_size voxels into its largest face neighbour (lowest id on a tie), repeated until none is left to merge.

Same result as the numpy loop of clean_temporal_slices. Returns (lgi, n_merged) with a new label array. Needs numba.

upxo.pxtal.twinned_simple_3d.fast_cleaning.remove_spikes(lgi, same_count_threshold=1)[source]

Reassign spike voxels (at most same_count_threshold face neighbours of their own grain) to the neighbouring grain with most faces, as StructureCleaner3D._fast_clean_spikes does. Returns (lgi, n_removed) with a new label array. Needs numba.

upxo.pxtal.twinned_simple_3d.fast_cleaning.group_voxels_by_label(lgi_flat)[source]

{label: 1-based voxel ids (int32, ascending)} for every positive label, from one stable sort instead of one scan per label. Same result as the per-label scan of AbaqusExporter3D.build_index.