---
file_format: mystnb
kernelspec:
  name: python3
---
(detrending_sec)=
# Detrending

Time series detrending is an essential preparatory step that helps to standardize data, remove trends, and make different time series comparable.
`delaynet` provides several detrending methods that can be applied to time series data.
Depending on the data source and {ref}`connectivity measure <connectivity_sec>` you might want to choose a specific detrending method.
First, the available methods are listed below with explanation and code examples.
The last paragraph presents the {ref}`convenience API <using_detrend_methods>` for applying these methods.

(using_detrend_methods)=
## Using Detrending Methods

`delaynet` provides a consistent interface {py:func}`~delaynet.detrending.detrend` for all detrending methods.
You can refer to each method by its full name or by its shorthand:

- {ref}`Delta detrending <delta>`: "delta" or "dt"
- {ref}`Second difference detrending <second_difference>`: "second_difference", "second difference", or "2dt"
- {ref}`Z-Score detrending <z_score>`: "z_score", "z-score", "zs", or "zscore"
- {ref}`Identity detrending <identity_func>`: "identity" or "id"

The full list can easily be pretty printed using {py:func}`dn.show_detrending_methods()<delaynet.detrending.show_detrending_methods>`.

```python
import delaynet as dn

# Detrend using the delta method
detrended_ts = dn.detrend(time_series, method="delta", window_size=10)

# Detrend using the Z-Score method
detrended_ts = dn.detrend(time_series, method="zs", periodicity=24)
```

For details about these detrending methods, see the next subsections.
Otherwise continue to read
the {ref}`connectivity methods <connectivity_sec>`.


```{toctree}
:hidden:
:name: table_of_detrending_methods
:caption: Table of Detrending Methods

delta
second_difference
z_score
identity
```
