pattern_to_sphere#

de_ebsd.index.backproject.pattern_to_sphere(patterns, detector, directions, pattern_center=None, padding_mode='border')[source]#

Back-project detector patterns onto directions on the unit sphere.

Each sphere direction reads the detector pixel that scatters along it (no crystal orientation is applied), bilinearly interpolating the pattern. The result is E(n) sampled on directions, ready to feed de_ebsd.index.spherical.harmonics.SphericalHarmonicTransform.forward() (reshape the (N_theta, N_phi) grid directions to (M, 3) and the samples back).

Parameters:
patterns

Detector images (..., H, W) (H = detector.nrows, W = detector.ncols), batched over arbitrary leading dimensions. Real floating dtype.

detector

The de_ebsd.sim EBSDDetector geometry (fixed pattern center). Its pixel -> direction map is inverted here.

directions

Target sphere directions (M, 3) in the sample/detector frame, e.g. SphericalHarmonicTransform.grid_directions().reshape(-1, 3).

pattern_center

Optional pattern-center override (3,) (pcx, pcy, pcz); pass a tensor with requires_grad to differentiate the samples in the pattern center (I6 refinement). Defaults to detector.pattern_center.

padding_mode

grid_sample padding for directions that fall (just) outside the pixel grid; "border" (default) clamps to the edge. Off-FOV samples are flagged by the returned mask regardless.

Returns:
samples

Sphere samples (..., M) (same leading dims and dtype as patterns). Entries outside the field of view are the padding_mode read-off and should be excluded via mask. Differentiable in patterns (and, via pattern_center, in the pattern center).

mask

Field-of-view weight (M,) in patterns’ dtype: 1 where the direction lands on the detector, 0 otherwise (the detector’s gnomonic bounds). Shared across the batch since the geometry is.