Window#

class kikuchipy.filters.Window(window: Union[None, str, ndarray, Array] = None, shape: Optional[Sequence[int]] = None, **kwargs)[source]#

Bases: ndarray

A window/kernel/mask/filter of a given shape with some values.

This class is a subclass of numpy.ndarray with some additional convenience methods.

It can be used to create a transfer function for filtering in the frequency domain, create an averaging window for averaging patterns with their nearest neighbours, and so on.

Parameters:
window

Window type to create. Available types are listed in scipy.signal.windows.get_window() and includes "rectangular" and "gaussian", in addition to a "circular" window (default) filled with ones in which corner data are set to zero, a "modified_hann" window and "lowpass" and "highpass" FFT windows. A window element is considered to be in a corner if its radial distance to the origin (window center) is shorter or equal to the half width of the windows’s longest axis. A 1D or 2D numpy.ndarray or dask.array.Array can also be passed.

shape

Shape of the window. Not used if a custom window is passed to window. This can be either 1D or 2D, and can be asymmetrical. Default is (3, 3).

**kwargs

Required keyword arguments passed to the window type.

Examples

>>> import numpy as np
>>> import kikuchipy as kp

The following passed parameters are the default

>>> w = kp.filters.Window(window="circular", shape=(3, 3))
>>> w
Window (3, 3) circular
[[0. 1. 0.]
 [1. 1. 1.]
 [0. 1. 0.]]

A window can be made circular

>>> w = kp.filters.Window(window="rectangular")
>>> w
Window (3, 3) rectangular
[[1. 1. 1.]
 [1. 1. 1.]
 [1. 1. 1.]]
>>> w.make_circular()
>>> w
Window (3, 3) circular
[[0. 1. 0.]
 [1. 1. 1.]
 [0. 1. 0.]]

A custom window can be created

>>> w = kp.filters.Window(np.arange(6).reshape(3, 2))
>>> w
Window (3, 2) custom
[[0 1]
 [2 3]
 [4 5]]

To create a Gaussian window with a standard deviation of 2, obtained from scipy.signal.windows.gaussian()

>>> w = kp.filters.Window(window="gaussian", std=2)
>>> w
Window (3, 3) gaussian
[[0.7788 0.8825 0.7788]
 [0.8825 1.     0.8825]
 [0.7788 0.8825 0.7788]]

Attributes

Window.circular

Return whether the window is circular.

Window.distance_to_origin

Return the radial distance for each pixel to the window origin.

Window.is_valid

Return whether the window is in a valid state.

Window.n_neighbours

Return the maximum number of nearest neighbours in each navigation axis to the origin.

Window.name

Return the name of the window.

Window.origin

Return the window origin.

Methods

Window.make_circular()

Make the window circular.

Window.plot([grid, show_values, textcolors, ...])

Plot window values with indices relative to the origin.

Window.shape_compatible(shape)

Return whether the window shape is compatible with another shape.