contextual_median#

Contextual median filter.

This is a basic median filter where the filter is applied if and only if the central pixel of the moving window is a peak/maximum or a trough/minimum over the whole window. This is aimed at filtering anomalous values in the form of lonely spikes, without smoothing out the rest of the signal too much.

DEFAULT_DIMS: list[Hashable] = ['lat', 'lon']#

Default dimensions names to use if none are provided.

cmf_dask(input_field, window_size=3, iterations=1, axes=None, **kwargs)#

Apply contextual median filter.

This is a basic median filter where the filter is applied if and only if the central pixel of the moving window is a peak/maximum or a trough/minimum over the whole window. This is aimed at filtering anomalous values in the form of lonely spikes, without smoothing out the rest of the signal too much.

Parameters:
  • input_field (DaskArray) – Array to filter.

  • window_size (int) – Size of the moving window. Default is 3 (ie 3x3).

  • iterations (int) – Number of times to apply the filter.

  • axes (Sequence[int] | None) – Indices of the the y/lat and x/lon axes on which to work. If None (default), the last two axes are used.

  • kwargs – See available kwargs for universal functions at Generalized universal function API.

Returns:

Filtered array.

Return type:

DaskArray

cmf_numpy(input_field, window_size=3, iterations=1, axes=None, **kwargs)#

Apply contextual median filter.

This is a basic median filter where the filter is applied if and only if the central pixel of the moving window is a peak/maximum or a trough/minimum over the whole window. This is aimed at filtering anomalous values in the form of lonely spikes, without smoothing out the rest of the signal too much.

Parameters:
  • input_field (NDArray) – Array to filter.

  • window_size (int) – Size of the moving window. Default is 3 (ie 3x3).

  • iterations (int) – Number of times to apply the filter.

  • axes (Sequence[int] | None) – Indices of the the y/lat and x/lon axes on which to work. If None (default), the last two axes are used.

  • kwargs – See available kwargs for universal functions at Generalized universal function API.

Returns:

Filtered array.

Return type:

NDArray

cmf_xarray(input_field, window_size=3, iterations=1, dims=None)#

Apply contextual median filter.

This is a basic median filter where the filter is applied if and only if the central pixel of the moving window is a peak/maximum or a trough/minimum over the whole window. This is aimed at filtering anomalous values in the form of lonely spikes, without smoothing out the rest of the signal too much.

Parameters:
  • input_field (DataArray) – Array to filter.

  • window_size (int) – Size of the moving window. Default is 3 (ie 3x3).

  • iterations (int) – Number of times to apply the filter.

  • kwargs – See available kwargs for universal functions at Generalized universal function API.

  • dims (Collection[Hashable] | None) – Names of the dimensions along which to apply the algorithm. Order is irrelevant, no reordering will be made between the two dimensions. If the window_size argument is given as a mapping, its keys are used instead. If not specified, is taken as module-wide variable DEFAULT_DIMS which defaults to {'lat', 'lon'}.

Returns:

Filtered array.

Return type:

DataArray