Skip to content

Commit

Permalink
add example of collection with a custom handler
Browse files Browse the repository at this point in the history
  • Loading branch information
lubojr committed Jun 28, 2024
1 parent 5e03526 commit ca3fd53
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 0 deletions.
24 changes: 24 additions & 0 deletions collections/sample_custom_processor.yaml
Original file line number Diff line number Diff line change
@@ -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"
27 changes: 27 additions & 0 deletions custom_handlers/custom_endpoint.py
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit ca3fd53

Please sign in to comment.