xrspatial.convolution.circle_kernel

xrspatial.convolution.circle_kernel(cellsize_x, cellsize_y, radius)[source]

Generates a circular kernel of a given cellsize and radius.

Parameters
  • cellsize_x (int) – Cell size of output kernel in x-direction.

  • cellsize_y (int) – Cell size of output kernel in y-direction.

  • radius (int) – Radius of output kernel.

Returns

kernel – 2D array where values of 1 indicate the kernel.

Return type

NumPy Array of float values

Examples

>>> import xarray as xr
>>> from xrspatial.convolution import circle_kernel

>>> # Create Kernel
>>> kernel = circle_kernel(1, 1, 3)
>>> print(kernel)
[[0. 0. 0. 1. 0. 0. 0.]
[0. 1. 1. 1. 1. 1. 0.]
[0. 1. 1. 1. 1. 1. 0.]
[1. 1. 1. 1. 1. 1. 1.]
[0. 1. 1. 1. 1. 1. 0.]
[0. 1. 1. 1. 1. 1. 0.]
[0. 0. 0. 1. 0. 0. 0.]]

>>> kernel = circle_kernel(1, 2, 3)
>>> print(kernel)
[[0. 0. 0. 1. 0. 0. 0.]
 [1. 1. 1. 1. 1. 1. 1.]
 [0. 0. 0. 1. 0. 0. 0.]]