{ "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": [ "# Load and save data\n", "\n", "## Load patterns\n", "\n", "### From a file\n", "\n", "kikuchipy can read and write experimental EBSD patterns and EBSD master patterns\n", "from/to multiple formats (see [supported formats](#Supported-EBSD-formats)). To\n", "load patterns from file use the [load()](../reference.rst#kikuchipy.io._io.load)\n", "function. Let's import the necessary libraries and read the Nickel EBSD test\n", "data set directly from file (not via\n", "[kikuchipy.data.nickel_ebsd_small()](../reference.rst#kikuchipy.data.nickel_ebsd_small)):" ] }, { "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 tempfile\n", "import dask.array as da\n", "import hyperspy.api as hs\n", "import kikuchipy as kp\n", "import numpy as np\n", "import matplotlib.pyplot as plt\n", "\n", "\n", "datadir = \"../../kikuchipy/data/\"\n", "nordif_ebsd = \"nordif/Pattern.dat\"\n", "s = kp.load(datadir + nordif_ebsd)\n", "s" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Or, load the stereographic projection of the northern hemisphere of an EBSD master\n", "pattern for a 20 keV beam energy from a modified version of EMsoft's master\n", "pattern file, returned from their `EMEBSDmaster.f90` program:" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "emsoft_master_pattern = (\n", " \"emsoft_ebsd_master_pattern/ni_mc_mp_20kv_uint8_gzip_opts9.h5\"\n", ")\n", "s_mp = kp.load(filename=datadir + emsoft_master_pattern)\n", "s_mp" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Both the stereographic and the square Lambert projections of this master pattern\n", "data is available via\n", "[kikuchipy.data.nickel_ebsd_master_pattern_small()](../reference.rst#kikuchipy.data.nickel_ebsd_master_pattern_small).\n", "\n", "All file readers support accessing the data without loading it into memory (with\n", "the [Dask library](https://docs.dask.org/en/latest)), which can be useful when\n", "processing large data sets to avoid memory errors:" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "s_lazy = kp.load(datadir + nordif_ebsd, lazy=True)\n", "print(s_lazy)\n", "s_lazy.data" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Parts or all of the data can be read into memory by calling\n", "[compute()](http://hyperspy.org/hyperspy-doc/current/api/hyperspy._signals.lazy.html#hyperspy._signals.lazy.LazySignal.compute):" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "s_lazy_copy = s_lazy.inav[:2, :].deepcopy()\n", "s_lazy_copy.compute()\n", "s_lazy_copy" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "s_lazy.compute()\n", "s_lazy" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "