Carbon Dioxide and Methane Concentrations from the Los Angeles Megacity Carbon Project

Atmospheric concentrations of carbon dioxide (CO₂) and methane (CH₄) collected at NIST Urban Test Bed tower and rooftop sites in California’s South Coast Air Basin
Author

Siddharth Chaudhary, Paridhi Parajuli

Published

September 19, 2024

Approach

  1. Identify available dates and temporal frequency of observations for the given data. The collection processed in this notebook is the Atmospheric concentrations of carbon dioxide (CO₂) and methane (CH₄) collected at NIST Urban Test Bed tower sites in the Northeastern U.S.
  2. Visualize the time series data

About the Data

NIST is engaged in research to improve measurement of greenhouse gas emissions in areas containing multiple emission sources and sinks, such as ciies. NIST’s objective is to develop measurement tools supporting independent means to increase the accuracy of greenhouse gas emissions data at urban and regional geospatial scales. NIST has established three test beds in U.S. ciies to develop and evaluate the performance of advanced measurement capabilities for emissions independent of their origin. Located in Indianapolis, Indiana, the Los Angeles air basin of California, and the U.S. Northeast corridor (beginning with the Baltimore/Washington D.C. region), the test beds have been selected for their varying meteorology, terrain and emissions characteristics. These test beds will serve as a means to independently diagnose the accuracy of emissions data obtained directly from emission or uptake sources.

For more information regarding this dataset, please visit the Carbon Dioxide and Methane Concentrations from the Los Angeles Megacity Carbon Project 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

import requests
import pandas as pd
import matplotlib.pyplot as plt
import plotly.graph_objs as go
from io import StringIO

Querying the Feature Vector API

First, we are going to import the required libraries. Once imported, they allow better executing a query in the GHG Center Feature Vector Application Programming Interface (API) where the items for this collection are stored.

FEATURE_API_URL="https://earth.gov/ghgcenter/api/features"
# Function to fetch CSV data for a station with a limit parameter
def get_station_data_csv(station_code, gas_type, frequency, elevation_m, limit=100000):
    # Use the ?f=csv and limit query to get more rows
    url = f"https://earth.gov/ghgcenter/api/features/collections/public.nist_testbed_lam_{station_code}_{gas_type}_{frequency}_concentrations/items?f=csv&elevation_m={elevation_m}&limit={limit}"
    print(url)
    try:
        response = requests.get(url)
        
        # Check if the response is successful
        if response.status_code != 200:
            print(f"Failed to fetch data for {station_code}. Status code: {response.status_code}")
            return pd.DataFrame()

        # Check if the content type is CSV
        content_type = response.headers.get('Content-Type')
        if 'text/csv' not in content_type:
            print(f"Unexpected content type for {station_code}: {content_type}")
            print("Response content:", response.text)
            return pd.DataFrame()

        # Read the CSV content into a pandas DataFrame
        csv_data = StringIO(response.text)
        return pd.read_csv(csv_data)
    
    except requests.exceptions.RequestException as e:
        print(f"Request failed: {e}")
        return pd.DataFrame()

Visualizing the CO₂ data for two NEC stations

# Get station name and elevation from metdata dataframe
# Fetch data for SCI (elevation 489) and COM (elevation 9), using limit=10000
# ch4/co2 select the ghg 
sci_data = get_station_data_csv('sci', 'co2', 'hourly', 489, limit=10000)
com_data = get_station_data_csv('com', 'co2', 'hourly', 9, limit=10000)

# Check if data was successfully retrieved before proceeding
if sci_data.empty or com_data.empty:
    print("No data available for one or both stations. Exiting.")
else:
    # Convert the 'datetime' column to datetime for plotting
    sci_data['datetime'] = pd.to_datetime(sci_data['datetime'], format='%Y-%m-%dT%H:%M:%SZ')
    com_data['datetime'] = pd.to_datetime(com_data['datetime'], format='%Y-%m-%dT%H:%M:%SZ')

    # Plot the data
    plt.figure(figsize=(10, 6))
    plt.plot(sci_data['datetime'], sci_data['value'], label='SCI (489m)', color='blue', marker='o')
    plt.plot(com_data['datetime'], com_data['value'], label='COM (9m)', color='green', marker='o')

    plt.title('Carbon Dioxide (CO₂) Hourly Concentrations Over Time for SCI and COM Stations')
    plt.xlabel('Time')
    plt.ylabel('CO₂ Concentration (ppm)')
    plt.legend()
    plt.grid(True)

    # Show plot
    plt.show()
https://earth.gov/ghgcenter/api/features/collections/public.nist_testbed_lam_sci_co2_hourly_concentrations/items?f=csv&elevation_m=489&limit=10000
https://earth.gov/ghgcenter/api/features/collections/public.nist_testbed_lam_com_co2_hourly_concentrations/items?f=csv&elevation_m=9&limit=10000

Back to top