import requests
from pystac_client import Client
# For displaying image in a jupyter notebook
from IPython.display import Image, display
Accessing and using the US GHG Center Data Catalog
The US GHG Center uses a Spatio-Temporal Asset Catalog (STAC) to catalog it listing of datasets. This tutorial teaches the basics of searching and accessing datasets using the US GHG Center STAC catalog.
Approach
- Use the
pystac_client
library to connect to the data catalog - List all the collections from the catalog
- Look at the items in one of the collections
- Access an asset in the item
- Use the US GHG Center TiTiler API to visualize the asset
Libraries Used
PySTAC Client
From the PySTAC Client Documentation:
The STAC Python Client (
pystac_client
) is a Python package for working with STAC Catalogs and APIs that conform to the STAC and STAC API specs in a seamless way.
PySTAC Client builds upon PySTAC through higher-level functionality and ability to leverage STAC API search endpoints.
We will use it to interact with the data catalog.
Requests
Requests (requests
) is a simple HTTP library. Requests allows you to send HTTP requests extremely easily.
We will use it to make API requests.
Here we import all the required libraries and modules.
Let’s define the data catalog (STAC catalog) API URL
# STAC API root URL
= 'https://ghg.center/api/stac' URL
Use the pystac_client.Client
module to connect to the catalog
= Client.open(URL)
catalog catalog
- type "Catalog"
- id "stac-fastapi"
- stac_version "1.0.0"
- description "veda-stac"
links [] 23 items
0
- rel "self"
- href "https://ghg.center/api/stac"
- type "application/json"
1
- rel "root"
- href "https://ghg.center/api/stac/"
- type "application/json"
2
- rel "data"
- href "https://ghg.center/api/stac/collections"
- type "application/json"
3
- rel "conformance"
- href "https://ghg.center/api/stac/conformance"
- type "application/json"
- title "STAC/WFS3 conformance classes implemented by this server"
4
- rel "search"
- href "https://ghg.center/api/stac/search"
- type "application/geo+json"
- title "STAC search"
- method "GET"
5
- rel "search"
- href "https://ghg.center/api/stac/search"
- type "application/geo+json"
- title "STAC search"
- method "POST"
6
- rel "child"
- href "https://ghg.center/api/stac/collections/epa-ch4emission-yeargrid-v2express-new"
- type "application/json"
- title "Gridded annual U.S. anthropogenic methane emissions 2012-2020"
7
- rel "child"
- href "https://ghg.center/api/stac/collections/lpjwsl-wetlandch4-monthgrid-v1"
- type "application/json"
- title "Wetland Methane Emissions, LPJ-wsl Model (Monthly)"
8
- rel "child"
- href "https://ghg.center/api/stac/collections/tm54dvar-ch4flux-monthgrid-v1"
- type "application/json"
- title "TM5-4DVar Isotopic CH4 Inverse Fluxes"
9
- rel "child"
- href "https://ghg.center/api/stac/collections/gosat-based-ch4budget-yeargrid-v1"
- type "application/json"
- title "GOSAT-based Top-down Methane Budgets."
10
- rel "child"
- href "https://ghg.center/api/stac/collections/sedac-popdensity-yeargrid5yr-v4.11"
- type "application/json"
- title "SEDAC Gridded World Population Data"
11
- rel "child"
- href "https://ghg.center/api/stac/collections/tm54dvar-ch4flux-mask-monthgrid-v1"
- type "application/json"
- title "TM5-4DVar Isotopic CH4 Inverse Fluxes"
12
- rel "child"
- href "https://ghg.center/api/stac/collections/casagfed-carbonflux-monthgrid-v3"
- type "application/json"
- title "CASA GFED3 Land Carbon Flux"
13
- rel "child"
- href "https://ghg.center/api/stac/collections/oco2geos-co2-daygrid-v10r"
- type "application/json"
- title "OCO-2 GEOS Assimilated CO2 Concentrations"
14
- rel "child"
- href "https://ghg.center/api/stac/collections/lpjwsl-wetlandch4-daygrid-v1"
- type "application/json"
- title "Wetland Methane Emissions, LPJ-wsl Model (Daily)"
15
- rel "child"
- href "https://ghg.center/api/stac/collections/epa-ch4emission-yeargrid-v2express"
- type "application/json"
- title "Gridded annual U.S. anthropogenic methane emissions 2012-2020"
16
- rel "child"
- href "https://ghg.center/api/stac/collections/emit-ch4plume-v1"
- type "application/json"
- title "Methane Point Source Plume Complexes"
17
- rel "child"
- href "https://ghg.center/api/stac/collections/oco2-mip-meanco2budget-yeargrid-v1"
- type "application/json"
- title "Pilot top-down CO2 Budget constrained by the v10 OCO-2 MIP Version 1 mean for all the years"
18
- rel "child"
- href "https://ghg.center/api/stac/collections/oco2-mip-co2budget-yeargrid-v1"
- type "application/json"
- title "Pilot top-down CO2 Budget constrained by the v10 OCO-2 MIP Version 1"
19
- rel "child"
- href "https://ghg.center/api/stac/collections/eccodarwin-co2flux-monthgrid-v5"
- type "application/json"
- title "Air-Sea CO2 Flux, ECCO-Darwin Model v5"
20
- rel "child"
- href "https://ghg.center/api/stac/collections/odiac-ffco2-monthgrid-v2022"
- type "application/json"
- title "ODIAC Fossil Fuel CO₂ Emissions"
21
- rel "service-desc"
- href "https://ghg.center/api/stac/openapi.json"
- type "application/vnd.oai.openapi+json;version=3.0"
- title "OpenAPI service description"
22
- rel "service-doc"
- href "https://ghg.center/api/stac/docs"
- type "text/html"
- title "OpenAPI service documentation"
conformsTo [] 16 items
- 0 "https://api.stacspec.org/v1.0.0/item-search"
- 1 "http://www.opengis.net/spec/ogcapi-features-1/1.0/conf/core"
- 2 "http://www.opengis.net/spec/cql2/1.0/conf/cql2-text"
- 3 "https://api.stacspec.org/v1.0.0-rc.2/item-search#sort"
- 4 "https://api.stacspec.org/v1.0.0/collections"
- 5 "http://www.opengis.net/spec/ogcapi-features-1/1.0/conf/geojson"
- 6 "http://www.opengis.net/spec/ogcapi-features-1/1.0/conf/oas30"
- 7 "http://www.opengis.net/spec/ogcapi-features-3/1.0/conf/features-filter"
- 8 "https://api.stacspec.org/v1.0.0/ogcapi-features"
- 9 "https://api.stacspec.org/v1.0.0/core"
- 10 "http://www.opengis.net/spec/ogcapi-features-3/1.0/conf/filter"
- 11 "https://api.stacspec.org/v1.0.0-rc.2/item-search#filter"
- 12 "https://api.stacspec.org/v1.0.0-rc.2/item-search#query"
- 13 "https://api.stacspec.org/v1.0.0-rc.3/item-search#fields"
- 14 "https://api.stacspec.org/v1.0.0-rc.2/item-search#context"
- 15 "http://www.opengis.net/spec/cql2/1.0/conf/basic-cql2"
- title "veda-stac"
List all the datasets (collections) in the catalog
= catalog.get_collections()
collections = list(collections) collections
for collection in collections:
# print(f">> {collection.id}: \n- {collection.description}\n")
print(">> " + collection.id)
print("- " + collection.description + "\n")
>> epa-ch4emission-yeargrid-v2express-new
- This gridded dataset represents an update to the original version 1 of the gridded GHGI from Maasakkers, et al., (2016). The annual files contain one year of emissions per source category but include a time dimension to make them suitable (COARDS-compliant) for atmospheric models. This main dataset also includes monthly source-specific methane emission scaling factors for those select sources with strong interannual variability.
>> lpjwsl-wetlandch4-monthgrid-v1
- Wetland methane emissions produced by the Lund–Potsdam–Jena Dynamic Global Vegetation Model (LPJ-DGVM) Wald Schnee und Landscaft version (LPJ-wsl). LPJ-wsl is a prognostic model used to simulate future changes in wetland emissions and independently verified with remote sensing data products. The LPJ-wsl model is regularly used in conjunction with NASA’s GEOS model to simulate the impact of wetlands and other methane sources on atmospheric methane concentrations.
>> tm54dvar-ch4flux-monthgrid-v1
- Global, monthly 1 degree resolution methane emission estimates from microbial, fossil and pyrogenic sources derived using inverse modeling, version 1.
>> gosat-based-ch4budget-yeargrid-v1
- Annual methane emissions gridded globally at 1° resolution for 2019, version.
>> sedac-popdensity-yeargrid5yr-v4.11
- The Gridded Population of the World, Version 4 (GPWv4): Population Density, Revision 11 consists of estimates of human population density (number of persons per square kilometer) based on counts consistent with national censuses and population registers, for the years 2000, 2005, 2010, 2015, and 2020.
>> tm54dvar-ch4flux-mask-monthgrid-v1
- Global, monthly 1 degree resolution methane emission estimates from microbial, fossil and pyrogenic sources derived using inverse modeling, version 1.
>> casagfed-carbonflux-monthgrid-v3
- This product provides Monthly average Net Primary Production (NPP), heterotrophic respiration (Rh), wildfire emissions (FIRE), and fuel wood burning emissions (FUEL) derived from the Carnegie-Ames-Stanford-Approach – Global Fire Emissions Database version 3 (CASA-GFED3) model.
>> oco2geos-co2-daygrid-v10r
- Daily, global 0.5 x 0.625 degree assimilated CO2 concentrations derived from OCO-2 satellite data, version 10r
>> lpjwsl-wetlandch4-daygrid-v1
- Wetland methane emissions produced by the Lund–Potsdam–Jena Dynamic Global Vegetation Model (LPJ-DGVM) Wald Schnee und Landscaft version (LPJ-wsl). LPJ-wsl is a prognostic model used to simulate future changes in wetland emissions and independently verified with remote sensing data products. The LPJ-wsl model is regularly used in conjunction with NASA’s GEOS model to simulate the impact of wetlands and other methane sources on atmospheric methane concentrations.
>> epa-ch4emission-yeargrid-v2express
- This gridded dataset represents an update to the original version 1 of the gridded GHGI from Maasakkers, et al., (2016). The annual files contain one year of emissions per source category but include a time dimension to make them suitable (COARDS-compliant) for atmospheric models. This main dataset also includes monthly source-specific methane emission scaling factors for those select sources with strong interannual variability.
>> emit-ch4plume-v1
- Methane plume complexes from point source emitters
>> oco2-mip-meanco2budget-yeargrid-v1
- National CO2 Budgets (2015-2020) inferred from atmospheric CO2 observations in support of the Global Stocktake
>> oco2-mip-co2budget-yeargrid-v1
- National CO2 Budgets (2015-2020) inferred from atmospheric CO2 observations in support of the Global Stocktake
>> eccodarwin-co2flux-monthgrid-v5
- Global, monthly average air-sea CO2 flux at ~1/3° resolution from 2020 to 2022
>> odiac-ffco2-monthgrid-v2022
- 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.
Pick a collection to interact with. Let’s pick eccodarwin-co2flux-monthgrid-v5
. This dataset represents the Air-Sea CO₂ flux, estimated using the ECCO (Estimating the Circulation and Climate of the Ocean) Darwin model.
Read more about the dataset in the GHG Center Web Portal: https://earth.gov/ghgcenter/data-catalog/eccodarwin-co2flux-monthgrid-v5
= catalog.get_collection("eccodarwin-co2flux-monthgrid-v5")
collection collection
- type "Collection"
- id "eccodarwin-co2flux-monthgrid-v5"
- stac_version "1.0.0"
- description "Global, monthly average air-sea CO2 flux at ~1/3° resolution from 2020 to 2022"
links [] 4 items
0
- rel "items"
- href "https://ghg.center/api/stac/collections/eccodarwin-co2flux-monthgrid-v5/items"
- type "application/geo+json"
1
- rel "parent"
- href "https://ghg.center/api/stac/"
- type "application/json"
2
- rel "root"
- href "https://ghg.center/api/stac"
- type "application/json"
- title "veda-stac"
3
- rel "self"
- href "https://ghg.center/api/stac/collections/eccodarwin-co2flux-monthgrid-v5"
- type "application/json"
item_assets
co2
- type "image/tiff; application=geotiff; profile=cloud-optimized"
roles [] 2 items
- 0 "data"
- 1 "layer"
- title "Air-Sea CO2 Flux"
- description "Monthly mean air-sea CO2 Flux (negative into ocean)"
- dashboard:is_periodic True
- dashboard:time_density "month"
- title "Air-Sea CO2 Flux, ECCO-Darwin Model v5"
extent
spatial
bbox [] 1 items
0 [] 4 items
- 0 -180.125
- 1 -90.12483215332031
- 2 179.875
- 3 89.87517547607422
temporal
interval [] 1 items
0 [] 2 items
- 0 "2020-01-01T00:00:00Z"
- 1 "2022-12-31T00:00:00Z"
- license "CC-BY-4.0"
summaries
datetime [] 2 items
- 0 "2020-01-01T00:00:00Z"
- 1 "2022-12-31T00:00:00Z"
Let’s look at the items within the collection, using the CollectionClient.get_items
method
# get_items
= list(collection.get_items()) items
for item in items[:10]:
print(item)
<Item id=eccodarwin-co2flux-monthgrid-v5-202212>
<Item id=eccodarwin-co2flux-monthgrid-v5-202211>
<Item id=eccodarwin-co2flux-monthgrid-v5-202210>
<Item id=eccodarwin-co2flux-monthgrid-v5-202209>
<Item id=eccodarwin-co2flux-monthgrid-v5-202208>
<Item id=eccodarwin-co2flux-monthgrid-v5-202207>
<Item id=eccodarwin-co2flux-monthgrid-v5-202206>
<Item id=eccodarwin-co2flux-monthgrid-v5-202205>
<Item id=eccodarwin-co2flux-monthgrid-v5-202204>
<Item id=eccodarwin-co2flux-monthgrid-v5-202203>
= collection.get_item(items[0].id) # item = collection.get_item("eccodarwin-co2flux-monthgrid-v5-202212")
item item
- type "Feature"
- stac_version "1.0.0"
- id "eccodarwin-co2flux-monthgrid-v5-202212"
properties
- end_datetime "2022-12-31T00:00:00+00:00"
- start_datetime "2022-12-01T00:00:00+00:00"
- datetime None
geometry
- type "Polygon"
coordinates [] 1 items
0 [] 5 items
0 [] 2 items
- 0 -180.125
- 1 -90.124826629681
1 [] 2 items
- 0 179.875
- 1 -90.124826629681
2 [] 2 items
- 0 179.875
- 1 89.875173370319
3 [] 2 items
- 0 -180.125
- 1 89.875173370319
4 [] 2 items
- 0 -180.125
- 1 -90.124826629681
links [] 4 items
0
- rel "self"
- href "https://ghg.center/api/stac/collections/eccodarwin-co2flux-monthgrid-v5/items/eccodarwin-co2flux-monthgrid-v5-202212"
- type "application/json"
1
- rel "collection"
- href "https://ghg.center/api/stac/collections/eccodarwin-co2flux-monthgrid-v5"
- type "application/json"
2
- rel "parent"
- href "https://ghg.center/api/stac/collections/eccodarwin-co2flux-monthgrid-v5"
- type "application/json"
3
- rel "root"
- href "https://ghg.center/api/stac/collections/eccodarwin-co2flux-monthgrid-v5"
- type "application/json"
- title "Air-Sea CO2 Flux, ECCO-Darwin Model v5"
assets
co2
- href "s3://ghgc-data-store/eccodarwin-co2flux-monthgrid-v5/ECCO-Darwin_CO2_flux_202212.tif"
- type "image/tiff; application=geotiff"
- title "Air-Sea CO2 Flux"
- description "Monthly mean air-sea CO2 Flux (negative into ocean)"
proj:bbox [] 4 items
- 0 -180.125
- 1 -90.124826629681
- 2 179.875
- 3 89.875173370319
- proj:epsg 4326.0
proj:shape [] 2 items
- 0 721.0
- 1 1440.0
raster:bands [] 1 items
0
- scale 1.0
- offset 0.0
- sampling "area"
- data_type "float64"
histogram
- max 1e+20
- min -0.0560546528687938
- count 11.0
buckets [] 10 items
- 0 338606.0
- 1 0.0
- 2 0.0
- 3 0.0
- 4 0.0
- 5 0.0
- 6 0.0
- 7 0.0
- 8 0.0
- 9 186706.0
statistics
- mean 3.554192556042885e+19
- stddev 4.786401658343999e+19
- maximum 1e+20
- minimum -0.0560546528687938
- valid_percent 0.0001903630604288499
proj:geometry
- type "Polygon"
coordinates [] 1 items
0 [] 5 items
0 [] 2 items
- 0 -180.125
- 1 -90.124826629681
1 [] 2 items
- 0 179.875
- 1 -90.124826629681
2 [] 2 items
- 0 179.875
- 1 89.875173370319
3 [] 2 items
- 0 -180.125
- 1 89.875173370319
4 [] 2 items
- 0 -180.125
- 1 -90.124826629681
proj:projjson
id
- code 4326.0
- authority "EPSG"
- name "WGS 84"
- type "GeographicCRS"
datum
- name "World Geodetic System 1984"
- type "GeodeticReferenceFrame"
ellipsoid
- name "WGS 84"
- semi_major_axis 6378137.0
- inverse_flattening 298.257223563
- $schema "https://proj.org/schemas/v0.4/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.25
- 1 0.0
- 2 -180.125
- 3 0.0
- 4 -0.24965325936199723
- 5 89.875173370319
- 6 0.0
- 7 0.0
- 8 1.0
roles [] 2 items
- 0 "data"
- 1 "layer"
bbox [] 4 items
- 0 -180.125
- 1 -90.124826629681
- 2 179.875
- 3 89.875173370319
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"
- collection "eccodarwin-co2flux-monthgrid-v5"
= item.assets["co2"].href
asset asset
's3://ghgc-data-store/eccodarwin-co2flux-monthgrid-v5/ECCO-Darwin_CO2_flux_202212.tif'
Visualize this asset using TiTiler
# Define the TiTiler url
= "https://ghg.center/api/raster" TITILER_URL
# TiTiler preview endpoint
= f"/cog/preview.png?url={asset}&rescale=-0.0007,0.0002&colormap_name=bwr" cog_preview
User requests.get
to make a GET
request for the preview
= requests.get(f"{TITILER_URL}{cog_preview}") #https://ghg.center/api/raster/cog/preview.png?url=s3://ghgc-data-store/eccodarwin-co2flux-monthgrid-v5/ECCO-Darwin_CO2_flux_202212.tif&rescale=-0.0007,0.0002&colormap_name=bwr
response response
<Response [200]>
display(Image(response.content))
Searching for datasets based on the Area of Interest (AOI) and/or datetime
# Rought AOI for Baltimore, MD area
= {
baltimore_aoi "type": "Polygon",
"coordinates": [
[
[-76.7413596126004,
39.37730408865011
],
[-76.7413596126004,
39.20129583511198
],
[-76.47249934044682,
39.20129583511198
],
[-76.47249934044682,
39.37730408865011
],
[-76.7413596126004,
39.37730408865011
]
]
], }
# Search the catalog for the given collection, aoi and datetime
= catalog.search(
search = 100,
max_items # limit = 5,
= "epa-ch4emission-yeargrid-v2express",
collections = baltimore_aoi,
intersects = "2012-04-01/2015-12-31",
datetime
)= list(search.item_collection())
items
len(items)
100
5] items[:
[<Item id=oco2geos-co2-daygrid-v10r-20151231>,
<Item id=lpjwsl-wetlandch4-daygrid-v1-20151231>,
<Item id=oco2geos-co2-daygrid-v10r-20151230>,
<Item id=lpjwsl-wetlandch4-daygrid-v1-20151230>,
<Item id=oco2geos-co2-daygrid-v10r-20151229>]
Summary
In this notebook, we used the pystac_client
library to interact with the US GHG Center Data Catalog. We learned how to list all the datasets, list all the items in a dataset, read the metadata for the dataset/items, access the data file, visualize it and finally search the catalog for specific area of interest and datetime.