Skip to content

Commit

Permalink
Replace reST user guide with Jupyter Notebook for image quality guide…
Browse files Browse the repository at this point in the history
…, remove unused images (#244)

* Add feature maps Jupyter Notebook, remove reST file and unused images

Signed-off-by: Håkon Wiik Ånes <hwaanes@gmail.com>

* Download dataset externally (kikuchipy-data)

Signed-off-by: Håkon Wiik Ånes <hwaanes@gmail.com>
  • Loading branch information
hakonanes authored Nov 4, 2020
1 parent 05ce685 commit 6617120
Show file tree
Hide file tree
Showing 26 changed files with 229 additions and 128 deletions.
Binary file not shown.
Binary file removed doc/_static/image/feature_maps/iq.png
Binary file not shown.
Binary file removed doc/_static/image/pattern_processing/adapthist.jpg
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file removed doc/_static/image/pattern_processing/pattern_raw.jpg
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
7 changes: 6 additions & 1 deletion doc/bibliography.bib
Original file line number Diff line number Diff line change
Expand Up @@ -66,4 +66,9 @@ @article{jackson2014h5ebsd
volume = {3},
year = {2014}
}

@phdthesis{lassen1994automated,
author = {Lassen, Niels Christian Krieger},
school = {Institute of Mathematical Modelling},
title = {{Automated Determanation of Crystal Orientations from Electron Backscattering Patterns}},
year = {1994}
}
17 changes: 9 additions & 8 deletions doc/changelog.rst
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@ Contributors
Added
-----
- A data module with a small Nickel EBSD data set and master pattern, and a
larger EBSD data set downloadable via the module.
larger EBSD data set downloadable via the module. Two dependencies, pooch and
tqdm, are added along with this module.
(`#236 <https://github.com/pyxem/kikuchipy/pull/236>`_,
`#237 <https://github.com/pyxem/kikuchipy/pull/237>`_,
`#243 <https://github.com/pyxem/kikuchipy/pull/243>`_)
Expand All @@ -35,9 +36,8 @@ Added
- EBSD.xmap property storing an orix CrystalMap object. So far only read from
a EMsoft simulated EBSD pattern file. Relevant documentation updated.
(`#226 <https://github.com/pyxem/kikuchipy/pull/226>`_)
- Dependency on the diffsims package (https://github.com/pyxem/diffsims/) for
handling of electron scattering and diffraction.
(`#220 <https://github.com/pyxem/kikuchipy/pull/220>`_)
- Dependency on the diffsims package for handling of electron scattering and
diffraction. (`#220 <https://github.com/pyxem/kikuchipy/pull/220>`_)
- Modified Lambert mapping, and its inverse, from points on the unit sphere to a
2D square grid, as implemented in Callahan and De Graef (2013).
(`#214 <https://github.com/pyxem/kikuchipy/pull/214>`_)
Expand All @@ -50,18 +50,19 @@ Added
gnomonic coordinates. EBSD reference frame documentation.
(`#204 <https://github.com/pyxem/kikuchipy/pull/204>`_,
`#215 <https://github.com/pyxem/kikuchipy/pull/215>`_)
- Reader for EMsoft's simulated EBSD patterns returned by their ``EMEBSD.f90``
- Reader for EMsoft's simulated EBSD patterns returned by their EMEBSD.f90
program. (`#202 <https://github.com/pyxem/kikuchipy/pull/202>`_)

Changed
-------
- EMsoft EBSD master pattern plugin can read a single energy pattern. Parameter
`energy_range` changed to `energy`.
(`240 <https://github.com/pyxem/kikuchipy/pull/240>`_)
- Migrating the user guide from `reStructuredText` files to Jupyter Notebooks
built to HTML via the `nbsphinx` package.
- Migrate user guide from reST files to Jupyter Notebooks converted to HTML with
the `nbsphinx` package.
(`#236 <https://github.com/pyxem/kikuchipy/pull/236>`_,
`#237 <https://github.com/pyxem/kikuchipy/pull/237>`_)
`#237 <https://github.com/pyxem/kikuchipy/pull/237>`_,
`#244 <https://github.com/pyxem/kikuchipy/pull/244>`_)
- Move GitHub repository to the pyxem organization. Update relevant URLs.
(`#198 <https://github.com/pyxem/kikuchipy/pull/198>`_)
- Allow scikit-image >= 0.16.
Expand Down
185 changes: 185 additions & 0 deletions doc/feature_maps.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,185 @@
{
"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": [
"# Feature maps\n",
"\n",
"This section details methods for extracting information from pattern\n",
"intensities, called feature maps (for lack of a better description).\n",
"\n",
"Let's import the necessary libraries and a Nickel EBSD test data set:"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"# exchange inline for qt5 for interactive plotting from the pyqt package\n",
"%matplotlib inline\n",
"\n",
"import matplotlib.pyplot as plt\n",
"plt.rcParams[\"font.size\"] = 15\n",
"import numpy as np\n",
"import kikuchipy as kp\n",
"\n",
"\n",
"# Use kp.load(\"data.h5\") to load your own data\n",
"s = kp.data.nickel_ebsd_large(allow_download=True) # External download\n",
"s"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Image quality\n",
"\n",
"The image quality metric $Q$ presented by Krieger Lassen\n",
"<cite data-cite=\"lassen1994automated\"> Lassen (1994)</cite>\n",
"can be calculated for an [EBSD](reference.rst#kikuchipy.signals.EBSD) signal\n",
"with\n",
"[get_image_quality()](reference.rst#kikuchipy.signals.EBSD.get_image_quality),\n",
"or, for a single pattern (`numpy.ndarray`), with\n",
"[get_image_quality()](reference.rst#kikuchipy.pattern.get_image_quality).\n",
"Following the notation in\n",
"<cite data-cite=\"marquardt2017quantitative\">Marquardt et al. (2017)</cite>, it\n",
"is given by\n",
"\n",
"$$\n",
"\\begin{align}\n",
"Q &= 1 - \\frac{J}{J_{\\mathrm{res}}w_{\\mathrm{tot}}},\\\\\n",
"J &= \\sum_{h = -N/2}^{N/2} \\sum_{k = -N/2}^{N/2} w(h, k)\n",
"\\left|\\mathbf{q}\\right|^2,\\\\\n",
"J_{\\mathrm{res}} &= \\frac{1}{N^2} \\sum_{h = -N/2}^{N/2}\n",
"\\sum_{k = -N/2}^{N/2} \\left|\\mathbf{q}\\right|^2,\\\\\n",
"w_{\\mathrm{tot}} &= \\sum_{h = -N/2}^{N/2} \\sum_{k = -N/2}^{N/2} w(h, k).\n",
"\\end{align}\n",
"$$\n",
"\n",
"The function $w(h, k)$ is the Fast Fourier Transform (FFT) power spectrum of the\n",
"EBSD pattern, and the vectors $\\mathbf{q}$ are the frequency vectors with\n",
"components $(h, k)$. The sharper the Kikuchi bands, the greater the high\n",
"frequency content of the power spectrum, and thus the closer $Q$ will be to\n",
"unity.\n",
"\n",
"Since we want to use the image quality metric to determine how pronounced the\n",
"Kikuchi bands in our patterns are, we first remove the static and dynamic\n",
"background:"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"s.remove_static_background()\n",
"s.remove_dynamic_background()"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"To visualize parts of the computation, we compute the power spectrum of a\n",
"pattern in the Nickel EBSD data set and the frequency vectors, shift the\n",
"zero-frequency components to the centre, and plot them:"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"p = s.inav[20, 11].data\n",
"p_fft = kp.pattern.fft(p, shift=True)\n",
"q = kp.pattern.fft_frequency_vectors(shape=p.shape)\n",
"\n",
"fig, ax = plt.subplots(figsize=(22, 6), ncols=3)\n",
"title_kwargs = dict(fontsize=22, pad=15)\n",
"fig.subplots_adjust(wspace=0.05)\n",
"\n",
"im0 = ax[0].imshow(p, cmap=\"gray\")\n",
"ax[0].set_title(\"Pattern\", **title_kwargs)\n",
"fig.colorbar(im0, ax=ax[0])\n",
"\n",
"im1 = ax[1].imshow(np.log(kp.pattern.fft_spectrum(p_fft)), cmap=\"gray\")\n",
"ax[1].set_title(\"Log of shifted power spectrum of FFT\", **title_kwargs)\n",
"fig.colorbar(im1, ax=ax[1])\n",
"\n",
"im2 = ax[2].imshow(np.fft.fftshift(q), cmap=\"gray\")\n",
"ax[2].set_title(r\"Shifted frequency vectors $q$\", **title_kwargs)\n",
"_ = fig.colorbar(im2, ax=ax[2])"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"If we don't want the EBSD patterns to be\n",
"[zero-mean normalized](pattern_processing.ipynb#normalize-intensity) before\n",
"computing $Q$, we must pass `get_image_quality(normalize=False)`.\n",
"\n",
"Let's compute the image quality $Q$ and plot it for the entire data set:"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"iq = s.get_image_quality(normalize=True) # Default\n",
"\n",
"plt.figure(figsize=(10, 6))\n",
"plt.imshow(iq, cmap=\"gray\")\n",
"_ = plt.colorbar(label=r\"Image quality, $Q$\")"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"If we want to use this map to navigate around in when plotting patterns, we can\n",
"easily do that as explained in the\n",
"[visualizing patterns](visualizing_patterns.rst) guide."
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.8.5"
}
},
"nbformat": 4,
"nbformat_minor": 4
}
92 changes: 0 additions & 92 deletions doc/feature_maps.rst

This file was deleted.

2 changes: 1 addition & 1 deletion doc/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ kikuchipy
reference_frames.rst
change_scan_pattern_size.rst
pattern_processing.ipynb
feature_maps.rst
feature_maps.ipynb
virtual_backscatter_electron_imaging.rst
visualizing_patterns.rst
multivariate_analysis.rst
Expand Down
Loading

0 comments on commit 6617120

Please sign in to comment.