Skip to content

Commit

Permalink
Merge 094a7a7 into 144c8f5
Browse files Browse the repository at this point in the history
  • Loading branch information
hakonanes committed Jan 20, 2021
2 parents 144c8f5 + 094a7a7 commit b9fe979
Show file tree
Hide file tree
Showing 16 changed files with 229 additions and 1,607 deletions.
9 changes: 4 additions & 5 deletions README.rst
Expand Up @@ -37,7 +37,7 @@ kikuchipy is an open-source Python library for processing and analysis of
electron backscatter diffraction (EBSD) patterns. The library builds on the
tools for multi-dimensional data analysis provided by the HyperSpy library.

- **User guide and API reference**: https://kikuchipy.org. The guide consists of
- **User guide and documentation**: https://kikuchipy.org. The guide consists of
Jupyter Notebooks with many links to detailed explanations of the input
parameters and output of functions and class methods (the API reference).
The notebooks can be inspected statically on the web page or via `nbviewer`,
Expand All @@ -49,7 +49,6 @@ tools for multi-dimensional data analysis provided by the HyperSpy library.
- **Contribute**: Do you have a question or want to contribute? Great! Our
`contributing guide <https://kikuchipy.org/en/latest/contributing.html>`_
explains how to best do that.
- The library is in an alpha stage, so there will be breaking changes with each
release. Please see
`the changelog <https://kikuchipy.org/en/latest/changelog.rst>`_ for all
developments.

The library is in an alpha stage, so there will be breaking changes with each
release.
9 changes: 0 additions & 9 deletions doc/bibliography.bib
Expand Up @@ -185,12 +185,3 @@ @inproceedings{aanes2020processing
volume = {891},
year = {2020}
}
@article{brewick2019nlpar,
author = {Brewick, Patrick T and Wright, Stuart and Rowenhorst, David J},
doi = {10.1016/j.ultramic.2019.02.013},
journal = {Ultramicroscopy},
pages = {50–61},
title = {{NLPAR: Non-local smoothing for enhanced EBSD pattern indexing}},
volume = {200},
year = {2019}
}
10 changes: 0 additions & 10 deletions doc/changelog.rst
Expand Up @@ -23,8 +23,6 @@ Contributors

Added
-----
- Calculation of an average dot product map, or just the dot product matrices.
(`#280 <https://github.com/pyxem/kikuchipy/pull/280>`_)
- A nice gallery to the documentation with links to each user guide page.
(`#285 <https://github.com/pyxem/kikuchipy/pull/285>`_)
- Support for writing/reading an EBSD signal with 1 or 0 navigation axes to/from
Expand Down Expand Up @@ -76,12 +74,6 @@ Added

Changed
-------
- The feature maps notebook to include how to obtain an average dot product map
and dot product matrices for an EBSD signal.
(`#280 <https://github.com/pyxem/kikuchipy/pull/280>`_)
- Averaging EBSD patterns with nearest neighbours now rescales to input data
type range, thus loosing relative intensities, to avoid clipping intensities.
(`#280 <https://github.com/pyxem/kikuchipy/pull/280>`_)
- Dependency requirement of diffsims from >= 0.3 to >= 0.4
(`#282 <https://github.com/pyxem/kikuchipy/pull/282>`_)
- Name of hemisphere axis in EBSDMasterPattern from "y" to "hemisphere".
Expand Down Expand Up @@ -119,8 +111,6 @@ Removed

