-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from lubojr/main
add example of collection with a custom handler
- Loading branch information
Showing
2 changed files
with
51 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |