lair.background.rolling_baseline#

lair.background.rolling_baseline(data, window='24h', q=0.01, min_periods=1, center=True)[source]#

Calculate the baseline concentration as a rolling quantile.

The baseline is the rolling q quantile over window, smoothed with a rolling mean over the same window.

Parameters:
  • data (pd.Series) – Time series of data to calculate the baseline from.

  • window (Any, optional) – Window size for the rolling calculation. Must be passable to pd.Timedelta. Default is ‘24h’.

  • q (float, optional) – Quantile to calculate the baseline from. Default is 0.01.

  • min_periods (int, optional) – Minimum number of periods within each window required to have a value. Default is 1.

  • center (bool, optional) – Center the window on the timestamp. Default is True.

Returns:

pd.Series – Baseline concentration

Return type:

Series

See also

phase_shift_corrected_baseline

A low quantile that follows fast changes in one-second data.

thoning

A smooth curve through the data.

Examples

Hourly methane at 2000 ppb with a spike of 50 ppb every morning at 08:00; the baseline leaves the spikes out:

>>> import pandas as pd
>>> from lair.background import rolling_baseline
>>> times = pd.date_range("2024-01-01", periods=72, freq="h")
>>> ch4 = pd.Series(2000.0, index=times)
>>> ch4[times.hour == 8] += 50.0
>>> rolling_baseline(ch4, window="24h").unique()
array([2000.])