API

numbamisc._filters.median_filter(data, kernel, mask='unspecified', mode=u'ignore', ignore_nan=True)[source]

Median filter ignoring masked and NaN values.

Parameters:
data : ndarray, MaskedArray, NDData

The data to filter.

kernel : int, tuple, ndarray, Kernel

See main documentation for explanation. The kernel is cast to dtype=bool before filtering.

mask : ndarray, optional

Mask for the filter. If given an implicit mask by data is ignored.

mode : string, optional

How to treat values outside the data. Default is ignore.

ignore_nan : bool, optional

Also ignore NaN values. Default is True.

Returns:
filtered : ndarray

The filtered array.

mask : ndarray

The mask of the filtered array.

See also

scipy.ndimage.median_filter
the same without mask support.

Examples

A simple example using a masked array:

>>> from numbamisc import median_filter
>>> import numpy as np

>>> data = np.ma.array([1,1000,2,1], mask=[0, 1, 0, 0])
>>> d, m = median_filter(data, [1,1,1])
>>> d
array([ 1. ,  1.5,  1.5,  1.5])
>>> m
array([False, False, False, False], dtype=bool)

Support for arbitarly dimensional arrays and masks is also implemented:

>>> data = np.arange(9).reshape(3, 3)
>>> data[1, 1] = 100
>>> mask = np.zeros((3, 3), dtype=bool)
>>> mask[1, 1] = 1
>>> d, m = median_filter(data, np.ones((3,3)), mask)
>>> d
array([[ 1.,  2.,  2.],
       [ 3.,  4.,  5.],
       [ 6.,  6.,  7.]])
>>> m
array([[False, False, False],
       [False, False, False],
       [False, False, False]], dtype=bool)

Explictly setting kernel elements to zero excludes those elements for the convolution:

>>> data = np.ma.array([1, 1000, 2, 1], mask=[0, 1, 0, 0])
>>> d, m = median_filter(data, [1, 0, 0])
>>> d
array([ nan,   1.,  nan,   2.])
>>> m
array([ True, False,  True, False], dtype=bool)

Here only the left element is used for the convolution. For the first element the left one is outside the data and for the third element the convolution element is masked so both of them result in NaN.

numbamisc._filters.median_filter_weigthed(data, kernel, mask='unspecified', mode=u'ignore', ignore_nan=True)[source]

Weighted median filter ignoring masked and NaN values.

Parameters:
data : ndarray, MaskedArray, NDData

The data to filter.

kernel : int, tuple, ndarray, Kernel

See main documentation for explanation. The kernel is cast to dtype=np.int_ before filtering.

mask : ndarray, optional

Mask for the filter. If given an implicit mask by data is ignored.

mode : string, optional

How to treat values outside the data. Default is ignore.

ignore_nan : bool, optional

Also ignore NaN values. Default is True.

Returns:
filtered : ndarray

The filtered array.

mask : ndarray

The mask of the filtered array.

numbamisc._filters.min_filter(data, kernel, mask='unspecified', mode=u'ignore', ignore_nan=True)[source]

Minimum filter ignoring masked and NaN values.

Parameters:
data : ndarray, MaskedArray, NDData

The data to filter.

kernel : int, tuple, ndarray, Kernel

See main documentation for explanation. The kernel is cast to dtype=bool before filtering.

mask : ndarray, optional

Mask for the filter. If given an implicit mask by data is ignored.

mode : string, optional

How to treat values outside the data. Default is ignore.

ignore_nan : bool, optional

Also ignore NaN values. Default is True.

Returns:
filtered : ndarray

The median filtered array.

mask : ndarray

The mask of the filtered array.

See also

scipy.ndimage.minimum_filter
the same without mask support.
numbamisc._filters.max_filter(data, kernel, mask='unspecified', mode=u'ignore', ignore_nan=True)[source]

Maximum filter ignoring masked and NaN values.

Parameters:
data : ndarray, MaskedArray, NDData

The data to filter.

kernel : int, tuple, ndarray, Kernel

See main documentation for explanation. The kernel is cast to dtype=bool before filtering.

mask : ndarray, optional

Mask for the filter. If given an implicit mask by data is ignored.

mode : string, optional

How to treat values outside the data. Default is ignore.

ignore_nan : bool, optional

Also ignore NaN values. Default is True.

Returns:
filtered : ndarray

The median filtered array.

mask : ndarray

The mask of the filtered array.

See also

scipy.ndimage.maximum_filter
the same without mask support.
numbamisc._filters.average_filter(data, kernel, mask='unspecified', mode=u'ignore', ignore_nan=True)[source]

Averaging filter ignoring masked and NaN values.

Parameters:
data : ndarray, MaskedArray, NDData

The data to filter.

kernel : int, tuple, ndarray, Kernel

See main documentation for explanation. The kernel must not contain mixed signed values. Either all values must be positive or all negative.

mask : ndarray, optional

Mask for the filter. If given an implicit mask by data is ignored.

mode : string, optional

How to treat values outside the data. Default is ignore.

ignore_nan : bool, optional

Also ignore NaN values. Default is True.

Returns:
filtered : ndarray

The median filtered array.

mask : ndarray

The mask of the filtered array.

numbamisc._filters.sum_filter(data, kernel, mask='unspecified', mode=u'ignore', ignore_nan=True)[source]

Summation filter ignoring masked and NaN values.

Parameters:
data : ndarray, MaskedArray, NDData

The data to filter.

kernel : int, tuple, ndarray, Kernel

See main documentation for explanation. The kernel must not contain mixed signed values. Either all values must be positive or all negative.

mask : ndarray, optional

Mask for the filter. If given an implicit mask by data is ignored.

mode : string, optional

How to treat values outside the data. Default is ignore.

ignore_nan : bool, optional

Also ignore NaN values. Default is True.

Returns:
filtered : ndarray

The median filtered array.

mask : ndarray

The mask of the filtered array.

See also

scipy.ndimage.convolve
the same without mask support.