Fixed
-----
- IndexError in neighbour pattern averaging
(`#280 <https://github.com/pyxem/kikuchipy/pull/280>`_)
- Square Lambert projection handles edge case vectors better
(`#272 <https://github.com/pyxem/kikuchipy/pull/272>`_)
- Reading of square Lambert projections from EMsoft's master pattern file now
Expand Down
225 changes: 5 additions & 220 deletions doc/feature_maps.ipynb
Expand Up @@ -31,7 +31,6 @@
"# exchange inline for qt5 for interactive plotting from the pyqt package\n",
"%matplotlib inline\n",
"\n",
"import hyperspy.api as hs\n",
"import matplotlib.pyplot as plt\n",
"plt.rcParams[\"font.size\"] = 15\n",
"import numpy as np\n",
Expand Down Expand Up @@ -148,50 +147,6 @@
"iq = s.get_image_quality(normalize=True) # Default"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"plt.figure(figsize=(10, 6))\n",
"plt.imshow(iq, cmap=\"gray\")\n",
"plt.colorbar(label=r\"Image quality, $Q$\", pad=0.01)\n",
"_ = plt.axis(\"off\")"
]
},
{
"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."
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Average dot product\n",
"\n",
"The average dot product, or normalized cross-correlation when centering each\n",
"pattern's intensity about zero and normalizing the intensities to a standard\n",
"deviation $\\sigma$ of 1 (which is the default behaviour), between each pattern\n",
"and their four nearest neighbours, can be obtained for an\n",
"[EBSD](reference.rst#kikuchipy.signals.EBSD) signal with\n",
"[get_average_neighbour_dot_product_map()](reference.rst#kikuchipy.signals.EBSD.get_average_neighbour_dot_product_map)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"adp = s.get_average_neighbour_dot_product_map()"
]
},
{
"cell_type": "code",
"execution_count": null,
Expand All @@ -206,188 +161,18 @@
"outputs": [],
"source": [
"plt.figure(figsize=(10, 6))\n",
"plt.imshow(adp, cmap=\"gray\")\n",
"plt.colorbar(label=\"Average dot product\", pad=0.01)\n",
"_ = plt.axis(\"off\")"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"The map displays how similar each pattern is to its neighbours. Grain\n",
"boundaries, and some scratches on the sample, can be clearly seen as pixels with\n",
"a lower value, signifying that they are more dissimilar to their neighbouring\n",
"pixels, as the ones within grains where the neighbour pixel similarity is high.\n",
"\n",
"The map above was created by averaging the dot product matrix per map point,\n",
"created by calculating the dot product between each pattern and their four\n",
"nearest neighbours, which can be seen in the black spots (uneven sample surface)\n",
"in the left grains"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"w1 = kp.filters.Window()\n",
"_ = w1.plot()"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"We could instead average with e.g. the eight nearest neighbours"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"w2 = kp.filters.Window(window=\"rectangular\", shape=(3, 3))\n",
"_ = w2.plot()"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"adp2 = s.get_average_neighbour_dot_product_map(window=w2)\n",
"\n",
"plt.figure(figsize=(10, 6))\n",
"plt.imshow(adp2, cmap=\"gray\")\n",
"plt.colorbar(label=\"Average dot product\", pad=0.01)\n",
"plt.imshow(iq, cmap=\"gray\")\n",
"plt.colorbar(label=r\"Image quality, $Q$\", pad=0.01)\n",
"_ = plt.axis(\"off\")"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Note that the window coefficients must be integers.\n",
"\n",
"We can also control whether pattern intensities should be centered about zero\n",
"and/or whether they should be normalized prior to calculating the dot products\n",
"by passing `zero_mean=False` and/or `normalize=False`. These are `True` by\n",
"default. The data type of the output map, 32-bit floating point by default,\n",
"can be set by passing e.g. `dtype_out=np.float64`.\n",
"\n",
"We can obtain the dot product matrices per map point, that is the matrices\n",
"before they are averaged, with\n",
"[get_neighbour_dot_product_matrices()](reference.rst#kikuchipy.signals.EBSD.get_neighbour_dot_product_matrices).\n",
"Let's see similar a pattern on a grain boundary in map point (x, y) = (50, 19)\n",
"is to all its nearest neighbour in a (5, 5) window centered on that point"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"w3 = kp.filters.Window(\"rectangular\", shape=(5, 5))\n",
"dp_matrices = s.get_neighbour_dot_product_matrices(window=w3)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"x, y = (50, 19)\n",
"s_dp_matrices = hs.signals.Signal2D(dp_matrices)\n",
"s_dp_matrices.inav[x, y].plot()"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"We can see that the pattern is more similar to the patterns up to the right,\n",
"while it is quite dissimilar to the patterns to the lower left. Let's visualize\n",
"this more clearly, as is done e.g. in Fig. 1 by\n",
"<cite data-cite=\"brewick2019nlpar\">Brewick et al. (2019)</cite>"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"y_n, x_n = w3.n_neighbours\n",
"\n",
"s2 = s.inav[x - x_n:x + x_n + 1, y - y_n:y + y_n + 1].deepcopy()\n",
"s2.rescale_intensity(percentiles=(0.5, 99.5)) # Stretch the contrast a bit\n",
"s3 = s2 * s_dp_matrices.inav[x, y].T # Signals must have same navigation shape"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"_ = hs.plot.plot_images(\n",
" images=s3,\n",
" per_row=5,\n",
" label=None,\n",
" suptitle=None,\n",
" axes_decor=None,\n",
" colorbar=None,\n",
" vmin=int(s3.data.min()),\n",
" vmax=int(s3.data.max()),\n",
" padding=dict(wspace=0, hspace=-0.05),\n",
" fig=plt.figure(figsize=(10, 10))\n",
")"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Finally, we can pass this dot product matrix directly to\n",
"[get_average_neighbour_dot_product_map()](reference.rst#kikuchipy.signals.EBSD.get_average_neighbour_dot_product_map)\n",
"via the `dp_matrices` parameter to obtain the average dot product map from these\n",
"matrices"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"adp3 = s.get_average_neighbour_dot_product_map(dp_matrices=dp_matrices)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Let's plot this and highlight the location of the pattern on the grain boundary\n",
"above with a red circle"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"plt.figure(figsize=(10, 6))\n",
"plt.imshow(adp3, cmap=\"gray\")\n",
"plt.colorbar(label=\"Average dot product\", pad=0.01)\n",
"plt.scatter(x=x, y=y, marker=\"o\", c=\"r\", s=50)\n",
"_ = plt.axis(\"off\")"
"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."
]
}
],
Expand Down

0 comments on commit b9fe979

Please sign in to comment.