scipp.scipy.ndimage.median_filter#
- scipp.scipy.ndimage.median_filter(x, /, *, size=None, footprint=None, origin=0, **kwargs)#
Calculate a multidimensional median filter.
This is a wrapper around
scipy.ndimage.median_filter()
. See there for full argument description. There are two key differences:This wrapper uses explicit dimension labels in the
size
,footprint
, andorigin
arguments. For example, instead ofsize=[4, 6]
usesize={'time':4, 'space':6}
(with appropriate dimension labels for the data).Coordinate values can be used (and should be preferred) for
size
andorigin
. For example, instead ofsize=[4, 6]
usesize={'time':sc.scalar(5.0, unit='ms'), 'space':sc.scalar(1.2, unit='mm')}
. In this case it is required that the corresponding coordinates exist and form a “linspace”, i.e., are evenly spaced.
Warning
When
size
is an integer or a mapping to integers or whenfootprint
is given, coordinate values are ignored. That is, the filter is applied even if the data points are not evenly spaced. The resulting filtered data may thus have no meaningful interpretation.- Parameters:
x (
scipp.typing.VariableLike
) – Input variable or data array.size (
Union
[int
,Variable
,Mapping
[str
,int
|Variable
],None
], default:None
) – Integer or scalar variable or mapping from dimension labels to integers or scalar variables. Defines the footprint (see below).footprint (
Optional
[Variable
], default:None
) – Variable with same dimension labels (but different shape) as the input data. The boolean values specify (implicitly) a shape, but also which of the elements within this shape will get passed to the filter function.origin (
int
|Variable
|Mapping
[str
,int
|Variable
], default:0
) – Integer or scalar variable or mapping from dimension labels to integers or scalar variables. Controls the placement of the filter on the input array.
- Returns:
scipp.typing.VariableLike
– Filtered variable or data array
Examples
>>> from scipp.scipy.ndimage import median_filter >>> da = sc.data.data_xy() >>> da.plot()
With size as integer:
>>> filtered = median_filter(da, size=4) >>> filtered.plot()
With size based on input coordinate values:
>>> filtered = median_filter(da, size=sc.scalar(0.2, unit='mm')) >>> filtered.plot()
With different size for different dimensions:
>>> filtered = median_filter(da, size={'x':sc.scalar(0.2, unit='mm'), ... 'y':sc.scalar(1.1, unit='mm')}) >>> filtered.plot()