Convert between detector coordinate formats#

This example shows how to convert between pixel and gnomonic detector coordinates.

Imports.

import numpy as np

import kikuchipy as kp

Convert a set of detector pixel coordinates (row, column) to gnomonic coordinates on an EBSD detector for all sample positions (patterns).

pc = np.random.random(5 * 10 * 3).reshape(5, 10, 3)
det = kp.detectors.EBSDDetector((60, 60), pc=pc)

print(det)
print(det.navigation_shape)

# 20 coordinates
px_coords1 = np.random.randint(0, det.shape[0], (20, 2))
gn_coords1 = det.to_gnomonic_coords(px_coords1)
print(gn_coords1.shape)
EBSDDetector
  shape (Ny, Nx):     (60, 60)
  pc (PCx, PCy, PCz): (0.551, 0.53, 0.464)
  sample_tilt:        70.0°
  tilt:               0.0°
  azimuthal:          0.0°
  twist:              0.0°
  binning:            1
  px_size:            1.0 um
(5, 10)
(5, 10, 20, 2)

This also works for a number of sets of coordinates, each set different for each sample position. Here, we have 7 sets of 20 coordinates.

(5, 10, 7, 20, 2)

Convert 7 sets of 20 coordinates, the same for all sample positions. This time, from gnomonic coordinates to pixels.

True

Total running time of the script: (0 minutes 8.082 seconds)

Estimated memory usage: 807 MB

Gallery generated by Sphinx-Gallery