For the purpose of comparison with STL decomposition we showcase the elimination of a linear trend and seasonal effects on carbon dioxide (CO2) data taken at the Mauna Loa Observatory in Hawaii
The Keeling Curve data, is provided by Dr. Pieter Tans, NOAA/ESRL and Dr. Ralph Keeling, Scripps Institution of Oceanography.
For the purpose of demonstration we focus on the period from 1990 to 2021.
# First, let's import the needed libraries.
import pandas as pd
import matplotlib.pyplot as plt
import numpy as np
from datetime import datetime
# open the respective dictionary stored as a .json file
df_co2 = pd.read_json(
"http://userpage.fu-berlin.de/soga/soga-py/300/307000_time_series/KeelingCurve.json"
)
df_co2 = df_co2.set_index("Date") # set datetimeindex
For the purpose of demonstration we focus on the period from 1990 to 2021.
Exercise: Subset the
df_co2
data set to the period 1990-2021.
## Your code here...
df_co2_1990_2021 = df_co2["2000-01-01":"2021-12-31"]["interpolated"]
Exercise: Plot the subset of the
df_co2
data.
plt.figure(figsize=(18, 6))
df_co2_1990_2021.plot(
title="$CO_2$ Concentration [ppm] at Mauna Loa Observatory, Hawaii (1990-2020)"
)
plt.show()
Finally, we store the time series data set in a .json
file for further processing.
df_co2_1990_2021 = df_co2_1990_2021.to_frame(name="co2_ppm").reset_index()
df_co2_1990_2021.to_json("../data/KeelingCurve_1990-2021.json", date_format="iso")
Citation
The E-Learning project SOGA-Py was developed at the Department of Earth Sciences by Annette Rudolph, Joachim Krois and Kai Hartmann. You can reach us via mail by soga[at]zedat.fu-berlin.de.
Please cite as follow: Rudolph, A., Krois, J., Hartmann, K. (2023): Statistics and Geodata Analysis using Python (SOGA-Py). Department of Earth Sciences, Freie Universitaet Berlin.