Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Static pattern matching framework, orientation similarity map and crystal map merging #234

Merged
merged 90 commits into from
Nov 13, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
90 commits
Select commit Hold shift + click to select a range
1fc5bd8
feat(SimilarityMetric): ZNCC, NDP and user defined metrics
ona-lab Oct 12, 2020
2e8adc9
fix(SimilarityMetric): squeeze dimensions of similarity matrix
ona-lab Oct 12, 2020
9d42d70
Merge branch 'similarity-metrics'
ona-lab Oct 12, 2020
ce40f63
fix(SimiliarityMetric): rechunk dask arrays after type conversion
ona-lab Oct 13, 2020
8d1b68b
Merge branch 'similarity-metrics'
ona-lab Oct 13, 2020
089e0d1
refactor(SimilarityMetric)
ona-lab Oct 13, 2020
83e87c7
test(SimilarityMetric): Many to many ZNCC
ona-lab Oct 13, 2020
0754523
refactor: removed metricscopes including ANY
ona-lab Oct 13, 2020
c1d70db
wip: tests cover most cases
ona-lab Oct 13, 2020
096540e
test: remove print statement
ona-lab Oct 13, 2020
0d5bbb4
Merge branch 'similarity-metrics' into template-matching
ona-lab Oct 13, 2020
21c8c63
refactor: indexation -> indexing
ona-lab Oct 13, 2020
405a587
Reformat docstrings, add Ole to credits, add indexing module to doc
hakonanes Oct 13, 2020
23d93d8
refactor: renamed variables and made functions private
ona-lab Oct 13, 2020
aaa0f12
Merge remote-tracking branch 'origin/similarity-metrics' into similar…
ona-lab Oct 13, 2020
e3f3815
Merge branch 'similarity-metrics' into template-matching
ona-lab Oct 13, 2020
9eb4310
refactor: underscore prefix
ona-lab Oct 13, 2020
6aa285e
Merge branch 'similarity-metrics' into template-matching
ona-lab Oct 13, 2020
c992d0b
refactor: underscore prefix
ona-lab Oct 13, 2020
fbe77be
Merge branch 'similarity-metrics' into template-matching
ona-lab Oct 13, 2020
eed1303
Update docstring table, and more
hakonanes Oct 13, 2020
9ed54a2
Merge branch 'similarity-metrics' of github.com:onatlandsmyr/kikuchip…
hakonanes Oct 13, 2020
b6f729f
Add indexing module to kikuchipy/__init__.py
hakonanes Oct 13, 2020
f6388c5
Add static dictionary indexing note in changelog
hakonanes Oct 13, 2020
be02b8d
fix: change standard shape of similarity matrix
ona-lab Oct 16, 2020
635e24d
test: update tests to new output standard
ona-lab Oct 16, 2020
97ea036
Merge remote-tracking branch 'origin/similarity-metrics' into similar…
ona-lab Oct 16, 2020
c8035c3
Merge branch 'similarity-metrics' into template-matching
ona-lab Oct 16, 2020
a9573d8
fix: _is_compatible to be working for all scopes
ona-lab Oct 16, 2020
2555edf
Clarify parameters in docstrings, some minor syntax changes, repr
hakonanes Oct 16, 2020
85aa302
Merge branch 'similarity-metrics' of github.com:onatlandsmyr/kikuchip…
hakonanes Oct 16, 2020
376e3dc
Merge branch 'similarity-metrics' into template-matching
ona-lab Oct 16, 2020
746893c
Docstring explanation of _is_compatible()
hakonanes Oct 16, 2020
ac5cc3b
Merge branch 'similarity-metrics' into template-matching
ona-lab Oct 16, 2020
dff8456
Return numpy where only numpy arrays are passed, test repr
hakonanes Oct 16, 2020
ed6104a
Improve return numpy/dask test
hakonanes Oct 16, 2020
182f3a0
Merge branch 'similarity-metrics' into template-matching
ona-lab Oct 16, 2020
a0725e9
feat(template_match): Keep n largest metric results and template indices
ona-lab Oct 16, 2020
6402e33
tests: simple tests covering all lines
ona-lab Oct 16, 2020
3f3e7eb
refactor: move code to give user more specific error
ona-lab Oct 16, 2020
869746d
Merge remote-tracking branch 'pyxem/master' into similarity-metrics
ona-lab Oct 16, 2020
1ad6d65
Merge branch 'similarity-metrics' into template-matching
ona-lab Oct 16, 2020
fa0e981
refactor: removed comment
ona-lab Oct 16, 2020
0b712e1
feat: StaticDictionaryIndexing, OSM and xmap merging
ona-lab Oct 17, 2020
2b0d7e2
wip: empty test files
ona-lab Oct 17, 2020
4a6feeb
docs: template_match and slicing of templates
ona-lab Oct 17, 2020
8071674
fix: accept all scopes in template_match
ona-lab Oct 17, 2020
3d1fed6
refactor: renamed variables and removed unnecessary code
ona-lab Oct 17, 2020
083e390
refactor: moved code to read metric str earlier
ona-lab Oct 18, 2020
192fbb0
docs: template slices and punctuation marks.
ona-lab Oct 18, 2020
5a7167b
fix: raise NotImplementedError
ona-lab Oct 18, 2020
89ef36f
fix: allow user-defined footprint in OSM
ona-lab Oct 18, 2020
0367312
refactor+test: _merge -> merge_crystalmaps
ona-lab Oct 18, 2020
ec1cefb
test: StaticDictionaryIndexing and OSM
ona-lab Oct 18, 2020
bb8d3fa
Merge branch 'template-matching' into static-dictionary
ona-lab Oct 18, 2020
2b6078a
docs: StaticDictionaryIndexing
ona-lab Oct 18, 2020
aa6d320
fix: OSM bug
ona-lab Oct 18, 2020
bb0ad78
refactor: template_match -> pattern_match
ona-lab Oct 19, 2020
08d31be
refactor(SimilarityMetric): patterns->experimental, templates->simulated
ona-lab Oct 20, 2020
ad46855
docs: data -> patterns
ona-lab Oct 20, 2020
d2a0782
Merge branch 'template-matching' into static-dictionary
ona-lab Oct 20, 2020
6179e32
feat: EBSD.index method using StaticDictionaryIndexing
ona-lab Oct 20, 2020
e004054
fix: cyclic import and some documentation
ona-lab Oct 20, 2020
be3c57b
Merge branch 'master' of github.com:pyxem/kikuchipy into static-dicti…
hakonanes Oct 26, 2020
b6179ba
Remove setting of n_slices to None in static dictionary comp.
hakonanes Oct 27, 2020
311df71
No longer raises ValueWarning instead of Error on merge equal phases
ona-lab Oct 28, 2020
ec96dcd
Warns instead of raising error on merge equal phases
ona-lab Oct 28, 2020
c56a972
Merge remote-tracking branch 'origin/static-dictionary' into static-d…
ona-lab Oct 28, 2020
7bff4c2
refactor: templates -> simulated
ona-lab Oct 28, 2020
4c691c2
refactor+test(EBSD): .index(...) -> .dictionary_indexing(...)
ona-lab Oct 28, 2020
b1f304e
test: fix to pass
ona-lab Oct 28, 2020
545d3fc
Merge branch 'master' of github.com:pyxem/kikuchipy into static-dicti…
hakonanes Oct 30, 2020
d431175
Merge branch 'master' into static-dictionary
hakonanes Oct 30, 2020
bdf53f7
Intermediate commit before merging master into this branch
hakonanes Nov 4, 2020
34a0ae9
Merge branch 'master' into static-dictionary
hakonanes Nov 4, 2020
51d1a03
Docstring changes, alternative merge_crystal_map [skip ci]
hakonanes Nov 4, 2020
37c257b
Enable single scores per point, return comb. scores/indices
hakonanes Nov 5, 2020
78c53cd
Cont. testing crystal map merging, ensuring all tests pass
hakonanes Nov 5, 2020
d3b69fe
100% coverage for xmap merging, some tests left
hakonanes Nov 6, 2020
c78db42
Finish crystal map merge tests
hakonanes Nov 6, 2020
6286481
Touch up merge_crystal_maps docstring
hakonanes Nov 9, 2020
5041904
Changes to static dictionary indexing and OSM [skip ci]
hakonanes Nov 10, 2020
35fe4a8
MetricScope SOME_TO_MANY/ONE, 100% coverage
hakonanes Nov 11, 2020
ca832e0
Rename ZNCC->NCC, make ncc and ndp available from module
hakonanes Nov 11, 2020
1e80f8d
Update changelog
hakonanes Nov 11, 2020
2716c8d
Add equation from Marquardt et al. (2017) to OSM docstring
hakonanes Nov 11, 2020
bf8b3fb
Print phase name and memory use % in indexing progressbar
hakonanes Nov 12, 2020
16d76ec
Clarify difference of keep_n variable in _pattern_matching funcs
hakonanes Nov 12, 2020
35eb2ce
Merge branch 'master' into static-dictionary
hakonanes Nov 13, 2020
fe9ca1c
Dictionary indexing (DI) -> pattern matching, but keep DI references
hakonanes Nov 13, 2020
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions doc/bibliography.bib
Original file line number Diff line number Diff line change
Expand Up @@ -72,3 +72,21 @@ @phdthesis{lassen1994automated
title = {{Automated Determanation of Crystal Orientations from Electron Backscattering Patterns}},
year = {1994}
}
@article{chen2015dictionary,
author = {Chen, Yu H. and Park, Se Un and Wei, Dennis and Newstadt, Greg and Jackson, Michael A. and Simmons, Jeff P. and {De Graef}, Marc and Hero, Alfred O.},
doi = {10.1017/S1431927615000756},
issn = {14358115},
journal = {Microscopy and Microanalysis},
keywords = {EBSD, Von Mises-Fisher mixture distribution, dictionary matching, dynamical electron scattering, electron backscatter diffraction pattern, maximum likelihood orientation estimates},
number = {3},
pages = {739–752},
title = {{A Dictionary Approach to Electron Backscatter Diffraction Indexing}},
volume = {21},
year = {2015}
}
@book{goshtasby2012image,
author = {Goshtasby, A Ardeshir},
publisher = {Springer Science \& Business Media},
title = {{Image registration: Principles, tools and methods}},
year = {2012}
}
14 changes: 9 additions & 5 deletions doc/changelog.rst
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,14 @@ Added
(`#236 <https://github.com/pyxem/kikuchipy/pull/236>`_,
`#237 <https://github.com/pyxem/kikuchipy/pull/237>`_,
`#243 <https://github.com/pyxem/kikuchipy/pull/243>`_)
- Indexing of EBSD patterns through matching of patterns with a static
dictionary of simulated patterns with known orientations.
- Pattern matching of EBSD patterns with a dictionary of pre-computed simulated
patterns with known crystal orientations, and related useful tools
(`#231 <https://github.com/pyxem/kikuchipy/pull/231>`_,
`#233 <https://github.com/pyxem/kikuchipy/pull/233>`_)
`#233 <https://github.com/pyxem/kikuchipy/pull/233>`_,
`#234 <https://github.com/pyxem/kikuchipy/pull/234>`_): (1) A framework for
creation of similarity metrics used in pattern matching, (2) computation of an
orientation similarity map from indexing results, and (3) creation of a multi
phase crystal map from single phase maps from pattern matching.
- 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>`_)
Expand All @@ -55,8 +59,8 @@ Added

Changed
-------
- The EBSDMasterPattern gets unsettable phase, hemisphere and projection
properties. (`#246 <https://github.com/pyxem/kikuchipy/pull/246>`_)
- The EBSDMasterPattern gets phase, hemisphere and projection properties.
(`#246 <https://github.com/pyxem/kikuchipy/pull/246>`_)
- 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>`_)
Expand Down
28 changes: 17 additions & 11 deletions doc/reference.rst
Original file line number Diff line number Diff line change
Expand Up @@ -224,22 +224,22 @@ indexing
.. currentmodule:: kikuchipy.indexing

.. autosummary::
pattern_matching
StaticPatternMatching
orientation_similarity_map
merge_crystal_maps
similarity_metrics

pattern_matching
----------------

.. currentmodule:: kikuchipy.indexing.pattern_matching

.. autosummary::
pattern_match

.. automodule:: kikuchipy.indexing.pattern_matching
.. autoclass:: StaticPatternMatching
:members:
:undoc-members:
:show-inheritance:

.. automethod:: __init__
.. automethod:: __call__

.. autofunction:: orientation_similarity_map
.. autofunction:: merge_crystal_maps

similarity_metrics
------------------

Expand All @@ -248,16 +248,21 @@ similarity_metrics
.. autosummary::
make_similarity_metric
MetricScope
ncc
ndp

.. automodule:: kikuchipy.indexing.similarity_metrics
:members:
:undoc-members:
:show-inheritance:

.. autofunction:: ncc
.. autofunction:: ndp

....

io
==
===

.. automodule:: kikuchipy.io

Expand Down Expand Up @@ -457,6 +462,7 @@ All methods listed here are also available to
.. autosummary::
adaptive_histogram_equalization
average_neighbour_patterns
match_patterns
fft_filter
get_decomposition_model
get_dynamic_background
Expand Down
63 changes: 60 additions & 3 deletions kikuchipy/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,12 @@
import gc
import os
import tempfile
from typing import Tuple

from diffpy.structure import Atom, Lattice, Structure
from diffsims.crystallography import ReciprocalLatticePoint
import numpy as np
from orix.crystal_map import Phase
from orix.crystal_map import CrystalMap, Phase, PhaseList
from orix.quaternion.rotation import Rotation
from orix.vector import Vector3d, neo_euler
import pytest
Expand All @@ -40,8 +41,8 @@

@pytest.fixture
def dummy_signal():
"""Dummy signal of shape <3, 3|3, 3>. If this is changed, all tests
using this signal will fail since they compare the output from
"""Dummy signal of shape <(3, 3)|(3, 3)>. If this is changed, all
tests using this signal will fail since they compare the output from
methods using this signal (as input) to hard-coded outputs.
"""
# fmt: off
Expand Down Expand Up @@ -292,3 +293,59 @@ def nickel_zone_axes(nickel_kikuchi_band, nickel_rotations, pc1):
in_pattern=uvw_in_pattern,
gnomonic_radius=detector.r_max,
)


@pytest.fixture
def rotations():
return Rotation([(2, 4, 6, 8), (-1, -3, -5, -7)])


@pytest.fixture
def get_single_phase_xmap(rotations):
def _get_single_phase_xmap(
nav_shape,
rotations_per_point=5,
prop_names=["scores", "simulation_indices"],
name="a",
phase_id=0,
):
d, map_size = _get_spatial_array_dicts(nav_shape)
rot_idx = np.random.choice(
np.arange(rotations.size), map_size * rotations_per_point
)
data_shape = (map_size,)
if rotations_per_point > 1:
data_shape += (rotations_per_point,)
d["rotations"] = rotations[rot_idx].reshape(*data_shape)
d["phase_id"] = np.ones(map_size) * phase_id
d["phase_list"] = PhaseList(Phase(name=name))
# Scores and simulation indices
d["prop"] = {
prop_names[0]: np.ones(data_shape, dtype=np.float32),
prop_names[1]: np.arange(np.prod(data_shape)).reshape(data_shape),
}
return CrystalMap(**d)

return _get_single_phase_xmap


def _get_spatial_array_dicts(
nav_shape: Tuple[int, int], step_sizes: Tuple[int, int] = (1.5, 1)
) -> Tuple[dict, int]:
ny, nx = nav_shape
dy, dx = step_sizes
d = {"x": None, "y": None, "z": None}
map_size = 1
if nx > 1:
if ny > 1:
d["x"] = np.tile(np.arange(nx) * dx, ny)
else:
d["x"] = np.arange(nx) * dx
map_size *= nx
if ny > 1:
if nx > 1:
d["y"] = np.sort(np.tile(np.arange(ny) * dy, nx))
else:
d["y"] = np.arange(ny) * dy
map_size *= ny
return d, map_size
4 changes: 2 additions & 2 deletions kikuchipy/generators/virtual_bse_generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -129,8 +129,8 @@ def get_rgb_image(

See Also
--------
kikuchipy.signals.EBSD.plot_virtual_bse_intensity,
kikuchipy.signals.EBSD.get_virtual_bse_intensity,
~kikuchipy.signals.EBSD.plot_virtual_bse_intensity
~kikuchipy.signals.EBSD.get_virtual_bse_intensity

Notes
-----
Expand Down
23 changes: 15 additions & 8 deletions kikuchipy/indexing/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,23 @@
# You should have received a copy of the GNU General Public License
# along with kikuchipy. If not, see <http://www.gnu.org/licenses/>.

"""Indexing of EBSD patterns."""
"""Tools for indexing of EBSD patterns by comparison to simulated
patterns.

from kikuchipy.indexing.similarity_metrics import (
make_similarity_metric,
MetricScope,
The EBSD method :meth:`~kikuchipy.signals.EBSD.match_patterns` uses
these tools for pattern matching.
"""

from kikuchipy.indexing._merge_crystal_maps import merge_crystal_maps
from kikuchipy.indexing.orientation_similarity_map import (
orientation_similarity_map,
)
from kikuchipy.indexing.pattern_matching import pattern_match
from kikuchipy.indexing import similarity_metrics
from kikuchipy.indexing._static_pattern_matching import StaticPatternMatching

__all__ = [
"make_similarity_metric",
"MetricScope",
"pattern_match",
"merge_crystal_maps",
"orientation_similarity_map",
"similarity_metrics",
"StaticPatternMatching",
]
Loading