SimilarityMetric#
- class kikuchipy.indexing.SimilarityMetric(n_experimental_patterns: Optional[int] = None, n_dictionary_patterns: Optional[int] = None, navigation_mask: Optional[ndarray] = None, signal_mask: Optional[ndarray] = None, dtype: Union[str, dtype, type] = 'float32', rechunk: bool = False)[source]#
Bases:
ABC
Abstract class implementing a similarity metric to match experimental and simulated EBSD patterns in a dictionary.
For use in
dictionary_indexing()
or directly on pattern arrays if a__call__()
method is implemented. Note that dictionary_indexing() will always reshape the dictionary pattern array to 2D (1 navigation dimension, 1 signal dimension) before callingprepare_dictionary()
andmatch()
.Take a look at the implementation of
NormalizedCrossCorrelationMetric
for how to write a concrete custom metric.When writing a custom similarity metric class, the methods listed as abstract below must be implemented. Any number of custom parameters can be passed. Also listed are the attributes available to the methods if set properly during initialization or after.
- Parameters:
- n_experimental_patterns
Number of experimental patterns. If not given, this is set to
None
and must be set later. Must be at least1
.- n_dictionary_patterns
Number of dictionary patterns. If not given, this is set to
None
and must be set later. Must be at least1
.- navigation_mask
A boolean mask equal to the experimental patterns’ navigation (map) shape, where only patterns equal to
False
are matched. If not given, all patterns are used.- signal_mask
A boolean mask equal to the experimental patterns’ detector shape
(n rows, n columns)
, where only pixels equal toFalse
are matched. If not given, all pixels are used.- dtype
Which data type to cast the patterns to before matching to.
- rechunk
Whether to allow rechunking of arrays before matching. Default is
False
.
Attributes
Return the list of allowed array data types used during matching.
Return or set which data type to cast the patterns to before matching.
Return or set the number of dictionary patterns to match.
Return or set the number of experimental patterns to match.
Return or set the boolean mask of patterns to match, equal to the navigation (map) shape.
Return or set whether to allow rechunking of arrays before matching.
Return the sign signifying whether a greater match is better, either +1 (greater is better) or -1 (lower is better).
Return or set the boolean mask equal to the experimental patterns' detector shape
(s rows, s columns)
.Methods
SimilarityMetric.match
(*args, **kwargs)Match all experimental patterns to all dictionary patterns and return their similarities.
SimilarityMetric.prepare_dictionary
(*args, ...)Prepare dictionary patterns before matching to experimental patterns in
match()
.SimilarityMetric.prepare_experimental
(*args, ...)Prepare experimental patterns before matching to dictionary patterns in
match()
.Raise a ValueError if
dtype
is not amongallowed_dtypes
and the latter is not an empty list.