convert_detector_coordinates#
- EBSDDetector.convert_detector_coordinates(coords: ndarray, direction: str, detector_index: None | int | tuple = None) ndarray [source]#
Convert between gnomonic and pixel coordinates on the detector screen.
- Parameters:
- coords
A 2D array of coordinates of any shape whereby the x and y coordinates to be converted are stored in the last axis.
- direction
Either “pix_to_gn” or “gn_to_pix”, depending on the direction of conversion needed.
- detector_index
Index showing which conversion factors in conversions[direction] should be applied to coords. If None, all conversion factors in conversions[direction] are applied to coords. If an int is supplied, this refers to an index in a 1D dataset. A 1D tuple e.g. (3,) can also be passed for a 1D dataset. A 2D index can be specified by supplying a tuple e.g. (2, 3). The default value is None
- Returns:
coords_out
Array of coords but with values converted as specified by direction. The shape is either the same as the input or is the navigation shape then the shape of the input.
Examples
Convert a single point on the detector in pixel coordinates into gnomonic coordinates for all patterns in the dataset.
>>> import numpy as np >>> import kikuchipy as kp >>> s = kp.data.nickel_ebsd_small() >>> det = s.detector >>> det.navigation_shape (3, 3) >>> coords = np.array([[36.2, 12.7]]) >>> coords.shape (1, 2) >>> coords_out = det.convert_detector_coordinates(coords, "pix_to_gn", None) >>> coords_out.shape (3, 3, 1, 2) >>> coords_out.squeeze() array([[[ 0.36223464, 0.00664684], [ 0.35762801, -0.00304659], [ 0.35361398, -0.00042112]], [[ 0.36432453, 0.00973461], [ 0.35219231, 0.00567801], [ 0.34417285, 0.00404584]], [[ 0.36296371, 0.00072557], [ 0.34447751, 0.00538137], [ 0.36136688, 0.00180754]]])
Convert three points on the detector in pixel coordinates into gnomonic coordinates for the pattern at navigation index (1, 2) in the dataset.
>>> import numpy as np >>> import kikuchipy as kp >>> s = kp.data.nickel_ebsd_small() >>> det = s.detector >>> det.navigation_shape (3, 3) >>> coords = np.array([[36.2, 12.7], [2.5, 43.7], [8.2, 27.7]]) >>> coords.shape (3, 2) >>> coords_out = det.convert_detector_coordinates(coords, "pix_to_gn", (1, 2)) >>> coords_out.shape (3, 2) >>> coords_out array([[ 0.34417285, 0.00404584], [-0.77639565, -1.02674418], [-0.58686329, -0.49472353]])