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
Pattern Matching: Compare experimental with simulated data #233
Conversation
Framework for calculating similarities between 2D gray-tone images of equal size.
length of shape -> ndim, and removed unnecessary squeeze call.
Produce value of 1 with equal pattern and template
Signed-off-by: Håkon Wiik Ånes <hwaanes@gmail.com>
Signed-off-by: Håkon Wiik Ånes <hwaanes@gmail.com>
…y into similarity-metrics
Signed-off-by: Håkon Wiik Ånes <hwaanes@gmail.com>
Signed-off-by: Håkon Wiik Ånes <hwaanes@gmail.com>
Change data shape from (N,nm) to (nm,N) to correspond better with cdist in scipy and general logic.
Signed-off-by: Håkon Wiik Ånes <hwaanes@gmail.com>
When compute=False and n_slices is not None.
I think we should rename this submodule to pattern matching, because many notable resources use "template matching" for describing finding a smaller image template in a larger image:
Further, I think renaming patterns -> experimental and templates -> simulated should be done. What do you think, @onatlandsmyr? |
That sounds better and more clear. I guess I should also change patterns and templates throughout SimilarityMetric/#231, for consistency. Pattern matching is probably better since we have an implicit understanding of it being diffraction patterns. Out of context, they both would be the same thing for me. "Simulation matching" may be an alternative, but I'll stick with pattern matching for now. |
And more importantly: patterns->experimental, templates->simulated
I agree that simulation matching would be equally descriptive. Pattern matching is used in the literature by e.g. Gert Nolze, Aimo Winkelmann, Angus Wilkinson, and others. Therefore I think it is safe to call it that! |
I've closed one review comment and re-commented on the remaining three. I'll go over the PR one more time after these are resolved, and then we'll see if anything remains. I'll update this branch with master and solve any potential conflicts now. |
Updated tests and docs
Also removed match_result tuple
Great work, @onatlandsmyr! I'm touching up formatting and API reference now, will then approve and we'll let the checks pass a last time before merging. |
Thank you, @hakonanes, for a great review and putting the finishing touch! It's a pleasure contributing to kikuchipy. |
Signed-off-by: Håkon Wiik Ånes <hwaanes@gmail.com>
Thanks, that's nice to hear (: |
I see that two tests where you divide by zero throw warnings: kikuchipy/indexing/tests/test_pattern_matching.py::TestPatternMatching::test_pattern_match_one_to_one
/home/hakon/kode/kikuchipy/kikuchipy/indexing/similarity_metrics.py:402: RuntimeWarning: invalid value encountered in true_divide
expt /= (expt ** 2).sum(axis=expt_sum_axis, keepdims=True) ** 0.5
kikuchipy/indexing/tests/test_pattern_matching.py::TestPatternMatching::test_pattern_match_one_to_one
/home/hakon/kode/kikuchipy/kikuchipy/indexing/similarity_metrics.py:403: RuntimeWarning: invalid value encountered in true_divide
sim /= (sim ** 2).sum(axis=sim_sum_axis, keepdims=True) ** 0.5 I would like to be warned when there are zero-intensities in my patterns, so I think this is okay. However, the tests shouldn't throw these I think, so I'll just add a np.errstate catch. |
Signed-off-by: Håkon Wiik Ånes <hwaanes@gmail.com>
Matching diffraction patterns
Compare experimental and simulated patterns and return
keep_n
sorted match results. The match result consists of simulation indices and metric results having the shape; (nx*ny, keep_n).The functions use dask functionality but accept both dask and numpy arrays as inputs. It is possible to divide the computation by slicing up simulations regardless of inputs being dask or numpy arrays. This is achieved by passing
n_slices
as keyword topattern_match
.Mainly to be used by StaticDictionaryIndexing and DynamicDictionaryIndexing and not directly by the user.
This PR depends on #231 .
Progress of the PR
Minimal example of the bug fix or new feature
For reviewers
later.
__init__.py
.the unreleased section in
doc/changelog.rst
.