SimilarityMetric#

class kikuchipy.indexing.SimilarityMetric(n_experimental_patterns: Optional[int] = None, n_dictionary_patterns: Optional[int] = 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 calling prepare_dictionary() and match().

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 least 1.

n_dictionary_patterns

Number of dictionary patterns. If not given, this is set to None and must be set later. Must be at least 1.

signal_mask

A boolean mask equal to the experimental patterns’ detector shape (n rows, n columns), where only pixels equal to False 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

SimilarityMetric.allowed_dtypes

Return the list of allowed array data types used during matching.

SimilarityMetric.dtype

Return or set which data type to cast the patterns to before matching.

SimilarityMetric.n_dictionary_patterns

Return or set the number of dictionary patterns to match.

SimilarityMetric.n_experimental_patterns

Return or set the number of experimental patterns to match.

SimilarityMetric.rechunk

Return or set whether to allow rechunking of arrays before matching.

SimilarityMetric.sign

Return the sign signifying whether a greater match is better, either +1 (greater is better) or -1 (lower is better).

SimilarityMetric.signal_mask

Return or set the boolean mask equal to the experimental patterns' detector shape (n rows, n 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().

SimilarityMetric.raise_error_if_invalid()

Raise a ValueError if dtype is not among allowed_dtypes and the latter is not an empty list.