scipp.scipy.ndimage.gaussian_filter#

scipp.scipy.ndimage.gaussian_filter(x, /, *, sigma, order=0, **kwargs)#

Multidimensional Gaussian filter.

This is a wrapper around scipy.ndimage.gaussian_filter(). See there for full argument description. There are two key differences:

  • This wrapper uses explicit dimension labels in the sigma and order arguments. For example, instead of sigma=[4, 6] use sigma={'time':4, 'space':6} (with appropriate dimension labels for the data).

  • Coordinate values can be used (and should be preferred) for sigma. For example, instead of sigma=[4, 6] use sigma={'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

If sigma is an integer or a mapping to integers then 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.

  • sigma (float | Variable | Mapping[str, float | Variable]) – Standard deviation for Gaussian kernel. The standard deviations of the Gaussian filter are given as a mapping from dimension labels to numbers or scalar variables, or as a single number or scalar variable, in which case it is equal for all axes.

  • order (int | Mapping[str, int] | None, default: 0) – The order of the filter along each dimension, given as mapping from dimension labels to integers, or as a single integer. An order of 0 corresponds to convolution with a Gaussian kernel. A positive order corresponds to convolution with that derivative of a Gaussian.

Returns:

scipp.typing.VariableLike – Filtered variable or data array

Examples

>>> from scipp.scipy.ndimage import gaussian_filter
>>> da = sc.data.data_xy()
>>> da.plot()

With sigma as integer:

>>> filtered = gaussian_filter(da, sigma=4)
>>> filtered.plot()

With sigma based on input coordinate values:

>>> filtered = gaussian_filter(da, sigma=sc.scalar(0.1, unit='mm'))
>>> filtered.plot()

With different sigma for different dimensions:

>>> filtered = gaussian_filter(da, sigma={'x':sc.scalar(0.01, unit='mm'),
...                                       'y':sc.scalar(1.0, unit='mm')})
>>> filtered.plot()