SphericalIndexer#
- class de_ebsd.index.spherical.SphericalIndexer(master, detector, bandwidth=53, device=None, energy_kev=None)[source]#
Bases:
objectIndex EBSD patterns against a master pattern by spherical cross-correlation.
Build once (the master spectrum is precomputed here), then call
index()on a single pattern or a stack.- Parameters:
- master
A
de_ebsd.sim.MasterPattern, sampled viamaster.sample.- detector
EBSDDetectorgeometry, inverted to back-project each pattern to the sphere.- bandwidth
Band limit
L, the accuracy/speed knob: the SOFT grid step is360 / (2L + 2)degrees. Cost grows ~``O(L^4)`` in both time and memory, sincewigner_d()materializes a(N, L+1, 2L+1, 2L+1)tensor.- device
Resolved as explicit argument >
master.device> CPU.- energy_kev
Energy bin to sample the master at;
None(default) selects the highest.
- Attributes:
- sht
SphericalHarmonicTransform The shared transform plan; master and patterns both go through it.
- a_lm, a2_lm
torch.Tensor Spectra of the master and of
M^2, complex, shape((L+1)**2,).
- sht
Methods
Index one pattern or a stack, returning orix orientations and quality.
Index a whole scan and assemble it into an orix
CrystalMap.Gradient-refine indexed orientations (and optionally the pattern center).
- index(patterns, normalize=True, return_surface=False)[source]#
Index one pattern or a stack, returning orix orientations and quality.
- Parameters:
- patterns
A detector image
(H, W)or stack(Np, H, W), numpy or torch.- normalize
Divide out the master’s local FOV norm (default), removing the bias toward orientations that place bright master regions in the field of view.
Falsekeeps the raw masked cross-correlation, unbiased only for near-uniform-norm masters.- return_surface
Also return the SO(3) score surface that was arg-maxed, as a third element. It feeds
de_ebsd.viz.maps.show_correlation()directly.
- Returns:
- rotations
orix.quaternion.Rotation Best-matching sample orientation per pattern, length
Np.- quality
torch.Tensor Peak score per pattern. Normalized, this is roughly in
[-1, 1]and comparable across patterns; unnormalized it has arbitrary scale.- surface
torch.Tensor Only when
return_surface: shape(Np, N, N, N),N = 2L + 2, on the(alpha, beta, gamma)grid. Detached.
- rotations
- index_scan(patterns, shape=None, step=1.0, phase=None, batch_size=None, normalize=True, refine=False, refine_iters=100, refine_lr=0.02)[source]#
Index a whole scan and assemble it into an orix
CrystalMap.- Parameters:
- patterns
Either
(rows, cols, H, W), from which the scan 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 64). The SO(3) surface is
(batch_size, N, N, N), which dominates memory at production bandwidth. Results are identical to a single batch.- refine
Gradient-refine each mini-batch before assembly, making
prop["quality"]the refined NCC. Orientation only – a scan shares one detector geometry, and joint pattern-center fitting over a whole scan is not done here.- refine_iters, refine_lr
Adam iterations and rotation learning rate used when
refine.
- Returns:
orix.crystal_map.CrystalMapOne orientation +
prop["quality"]per scan point, single phase.
- refine(patterns, rotations=None, pattern_center=None, refine_pattern_center=False, n_iterations=100, learning_rate=0.02, pattern_center_learning_rate=None, keep_best=True, return_history=False)[source]#
Gradient-refine indexed orientations (and optionally the pattern center).
Wraps
de_ebsd.index.refine.orientation.refine_orientation()with this indexer’s master, detector, device and SHT quadrature directions, so refinement scores over the same grid the coarse index used. Withrotations=Nonethe seeds come fromindex(), taking raw patterns straight to sharpened orientations.pattern_centerdefaults todetector.pattern_center; the remaining arguments pass through. Returns(rotation, score), withpattern_centerappended whenrefine_pattern_centerandhistorywhenreturn_history.