xrspatial.convolution.annulus_kernel#
- xrspatial.convolution.annulus_kernel(cellsize_x, cellsize_y, outer_radius, inner_radius)[source]#
Generates an annulus (ring-shaped) 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.
outer_radius (int) – Outer ring radius of output kernel.
inner_radius (int) – Inner circle radius of output kernel.
- Returns
kernel – 2D array of 0s and 1s where values of 1 indicate the kernel.
- Return type
NumPy Array of float values.
Examples
>>> import xarray as xr >>> from xrspatial.convolution import annulus_kernel >>> # Create Kernel >>> kernel = annulus_kernel(1, 1, 3, 1) >>> print(kernel) [[0., 0., 0., 1., 0., 0., 0.], [0., 1., 1., 1., 1., 1., 0.], [0., 1., 1., 0., 1., 1., 0.], [1., 1., 0., 0., 0., 1., 1.], [0., 1., 1., 0., 1., 1., 0.], [0., 1., 1., 1., 1., 1., 0.], [0., 0., 0., 1., 0., 0., 0.]] >>> kernel = annulus_kernel(1, 2, 5, 2) >>> print(kernel) [[0., 0., 0., 0., 0., 1., 0., 0., 0., 0., 0.], [0., 1., 1., 1., 1., 0., 1., 1., 1., 1., 0.], [1., 1., 1., 0., 0., 0., 0., 0., 1., 1., 1.], [0., 1., 1., 1., 1., 0., 1., 1., 1., 1., 0.], [0., 0., 0., 0., 0., 1., 0., 0., 0., 0., 0.]])