{ "cells": [ { "cell_type": "markdown", "id": "81b96c07-56ce-47b8-8a63-bbbb27263f5c", "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", "id": "3f42fed2-753b-431b-9469-b3351176f757", "metadata": {}, "source": [ "# PC calibration: \"moving-screen\" technique\n", "\n", "The gnomonic projection (pattern) center (PC) of an EBSD detector can be\n", "estimated by the \"moving-screen\" technique\n", "Hjelen et al., which we will test in\n", "this tutorial.\n", "\n", "The technique relies on the assumption that the beam normal, shown in the\n", "[top figure (d) in the reference frames tutorial](reference_frames.ipynb#Detector-sample-geometry),\n", "is normal to the detector screen as well as the incoming electron beam, and will\n", "therefore intersect the screen at a position independent of the detector\n", "distance (DD). To find this position, we need two EBSD patterns acquired with a\n", "stationary beam but with a known difference $\\Delta z$ in DD, say 5 mm.\n", "\n", "First, the goal is to find the pattern position which does not shift between the\n", "two camera positions, ($PC_x$, $PC_y$). This point can be estimated in fractions\n", "of screen width and height, respectively, by selecting the same pattern features\n", "in both patterns. The two points of each pattern feature can then be used to\n", "form a straight line, and two or more such lines should intersect at ($PC_x$,\n", "$PC_y$).\n", "\n", "Second, the DD ($PC_z$) can be estimated from the same points. After finding\n", "the distances $L_{in}$ and $L_{out}$ between two points (features) in both\n", "patterns (in = operating position, out = 5 mm from operating position), the DD\n", "can be found from the relation\n", "\n", "$$\n", "\\mathrm{DD} = \\frac{\\Delta z}{L_{out}/L_{in} - 1},\n", "$$\n", "\n", "where DD is given in the same unit as the known camera distance difference. If\n", "also the detector pixel size $\\delta$ is known (e.g. 46 mm / 508 px), $PC_z$ can\n", "be given in the fraction of the detector screen height\n", "\n", "$$\n", "PC_z = \\frac{\\mathrm{DD}}{N_r \\delta b},\n", "$$\n", "\n", "where $N_r$ is the number of detector rows and $b$ is the binning factor.\n", "\n", "Let's first import necessary libraries" ] }, { "cell_type": "code", "execution_count": null, "id": "4d17ba0c-17d7-42bc-9792-bef0aac7e8d6", "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", "\n", "from diffsims.crystallography import ReciprocalLatticeVector\n", "from orix.crystal_map import PhaseList\n", "import kikuchipy as kp" ] }, { "cell_type": "markdown", "id": "f01ebf69-77e9-40bf-a219-e937a4516c08", "metadata": {}, "source": [ "We will find an estimate of the PC from two single crystal Silicon EBSD\n", "patterns, which are included in the\n", "[kikuchipy.data](../reference/generated/kikuchipy.data.rst) module" ] }, { "cell_type": "code", "execution_count": null, "id": "35f5fdb8-360d-47d2-851a-d1ad0d49c9f5", "metadata": {}, "outputs": [], "source": [ "s_in = kp.data.si_ebsd_moving_screen(0, allow_download=True)\n", "s_in.remove_static_background()\n", "s_in.remove_dynamic_background()\n", "\n", "s_out5mm = kp.data.si_ebsd_moving_screen(5, allow_download=True)\n", "s_out5mm.remove_static_background()\n", "s_out5mm.remove_dynamic_background()" ] }, { "cell_type": "markdown", "id": "2ad933d0-31d8-44e9-8591-60eca7867039", "metadata": {}, "source": [ "As a first approximation, we can find the detector pixel positions of the same\n", "features in both patterns by plotting them and noting the coordinates in the upper\n", "right in the Matplotlib window when plotting with an interactive backend (e.g.\n", "qt5 or notebook) and hovering over image pixels" ] }, { "cell_type": "code", "execution_count": null, "id": "b6b7634b-2295-49f1-bbb7-ab567486209b", "metadata": {}, "outputs": [], "source": [ "fig, axes = plt.subplots(ncols=2, sharex=True, sharey=True, figsize=(14, 7))\n", "for ax, data in zip(axes, [s_in.data, s_out5mm.data]):\n", " ax.imshow(data, cmap=\"gray\")\n", "fig.subplots_adjust(wspace=0.02)" ] }, { "cell_type": "markdown", "id": "32839589-ac31-4965-be22-fc7b3a8e94fe", "metadata": {}, "source": [ "For this example we choose the positions of three zone axes. The PC calibration\n", "is performed by creating an instance of the\n", "[PCCalibrationMovingScreen](../reference/generated/kikuchipy.detectors.PCCalibrationMovingScreen.rst)\n", "class" ] }, { "cell_type": "code", "execution_count": null, "id": "24657337-00fe-4e78-bf33-820b699b636a", "metadata": {}, "outputs": [], "source": [ "cal = kp.detectors.PCCalibrationMovingScreen(\n", " pattern_in=s_in.data,\n", " pattern_out=s_out5mm.data,\n", " points_in=[(109, 131), (390, 139), (246, 232)],\n", " points_out=[(77, 146), (424, 156), (246, 269)],\n", " delta_z=5,\n", " px_size=None, # Default\n", " convention=\"tsl\", # Default\n", ")\n", "cal" ] }, { "cell_type": "markdown", "id": "e219623f-366c-49b5-97da-262cf10e4c14", "metadata": {}, "source": [ "We see that ($PC_x$, $PC_y$) = (0.5123, 0.8606), while DD = 21.7 mm. To get\n", "$PC_z$ in fractions of detector height, we have to provide the detector pixel\n", "size $\\delta$ upon initialization, or set it directly and recalculate the PC" ] }, { "cell_type": "code", "execution_count": null, "id": "65cefee2-3cda-447c-bc01-52f490464136", "metadata": {}, "outputs": [], "source": [ "cal.px_size = 90e-3 # mm/px\n", "cal" ] }, { "cell_type": "markdown", "id": "1185a0bd-a281-45e4-8780-fee70a0d0100", "metadata": {}, "source": [ "We can visualize the estimation by using the convenience method\n", "[PCCalibrationMovingScreen.plot()](../reference/generated/kikuchipy.detectors.PCCalibrationMovingScreen.plot.rst)" ] }, { "cell_type": "code", "execution_count": null, "id": "805760aa-350f-4dbe-8d26-421c499d060c", "metadata": {}, "outputs": [], "source": [ "cal.plot()" ] }, { "cell_type": "markdown", "id": "b98843b2-33d6-47a2-9780-856149d6b229", "metadata": {}, "source": [ "As expected, the three lines in the right figure meet at approimately the same\n", "point. We can replot the three images and zoom in on the PC to see how close\n", "they are to each other" ] }, { "cell_type": "code", "execution_count": null, "id": "9bd67169-35af-4df5-bad4-632f9c855836", "metadata": {}, "outputs": [], "source": [ "# PCy defined from top to bottom, otherwise \"tsl\", defined from bottom to top\n", "cal.convention = \"bruker\"\n", "pcx, pcy, _ = cal.pc\n", "\n", "# Use two standard deviations of all $PC_x$ estimates as the axis limits\n", "# (scaled with pattern shape)\n", "two_std = 2 * np.std(cal.pcx_all, axis=0)\n", "\n", "fig = cal.plot(return_figure=True)\n", "ax2 = fig.axes[2]\n", "ax2.set_xlim([cal.ncols * (pcx - two_std), cal.ncols * (pcx + two_std)])\n", "ax2.set_ylim([cal.nrows * (pcy - two_std), cal.nrows * (pcy + two_std)])\n", "fig.subplots_adjust(wspace=0.05)" ] }, { "cell_type": "markdown", "id": "d0cdf7ed-73cc-4ae1-936c-6c38e2b977f4", "metadata": {}, "source": [ "We can use this PC estimate as an initial guess when refining the PC using Hough indexing available from the [PyEBSDIndex](https://pyebsdindex.readthedocs.io) Python package.\n", "See the [Hough indexing tutorial](hough_indexing.ipynb) for details on the below commands.\n", "\n", "