raster_tools.focal.focal#
- raster_tools.focal.focal(raster, focal_type, width_or_radius, height=None, ignore_null=False)[source]#
Applies a focal filter to raster bands individually.
The filter uses a window/footprint that is created using the width_or_radius and height parameters. The window can be a rectangle, circle or annulus.
- Parameters
raster (Raster or path str) – The raster to perform the focal operation on.
focal_type (str) –
Specifies the aggregation function to apply to the focal neighborhood at each pixel. Can be one of the following string values:
- ’min’
Finds the minimum value in the neighborhood.
- ’max’
Finds the maximum value in the neighborhood.
- ’mean’
Finds the mean of the neighborhood.
- ’median’
Finds the median of the neighborhood.
- ’mode’
Finds the mode of the neighborhood.
- ’sum’
Finds the sum of the neighborhood.
- ’std’
Finds the standard deviation of the neighborhood.
- ’var’
Finds the variance of the neighborhood.
- ’asm’
Angular second moment. Applies -sum(P(g)**2) where P(g) gives the probability of g within the neighborhood.
- ’entropy’
Calculates the entropy. Applies -sum(P(g) * log(P(g))). See ‘asm’ above.
- ’unique’
Calculates the number of unique values in the neighborhood.
width_or_radius (int or 2-tuple of ints) – If an int and height is None, specifies the radius of a circle window. If an int and height is also an int, specifies the width of a rectangle window. If a 2-tuple of ints, the values specify the inner and outer radii of an annulus window.
height (int or None) – If None (default), width_or_radius will be used to construct a circle or annulus window. If an int, specifies the height of a rectangle window.
ignore_null (bool) – If False, cells marked as null remain null. If True, cells marked as null may receive a data value, provided there are valid cells in the neighborhood. The default is False.
- Returns
The resulting raster with focal filter applied to each band. The bands will have the same shape as the original Raster.
- Return type
Raster