# 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_utils
GRA²PES Greenhouse Gas and Air Quality Species
Access this Notebook
You can launch this notebook in the US GHG Center JupyterHub by clicking the link below. 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.
Access the GRA²PES Greenhouse Gas and Air Quality Species notebook in the US GHG Center JupyterHub.
Table of Contents
Data Summary and Application
- Spatial coverage: Contiguous United States
- Spatial resolution: 0.036° x 0.036°
- Temporal extent: January 2021 - December 2021
- Temporal resolution: Monthly
- Unit: Metric tons per kilometer squared per month (tonne/km²/month) for carbon dioxide (CO₂), carbon monoxide (CO), nitrogen oxides (NOₓ), sulfur dioxide (SO₂), and particulate matter (PM2.5)
- Utility: Climate Research
For more, visit the GRA²PES Greenhouse Gas and Air Quality Species data overview page.
Approach
- Identify available dates and temporal frequency of observations for the given collection using the GHGC API
/stac
endpoint. The collection processed in this notebook is the Vulcan Fossil Fuel CO₂ Emissions Data product. - Pass the STAC item into the raster API
/stac/tilejson.json
endpoint. - Using
folium.plugins.DualMap
, we will visualize two tiles (side-by-side), allowing us to compare time points. - After the visualization, we will perform zonal statistics for a given polygon.
About the Data
GRA2PES Greenhouse Gas and Air Quality Species
The Greenhouse gas And Air Pollutants Emissions System (GRA2PES) dataset at the GHG Center is an aggregated, regridded, monthly high-resolution (0.036 x 0.036°) data product with emissions of both greenhouse gases and air pollutants developed in a consistent framework. The dataset contains emissions over the contiguous United States covering major anthropogenic sectors, including energy, industrial fuel combustion and processes, commercial and residential combustion, oil and gas production, on-road and off-road transportation, etc. (see Table 1 in the Scientific Details section below for a full sector list). Fossil fuel CO2 (ffCO2) emissions are developed along with those of air pollutants including CO, NOx, SOx, and PM2.5 with consistency in spatial and temporal distributions. Emissions by sectors are grouped into point and area sources, reported as column totals in units of metric tons per km2 per month. Spatial-temporal surrogates are developed to distribute CO2 emissions to grid cells to keep consistency between greenhouse gases and air quality species. The current version of GRA2PES is for 2021. Long-term emissions and more greenhouse gas species (e.g., methane) are under development and will be added in the future.
For more information regarding this dataset, please visit the GRA2PES Greenhouse Gas and Air Quality Species, Version 1 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 /stac
endpoint - collection
: A specific dataset, e.g. GRA2PES - item
: One granule in the dataset, e.g. one monthly file of greenhouse gas emissions - asset
: A variable available within the granule, e.g. CO, CO2, or NOx emissions - STAC API
: SpatioTemporal Asset Catalogs - Endpoint for fetching metadata about available datasets - Raster API
: Endpoint for fetching data itself, for imagery and statistics
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
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 GRA2PES Greenhouse Gas and Air Quality Species dataset is gra2pes-ghg-monthgrid-v1.*
**You can find the collection name of any dataset on the GHGC data portal by navigating to the dataset landing page within the data catalog. The collection name is the last portion of the dataset landing page’s URL, and is also listed in the pop-up box after clicking “ACCESS DATA.”*
# Provide STAC and RASTER API endpoints
= "https://earth.gov/ghgcenter/api/stac"
STAC_API_URL = "https://earth.gov/ghgcenter/api/raster"
RASTER_API_URL
# Please use the collection name similar to the one used in the STAC collection.
# Name of the collection for Vulcan Fossil Fuel CO₂ Emissions, Version 4.
= "gra2pes-ghg-monthgrid-v1" collection_name
# Using PySTAC client
# Fetch the collection from the STAC API using the appropriate endpoint
# The 'pystac' library enables an HTTP request
= Client.open(STAC_API_URL)
catalog = catalog.get_collection(collection_name)
collection
# Print the properties of the collection to the console
collection
- type "Collection"
- id "gra2pes-ghg-monthgrid-v1"
- stac_version "1.0.0"
- description "The Greenhouse gas And Air Pollutants Emissions System (GRA²PES) dataset at the GHG Center is an aggregated, regridded, monthly high-resolution (0.036 x 0.036°) data product with emissions of both greenhouse gases and air pollutants developed in a consistent framework. The dataset contains emissions over the contiguous United States covering major anthropogenic sectors, including energy, industrial fuel combustion and processes, commercial and residential combustion, oil and gas production, on-road and off-road transportation, etc. Carbon dioxide (CO₂) emissions are developed along with those of air pollutants including CO, NOₓ, SO₂, and PM2.5 with consistency in spatial and temporal distributions. Emissions by sectors are reported as column totals in units of metric tons per km² per month. Spatial-temporal surrogates are developed to distribute CO₂ emissions to grid cells to keep consistency between greenhouse gases and air quality species. The current version of GRA²PES is for 2021. Long-term emissions and more greenhouse gas species (e.g., methane) are under development and will be added in the future. Description of data processing: Derived from wrfchem_d01 files. Totaled in Z space; native 12-hour (00z and 12z) files averaged to get mean daily emissions; weighted average calculated using weekdy, sundy, satdy to produce average emissions rates for given month. Regridded from native LCC projection and 4000m resolution to EPSG 4326. The native dataset can be accessed from the NIST data center: https://doi.org/10.18434/mds2-3520"
links[] 5 items
0
- rel "items"
- href "https://earth.gov/ghgcenter/api/stac/collections/gra2pes-ghg-monthgrid-v1/items"
- type "application/geo+json"
1
- rel "parent"
- href "https://earth.gov/ghgcenter/api/stac/"
- type "application/json"
2
- rel "root"
- href "https://earth.gov/ghgcenter/api/stac"
- type "application/json"
- title "US GHG Center STAC API"
3
- rel "self"
- href "https://earth.gov/ghgcenter/api/stac/collections/gra2pes-ghg-monthgrid-v1"
- type "application/json"
4
- rel "http://www.opengis.net/def/rel/ogc/1.0/queryables"
- href "https://earth.gov/ghgcenter/api/stac/collections/gra2pes-ghg-monthgrid-v1/queryables"
- type "application/schema+json"
- title "Queryables"
stac_extensions[] 2 items
- 0 "https://stac-extensions.github.io/render/v1.0.0/schema.json"
- 1 "https://stac-extensions.github.io/item-assets/v1.0.0/schema.json"
renders
co
assets[] 1 items
- 0 "co"
rescale[] 1 items
0[] 2 items
- 0 0
- 1 2
- colormap_name "spectral_r"
nox
assets[] 1 items
- 0 "nox"
rescale[] 1 items
0[] 2 items
- 0 0
- 1 2
- colormap_name "greens"
so2
assets[] 1 items
- 0 "so2"
rescale[] 1 items
0[] 2 items
- 0 0
- 1 0.5
- colormap_name "blues"
pm25
assets[] 1 items
- 0 "pm25"
rescale[] 1 items
0[] 2 items
- 0 0
- 1 0.2
- colormap_name "purples"
dashboard
assets[] 1 items
- 0 "co2"
rescale[] 1 items
0[] 2 items
- 0 0
- 1 2000
- colormap_name "spectral_r"
item_assets
co
- type "image/tiff; application=geotiff; profile=cloud-optimized"
roles[] 2 items
- 0 "data"
- 1 "layer"
- title "CO Emissions"
- description "Estimated monthly total carbon monoxide (CO) emissions across all sectors."
co2
- type "image/tiff; application=geotiff; profile=cloud-optimized"
roles[] 2 items
- 0 "data"
- 1 "layer"
- title "CO₂ Emissions"
- description "Estimated monthly total CO₂ emissions across all sectors."
nox
- type "image/tiff; application=geotiff; profile=cloud-optimized"
roles[] 2 items
- 0 "data"
- 1 "layer"
- title "NOₓ Emissions"
- description "Estimated monthly total nitrogen oxide (NOₓ) emissions across all sectors."
so2
- type "image/tiff; application=geotiff; profile=cloud-optimized"
roles[] 2 items
- 0 "data"
- 1 "layer"
- title "SO₂ Emissions"
- description "Estimated monthly total sulfur dioxide (SO₂) emissions across all sectors."
pm25
- type "image/tiff; application=geotiff; profile=cloud-optimized"
roles[] 2 items
- 0 "data"
- 1 "layer"
- title "Particulate Matter (PM2.5)"
- description "Estimated monthly total emissions of fine particulate matter (PM2.5) across all sectors."
- dashboard:is_periodic True
- dashboard:time_density "month"
- title "GRA²PES Greenhouse Gas and Air Quality Species v1"
extent
spatial
bbox[] 1 items
0[] 4 items
- 0 -128.22655
- 1 47.89015278
- 2 -65.30824167
- 3 22.85824167
temporal
interval[] 1 items
0[] 2 items
- 0 "2021-01-01T00:00:00Z"
- 1 "2021-12-31T00:00:00Z"
- license "CC-BY-NC-4.0"
providers[] 1 items
0
- name "Colin Harkins"
roles[] 2 items
- 0 "producer"
- 1 "licensor"
- url "Colin.harkins@noaa.gov"
Examining the contents of our collection
under the temporal
variable, we see that the data is available from January 2010 to December 2021. By looking at the dashboard:time density
, we observe that the data is periodic with monthly time density.
= list(collection.get_items()) # Convert the iterator to a list
items print(f"Found {len(items)} items")
Found 12 items
# Examine the first item in the collection
# Keep in mind that a list starts from 0, 1, 2... therefore items[0] is referring to the first item in the list/collection
0] items[
- type "Feature"
- stac_version "1.0.0"
stac_extensions[] 2 items
- 0 "https://stac-extensions.github.io/raster/v1.1.0/schema.json"
- 1 "https://stac-extensions.github.io/projection/v1.1.0/schema.json"
- id "gra2pes-ghg-monthgrid-v1-202112"
geometry
- type "Polygon"
coordinates[] 1 items
0[] 5 items
0[] 2 items
- 0 -137.3143
- 1 18.173376
1[] 2 items
- 0 -58.58229999999702
- 1 18.173376
2[] 2 items
- 0 -58.58229999999702
- 1 52.229376000001295
3[] 2 items
- 0 -137.3143
- 1 52.229376000001295
4[] 2 items
- 0 -137.3143
- 1 18.173376
bbox[] 4 items
- 0 -137.3143
- 1 18.173376
- 2 -58.58229999999702
- 3 52.229376000001295
properties
- end_datetime "2021-12-31T00:00:00+00:00"
- start_datetime "2021-12-01T00:00:00+00:00"
- datetime None
links[] 5 items
0
- rel "collection"
- href "https://earth.gov/ghgcenter/api/stac/collections/gra2pes-ghg-monthgrid-v1"
- type "application/json"
1
- rel "parent"
- href "https://earth.gov/ghgcenter/api/stac/collections/gra2pes-ghg-monthgrid-v1"
- type "application/json"
2
- rel "root"
- href "https://earth.gov/ghgcenter/api/stac/"
- type "application/json"
3
- rel "self"
- href "https://earth.gov/ghgcenter/api/stac/collections/gra2pes-ghg-monthgrid-v1/items/gra2pes-ghg-monthgrid-v1-202112"
- type "application/geo+json"
4
- rel "preview"
- href "https://earth.gov/ghgcenter/api/raster/collections/gra2pes-ghg-monthgrid-v1/items/gra2pes-ghg-monthgrid-v1-202112/map?assets=co2&rescale=0%2C2000&colormap_name=spectral_r"
- type "text/html"
- title "Map of Item"
assets
co
- href "s3://ghgc-data-store/gra2pes-ghg-monthgrid-v1/GRA2PESv1.0_total_CO_202112.tif"
- type "image/tiff; application=geotiff"
- title "CO Emissions"
- description "Estimated monthly total carbon monoxide (CO) emissions across all sectors."
proj:bbox[] 4 items
- 0 -137.3143
- 1 52.229376000001295
- 2 -58.58229999999702
- 3 18.173376
- proj:epsg 4326
- proj:wkt2 "GEOGCS["WGS 84",DATUM["WGS_1984",SPHEROID["WGS 84",6378137,298.257223563,AUTHORITY["EPSG","7030"]],AUTHORITY["EPSG","6326"]],PRIMEM["Greenwich",0,AUTHORITY["EPSG","8901"]],UNIT["degree",0.0174532925199433,AUTHORITY["EPSG","9122"]],AXIS["Latitude",NORTH],AXIS["Longitude",EAST],AUTHORITY["EPSG","4326"]]"
proj:shape[] 2 items
- 0 946
- 1 2187
raster:bands[] 1 items
0
- scale 1.0
- nodata -9999.0
- offset 0.0
- sampling "area"
- data_type "float32"
histogram
- max 274.5063781738281
- min 0.0
- count 11
buckets[] 10 items
- 0 334968
- 1 20
- 2 2
- 3 2
- 4 0
- 5 0
- 6 0
- 7 1
- 8 0
- 9 1
statistics
- mean 0.15977390873045488
- stddev 0.9283820264267031
- maximum 274.5063781738281
- minimum 0.0
- valid_percent 73.84708309819413
proj:geometry
- type "Polygon"
coordinates[] 1 items
0[] 5 items
0[] 2 items
- 0 -137.3143
- 1 52.229376000001295
1[] 2 items
- 0 -58.58229999999702
- 1 52.229376000001295
2[] 2 items
- 0 -58.58229999999702
- 1 18.173376
3[] 2 items
- 0 -137.3143
- 1 18.173376
4[] 2 items
- 0 -137.3143
- 1 52.229376000001295
proj:projjson
id
- code 4326
- authority "EPSG"
- name "WGS 84"
- type "GeographicCRS"
datum
- name "World Geodetic System 1984"
- type "GeodeticReferenceFrame"
ellipsoid
- name "WGS 84"
- semi_major_axis 6378137
- inverse_flattening 298.257223563
- $schema "https://proj.org/schemas/v0.7/projjson.schema.json"
coordinate_system
axis[] 2 items
0
- name "Geodetic latitude"
- unit "degree"
- direction "north"
- abbreviation "Lat"
1
- name "Geodetic longitude"
- unit "degree"
- direction "east"
- abbreviation "Lon"
- subtype "ellipsoidal"
proj:transform[] 9 items
- 0 0.036000000000001364
- 1 0.0
- 2 -137.3143
- 3 0.0
- 4 0.036000000000001364
- 5 18.173376
- 6 0.0
- 7 0.0
- 8 1.0
roles[] 2 items
- 0 "data"
- 1 "layer"
co2
- href "s3://ghgc-data-store/gra2pes-ghg-monthgrid-v1/GRA2PESv1.0_total_CO2_202112.tif"
- type "image/tiff; application=geotiff"
- title "CO₂ Emissions"
- description "Estimated monthly total CO₂ emissions across all sectors."
proj:bbox[] 4 items
- 0 -137.3143
- 1 52.229376000001295
- 2 -58.58229999999702
- 3 18.173376
- proj:epsg 4326
- proj:wkt2 "GEOGCS["WGS 84",DATUM["WGS_1984",SPHEROID["WGS 84",6378137,298.257223563,AUTHORITY["EPSG","7030"]],AUTHORITY["EPSG","6326"]],PRIMEM["Greenwich",0,AUTHORITY["EPSG","8901"]],UNIT["degree",0.0174532925199433,AUTHORITY["EPSG","9122"]],AXIS["Latitude",NORTH],AXIS["Longitude",EAST],AUTHORITY["EPSG","4326"]]"
proj:shape[] 2 items
- 0 946
- 1 2187
raster:bands[] 1 items
0
- scale 1.0
- nodata -9999.0
- offset 0.0
- sampling "area"
- data_type "float32"
histogram
- max 24279.318359375
- min 0.0
- count 11
buckets[] 10 items
- 0 334533
- 1 293
- 2 94
- 3 38
- 4 17
- 5 8
- 6 4
- 7 3
- 8 2
- 9 2
statistics
- mean 26.803277073619228
- stddev 247.21265875450922
- maximum 24279.318359375
- minimum 0.0
- valid_percent 73.84708309819413
proj:geometry
- type "Polygon"
coordinates[] 1 items
0[] 5 items
0[] 2 items
- 0 -137.3143
- 1 52.229376000001295
1[] 2 items
- 0 -58.58229999999702
- 1 52.229376000001295
2[] 2 items
- 0 -58.58229999999702
- 1 18.173376
3[] 2 items
- 0 -137.3143
- 1 18.173376
4[] 2 items
- 0 -137.3143
- 1 52.229376000001295
proj:projjson
id
- code 4326
- authority "EPSG"
- name "WGS 84"
- type "GeographicCRS"
datum
- name "World Geodetic System 1984"
- type "GeodeticReferenceFrame"
ellipsoid
- name "WGS 84"
- semi_major_axis 6378137
- inverse_flattening 298.257223563
- $schema "https://proj.org/schemas/v0.7/projjson.schema.json"
coordinate_system
axis[] 2 items
0
- name "Geodetic latitude"
- unit "degree"
- direction "north"
- abbreviation "Lat"
1
- name "Geodetic longitude"
- unit "degree"
- direction "east"
- abbreviation "Lon"
- subtype "ellipsoidal"
proj:transform[] 9 items
- 0 0.036000000000001364
- 1 0.0
- 2 -137.3143
- 3 0.0
- 4 0.036000000000001364
- 5 18.173376
- 6 0.0
- 7 0.0
- 8 1.0
roles[] 2 items
- 0 "data"
- 1 "layer"
nox
- href "s3://ghgc-data-store/gra2pes-ghg-monthgrid-v1/GRA2PESv1.0_total_NOX_202112.tif"
- type "image/tiff; application=geotiff"
- title "NOₓ Emissions"
- description "Estimated monthly total nitrogen oxide (NOₓ) emissions across all sectors."
proj:bbox[] 4 items
- 0 -137.3143
- 1 52.229376000001295
- 2 -58.58229999999702
- 3 18.173376
- proj:epsg 4326
- proj:wkt2 "GEOGCS["WGS 84",DATUM["WGS_1984",SPHEROID["WGS 84",6378137,298.257223563,AUTHORITY["EPSG","7030"]],AUTHORITY["EPSG","6326"]],PRIMEM["Greenwich",0,AUTHORITY["EPSG","8901"]],UNIT["degree",0.0174532925199433,AUTHORITY["EPSG","9122"]],AXIS["Latitude",NORTH],AXIS["Longitude",EAST],AUTHORITY["EPSG","4326"]]"
proj:shape[] 2 items
- 0 946
- 1 2187
raster:bands[] 1 items
0
- scale 1.0
- nodata -9999.0
- offset 0.0
- sampling "area"
- data_type "float32"
histogram
- max 23.535017013549805
- min 0.0
- count 11
buckets[] 10 items
- 0 334546
- 1 308
- 2 82
- 3 27
- 4 16
- 5 7
- 6 3
- 7 1
- 8 1
- 9 3
statistics
- mean 0.041980669686434685
- stddev 0.23602874947404007
- maximum 23.535017013549805
- minimum 0.0
- valid_percent 73.84708309819413
proj:geometry
- type "Polygon"
coordinates[] 1 items
0[] 5 items
0[] 2 items
- 0 -137.3143
- 1 52.229376000001295
1[] 2 items
- 0 -58.58229999999702
- 1 52.229376000001295
2[] 2 items
- 0 -58.58229999999702
- 1 18.173376
3[] 2 items
- 0 -137.3143
- 1 18.173376
4[] 2 items
- 0 -137.3143
- 1 52.229376000001295
proj:projjson
id
- code 4326
- authority "EPSG"
- name "WGS 84"
- type "GeographicCRS"
datum
- name "World Geodetic System 1984"
- type "GeodeticReferenceFrame"
ellipsoid
- name "WGS 84"
- semi_major_axis 6378137
- inverse_flattening 298.257223563
- $schema "https://proj.org/schemas/v0.7/projjson.schema.json"
coordinate_system
axis[] 2 items
0
- name "Geodetic latitude"
- unit "degree"
- direction "north"
- abbreviation "Lat"
1
- name "Geodetic longitude"
- unit "degree"
- direction "east"
- abbreviation "Lon"
- subtype "ellipsoidal"
proj:transform[] 9 items
- 0 0.036000000000001364
- 1 0.0
- 2 -137.3143
- 3 0.0
- 4 0.036000000000001364
- 5 18.173376
- 6 0.0
- 7 0.0
- 8 1.0
roles[] 2 items
- 0 "data"
- 1 "layer"
so2
- href "s3://ghgc-data-store/gra2pes-ghg-monthgrid-v1/GRA2PESv1.0_total_SO2_202112.tif"
- type "image/tiff; application=geotiff"
- title "Estimated so₂ Emissions"
- description "Estimated monthly total sulfur dioxide (SO₂) emissions across all sectors."
proj:bbox[] 4 items
- 0 -137.3143
- 1 52.229376000001295
- 2 -58.58229999999702
- 3 18.173376
- proj:epsg 4326
- proj:wkt2 "GEOGCS["WGS 84",DATUM["WGS_1984",SPHEROID["WGS 84",6378137,298.257223563,AUTHORITY["EPSG","7030"]],AUTHORITY["EPSG","6326"]],PRIMEM["Greenwich",0,AUTHORITY["EPSG","8901"]],UNIT["degree",0.0174532925199433,AUTHORITY["EPSG","9122"]],AXIS["Latitude",NORTH],AXIS["Longitude",EAST],AUTHORITY["EPSG","4326"]]"
proj:shape[] 2 items
- 0 946
- 1 2187
raster:bands[] 1 items
0
- scale 1.0
- nodata -9999.0
- offset 0.0
- sampling "area"
- data_type "float32"
histogram
- max 71.14561462402344
- min 0.0
- count 11
buckets[] 10 items
- 0 334881
- 1 73
- 2 19
- 3 11
- 4 4
- 5 5
- 6 0
- 7 0
- 8 0
- 9 1
statistics
- mean 0.016292455984286285
- stddev 0.35639066244144724
- maximum 71.14561462402344
- minimum 0.0
- valid_percent 73.84708309819413
proj:geometry
- type "Polygon"
coordinates[] 1 items
0[] 5 items
0[] 2 items
- 0 -137.3143
- 1 52.229376000001295
1[] 2 items
- 0 -58.58229999999702
- 1 52.229376000001295
2[] 2 items
- 0 -58.58229999999702
- 1 18.173376
3[] 2 items
- 0 -137.3143
- 1 18.173376
4[] 2 items
- 0 -137.3143
- 1 52.229376000001295
proj:projjson
id
- code 4326
- authority "EPSG"
- name "WGS 84"
- type "GeographicCRS"
datum
- name "World Geodetic System 1984"
- type "GeodeticReferenceFrame"
ellipsoid
- name "WGS 84"
- semi_major_axis 6378137
- inverse_flattening 298.257223563
- $schema "https://proj.org/schemas/v0.7/projjson.schema.json"
coordinate_system
axis[] 2 items
0
- name "Geodetic latitude"
- unit "degree"
- direction "north"
- abbreviation "Lat"
1
- name "Geodetic longitude"
- unit "degree"
- direction "east"
- abbreviation "Lon"
- subtype "ellipsoidal"
proj:transform[] 9 items
- 0 0.036000000000001364
- 1 0.0
- 2 -137.3143
- 3 0.0
- 4 0.036000000000001364
- 5 18.173376
- 6 0.0
- 7 0.0
- 8 1.0
roles[] 2 items
- 0 "data"
- 1 "layer"
pm25
- href "s3://ghgc-data-store/gra2pes-ghg-monthgrid-v1/GRA2PESv1.0_total_PM25-PRI_202112.tif"
- type "image/tiff; application=geotiff"
- title "Estimated PM2.5 Emissions"
- description "Estimated monthly total emissions of fine particulate matter (PM2.5) across all sectors."
proj:bbox[] 4 items
- 0 -137.3143
- 1 52.229376000001295
- 2 -58.58229999999702
- 3 18.173376
- proj:epsg 4326
- proj:wkt2 "GEOGCS["WGS 84",DATUM["WGS_1984",SPHEROID["WGS 84",6378137,298.257223563,AUTHORITY["EPSG","7030"]],AUTHORITY["EPSG","6326"]],PRIMEM["Greenwich",0,AUTHORITY["EPSG","8901"]],UNIT["degree",0.0174532925199433,AUTHORITY["EPSG","9122"]],AXIS["Latitude",NORTH],AXIS["Longitude",EAST],AUTHORITY["EPSG","4326"]]"
proj:shape[] 2 items
- 0 946
- 1 2187
raster:bands[] 1 items
0
- scale 1.0
- nodata -9999.0
- offset 0.0
- sampling "area"
- data_type "float32"
histogram
- max 10.905590057373047
- min 0.0
- count 11
buckets[] 10 items
- 0 334965
- 1 20
- 2 4
- 3 4
- 4 0
- 5 0
- 6 0
- 7 0
- 8 0
- 9 1
statistics
- mean 0.012796561981333995
- stddev 0.04822644065182158
- maximum 10.905590057373047
- minimum 0.0
- valid_percent 73.84708309819413
proj:geometry
- type "Polygon"
coordinates[] 1 items
0[] 5 items
0[] 2 items
- 0 -137.3143
- 1 52.229376000001295
1[] 2 items
- 0 -58.58229999999702
- 1 52.229376000001295
2[] 2 items
- 0 -58.58229999999702
- 1 18.173376
3[] 2 items
- 0 -137.3143
- 1 18.173376
4[] 2 items
- 0 -137.3143
- 1 52.229376000001295
proj:projjson
id
- code 4326
- authority "EPSG"
- name "WGS 84"
- type "GeographicCRS"
datum
- name "World Geodetic System 1984"
- type "GeodeticReferenceFrame"
ellipsoid
- name "WGS 84"
- semi_major_axis 6378137
- inverse_flattening 298.257223563
- $schema "https://proj.org/schemas/v0.7/projjson.schema.json"
coordinate_system
axis[] 2 items
0
- name "Geodetic latitude"
- unit "degree"
- direction "north"
- abbreviation "Lat"
1
- name "Geodetic longitude"
- unit "degree"
- direction "east"
- abbreviation "Lon"
- subtype "ellipsoidal"
proj:transform[] 9 items
- 0 0.036000000000001364
- 1 0.0
- 2 -137.3143
- 3 0.0
- 4 0.036000000000001364
- 5 18.173376
- 6 0.0
- 7 0.0
- 8 1.0
roles[] 2 items
- 0 "data"
- 1 "layer"
rendered_preview
- href "https://earth.gov/ghgcenter/api/raster/collections/gra2pes-ghg-monthgrid-v1/items/gra2pes-ghg-monthgrid-v1-202112/preview.png?assets=co2&rescale=0%2C2000&colormap_name=spectral_r"
- type "image/png"
- title "Rendered preview"
- rel "preview"
roles[] 1 items
- 0 "overview"
- collection "gra2pes-ghg-monthgrid-v1"
# Restructure our items into a dictionary where keys are the datetime items
# Then we can query more easily by date/time, e.g. "2020-02"
= {item.properties["start_datetime"][:7]: item for item in collection.get_items()} items_dict
# Before we go further, let's pick which asset to focus on for the remainder of the notebook.
# For now, we'll look at:
= "co2" asset_name
Creating Maps Using Folium
You will now explore changes in CO2 emissions for two different dates/times. You will visualize the outputs 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()
= ["2021-01","2021-07"] dates
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
= items_dict[dates[0]]
first_date = first_date.collection_id
collection_id = first_date.id
item_id # Select relevant asset (microbial CH4 emissions)
object = first_date.assets[asset_name]
= object.extra_fields.get("raster:bands", [{}])
raster_bands # Print raster bands' information
print(raster_bands)
[{'scale': 1.0, 'nodata': -9999.0, 'offset': 0.0, 'sampling': 'area', 'data_type': 'float32', 'histogram': {'max': 27284.111328125, 'min': 0.0, 'count': 11, 'buckets': [334564, 276, 81, 37, 17, 7, 2, 6, 3, 1]}, 'statistics': {'mean': 27.047150098210714, 'stddev': 271.37551127034317, 'maximum': 27284.111328125, 'minimum': 0.0, 'valid_percent': 73.84708309819413}}]
# Use statistics to generate appropriate colorbar range
= {
rescale_values "max": raster_bands[0]["statistics"]["mean"] + 2.5*raster_bands[0]["statistics"]["stddev"],
"min": raster_bands[0]["statistics"]["minimum"],
}
print(rescale_values)
{'max': 705.4859282740687, 'min': 0.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 conventions
# For more information on Colormaps in Matplotlib, please visit https://matplotlib.org/stable/users/explain/colors/colormaps.html
= "Spectral_r" color_map
# Make a GET request to retrieve information for the date mentioned below
= requests.get(
date_1_tile f"{RASTER_API_URL}/collections/{collection_id}/items/{item_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
date_1_tile
{'tilejson': '2.2.0',
'version': '1.0.0',
'scheme': 'xyz',
'tiles': ['https://earth.gov/ghgcenter/api/raster/collections/gra2pes-ghg-monthgrid-v1/items/gra2pes-ghg-monthgrid-v1-202101/tiles/WebMercatorQuad/{z}/{x}/{y}@1x?assets=co2&color_formula=gamma+r+1.05&colormap_name=spectral_r&rescale=0.0%2C705.4859282740687'],
'minzoom': 0,
'maxzoom': 24,
'bounds': [-137.3143, 18.173376, -58.58229999999702, 52.229376000001295],
'center': [-97.94829999999851, 35.20137600000065, 0]}
# Repeat the above for your second date/time
# Note that we do not calculate new rescale_values for this tile
# because we want date tiles 1 and 2 to have the same colorbar range for visual comparison.
= items_dict[dates[1]]
second_date
# Extract collection name and item ID
= second_date.collection_id
collection_id = second_date.id
item_id
object = second_date.assets[asset_name]
= object.extra_fields.get("raster:bands", [{}])
raster_bands = {
rescale_values "max": raster_bands[0].get("histogram", {}).get("max"),
"min": raster_bands[0].get("histogram", {}).get("min"),
}
print(rescale_values)
= requests.get(
date_2_tile f"{RASTER_API_URL}/collections/{collection_id}/items/{item_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
date_2_tile
{'max': 31301.15625, 'min': 0.0}
{'tilejson': '2.2.0',
'version': '1.0.0',
'scheme': 'xyz',
'tiles': ['https://earth.gov/ghgcenter/api/raster/collections/gra2pes-ghg-monthgrid-v1/items/gra2pes-ghg-monthgrid-v1-202107/tiles/WebMercatorQuad/{z}/{x}/{y}@1x?assets=co2&color_formula=gamma+r+1.05&colormap_name=spectral_r&rescale=0.0%2C31301.15625'],
'minzoom': 0,
'maxzoom': 24,
'bounds': [-137.3143, 18.173376, -58.58229999999702, 52.229376000001295],
'center': [-97.94829999999851, 35.20137600000065, 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)"
= folium.plugins.DualMap(location=(34, -118), zoom_start=6)
map_
# Define the first map layer (January 2020)
= TileLayer(
map_layer_1 =date_1_tile["tiles"][0], # Path to retrieve the tile
tiles="GHG", # Set the attribution
attr=0.8, # Adjust the transparency of the layer
opacity=f"GRA2PES, {dates[0]}",
name=True
overlay
)
# Add the first layer to the Dual Map
map_layer_1.add_to(map_.m1)
# Define the second map layer (January 2000)
= TileLayer(
map_layer_2 =date_2_tile["tiles"][0], # Path to retrieve the tile
tiles="GHG", # Set the attribution
attr=0.8, # Adjust the transparency of the layer
opacity=f"GRA2PES, {dates[1]}",
name=True
overlay
)
# Add the second layer to the Dual Map
map_layer_2.add_to(map_.m2)
# Add a layer control to switch between map layers
=False).add_to(map_)
folium.LayerControl(collapsed
# Add colorbar
# First we'll rescale our data to make nicer labels
= {
re_rescale_values "min": rescale_values["min"]/1e4,
"max": rescale_values["max"]/1e4
}# We can use 'generate_html_colorbar' from the 'ghgc_utils' module
# to create an HTML colorbar representation.
= ghgc_utils.generate_html_colorbar(
legend_html
color_map,
re_rescale_values,=f'{items[0].assets[asset_name].title} (10^4 tonne/km2/month)'
label
)
# Add colorbar to the map
map_.get_root().html.add_child(folium.Element(legend_html))
# Visualize the Dual Map
map_
Observe higher CO2 emissions in January than in July in urban areas. Which sectors do you think might contribute to this seasonal difference?
Summary
In this notebook we have successfully explored, analyzed, and visualized the STAC collection for GRA2PES greenhouse gases Emissions, Version 1 dataset.
- Install and import the necessary libraries
- Fetch the collection from STAC collections using the appropriate endpoints
- Count the number of existing granules within the collection
- Map and compare the total CO₂ emissions for two distinctive months/years
If you have any questions regarding this user notebook, please contact us using the feedback form.