first commit

parent e391755a
{ {
"cells": [], "cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# CO₂ concentration in the atmosphere since 1958\n",
"\n",
"This computational document analyzes the evolution of atmospheric carbon dioxide concentration measured at Mauna Loa Observatory since 1958.\n",
"\n",
"The data come from NOAA Global Monitoring Laboratory. The objective is to visualize the long-term trend, the seasonal cycle, and the annual increase in CO₂ concentration."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"import pandas as pd\n",
"import numpy as np\n",
"import matplotlib.pyplot as plt\n",
"from scipy.stats import linregress"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## 1. Loading the data\n",
"\n",
"We use the monthly mean CO₂ concentration data from Mauna Loa Observatory.\n",
"The concentration is expressed in parts per million, abbreviated ppm."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"url = \"https://gml.noaa.gov/webdata/ccgg/trends/co2/co2_mm_mlo.txt\"\n",
"\n",
"columns = [\n",
" \"year\",\n",
" \"month\",\n",
" \"decimal_date\",\n",
" \"average\",\n",
" \"deseasonalized\",\n",
" \"days\",\n",
" \"stdev\",\n",
" \"uncertainty\"\n",
"]\n",
"\n",
"co2 = pd.read_csv(\n",
" url,\n",
" comment=\"#\",\n",
" sep=r\"\\s+\",\n",
" names=columns\n",
")\n",
"\n",
"co2.head()"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## 2. Cleaning the data\n",
"\n",
"Missing monthly values are coded as negative values in the NOAA file. We replace them by missing values and remove them from the analysis."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"co2[\"average\"] = co2[\"average\"].replace(-99.99, np.nan)\n",
"co2[\"deseasonalized\"] = co2[\"deseasonalized\"].replace(-99.99, np.nan)\n",
"\n",
"co2 = co2.dropna(subset=[\"average\"])\n",
"\n",
"co2[\"date\"] = pd.to_datetime(\n",
" co2[\"year\"].astype(str) + \"-\" + co2[\"month\"].astype(str) + \"-15\"\n",
")\n",
"\n",
"co2.head()"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## 3. Descriptive statistics\n",
"\n",
"We compute basic descriptive statistics for monthly atmospheric CO₂ concentration."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"stats = co2[\"average\"].describe()\n",
"stats"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"print(\"Minimum CO2 concentration:\", round(co2[\"average\"].min(), 2), \"ppm\")\n",
"print(\"Maximum CO2 concentration:\", round(co2[\"average\"].max(), 2), \"ppm\")\n",
"print(\"Mean CO2 concentration:\", round(co2[\"average\"].mean(), 2), \"ppm\")\n",
"print(\"Median CO2 concentration:\", round(co2[\"average\"].median(), 2), \"ppm\")"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## 4. Evolution of monthly CO₂ concentration\n",
"\n",
"The following graph shows the monthly average CO₂ concentration since 1958."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"plt.figure(figsize=(10, 5))\n",
"plt.plot(co2[\"date\"], co2[\"average\"])\n",
"plt.xlabel(\"Year\")\n",
"plt.ylabel(\"CO₂ concentration (ppm)\")\n",
"plt.title(\"Monthly CO₂ concentration at Mauna Loa since 1958\")\n",
"plt.grid(True)\n",
"plt.show()"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## 5. Seasonal variability\n",
"\n",
"The monthly data show a seasonal cycle. To see this more clearly, we compute the average CO₂ concentration for each month of the year."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"monthly_cycle = co2.groupby(\"month\")[\"average\"].mean()\n",
"\n",
"plt.figure(figsize=(8, 5))\n",
"plt.plot(monthly_cycle.index, monthly_cycle.values, marker=\"o\")\n",
"plt.xlabel(\"Month\")\n",
"plt.ylabel(\"Average CO₂ concentration (ppm)\")\n",
"plt.title(\"Average seasonal cycle of CO₂ concentration\")\n",
"plt.xticks(range(1, 13))\n",
"plt.grid(True)\n",
"plt.show()"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## 6. Annual mean CO₂ concentration\n",
"\n",
"We compute the annual average concentration to remove most of the seasonal variation and focus on the long-term trend."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"annual = co2.groupby(\"year\")[\"average\"].mean().reset_index()\n",
"annual.head()"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"plt.figure(figsize=(10, 5))\n",
"plt.plot(annual[\"year\"], annual[\"average\"], marker=\"o\")\n",
"plt.xlabel(\"Year\")\n",
"plt.ylabel(\"Annual average CO₂ concentration (ppm)\")\n",
"plt.title(\"Annual average CO₂ concentration at Mauna Loa\")\n",
"plt.grid(True)\n",
"plt.show()"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## 7. Linear trend\n",
"\n",
"We estimate a simple linear trend for annual average CO₂ concentration."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"slope, intercept, r_value, p_value, std_err = linregress(\n",
" annual[\"year\"],\n",
" annual[\"average\"]\n",
")\n",
"\n",
"annual[\"trend\"] = intercept + slope * annual[\"year\"]\n",
"\n",
"print(\"Estimated annual increase:\", round(slope, 3), \"ppm per year\")\n",
"print(\"R-squared:\", round(r_value**2, 4))"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"plt.figure(figsize=(10, 5))\n",
"plt.plot(annual[\"year\"], annual[\"average\"], marker=\"o\", label=\"Annual mean\")\n",
"plt.plot(annual[\"year\"], annual[\"trend\"], label=\"Linear trend\")\n",
"plt.xlabel(\"Year\")\n",
"plt.ylabel(\"CO₂ concentration (ppm)\")\n",
"plt.title(\"Linear trend of annual CO₂ concentration\")\n",
"plt.legend()\n",
"plt.grid(True)\n",
"plt.show()"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## 8. Annual growth rate\n",
"\n",
"We compute the year-to-year difference in annual mean CO₂ concentration."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"annual[\"growth\"] = annual[\"average\"].diff()\n",
"\n",
"plt.figure(figsize=(10, 5))\n",
"plt.bar(annual[\"year\"], annual[\"growth\"])\n",
"plt.xlabel(\"Year\")\n",
"plt.ylabel(\"Annual increase (ppm)\")\n",
"plt.title(\"Year-to-year increase in atmospheric CO₂\")\n",
"plt.grid(True)\n",
"plt.show()"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"largest_growth = annual.loc[annual[\"growth\"].idxmax()]\n",
"smallest_growth = annual.loc[annual[\"growth\"].idxmin()]\n",
"\n",
"print(\"Largest annual increase:\")\n",
"print(largest_growth[[\"year\", \"growth\"]])\n",
"\n",
"print(\"\\nSmallest annual increase:\")\n",
"print(smallest_growth[[\"year\", \"growth\"]])"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## 9. Conclusion\n",
"\n",
"The analysis shows a clear long-term increase in atmospheric CO₂ concentration at Mauna Loa since 1958. The monthly data also show a seasonal cycle, which is visible when averaging observations by month. The annual averages confirm that CO₂ concentration has increased steadily over the period covered by the dataset.\n",
"\n",
"This notebook is reproducible because it downloads the data from the original source, documents each transformation step, and produces the tables and figures directly from the code."
]
}
],
"metadata": { "metadata": {
"kernelspec": { "kernelspec": {
"display_name": "Python 3", "display_name": "Python 3",
...@@ -16,10 +318,9 @@ ...@@ -16,10 +318,9 @@
"name": "python", "name": "python",
"nbconvert_exporter": "python", "nbconvert_exporter": "python",
"pygments_lexer": "ipython3", "pygments_lexer": "ipython3",
"version": "3.6.3" "version": "3.6.4"
} }
}, },
"nbformat": 4, "nbformat": 4,
"nbformat_minor": 2 "nbformat_minor": 2
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment