# 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_utilsGRA²PES Greenhouse Gas and Air Quality Species
Siddharth Chaudhary, Paridhi Parajuli
August 30, 2024
Access this Notebook
You can launch this notebook in the US GHG Center JupyterHub (requires access) by clicking the following link: GRA²PES Greenhouse Gas and Air Quality Species. 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: 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 information, 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 US Greenhouse Gas Center (GHGC) Application Programming Interface (API)
/stacendpoint. The collection processed in this notebook is the GRA²PES Greenhouse Gas and Air Quality Species data product. - Pass the STAC item into the 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.
About the Data
GRA²PES Greenhouse Gas and Air Quality Species
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. (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 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.
For more information regarding this dataset, please visit the GRA²PES Greenhouse Gas and Air Quality Species data overview page.
Terminology
Navigating data via the US Greenhouse Gas Center (GHGC) Application Programming Interface (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. GRA²PES Greenhouse Gas and Air Quality Speciesitem: One file (i.e. granule) in the dataset, e.g. one monthly file of greenhouse gas emissionsasset: A variable available within the granule, e.g. CO, CO2, or NOx emissionsSTAC 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 US GHG Center STAC API by defining its associated STAC API collection ID as a variable. The collection ID, also known as the collection name, for the GRA²PES Greenhouse Gas and Air Quality Species dataset is gra2pes-ghg-monthgrid-v1.
# Provide STAC and RASTER API endpoints
STAC_API_URL = "https://earth.gov/ghgcenter/api/stac"
RASTER_API_URL = "https://earth.gov/ghgcenter/api/raster"
# Please use the collection name similar to the one used in the STAC collection.
# Name of the collection for GRA²PES Greenhouse Gas and Air Quality Species
collection_name = "gra2pes-ghg-monthgrid-v1"- type "Collection"
- id "gra2pes-ghg-monthgrid-v1"
- stac_version "1.1.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 2021 to December 2021. By looking at the dashboard:time density, we observe that the data is periodic with monthly time density.
Found 12 items
- type "Feature"
- stac_version "1.1.0"
stac_extensions[] 2 items
- 0 "https://stac-extensions.github.io/raster/v1.1.0/schema.json"
- 1 "https://stac-extensions.github.io/projection/v2.0.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"
- title "US GHG Center STAC API"
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/WebMercatorQuad/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: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
- proj:code "EPSG:4326"
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: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
- proj:code "EPSG:4326"
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: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
- proj:code "EPSG:4326"
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: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
- proj:code "EPSG:4326"
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: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
- proj:code "EPSG:4326"
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"
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.
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 = first_date.collection_id
item_id = first_date.id
tile_matrix_set_id = "WebMercatorQuad"
# Select relevant asset (CO2)
object = first_date.assets[asset_name]
raster_bands = object.extra_fields.get("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}}]
{'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.
# Make a GET request to retrieve information for the date mentioned below
date_1_tile = requests.get(
f"{RASTER_API_URL}/collections/{collection_id}/items/{item_id}/{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
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.
second_date = items_dict[dates[1]]
# Extract collection name and item ID
collection_id = second_date.collection_id
item_id = second_date.id
object = second_date.assets[asset_name]
raster_bands = object.extra_fields.get("raster:bands", [{}])
rescale_values = {
"max": raster_bands[0].get("histogram", {}).get("max"),
"min": raster_bands[0].get("histogram", {}).get("min"),
}
print(rescale_values)
date_2_tile = requests.get(
f"{RASTER_API_URL}/collections/{collection_id}/items/{item_id}/{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
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)"
map_ = folium.plugins.DualMap(location=(34, -118), zoom_start=6)
# Define the first map layer (January 2020)
map_layer_1 = TileLayer(
tiles=date_1_tile["tiles"][0], # Path to retrieve the tile
attr="US GHG Center", # Set the attribution
opacity=0.8, # Adjust the transparency of the layer
name=f"GRA²PES, {dates[0]}",
overlay=True
)
# Add the first layer to the Dual Map
map_layer_1.add_to(map_.m1)
# Define the second map layer (January 2000)
map_layer_2 = TileLayer(
tiles=date_2_tile["tiles"][0], # Path to retrieve the tile
attr="US GHG Center", # Set the attribution
opacity=0.8, # Adjust the transparency of the layer
name=f"GRA²PES, {dates[1]}",
overlay=True
)
# 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
# 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.
legend_html = ghgc_utils.generate_html_colorbar(
color_map,
re_rescale_values,
label=f'{items[0].assets[asset_name].title} (10^4 tonne/km2/month)'
)
# Add colorbar to the map
map_.get_root().html.add_child(folium.Element(legend_html))
# Visualize the Dual Map
map_Observe the 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 completed the following steps for the GRA²PES Greenhouse Gas and Air Quality Species dataset:
- Install and import the necessary libraries
- Fetch the collection from STAC using the appropriate endpoints
- Count the number of existing files (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.