xrspatial.focal.custom_kernel#

xrspatial.focal.custom_kernel(kernel)[source]#

Validates a custom convolution kernel. If the kernel is valid, returns it unchanged; otherwise raises ValueError. A valid kernel is a 2D NumPy array with an odd number of rows and columns.

Parameters:

kernel (numpy.ndarray) – 2D array with an odd number of rows and columns.

Returns:

kernel – The input kernel, unchanged.

Return type:

numpy.ndarray

Examples

>>> import numpy as np
>>> from xrspatial.convolution import custom_kernel
>>> kernel = custom_kernel(np.array([
...     [0, 1, 0],
...     [1, 1, 1],
...     [0, 1, 0],
... ]))
>>> kernel
array([[0, 1, 0],
       [1, 1, 1],
       [0, 1, 0]])