import numpy as np
import pandas as pd
from glob import glob
from io import StringIO
import matplotlib.pyplot as plt
import requests
Atmospheric Carbon Dioxide Concentrations from NOAA Global Monitoring Laboratory
Approach
- Identify available dates and temporal frequency of observations for the given data. The collection processed in this notebook is the Atmospheric Carbon Dioxide Concentrations from NOAA Global Monitoring Laboratory.
- Visualize the time series data
About the Data
The Global Greenhouse Gas Reference Network (GGGRN) for the Carbon Cycle and Greenhouse Gases (CCGG) Group is part of NOAA’S Global Monitoring Laboratory (GML) in Boulder, CO. The Reference Network measures the atmospheric distribution and trends of the three main long-term drivers of climate change, carbon dioxide (CO₂), methane (CH₄), and nitrous oxide (N2O), as well as carbon monoxide (CO) and many other trace gases which help interpretation of the main GHGs. The Reference Network measurement program includes continuous in-situ measurements at 4 baseline observatories (global background sites) and 8 tall towers, as well as flask-air samples collected by volunteers at over 50 additional regional background sites and from small aircraft conducting regular vertical profiles. The air samples are returned to GML for analysis where measurements of about 55 trace gases are done. NOAA’s GGGRN maintains the World Meteorological Organization international calibration scales for CO₂, CH₄, CO, N2O, and SF6 in air. The measurements from the GGGRN serve as a comparison with measurements made by many other international laboratories, and with regional studies. They are widely used in modeling studies that infer space-time patterns of emissions and removals of greenhouse gases that are optimally consistent with the atmospheric observations, given wind patterns. These data serve as an early warning for climate “surprises”. The measurements are also helpful for the ongoing evaluation of remote sensing technologies.
For more information regarding this dataset, please visit the Atmospheric Carbon Dioxide Concentrations from NOAA GML data overview page.
Install the Required Libraries
Required libraries are pre-installed on the GHG Center Hub. If you need to run this notebook elsewhere, please install them with this line in a code cell:
%pip install requests folium rasterstats pystac_client pandas matplotlib –quiet
Importing required libraries
Reading the NOAA data from GitHub repo
= "NASA-IMPACT"
github_repo_owner = "noaa-viz"
github_repo_name = "flask/ch4", "flask/c02"
folder_path_ch4, folder_path_co2 = pd.DataFrame(), pd.DataFrame()
combined_df_co2, combined_df_ch4
# Function to fetch and append a file from GitHub
def append_github_file(file_url):
= requests.get(file_url)
response
response.raise_for_status()return response.text
# Get the list of CH4 files in the specified directory using GitHub API
= f"https://api.github.com/repos/{github_repo_owner}/{github_repo_name}/contents/{folder_path_ch4}"
github_api_url = requests.get(github_api_url)
response
response.raise_for_status()= response.json()
file_list_ch4
# Get the list of CO2 files in the specified directory using GitHub API
= f"https://api.github.com/repos/{github_repo_owner}/{github_repo_name}/contents/{folder_path_ch4}"
github_api_url = requests.get(github_api_url)
response
response.raise_for_status()= response.json() file_list_co2
Concatenating the CH4 data into a single DataFrame
for file_info in file_list_ch4:
if file_info["name"].endswith("txt"):
= append_github_file(file_info["download_url"])
file_content = file_content.splitlines()
Lines = Lines.index("# VARIABLE ORDER")+2
index = pd.read_csv(StringIO("\n".join(Lines[index:])), delim_whitespace=True)
df = pd.concat([combined_df_ch4, df], ignore_index=True)
combined_df_ch4
Concatenating the CO2 data into a single DataFrame
for file_info in file_list_co2:
if file_info["name"].endswith("txt"):
= append_github_file(file_info["download_url"])
file_content = file_content.splitlines()
Lines = Lines.index("# VARIABLE ORDER")+2
index = pd.read_csv(StringIO("\n".join(Lines[index:])), delim_whitespace=True)
df = pd.concat([combined_df_co2, df], ignore_index=True)
combined_df_co2
Visualizing the NOAA data for CH4 and CO2
= 'ABP'
site_to_filter = combined_df_co2[combined_df_co2['site_code'] == site_to_filter]
filtered_df
'datetime'] = pd.to_datetime(filtered_df['datetime'])
filtered_df[
# Set the "Date" column as the index
'datetime', inplace=True)
filtered_df.set_index(
# Create a time series plot for 'Data' and 'Value'
=(12, 6))
plt.figure(figsize'value'], label='Carbon Dioxide(CO2) Concentration (ppm)')
plt.plot(filtered_df.index, filtered_df["Observed Date/Time")
plt.xlabel("Carbon Dioxide(CO2) Concentration (ppm)")
plt.ylabel(f"Observed Co2 Concentration {site_to_filter}")
plt.title(
plt.legend()True)
plt.grid(# plt.show()
/var/folders/7b/5rrvrjx51l54jchgs0tqps0c0000gn/T/ipykernel_70808/2606016741.py:4: SettingWithCopyWarning:
A value is trying to be set on a copy of a slice from a DataFrame.
Try using .loc[row_indexer,col_indexer] = value instead
See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy
filtered_df['datetime'] = pd.to_datetime(filtered_df['datetime'])
= 'ABP'
site_to_filter = combined_df_ch4[combined_df_ch4['site_code'] == site_to_filter]
filtered_df 'datetime'] = pd.to_datetime(filtered_df['datetime'])
filtered_df[
# Set the "Date" column as the index
'datetime', inplace=True)
filtered_df.set_index(
# Create a time series plot for 'Data' and 'Value'
=(12, 6))
plt.figure(figsize'value'], label='Methane Ch4 Concentration (ppb)')
plt.plot(filtered_df.index, filtered_df["Observation Date/Time")
plt.xlabel("Methane Ch4 Concentration (ppb)")
plt.ylabel(f"Observed CH4 Concentration {site_to_filter}")
plt.title(
plt.legend()True)
plt.grid( plt.show()
/var/folders/7b/5rrvrjx51l54jchgs0tqps0c0000gn/T/ipykernel_70808/1635934907.py:3: SettingWithCopyWarning:
A value is trying to be set on a copy of a slice from a DataFrame.
Try using .loc[row_indexer,col_indexer] = value instead
See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy
filtered_df['datetime'] = pd.to_datetime(filtered_df['datetime'])
Summary
In this notebook we have successfully visualized the data for Atmospheric Carbon Dioxide Concentrations from NOAA Global Monitoring Laboratory.
- Install and import the necessary libraries
- Fetch the collection from GitHub API using the appropriate endpoints
- Concatenating the CO2 and CH4 data into a single DataFrame
- Visualizing the NOAA data for CO2 and CH4
If you have any questions regarding this user notebook, please contact us using the feedback form.