# Import the following libraries
import requests
import folium
import folium.plugins
from folium import Map, TileLayer
from pystac_client import Client
import branca
import pandas as pd
import matplotlib.pyplot as plt
Geostationary Satellite Observations of Extreme and Transient Methane Emissions from Oil and Gas Infrastructure
Run this notebook
You can launch this notebook in the US GHG Center JupyterHub by clicking the link below.
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 gridded methane emissions data product. - Pass the STAC item into the raster API
/collections/{collection_id}/items/{item_id}/tilejson.json
endpoint. - Using
folium.plugins.DualMap
, we will visualize two tiles (side-by-side), allowing us to compare time points.
About the Data
A sample of methane plumes from point sources observed since 2019 by the U.S. Geostationary Operational Environmental Satellites (GOES) over North and South America.
For more information regarding this dataset, please visit the Geostationary Satellite Observations of Extreme and Transient Methane Emissions from Oil and Gas Infrastructure data overview page.
Install the Required Libraries
Required libraries are pre-installed on the GHG Center Hub. If you need to run this notebook elsewhere, please install them with this line in a code cell:
%pip install requests folium rasterstats pystac_client pandas matplotlib –quiet
Querying the STAC API
First, we are going to import the required libraries. Once imported, they allow better executing a query in the GHG Center Spatio Temporal Asset Catalog (STAC) Application Programming Interface (API) where the granules for this collection are stored.
# 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 STAC collection.
# Name of the collection for gosat budget methane.
= "goes-ch4plume-v1" collection_name
# Fetching the collection from STAC collections using appropriate endpoint.
= requests.get(f"{STAC_API_URL}/collections/{collection_name}").json()
collection collection
{'id': 'goes-ch4plume-v1',
'type': 'Collection',
'links': [{'rel': 'items',
'type': 'application/geo+json',
'href': 'https://earth.gov/ghgcenter/api/stac/collections/goes-ch4plume-v1/items'},
{'rel': 'parent',
'type': 'application/json',
'href': 'https://earth.gov/ghgcenter/api/stac/'},
{'rel': 'root',
'type': 'application/json',
'href': 'https://earth.gov/ghgcenter/api/stac/'},
{'rel': 'self',
'type': 'application/json',
'href': 'https://earth.gov/ghgcenter/api/stac/collections/goes-ch4plume-v1'}],
'title': 'Geostationary Satellite Observations of Extreme and Transient Methane Emissions from Oil and Gas Infrastructure',
'extent': {'spatial': {'bbox': [[-104.72692922440127,
25.251622016105113,
-86.82596069124111,
41.12229053684302]]},
'temporal': {'interval': [['2019-04-07 16:16:00+00',
'2023-07-26 18:01:00+00']]}},
'license': 'CC-BY-4.0',
'renders': {'rad': {'assets': ['rad'],
'rescale': [[0.0, 0.4]],
'colormap_name': 'plasma'},
'dashboard': {'assets': ['rad'],
'rescale': [[0.0, 0.4]],
'colormap_name': 'plasma'}},
'summaries': {'datetime': ['2019-04-07T16:16:00Z', '2023-07-26T18:01:00Z']},
'description': 'A sample of methane plumes from point sources observed since 2019 by the U.S. Geostationary Operational Environmental Satellites (GOES) over North and South America',
'item_assets': {'rad': {'type': 'image/tiff; application=geotiff; profile=cloud-optimized',
'roles': ['data', 'layer'],
'title': 'Methane Column Enhancement',
'description': 'Sample of methane plumes from point sources.'}},
'stac_version': '1.0.0',
'stac_extensions': ['https://stac-extensions.github.io/render/v1.0.0/schema.json',
'https://stac-extensions.github.io/item-assets/v1.0.0/schema.json'],
'dashboard:is_periodic': True,
'dashboard:time_density': 'daily'}
Examining the contents of our collection
under the temporal
variable, we see that the data is available from April 7, 2019 . By looking at the dashboard:time density
, we observe that the data is available for multiple days.
def get_item_count(collection_id):
= 0
count = f"{STAC_API_URL}/collections/{collection_id}/items"
items_url
while True:
= requests.get(items_url)
response
if not response.ok:
print("error getting items")
exit()
= response.json()
stac += int(stac["context"].get("returned", 0))
count next = [link for link in stac["links"] if link["rel"] == "next"]
if not next:
break
= next[0]["href"]
items_url
return count
# Check total number of items available
= get_item_count(collection_name)
number_of_items = requests.get(f"{STAC_API_URL}/collections/{collection_name}/items?limit={number_of_items}").json()["features"]
items print(f"Found {len(items)} items")
Found 457 items
# Examining the first item in the collection
0] items[
{'id': 'goes-ch4plume-v1-GOES-CH4_USA_Texas_Permian_PB-1_2023-07-26T18:01:00Z',
'bbox': [-104.05592607423101,
31.603935693136833,
-103.94719869425685,
31.697130590257547],
'type': 'Feature',
'links': [{'rel': 'collection',
'type': 'application/json',
'href': 'https://earth.gov/ghgcenter/api/stac/collections/goes-ch4plume-v1'},
{'rel': 'parent',
'type': 'application/json',
'href': 'https://earth.gov/ghgcenter/api/stac/collections/goes-ch4plume-v1'},
{'rel': 'root',
'type': 'application/json',
'href': 'https://earth.gov/ghgcenter/api/stac/'},
{'rel': 'self',
'type': 'application/geo+json',
'href': 'https://earth.gov/ghgcenter/api/stac/collections/goes-ch4plume-v1/items/goes-ch4plume-v1-GOES-CH4_USA_Texas_Permian_PB-1_2023-07-26T18:01:00Z'},
{'title': 'Map of Item',
'href': 'https://earth.gov/ghgcenter/api/raster/collections/goes-ch4plume-v1/items/goes-ch4plume-v1-GOES-CH4_USA_Texas_Permian_PB-1_2023-07-26T18:01:00Z/map?assets=rad&rescale=0.0%2C0.4&colormap_name=plasma',
'rel': 'preview',
'type': 'text/html'}],
'assets': {'rad': {'href': 's3://ghgc-data-store/goes-ch4plume-v1/GOES-CH4_USA_Texas_Permian_PB-1_2023-07-26T18:01:00Z.tif',
'type': 'image/tiff; application=geotiff',
'roles': ['data', 'layer'],
'title': 'Methane Column Enhancement',
'proj:bbox': [-104.05592607423101,
31.603935693136833,
-103.94719869425685,
31.697130590257547],
'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': [6, 7],
'description': 'Sample of methane plumes from point sources',
'raster:bands': [{'scale': 1.0,
'nodata': 0.0,
'offset': 0.0,
'sampling': 'area',
'data_type': 'float64',
'histogram': {'max': 0.11519252942615393,
'min': 0.021999548698559218,
'count': 11,
'buckets': [2, 3, 2, 1, 1, 0, 2, 2, 1, 2]},
'statistics': {'mean': 0.0651174719845713,
'stddev': 0.02977607649044455,
'maximum': 0.11519252942615393,
'minimum': 0.021999548698559218,
'valid_percent': 38.095238095238095}}],
'proj:geometry': {'type': 'Polygon',
'coordinates': [[[-104.05592607423101, 31.603935693136833],
[-103.94719869425685, 31.603935693136833],
[-103.94719869425685, 31.697130590257547],
[-104.05592607423101, 31.697130590257547],
[-104.05592607423101, 31.603935693136833]]]},
'proj:transform': [0.015532482853451768,
0.0,
-104.05592607423101,
0.0,
-0.015532482853452479,
31.697130590257547,
0.0,
0.0,
1.0]},
'rendered_preview': {'title': 'Rendered preview',
'href': 'https://earth.gov/ghgcenter/api/raster/collections/goes-ch4plume-v1/items/goes-ch4plume-v1-GOES-CH4_USA_Texas_Permian_PB-1_2023-07-26T18:01:00Z/preview.png?assets=rad&rescale=0.0%2C0.4&colormap_name=plasma',
'rel': 'preview',
'roles': ['overview'],
'type': 'image/png'}},
'geometry': {'type': 'Polygon',
'coordinates': [[[-104.05592607423101, 31.603935693136833],
[-103.94719869425685, 31.603935693136833],
[-103.94719869425685, 31.697130590257547],
[-104.05592607423101, 31.697130590257547],
[-104.05592607423101, 31.603935693136833]]]},
'collection': 'goes-ch4plume-v1',
'properties': {'datetime': '2023-07-26T18:01:00+00:00'},
'stac_version': '1.0.0',
'stac_extensions': ['https://stac-extensions.github.io/raster/v1.1.0/schema.json',
'https://stac-extensions.github.io/projection/v1.1.0/schema.json']}
Below, we enter minimum and maximum values to provide our upper and lower bounds in rescale_values.
Exploring Changes in GOES Methne (CH4) Levels Using the Raster API
In this notebook, we will explore the impacts of methane emissions and by examining changes over time in urban regions. We will visualize the outputs on a map using folium.
# To access the year value from each item more easily, this will let us query more explicity by year and month (e.g., 2020-02)
= {item["properties"]["datetime"][:10]: item for item in items}
items = "rad" asset_name
# Fetching the min and max values for a specific item
= {"max":items[list(items.keys())[0]]["assets"][asset_name]["raster:bands"][0]["histogram"]["max"], "min":items[list(items.keys())[0]]["assets"][asset_name]["raster:bands"][0]["histogram"]["min"]} rescale_values
items.keys()
Now, we will pass the item id, collection name, and rescaling_factor
to the Raster API
endpoint.
= "plasma" # please select the color ramp from matplotlib library.
color_map = requests.get(
april_2019_tile f"{RASTER_API_URL}/collections/{items['2019-04-07']['collection']}/items/{items['2019-04-07']['id']}/tilejson.json?"
f"&assets={asset_name}"
f"&color_formula=gamma+r+1.05&colormap_name={color_map}"
f"&rescale={rescale_values['min']},{rescale_values['max']}",
).json() april_2019_tile
{'tilejson': '2.2.0',
'version': '1.0.0',
'scheme': 'xyz',
'tiles': ['https://earth.gov/ghgcenter/api/raster/collections/goes-ch4plume-v1/items/goes-ch4plume-v1-GOES-CH4_Mexico_Durango_BV1_BV1-1_2019-04-07T16:16:00Z/tiles/WebMercatorQuad/{z}/{x}/{y}@1x?assets=rad&color_formula=gamma+r+1.05&colormap_name=plasma&rescale=0.026619306576566443%2C0.07300545309991482'],
'minzoom': 0,
'maxzoom': 24,
'bounds': [-104.5738874776177,
26.1684406557021,
-104.43664236204742,
26.305685771272373],
'center': [-104.50526491983257, 26.237063213487236, 0]}
Visualizing CH₄ Emissions
# Set initial zoom and center of map for CH₄ Layer
# Centre of map [latitude,longitude]
= folium.Map(location=(26.29, -104.53), zoom_start=10)
map_
# January 2019
= TileLayer(
map_layer_2019 =april_2019_tile["tiles"][0],
tiles="GHG",
attr=0.7,
opacity
)
map_layer_2019.add_to(map_) map_
Summary
In this notebook we have successfully completed the following steps for the STAC collection for the GOSAT-based Top-down Total and Natural Methane Emissions 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 the methane emission levels
If you have any questions regarding this user notebook, please contact us using the feedback form.