scippneutron.smoothing.smooth#

scippneutron.smoothing.smooth(data, *, scale, kernel='gaussian', tail=1e-12, max_grid_points=1000000)[source]#

Smooth sampled data with a translation-invariant kernel.

The kernel describes a distribution of displacements Z, with displaced coordinates given by x' = x + scale * Z. At the boundaries, the kernel is renormalized over the available finite input domain.

Input that is not uniformly spaced is interpolated to a uniform grid, smoothed, and interpolated back to the original coordinates.

Parameters:
  • data (DataArray) – One-dimensional data to smooth. Must have a strictly increasing dimension coordinate.

  • scale (Variable) – Finite, non-negative scale factor for the displacement distribution. Must be a scalar with a unit compatible with the coordinate. Set to zero to return a copy of the input without smoothing.

  • kernel (smoothing._Kernel (types.str | scippneutron.smoothing._Distribution[str, _Distribution]), default: 'gaussian') – Kernel distribution. The canonical names are 'gaussian', 'boxcar', and 'triangular'. They represent a standard normal distribution, a uniform distribution on [-1, 1], and a symmetric triangular distribution on [-1, 1], respectively. Other aliases are accepted. Alternatively, provide a fully specified distribution with cdf, ppf, and support methods.

  • tail (float, default: 1e-12) – Total probability omitted when truncating a kernel with unbounded support. Must be strictly between zero and one.

  • max_grid_points (int, default: 1000000) – Intermediate uniform grids no larger than this are always allowed. Larger grids may be rejected to guard against excessive resampling.

Returns:

DataArray – Smoothed data. Coordinates and units are preserved. Points where no kernel mass falls inside the input domain are NaN; this can occur at the boundaries for one-sided kernels.

Raises:
  • ValueError – If the inputs have invalid values, if a data array has masks, if a string does not identify a supported kernel, or if the required intermediate grid exceeds max_grid_points.

  • scipp.DimensionError – If the input is not one-dimensional or scale is not scalar.

  • scipp.CoordError – If a data array has no dimension coordinate or has a bin-edge coordinate.

  • scipp.DTypeError – If data is binned.

  • scipp.UnitError – If the unit of scale is incompatible with the coordinate unit.

  • scipp.VariancesError – If the signal or scale has variances.

  • TypeError – If data is not a data array, scale is not a variable, kernel is not a distribution-like object, or max_grid_points is not an integer.

Warns:

UserWarning – If the data contains NaNs or infinities, since smoothing may fall back to a slower method.