lair.background.thoning#
- lair.background.thoning(data, smooth_time=None, **kwargs)[source]#
Thoning curve fitting.
Wraps code published by NOAA GML: https://gml.noaa.gov/ccgg/mbl/crvfit/crvfit.html
- Thoning, K.W., P.P. Tans, and W.D. Komhyr, 1989,
Atmospheric carbon dioxide at Mauna Loa Observatory, 2. Analysis of the NOAA/GMCC data, 1974 1985., J. Geophys. Res. ,94, 8549 8565.
- Parameters:
data (pd.Series) – Time series of data to be smoothed. Must have a datetime index. NaN values are dropped before the curve is fitted.
smooth_time (list[datetime] | pd.Index, optional) – Times at which to evaluate the fitted curve; they become the index of the result. Default is the index of
data, so rows wheredatais NaN get the curve’s value.**kwargs – Additional keyword arguments to pass to the ccgFilter class (see
thoning_filter()).sampleintervalis the step, in days, of the even grid the filter interpolates the data onto. The default (0) lets the filter estimate it from the steps of about a day or more; when the data has none, as hourly data without a gap of a day does, lair uses the median step (1/24 for hourly data). Hourly data with such gaps needssampleinterval=1/24.
- Returns:
pd.Series – Smoothed data, at
smooth_time.- Return type:
See also
thoning_filterThe filter itself, for its trend and harmonics.
rolling_baselineA low quantile instead of a curve through everything.
Examples
Three years of made-up daily CO2 that grows 2.5 ppm a year, with a seasonal cycle and noise, smoothed, then read on the first of each month:
>>> import numpy as np >>> import pandas as pd >>> from lair.background import thoning >>> rng = np.random.default_rng(0) >>> days = pd.date_range("2020-01-01", "2022-12-31", freq="D") >>> years = (days - days[0]).days / 365.25 >>> seasons = 3 * np.cos(2 * np.pi * years) >>> noise = rng.normal(0, 0.5, days.size) >>> co2 = pd.Series(410 + 2.5 * years + seasons + noise, index=days) >>> smooth = thoning(co2) >>> round(float(smooth.iloc[-1] - smooth.iloc[0]), 1) 7.6 >>> months = pd.date_range("2020-01-01", "2022-12-01", freq="MS") >>> thoning(co2, smooth_time=months).round(1).head(3).tolist() [413.0, 412.8, 412.1]