Skip to content

Streamlining STAC queries via pystac #36

Description

@dmoglioni

Optimizing STAC queries to expose services associated to a data collections (for example SH statistical API and the corresponding dataId).
Below an example @lubojr shared with me on how currently it is implemented (data collection: S5p-NO2).
To investigate how the steps below can be streamlined.
cc: @aapopescu

Step 1: Access the EODashboard STAC Catalog via PySTAC

from
pystac import
Catalog

URL to the root STAC catalog (adjust if necessary)

catalog_url
= "https://esa-eodashboards.github.io/eodashboard-catalog/trilateral/catalog.json"

Load the catalog

catalog
= Catalog.from_file(catalog_url)

Print basic information

print(f"Catalog ID:
{catalog.id}")

print(f"Description:
{catalog.description}")

indicators
= list(catalog.get_children())

print(f"Number of child indicators:
{len(indicators)}")

no2_indicators_s5p
= [

ind
for ind
in indicators

if
"NO2" in
ind.extra_fields.get("tags",{})

and
"Sentinel-5P" in
ind.extra_fields.get("satellite",{})

]

print("retrieved indicators",
no2_indicators_s5p)

we "know" that we need to take NO2_daily but metadata-wise it is tricky to deduct that from the collections

daily_no2_indicator
= next(ind
for
ind in
no2_indicators_s5p if
ind.id
== "NO2_daily")

Get child links that are STAC collections

child_collections
= []

for
link in
daily_no2_indicator.get_links("child"):

if
link.rel
== "child":

child_collection
= link.resolve_stac_object().target

child_collections.append(child_collection)

Show child collection IDs and titles

print(f"{len(child_collections)}
child collections found under 'no2_daily': indicator")

for
col in
child_collections:

print(f"-
{col.id}:
{col.title}")

get actual service links connected to this collection

daily_no2_collection
= next(ind
for
ind in
child_collections if
ind.id
== "NO2_daily")

for
link in
daily_no2_collection.links:

print("available link:",
link)

we need to extract the link with relationship "example"

example_link
= next(link
for
link in
daily_no2_collection.links if
link.rel ==
"example")

list available fields of the link:

print("properties of the example link",
example_link.extra_fields)

we see that the SH collection ID is in dataID field

print("retrieved collection id:",
example_link.extra_fields["dataId"])

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions