raster_tools.focal.convolve#

raster_tools.focal.convolve(raster, kernel, mode='constant', cval=0.0)[source]#

Convolve kernel with each band individually. Returns a new Raster.

This is the same as correlation but the kernel is rotated 180 degrees, e.g. kernel = kernel[::-1, ::-1]. The kernel is applied to each band in isolation so the returned raster has the same shape as the original.

Parameters
  • raster (Raster) – The raster to convolve kernel with. Can be multibanded.

  • kernel (array_like) – 2D array of kernel weights

  • mode ({'reflect', 'constant', 'nearest', 'wrap'}, optional) –

    Determines how the data is extended beyond its boundaries. The default is ‘constant’.

    ’reflect’ (d c b a | a b c d | d c b a)

    The data pixels are reflected at the boundaries.

    ’constant’ (k k k k | a b c d | k k k k)

    A constant value determined by cval is used to extend the data pixels.

    ’nearest’ (a a a a | a b c d | d d d d)

    The data is extended using the boundary pixels.

    ’wrap’ (a b c d | a b c d | a b c d)

    The data is extended by wrapping to the opposite side of the grid.

  • cval (scalar, optional) – Value used to fill when mode is ‘constant’. Default is 0.0.

Returns

The resulting new Raster.

Return type

Raster