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"])
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"])