{ "cells": [ { "cell_type": "markdown", "metadata": { "nbsphinx": "hidden" }, "source": [ "This notebook is part of the `kikuchipy` documentation https://kikuchipy.org.\n", "Links to the documentation won't work from the notebook." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "# Reference frames\n", "\n", "## Sample-detector geometry\n", "\n", "The figure below shows the [sample reference frame](#detector-sample-geometry)\n", "and the [detector reference frame](#detector-coordinates) used in kikuchipy, all\n", "of which are right handed. In short, the sample reference frame is the one used\n", "by EDAX TSL, RD-TD-ND, while the pattern center is defined as in the Bruker\n", "software." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "In **(a)** (lower left), a schematic of the microscope chamber shows the\n", "definition of the sample reference frame, RD-TD-ND. The\n", "$x_{euler}-y_{euler}-z_{euler}$ crystal reference frame used by Bruker is shown\n", "for reference. An EBSD pattern on the detector screen is viewed from *behind*\n", "the screen *towards* the sample. The inset **(b)** shows the detector and sample\n", "normals viewed from above, and the azimuthal angle $\\omega$ which is defined as\n", "the sample tilt angle round the RD axis. **(c)** shows how the EBSD map appears\n", "within the data collection software, with the sample reference frame and the\n", "scanning reference frame, $x_{scan}-y_{scan}-z_{scan}$, attached. Note the\n", "$180^{\\circ}$ rotation of the map about ND. **(d)** shows the relationship\n", "between the sample reference frame and the detector reference frame,\n", "$x_{detector}-y_{detector}-z_{detector}$, with the projection center\n", "highlighted. The detector tilt $\\theta$ and sample tilt $\\sigma$, in this case\n", "$10^{\\circ}$ and $70^{\\circ}$, respectively, are also shown." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "The above figure shows the EBSD pattern in the\n", "[sample reference frame figure](#detector-sample-geometry) (a) as viewed from\n", "behind the screen towards the sample (left), with the detector reference frame\n", "the same as in (d) with its origin (0, 0) in the upper left pixel. The detector\n", "pixels' gnomonic coordinates can be described with a calibrated projection\n", "center (PC) (right), with the gnomonic reference frame origin (0, 0) in ($PC_x,\n", "PC_y$). The circles indicate the angular distance from the PC in steps of\n", "$10^{\\circ}$." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## The EBSD detector\n", "\n", "All relevant parameters for the sample-detector geometry are stored in an\n", "[kikuchipy.detectors.EBSDDetector](../reference.rst#kikuchipy.detectors.EBSDDetector)\n", "instance. Let's first import necessary libraries and a small Nickel EBSD test\n", "data set" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "# Exchange inline for notebook or qt5 (from pyqt) for interactive plotting\n", "%matplotlib inline\n", "\n", "import matplotlib.pyplot as plt\n", "import numpy as np\n", "import kikuchipy as kp\n", "\n", "\n", "s = kp.data.nickel_ebsd_small() # Use kp.load(\"data.h5\") to load your own data\n", "s" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Then we can define a detector with the same parameters as the one used to\n", "acquire the small Nickel data set" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "detector = kp.detectors.EBSDDetector(\n", " shape=s.axes_manager.signal_shape[::-1],\n", " pc=[0.421, 0.779, 0.505],\n", " convention=\"tsl\",\n", " px_size=70, # microns\n", " binning=8,\n", " tilt=0,\n", " sample_tilt=70\n", ")\n", "detector" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "detector.pc_tsl()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "The projection/pattern center (PC) is stored internally in the Bruker\n", "convention:\n", "\n", "- $PC_x$ is measured from the left border of the detector in fractions of detector\n", " width.\n", "\n", "- $PC_y$ is measured from the top border of the detector in fractions of detector\n", " height.\n", "\n", "- $PC_z$ is the distance from the detector scintillator to the sample divided by\n", " pattern height.\n", "\n", "Above, the PC was passed in the EDAX TSL convention. Passing the PC in the\n", "Bruker, Oxford, or EMsoft v4 or v5 convention is also supported. The definitions\n", "of the conventions are given in the\n", "[EBSDDetector](../reference.rst#kikuchipy.detectors.EBSDDetector) API reference,\n", "together with the conversion from PC coordinates in the TSL, Oxford, or EMsoft\n", "conventions to PC coordinates in the Bruker convention.\n", "\n", "The PC coordinates in the TSL, Oxford, or EMsoft conventions can be retreived\n", "via [EBSDDetector.pc_tsl()](../reference.rst#kikuchipy.detectors.EBSDDetector.pc_tsl),\n", "[EBSDDetector.pc_oxford()](../reference.rst#kikuchipy.detectors.EBSDDetector.pc_oxford),\n", "and [EBSDDetector.pc_emsoft()](../reference.rst#kikuchipy.detectors.EBSDDetector.pc_emsoft),\n", "respectively. The latter requires the unbinned detector pixel size in microns\n", "and the detector binning to be given upon initialization." ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "detector.pc_emsoft()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "The detector can be plotted to show whether the average PC is placed as\n", "expected using\n", "[EBSDDetector.plot()](../reference.rst#kikuchipy.detectors.EBSDDetector.plot) (see\n", "its docstring for a complete explanation of its parameters)" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "nbsphinx-thumbnail": { "tooltip": "Definitions of the sample and projection/pattern center reference frames" }, "tags": [ "nbsphinx-thumbnail" ] }, "outputs": [], "source": [ "detector.plot(pattern=s.inav[0, 0].data)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "This will produce a figure similar to the left panel in the\n", "[detector coordinates figure](#detector-coordinates) above, without the arrows\n", "and colored labels.\n", "\n", "Multiple PCs with a 1D or 2D navigation shape can be passed to the `pc`\n", "parameter upon initialization, or can be set directly. This gives the detector\n", "a navigation shape (not to be confused with the detector shape) and a navigation\n", "dimension (maximum of two)" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "detector.pc = np.ones([3, 4, 3]) * [0.421, 0.779, 0.505]\n", "detector.navigation_shape" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "detector.navigation_dimension" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "detector.pc = detector.pc[0, 0]\n", "detector.navigation_shape" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "