spectral_connectivity.transforms.detrend#
- detrend(data: ndarray[tuple[int, ...], dtype[floating]], axis: int = -1, type: str = 'linear', bp: int | list[int] | ndarray[tuple[int, ...], dtype[integer]] = 0, overwrite_data: bool = False) ndarray[tuple[int, ...], dtype[floating]][source]#
Remove linear trend along axis from data.
Thin wrapper that validates
type/bp(raising actionable errors) and delegates the computation toscipy.signal.detrendon CPU orcupyx.scipy.signal.detrendon GPU.- Parameters:
data (array_like) – The input data.
axis (int, optional) – The axis along which to detrend the data. By default this is the last axis (-1).
type ({'linear', 'constant'}, optional) – The type of detrending. If
type == 'linear'(default), the result of a linear least-squares fit to data is subtracted from data. Iftype == 'constant', only the mean of data is subtracted.bp (array_like of ints, optional) – A sequence of break points. If given, an individual linear fit is performed for each part of data between two break points. Break points are specified as indices into data. This parameter only has an effect when
type == 'linear'.overwrite_data (bool, optional) – If True, perform in place detrending and avoid a copy. Default is False
- Returns:
ret – The detrended input data.
- Return type:
ndarray
Examples
>>> import numpy as np >>> from scipy import signal >>> rng = np.random.default_rng(0) >>> npoints = 1000 >>> noise = rng.standard_normal(npoints) >>> x = 3 + 2 * np.linspace(0, 1, npoints) + noise >>> # Removing the linear trend leaves (approximately) the original noise. >>> bool(np.abs(signal.detrend(x) - noise).max() < 0.2) True