grid_indices#
- kikuchipy.signals.util.grid_indices(grid_shape: Tuple[int, int] | int, nav_shape: Tuple[int, int] | int, return_spacing: bool = False) ndarray | Tuple[ndarray, ndarray] [source]#
Return indices of a grid evenly spaced in a larger grid of max. two dimensions.
- Parameters:
- grid_shape
Tuple of integers or just an integer signifying the number of grid indices in each dimension. If 2D, the shape is (n rows, n columns).
- nav_shape
Tuple of integers or just an integer of giving the shape of the larger grid. If 2D, the shape is (n rows, n columns).
- return_spacing
Whether to return the spacing in each dimension. Default is
False
.
- Returns:
indices
Array of indices of shape
(2,) + grid_shape
or(1,) + grid_shape
into the larger grid spanned bynav_shape
.spacing
The spacing in each dimension. Only returned if
return_spacing=True
.
Examples
>>> import kikuchipy as kp >>> kp.signals.util.grid_indices((4, 5), (55, 75)) array([[[11, 11, 11, 11, 11], [22, 22, 22, 22, 22], [33, 33, 33, 33, 33], [44, 44, 44, 44, 44]], [[12, 25, 38, 51, 64], [12, 25, 38, 51, 64], [12, 25, 38, 51, 64], [12, 25, 38, 51, 64]]]) >>> idx, spacing = kp.signals.util.grid_indices(10, 105, return_spacing=True) >>> idx array([[ 8, 18, 28, 38, 48, 58, 68, 78, 88, 98]]) >>> spacing array([10])