DictionaryIndexer#
- class de_ebsd.index.dictionary.DictionaryIndexer(master, detector, point_group=None, resolution=3.0, device=None, dtype=None, energy_kev=None, match_binning=1)[source]#
Bases:
objectIndex EBSD patterns against a fundamental-zone dictionary by matmul.
The dictionary – the master projected at every fundamental-zone orientation, normalized – is built once in
__init__();index()then scores a whole stack with one matmul. The grid is coarse by design, so the intended workflow is this fast coarse pass followed byrefine().- Parameters:
- master
A
de_ebsd.sim.MasterPattern, projected onto the detector at every dictionary orientation.- detector
EBSDDetectorgeometry; indexed patterns must match its(nrows, ncols).- point_group
orix
Symmetrywhose fundamental zone is sampled. Falls back tomaster.metadata["crystal"]; one or the other is required.- resolution
Target average disorientation (degrees) of the sampling. Default
3.0, which refines to the same sub-degree accuracy as2.0at a ~3x cheaper build, while4.0starts dropping patterns into a wrong basin that refinement cannot escape. Go finer only for strongly pseudo-symmetric phases.- device
Explicit argument >
master.device> CPU.- dtype
None(default) auto-selects fp16 on tensor-core GPUs (compute capability >= 7.0) and fp32 elsewhere – on Pascal (native fp16 at 1/64 the fp32 rate) and on CPU (no fp16 matmul) fp16 is a pessimization.- energy_kev
Energy bin the master is projected at;
None(default) is the highest.- match_binning
Bin factor for the coarse match only (default
1). Kikuchi bands are low-frequency, so a binned pattern resolves the coarse cell just as well while the match shrinks bymatch_binning**2. Must divide both detector dimensions. Refinement still runs at full resolution, so this trades nothing away.
- Attributes:
- dictionary_rotations
orix.quaternion.Rotation The fundamental-zone orientations, length
n_dict.- dictionary
torch.Tensor Normalized, stored transposed and contiguous as
(n_px, n_dict)so the match runs at full matmul throughput (a transposed view runs at ~half).- n_dict
int Number of orientations in the dictionary.
- dictionary_rotations
Methods
Index one pattern or a stack against the fundamental-zone dictionary.
Index a whole scan and assemble it into an orix
CrystalMap.Gradient-refine the coarse dictionary orientations to sub-grid accuracy.
- index(patterns, return_scores=False)[source]#
Index one pattern or a stack against the fundamental-zone dictionary.
Patterns are always given at full detector resolution; binning to the match resolution happens internally.
- Parameters:
- patterns
A detector image
(H, W)or stack(Np, H, W), numpy or torch.- return_scores
Also return the full
(Np, n_dict)float32 score matrix.
- Returns:
- rotations
orix.quaternion.Rotation Best-matching fundamental-zone orientation per pattern.
- quality
torch.Tensor Peak NCC per pattern, roughly in
[-1, 1]; higher is better.- scores
torch.Tensor Only when
return_scores: the(Np, n_dict)matrix whose per-row argmax givesrotations.
- rotations
- index_scan(patterns, shape=None, step=1.0, phase=None, batch_size=None, refine=False, refine_iters=12)[source]#
Index a whole scan and assemble it into an orix
CrystalMap.Mirrors
index_scan().- Parameters:
- patterns
Either
(rows, cols, H, W), from which the grid is inferred, or a flat row-major(N, H, W), which requiresshape.- shape
(rows, cols)of the scan. Cross-checked against 4-D input.- step
Scan step size, written onto the map’s
x/y.- phase
An orix
Phaseor a de_ebsdCrystal. IfNone, derived frommaster.metadata["crystal"].- batch_size
Patterns per mini-batch (default
256). Results are identical to a single batch.- refine
Gradient-refine each mini-batch before assembly, making
prop["quality"]the refined NCC. The coarse grid makes this the intended finish.- refine_iters
Levenberg-Marquardt steps when
refine(default12).
- Returns:
orix.crystal_map.CrystalMapOne orientation +
prop["quality"]per scan point, single phase.
- refine(patterns, rotations=None, **kw)[source]#
Gradient-refine the coarse dictionary orientations to sub-grid accuracy.
Wraps
de_ebsd.index.refine.orientation.refine_orientation(), seeding from this indexer’s master and detector (fromindex()whenrotationsisNone).Defaults to
method="lm": the second-order refiner reaches the same sub-degree accuracy in ~10 steps rather than Adam’s ~60. LM is orientation-only, sorefine_pattern_center=Truefalls back to Adam.**kwis forwarded;devicedefaults to this indexer’s.