Skip to content

Description:

  • Planetary scale Earth Observation platform

Resources:

Work with datasets in MPC and create stac complient assets

import pystac
import planetary_computer
import rioxarray as rxr
item_url = "https://planetarycomputer.microsoft.com/api/stac/v1/collections/landsat-c2-l2/items/LC09_L2SP_217066_20231126_02_T1"
# Load the individual item metadata and sign the assets
item = pystac.Item.from_file(item_url)
signed_item = planetary_computer.sign(item)
# Open one of the data assets (other asset keys to use: 'red', 'blue', 'drad', 'emis', 'emsd', 'trad', 'urad', 'atran', 'cdist', 'green', 'nir08', 'lwir11', 'swir16', 'swir22', 'coastal', 'qa_pixel', 'qa_radsat', 'qa_aerosol')
asset_href = signed_item.assets["qa"].href
ds = rxr.open_rasterio(asset_href)
ds

Search the MPC catalog and open the dataset

from pystac_client import Client
import planetary_computer as pc
import rioxarray as rxr
# Search against the Planetary Computer STAC API
catalog = Client.open(
"https://planetarycomputer.microsoft.com/api/stac/v1"
)
# Define your area of interest
aoi = {
"type": "Polygon",
"coordinates": [
[
[-56.60156250000078, -39.97712009843911],
[116.71875000000045, -39.97712009843911],
[116.71875000000045, 72.31578530526212],
[-56.60156250000078, 72.31578530526212],
[-56.60156250000078, -39.97712009843911]
]
]
}
# Define your search with CQL2 syntax
search = catalog.search(filter_lang="cql2-json", filter={
"op": "and",
"args": [
{"op": "s_intersects", "args": [{"property": "geometry"}, aoi]},
{"op": "=", "args": [{"property": "collection"}, "landsat-c2-l2"]},
{"op": "<=", "args": [{"property": "eo:cloud_cover"}, 10]}
]
})
# Grab the first item from the search results and sign the assets
first_item = next(search.items())
signed_item = pc.sign_item(first_item).assets
asset_href = signed_item["coastal"].href
ds = rxr.open_rasterio(asset_href)
ds

ganymede is made by Eugo