# Import the following libraries
# For fetching from the Raster API
import requests
# For making maps
import folium
import folium.plugins
from folium import Map, TileLayer
# For talking to the STAC API
from pystac_client import Client
# For working with data
import pandas as pd
# For making time series
import matplotlib.pyplot as plt
# For formatting date/time data
import datetime
# Custom functions for working with GHGC data via the API
import ghgc_utilsODIAC Fossil Fuel CO₂ Emissions
Access this Notebook
You can launch this notebook in the US GHG Center JupyterHub (requires access) by clicking the following link: ODIAC Fossil Fuel CO₂ Emissions. If you are a new user, you should first sign up for the hub by filling out this request form and providing the required information.
If you do not have a US GHG Center Jupyterhub account, you can access this notebook through MyBinder by clicking the button below.
Table of Contents
Data Summary and Application
- Spatial coverage: Global
- Spatial resolution: 1 km x 1 km
- Temporal extent: January 2000 - December 2023
- Temporal resolution: Monthly
- Unit: Metric tonnes of carbon per 1 km x 1 km cell per month (tonne C/km²/month)
- Utility: Climate Research
For more information, visit the ODIAC Fossil Fuel CO₂ Emissions data overview page.
Approach
- Identify available dates and temporal frequency of observations for the given collection using the US Greenhouse Gas Center (GHGC) Application Programming Interface (API)
/stacendpoint. The collection processed in this notebook is ODIAC Fossil Fuel CO₂ Emissions. - Pass the STAC item into raster API
/collections/{collection_id}/items/{item_id}/{tile_matrix_set_id}/tilejson.jsonendpoint - Using
folium.plugins.DualMap, visualize two tiles (side-by-side), allowing time point comparison. - After the visualization, perform zonal statistics for a given polygon.
- Create a time-series analysis.
About the Data
ODIAC Fossil Fuel CO₂ Emissions
The Open-Data Inventory for Anthropogenic Carbon dioxide (ODIAC) is a high-spatial resolution global emission data product of CO₂ emissions from fossil fuel combustion (Oda and Maksyutov, 2011). ODIAC pioneered the combined use of space-based nighttime light data and individual power plant emission/location profiles to estimate the global spatial extent of fossil fuel CO₂ emissions. With the innovative emission modeling approach, ODIAC achieved the fine picture of global fossil fuel CO₂ emissions at a 1x1km.
For more information regarding this dataset, please visit the ODIAC Fossil Fuel CO₂ Emissions data overview page.
Terminology
Navigating data via the GHGC API, you will encounter terminology that is different from browsing in a typical filesystem. We’ll define some terms here which are used throughout this notebook.
catalog: All datasets available at the/stacendpointcollection: A specific dataset, e.g. ODIAC Fossil Fuel CO2 Emissionsitem: One data file (i.e. granule) in the dataset, e.g. one monthly file of CO2 emissionsasset: A variable available within the granule, e.g. fossil fuel CO2 emisisonsSTAC API: SpatioTemporal Asset Catalogs - Endpoint for fetching metadata about available datasetsRaster API: Endpoint for fetching data itself, for imagery and statistics
Install the Required Libraries
Required libraries are pre-installed on the US 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
Query the STAC API
STAC API Collection Names
Now, you must fetch the dataset from the STAC API by defining its associated STAC API collection ID as a variable. The collection ID, also known as the collection name, for the ODIAC Fossil Fuel CO2 Emissions dataset is odiac-ffco2-monthgrid-v2024.
# Provide the STAC and RASTER API endpoints
# The endpoint is referring to a location within the API that executes a request on a data collection nesting on the server.
# The STAC API is a catalog of all the existing data collections that are stored in the GHG Center.
STAC_API_URL = "https://earth.gov/ghgcenter/api/stac"
# The RASTER API is used to fetch collections for visualization
RASTER_API_URL = "https://earth.gov/ghgcenter/api/raster"
# The collection name is used to fetch the dataset from the STAC API. First, we define the collection name as a variable
# Name of the collection for ODIAC dataset
collection_name = "odiac-ffco2-monthgrid-v2024"# Using PySTAC client
# Fetch the collection from the STAC API using the appropriate endpoint
# The 'pystac' library makes an HTTP request
catalog = Client.open(STAC_API_URL)
collection = catalog.get_collection(collection_name)
# Print the properties of the collection to the console
collectionExamining the contents of our collection under summaries we see that the data is available from January 2000 to December 2023. By looking at the dashboard:time density we observe that the periodic frequency of these observations is monthly.
#items = list(collection.get_items()) # Convert the iterator to a list
#print(f"Found {len(items)} items")# The search function lets you search for items within a specific date/time range
search = catalog.search(
collections=collection_name,
datetime=['2010-01-01T00:00:00Z','2015-12-31T00:00:00Z']
)
items = search.item_collection()
# Take a look at the items we found
for item in items:
print(item)<Item id=odiac-ffco2-monthgrid-v2024-odiac2024_1km_excl_intl_201512>
<Item id=odiac-ffco2-monthgrid-v2024-odiac2024_1km_excl_intl_201511>
<Item id=odiac-ffco2-monthgrid-v2024-odiac2024_1km_excl_intl_201510>
<Item id=odiac-ffco2-monthgrid-v2024-odiac2024_1km_excl_intl_201509>
<Item id=odiac-ffco2-monthgrid-v2024-odiac2024_1km_excl_intl_201508>
<Item id=odiac-ffco2-monthgrid-v2024-odiac2024_1km_excl_intl_201507>
<Item id=odiac-ffco2-monthgrid-v2024-odiac2024_1km_excl_intl_201506>
<Item id=odiac-ffco2-monthgrid-v2024-odiac2024_1km_excl_intl_201505>
<Item id=odiac-ffco2-monthgrid-v2024-odiac2024_1km_excl_intl_201504>
<Item id=odiac-ffco2-monthgrid-v2024-odiac2024_1km_excl_intl_201503>
<Item id=odiac-ffco2-monthgrid-v2024-odiac2024_1km_excl_intl_201502>
<Item id=odiac-ffco2-monthgrid-v2024-odiac2024_1km_excl_intl_201501>
<Item id=odiac-ffco2-monthgrid-v2024-odiac2024_1km_excl_intl_201412>
<Item id=odiac-ffco2-monthgrid-v2024-odiac2024_1km_excl_intl_201411>
<Item id=odiac-ffco2-monthgrid-v2024-odiac2024_1km_excl_intl_201410>
<Item id=odiac-ffco2-monthgrid-v2024-odiac2024_1km_excl_intl_201409>
<Item id=odiac-ffco2-monthgrid-v2024-odiac2024_1km_excl_intl_201408>
<Item id=odiac-ffco2-monthgrid-v2024-odiac2024_1km_excl_intl_201407>
<Item id=odiac-ffco2-monthgrid-v2024-odiac2024_1km_excl_intl_201406>
<Item id=odiac-ffco2-monthgrid-v2024-odiac2024_1km_excl_intl_201405>
<Item id=odiac-ffco2-monthgrid-v2024-odiac2024_1km_excl_intl_201404>
<Item id=odiac-ffco2-monthgrid-v2024-odiac2024_1km_excl_intl_201403>
<Item id=odiac-ffco2-monthgrid-v2024-odiac2024_1km_excl_intl_201402>
<Item id=odiac-ffco2-monthgrid-v2024-odiac2024_1km_excl_intl_201401>
<Item id=odiac-ffco2-monthgrid-v2024-odiac2024_1km_excl_intl_201312>
<Item id=odiac-ffco2-monthgrid-v2024-odiac2024_1km_excl_intl_201311>
<Item id=odiac-ffco2-monthgrid-v2024-odiac2024_1km_excl_intl_201310>
<Item id=odiac-ffco2-monthgrid-v2024-odiac2024_1km_excl_intl_201309>
<Item id=odiac-ffco2-monthgrid-v2024-odiac2024_1km_excl_intl_201308>
<Item id=odiac-ffco2-monthgrid-v2024-odiac2024_1km_excl_intl_201307>
<Item id=odiac-ffco2-monthgrid-v2024-odiac2024_1km_excl_intl_201306>
<Item id=odiac-ffco2-monthgrid-v2024-odiac2024_1km_excl_intl_201305>
<Item id=odiac-ffco2-monthgrid-v2024-odiac2024_1km_excl_intl_201304>
<Item id=odiac-ffco2-monthgrid-v2024-odiac2024_1km_excl_intl_201303>
<Item id=odiac-ffco2-monthgrid-v2024-odiac2024_1km_excl_intl_201302>
<Item id=odiac-ffco2-monthgrid-v2024-odiac2024_1km_excl_intl_201301>
<Item id=odiac-ffco2-monthgrid-v2024-odiac2024_1km_excl_intl_201212>
<Item id=odiac-ffco2-monthgrid-v2024-odiac2024_1km_excl_intl_201211>
<Item id=odiac-ffco2-monthgrid-v2024-odiac2024_1km_excl_intl_201210>
<Item id=odiac-ffco2-monthgrid-v2024-odiac2024_1km_excl_intl_201209>
<Item id=odiac-ffco2-monthgrid-v2024-odiac2024_1km_excl_intl_201208>
<Item id=odiac-ffco2-monthgrid-v2024-odiac2024_1km_excl_intl_201207>
<Item id=odiac-ffco2-monthgrid-v2024-odiac2024_1km_excl_intl_201206>
<Item id=odiac-ffco2-monthgrid-v2024-odiac2024_1km_excl_intl_201205>
<Item id=odiac-ffco2-monthgrid-v2024-odiac2024_1km_excl_intl_201204>
<Item id=odiac-ffco2-monthgrid-v2024-odiac2024_1km_excl_intl_201203>
<Item id=odiac-ffco2-monthgrid-v2024-odiac2024_1km_excl_intl_201202>
<Item id=odiac-ffco2-monthgrid-v2024-odiac2024_1km_excl_intl_201201>
<Item id=odiac-ffco2-monthgrid-v2024-odiac2024_1km_excl_intl_201112>
<Item id=odiac-ffco2-monthgrid-v2024-odiac2024_1km_excl_intl_201111>
<Item id=odiac-ffco2-monthgrid-v2024-odiac2024_1km_excl_intl_201110>
<Item id=odiac-ffco2-monthgrid-v2024-odiac2024_1km_excl_intl_201109>
<Item id=odiac-ffco2-monthgrid-v2024-odiac2024_1km_excl_intl_201108>
<Item id=odiac-ffco2-monthgrid-v2024-odiac2024_1km_excl_intl_201107>
<Item id=odiac-ffco2-monthgrid-v2024-odiac2024_1km_excl_intl_201106>
<Item id=odiac-ffco2-monthgrid-v2024-odiac2024_1km_excl_intl_201105>
<Item id=odiac-ffco2-monthgrid-v2024-odiac2024_1km_excl_intl_201104>
<Item id=odiac-ffco2-monthgrid-v2024-odiac2024_1km_excl_intl_201103>
<Item id=odiac-ffco2-monthgrid-v2024-odiac2024_1km_excl_intl_201102>
<Item id=odiac-ffco2-monthgrid-v2024-odiac2024_1km_excl_intl_201101>
<Item id=odiac-ffco2-monthgrid-v2024-odiac2024_1km_excl_intl_201012>
<Item id=odiac-ffco2-monthgrid-v2024-odiac2024_1km_excl_intl_201011>
<Item id=odiac-ffco2-monthgrid-v2024-odiac2024_1km_excl_intl_201010>
<Item id=odiac-ffco2-monthgrid-v2024-odiac2024_1km_excl_intl_201009>
<Item id=odiac-ffco2-monthgrid-v2024-odiac2024_1km_excl_intl_201008>
<Item id=odiac-ffco2-monthgrid-v2024-odiac2024_1km_excl_intl_201007>
<Item id=odiac-ffco2-monthgrid-v2024-odiac2024_1km_excl_intl_201006>
<Item id=odiac-ffco2-monthgrid-v2024-odiac2024_1km_excl_intl_201005>
<Item id=odiac-ffco2-monthgrid-v2024-odiac2024_1km_excl_intl_201004>
<Item id=odiac-ffco2-monthgrid-v2024-odiac2024_1km_excl_intl_201003>
<Item id=odiac-ffco2-monthgrid-v2024-odiac2024_1km_excl_intl_201002>
<Item id=odiac-ffco2-monthgrid-v2024-odiac2024_1km_excl_intl_201001>
# Examine the first item in the search results
# Keep in mind that a list starts from 0, 1, 2... therefore items[0] is referring to the first item in the list/collection
items[0]# Restructure our items into a dictionary where keys are the datetime items
# Then we can query more easily by date/time, e.g. "2020-05-20"
items_dict = {item.properties["start_datetime"][:7]: item for item in items}# Before we go further, let's pick which asset to focus on for the remainder of the notebook.
# This dataset only has one asset:
asset_name = "co2-emissions"Creating Maps Using Folium
We will explore changes in fossil fuel emissions in urban regions, visualizing the data on a map using folium.
Fetch Imagery Using Raster API
Here we get information from the Raster API, which we will add to our map in the next section.
# Specify two date/times that you would like to visualize, using the format of items_dict.keys()
dates = ["2015-01","2015-04"]Below, we use some statistics of the raster data to set upper and lower limits for our color bar. These are saved as the rescale_values, and will be passed to the Raster API in the following step(s).
# Extract collection name and item ID for the first date
first_date = items_dict[dates[0]]
collection_id_1 = first_date.collection_id
item_id_1 = first_date.id
# Select relevant asset
object = first_date.assets[asset_name]
raster_bands = object.extra_fields.get("raster:bands", [{}])
# Print raster bands' information
raster_bands[{'scale': 1.0,
'nodata': -9999.0,
'offset': 0.0,
'sampling': 'area',
'data_type': 'float32',
'histogram': {'max': 38934.10546875,
'min': -768.0534057617188,
'count': 11,
'buckets': [14879, 6, 0, 1, 0, 0, 0, 0, 0, 1]},
'statistics': {'mean': 35.59434825686841,
'stddev': 360.9807471537631,
'maximum': 38934.10546875,
'minimum': -768.0534057617188,
'valid_percent': 2.8394699096679688}}]
# Use statistics to generate an appropriate colorbar range
rescale_values = {
"max": raster_bands[0]["statistics"]["mean"] + 2*raster_bands[0]["statistics"]["stddev"],
"min": 0,
}
print(rescale_values){'max': 757.5558425643947, 'min': 0}
Now, you will pass the item id, collection name, asset name, and the rescale values to the Raster API endpoint, along with a colormap. This step is done twice, one for each date/time you will visualize, and tells the Raster API which collection, item, and asset you want to view, specifying the colormap and colorbar ranges to use for visualization. The API returns a JSON with information about the requested image. Each image will be referred to as a tile.
# Choose a colormap for displaying the data
# Make sure to capitalize per Matplotlib standard colormap names
# For more information on Colormaps in Matplotlib, please visit https://matplotlib.org/stable/users/explain/colors/colormaps.html
color_map = "Spectral_r" # Make a GET request to retrieve information for the date mentioned below
tile_matrix_set_id = "WebMercatorQuad"
tile1 = requests.get(
f"{RASTER_API_URL}/collections/{collection_id_1}/items/{item_id_1}/{tile_matrix_set_id}/tilejson.json?"
f"&assets={asset_name}"
f"&color_formula=gamma+r+1.05&colormap_name={color_map.lower()}"
f"&rescale={rescale_values['min']},{rescale_values['max']}"
).json()
# Print the properties of the retrieved granule to the console
tile1{'tilejson': '2.2.0',
'version': '1.0.0',
'scheme': 'xyz',
'tiles': ['https://earth.gov/ghgcenter/api/raster/collections/odiac-ffco2-monthgrid-v2024/items/odiac-ffco2-monthgrid-v2024-odiac2024_1km_excl_intl_201501/tiles/WebMercatorQuad/{z}/{x}/{y}@1x?assets=co2-emissions&color_formula=gamma+r+1.05&colormap_name=spectral_r&rescale=0%2C757.5558425643947'],
'minzoom': 0,
'maxzoom': 24,
'bounds': [-180.0, -90.0, 180.0, 90.0],
'center': [0.0, 0.0, 0]}
# Repeat the above for your second date/time
# Note that we do not calculate new rescale_values for this tile
# We want date tiles 1 and 2 to have the same colorbar range for visual comparison.
second_date = items_dict[dates[1]]
# Extract collection name and item ID
collection_id_2 = second_date.collection_id
item_id_2 = second_date.id
tile2 = requests.get(
f"{RASTER_API_URL}/collections/{collection_id_2}/items/{item_id_2}/{tile_matrix_set_id}/tilejson.json?"
f"&assets={asset_name}"
f"&color_formula=gamma+r+1.05&colormap_name={color_map.lower()}"
f"&rescale={rescale_values['min']},{rescale_values['max']}"
).json()
# Print the properties of the retrieved granule to the console
tile2{'tilejson': '2.2.0',
'version': '1.0.0',
'scheme': 'xyz',
'tiles': ['https://earth.gov/ghgcenter/api/raster/collections/odiac-ffco2-monthgrid-v2024/items/odiac-ffco2-monthgrid-v2024-odiac2024_1km_excl_intl_201504/tiles/WebMercatorQuad/{z}/{x}/{y}@1x?assets=co2-emissions&color_formula=gamma+r+1.05&colormap_name=spectral_r&rescale=0%2C757.5558425643947'],
'minzoom': 0,
'maxzoom': 24,
'bounds': [-180.0, -90.0, 180.0, 90.0],
'center': [0.0, 0.0, 0]}
Generate Map
# Initialize the map, specifying the center of the map and the starting zoom level.
# 'folium.plugins' allows mapping side-by-side via 'DualMap'
# Map is centered on the position specified by "location=(lat,lon)"
map_ = folium.plugins.DualMap(location=(41.8, -87.6), zoom_start=9)
# Define the first map layer using the tile fetched for the first date
# The TileLayer library helps in manipulating and displaying raster layers on a map
map_layer_1 = TileLayer(
tile1["tiles"][0], # Path to retrieve the tile
attr="US GHG Center", # Set the attribution
opacity=0.8, # Adjust the transparency of the layer
overlay=True,
name=f"{collection.title}, {dates[0]}"
)
# Add the first layer to the Dual Map
map_layer_1.add_to(map_.m1)
# Define the second map layer using the tile fetched for the second date
map_layer_2 = TileLayer(
tile2["tiles"][0], # Path to retrieve the tile
attr="US GHG Center", # Set the attribution
opacity=0.8, # Adjust the transparency of the layer
overlay=True,
name=f"{collection.title}, {dates[1]}"
)
# Add the second layer to the Dual Map
map_layer_2.add_to(map_.m2)
# Add a layer control to switch between map layers
folium.LayerControl(collapsed=False).add_to(map_)
# Add colorbar
# We can use 'generate_html_colorbar' from the 'ghgc_utils' module
# to create an HTML colorbar representation.
legend_html = ghgc_utils.generate_html_colorbar(color_map,rescale_values,label=f'{items[0].assets[asset_name].title} (tonne C/km2/month)')
# Add colorbar to the map
map_.get_root().html.add_child(folium.Element(legend_html))
# Visualize the Dual Map
map_Observe that fossil fuel CO2 emissions are much higher in January than in April in Chicago. This is due in large part to the use of central heating, which often relies on burning oil or natural gas during the cold Midwestern months.
Calculate Zonal Statistics
To perform zonal statistics, first we need to create a polygon.
# We'll start with an AOI over Chicago, US. Give it a name for use later
aoi_name = "Chicago, USA"
# Define the AOI as a GeoJSON
aoi = {
"type": "Feature", # Create a feature object
"properties": {},
"geometry": { # Set the bounding coordinates for the polygon
"coordinates": [
[
[-88.5, 42.2], # Northwest bounding coordinate
[-88.5, 41.4], # Southwest bounding coordinate
[-87.5, 41.4], # Southeast bounding coordinate
[-87.5, 42.2], # Northeast bounding coordinate
[-88.5, 42.2] # Northwest bounding coordinate (closing the polygon)
]
],
"type": "Polygon",
},
}# Quick Folium map to visualize this AOI
map_ = folium.Map(location=(41.8, -88), zoom_start=8)
# Add AOI to map
folium.GeoJson(aoi, name=aoi_name,style_function=lambda feature:{"fillColor":"none","color":"#E467E8"}).add_to(map_)
# Add data layer to visualize number of grid cells within AOI
map_layer_1.add_to(map_)
# Add a colorbar
legend_html = ghgc_utils.generate_html_colorbar(color_map,rescale_values,label='tonne CO2/km2/month',dark=True)
map_.get_root().html.add_child(folium.Element(legend_html))
map_We will perform zonal statistics and create a dataframe using our defined AOI for Chicago, the items from our initial catalog search spanning from January 1, 2010 through December 31, 2015, and the “co2-emissions” asset.
We can generate the statistics for the AOI using a function from the ghgc_utils module, which fetches the data and its statistics from the Raster API.
%%time
# %%time = Wall time (execution time) for running the code below
# Statistics will be returned as a Pandas DataFrame
df = ghgc_utils.generate_stats(items,aoi,url=RASTER_API_URL,asset=asset_name)
# Print the first 5 rows of our statistics DataFrame
df.head(5)Generating stats...
Done!
CPU times: user 3.82 s, sys: 157 ms, total: 3.98 s
Wall time: 49 s
| datetime | min | max | mean | count | sum | std | median | majority | minority | unique | histogram | valid_percent | masked_pixels | valid_pixels | percentile_2 | percentile_98 | date | |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 0 | 2015-12-01T00:00:00Z | 4.67938470840454101562 | 167770.23437500000000000000 | 243.48347473144531250000 | 10410.00000000000000000000 | 2534663.00000000000000000000 | 2459.67101458711340455920 | 165.95074462890625000000 | 581.76385498046875000000 | 4.67938470840454101562 | 9074.00000000000000000000 | [[10403, 1, 2, 0, 1, 1, 0, 0, 1, 1], [4.679384... | 90.35999999999999943157 | 1110.00000000000000000000 | 10410.00000000000000000000 | 7.64125776290893554688 | 693.57031250000000000000 | 2015-12-01 00:00:00+00:00 |
| 1 | 2015-11-01T00:00:00Z | 4.16928482055664062500 | 149296.93750000000000000000 | 218.57122802734375000000 | 10410.00000000000000000000 | 2275326.50000000000000000000 | 2188.83542094877475392423 | 149.50103759765625000000 | 518.34576416015625000000 | 4.16928482055664062500 | 9024.00000000000000000000 | [[10403, 1, 2, 0, 1, 1, 0, 0, 1, 1], [4.169284... | 90.35999999999999943157 | 1110.00000000000000000000 | 10410.00000000000000000000 | 6.80828428268432617188 | 617.96423339843750000000 | 2015-11-01 00:00:00+00:00 |
| 2 | 2015-10-01T00:00:00Z | 4.12834739685058593750 | 147730.53125000000000000000 | 216.55181884765625000000 | 10410.00000000000000000000 | 2254304.50000000000000000000 | 2165.87615066051284884452 | 148.14408874511718750000 | 513.25622558593750000000 | 4.12834739685058593750 | 8954.00000000000000000000 | [[10403, 1, 2, 0, 1, 1, 0, 0, 1, 1], [4.128347... | 90.35999999999999943157 | 1110.00000000000000000000 | 10410.00000000000000000000 | 6.74143505096435546875 | 611.89654541015625000000 | 2015-10-01 00:00:00+00:00 |
| 3 | 2015-09-01T00:00:00Z | 4.02172708511352539062 | 143930.67187500000000000000 | 211.35942077636718750000 | 10410.00000000000000000000 | 2200251.50000000000000000000 | 2110.16610720578091786592 | 144.87901306152343750000 | 500.00067138671875000000 | 4.02172708511352539062 | 9109.00000000000000000000 | [[10403, 1, 2, 0, 1, 1, 0, 0, 1, 1], [4.021727... | 90.35999999999999943157 | 1110.00000000000000000000 | 10410.00000000000000000000 | 6.56732845306396484375 | 596.09350585937500000000 | 2015-09-01 00:00:00+00:00 |
| 4 | 2015-08-01T00:00:00Z | 4.37767410278320312500 | 156797.85937500000000000000 | 228.73756408691406250000 | 10410.00000000000000000000 | 2381158.00000000000000000000 | 2298.80642943245675269281 | 156.43536376953125000000 | 544.25378417968750000000 | 4.37767410278320312500 | 8924.00000000000000000000 | [[10403, 1, 2, 0, 1, 1, 0, 0, 1, 1], [4.377674... | 90.35999999999999943157 | 1110.00000000000000000000 | 10410.00000000000000000000 | 7.14857625961303710938 | 648.85137939453125000000 | 2015-08-01 00:00:00+00:00 |
Time-Series Analysis
Let’s explore the fossil fuel CO₂ emission values in this data collection from 2010 to 2016. We can plot the dataset using the code below.
# Figure size: 20 representing the width, 10 representing the height
fig = plt.figure(figsize=(10,5))
# Use which_stat to pick which statisticm from our DataFrame to visualize
# Change 'which_stat' below if you would rather look at a different statistic, like minimum or maximum
which_stat = "mean"
plt.plot(
df["date"], # X-axis: sorted datetime
df[which_stat], # Y-axis: maximum CO₂ level
color="red", # Line color
linestyle="-", # Line style
linewidth=2, # Line width
label=f"{which_stat.capitalize()} {items[0].assets[asset_name].title}" # Legend label
)
# Display legend
plt.legend()
# Insert label for the X-axis
plt.xlabel("Years")
# Insert label for the Y-axis
plt.ylabel("tonne CO$_2$/km2/month")
# Insert title for the plot
plt.title(f"{which_stat.capitalize()} {items[0].assets[asset_name].title} for {aoi_name}")
# Add data citation
plt.text(
df["date"].iloc[40], # X-coordinate of the text
df[which_stat].min(), # Y-coordinate of the text
# Text to be displayed
f"Source: {collection.title}",
fontsize=9, # Font size
color="blue", # Text color
)
# Plot the time series
plt.show()
You can see emissions peak in winter in this time series, similarly to the dual map in the previous section!
Summary
In this notebook, we have successfully completed the following steps for the ODIAC Fossil Fuel CO₂ Emissions dataset:
- Install and import the necessary libraries
- Fetch the collection from STAC using the appropriate endpoints
- Count the number of existing granules within the collection
- Map and compare the CO₂ levels for two distinctive months/years
- Generate zonal statistics for the area of interest (AOI)
- Plot a time series of mean CO₂ emissions for a specified region
If you have any questions regarding this user notebook, please contact us using the feedback form.