lair.background.phase_shift_corrected_baseline#

lair.background.phase_shift_corrected_baseline(data, n=3600, q=0.01)[source]#

Derive a baseline concentration from a low quantile, minimizing phase shift.

This method uses forward-looking and backward-looking windows to better represent the lowest observed concentrations during periods of rapid change.

Note

Original developed by Ben Fasoli for the Google Street View project. See supplementary material in: https://doi.org/10.1016/j.atmosenv.2023.119995

Parameters:
  • data (pd.Series) – Signal time series with a datetime index. The baseline is calculated separately for each calendar day of the index, in the index’s own time zone (the function does no time zone conversion), so pass local time to get local days. The windows are counted on a one-second grid that starts at each day’s first time, so the times must fall on whole seconds from it (one-second data, or a slower rate on whole seconds).

  • n (int, optional) – Window size in seconds. Default is 3600.

  • q (float, optional) – Quantile to extract from signal. Default is 0.01.

Returns:

pd.Series – Baseline concentration at the times of data, so data - baseline lines up row for row. A time off the one-second grid gets NaN.

Return type:

Series

See also

rolling_baseline

A rolling low quantile for data of any rate.

Examples

Two hours of one-second methane at 2000 ppb with a plume of 100 ppb for five minutes, and a window of ten minutes:

>>> import pandas as pd
>>> from lair.background import phase_shift_corrected_baseline
>>> times = pd.date_range("2024-01-01 12:00", periods=7200, freq="s")
>>> ch4 = pd.Series(2000.0, index=times)
>>> ch4.iloc[3000:3300] += 100.0
>>> baseline = phase_shift_corrected_baseline(ch4, n=600)
>>> baseline.round(6).unique()
array([2000.])
>>> round(float((ch4 - baseline).max()), 6)  # the plume above the baseline
100.0