From ca3fd538bc70d5e43e0d5d4523b89e267134d09e Mon Sep 17 00:00:00 2001 From: Lubomir Dolezal Date: Fri, 28 Jun 2024 13:13:46 +0200 Subject: [PATCH] add example of collection with a custom handler --- collections/sample_custom_processor.yaml | 24 +++++++++++++++++++++ custom_handlers/custom_endpoint.py | 27 ++++++++++++++++++++++++ 2 files changed, 51 insertions(+) create mode 100644 collections/sample_custom_processor.yaml create mode 100644 custom_handlers/custom_endpoint.py diff --git a/collections/sample_custom_processor.yaml b/collections/sample_custom_processor.yaml new file mode 100644 index 0000000..f7a0c77 --- /dev/null +++ b/collections/sample_custom_processor.yaml @@ -0,0 +1,24 @@ +Name: test_custom_processor +Title: test_custom_processor +EodashIdentifier: test_custom_processor +Description: "" +Themes: + - example theme +Tags: + - example tag +DataSource: + Spaceborne: + Satellite: + - example satellite + Sensor: + - example sensorname +Agency: + - EEA +Resources: + - Name: Custom-Endpoint + Python_Function_Location: "custom_handlers.custom_endpoint.execute" + CustomParameter: "test" + STAC_Url: "https://s3.us-west-2.amazonaws.com/umbra-open-data-catalog/stac/catalog.json" + Subset_Dates: + - "2023-01-16" + - "2023-04-16" diff --git a/custom_handlers/custom_endpoint.py b/custom_handlers/custom_endpoint.py new file mode 100644 index 0000000..523eea6 --- /dev/null +++ b/custom_handlers/custom_endpoint.py @@ -0,0 +1,27 @@ +from pystac import Collection, Catalog +from pystac_client import Client + + +def execute( + collection: Collection, + catalog_config: dict, + endpoint_config: dict, + collection_config: dict, +): + if "cerulean" not in catalog_config["title"].lower(): + raise Exception("This demo handler should be run only on cerulean catalog.") + stac_endpoint_url = endpoint_config["STAC_Url"] + api = Client.open(stac_endpoint_url) + + # catalog structure is {year}/{year-month}/{year-month-day}/items + for date_entry in endpoint_config["Subset_Dates"]: + year, month, day = date_entry.split("-") + catalog: Catalog = ( + api.get_child(year) + .get_child(f"{year}-{month}") # type: ignore + .get_child(f"{year}-{month}-{day}") # type: ignore + ) + + for item in catalog.get_items(): + collection.add_item(item) + return collection