Skip to content

Commit

Permalink
add Query mechanic to zarr endpoint as well
Browse files Browse the repository at this point in the history
  • Loading branch information
lubojr committed Aug 5, 2024
1 parent 0b37784 commit 6be0a93
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 16 deletions.
22 changes: 7 additions & 15 deletions src/eodash_catalog/endpoints.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import sys
import uuid
from collections.abc import Callable
from datetime import datetime, timedelta, timezone
from datetime import datetime, timedelta
from itertools import groupby
from operator import itemgetter

Expand All @@ -27,6 +27,7 @@
Options,
create_geojson_from_bbox,
create_geojson_point,
filter_time_entries,
generate_veda_cog_link,
replace_with_env_variables,
retrieveExtentFromWMSWMTS,
Expand Down Expand Up @@ -69,6 +70,10 @@ def process_STAC_Datacube_Endpoint(
time_dimension = k
break
time_entries = dimensions.get(time_dimension).get("values")
# optionally subset time results based on config
if query := endpoint_config.get("Query"):
time_entries = filter_time_entries(time_entries, query)

for t in time_entries:
item = Item(
id=t,
Expand Down Expand Up @@ -527,20 +532,7 @@ def handle_WMS_endpoint(
)
# optionally filter time results
if query := endpoint_config.get("Query"):
datetime_query = [
parser.isoparse(times[0]).replace(tzinfo=timezone.utc),
parser.isoparse(times[-1]).replace(tzinfo=timezone.utc),
]
if start := query.get("Start"):
datetime_query[0] = parser.isoparse(start).replace(tzinfo=timezone.utc)
if end := query.get("End"):
datetime_query[1] = parser.isoparse(end).replace(tzinfo=timezone.utc)
# filter times based on query Start/End
times = [
datetime_str
for datetime_str in times
if datetime_query[0] <= parser.isoparse(datetime_str) < datetime_query[1]
]
times = filter_time_entries(times, query)
# Create an item per time to allow visualization in stac clients
if len(times) > 0:
for t in times:
Expand Down
20 changes: 19 additions & 1 deletion src/eodash_catalog/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import uuid
from collections.abc import Iterator
from dataclasses import dataclass
from datetime import datetime, timedelta
from datetime import datetime, timedelta, timezone
from decimal import Decimal
from functools import reduce, wraps
from typing import Any
Expand Down Expand Up @@ -307,3 +307,21 @@ def wrapper(*args, **kwargs):
return wrapper

return decorator


def filter_time_entries(time_entries: list[str], query: dict[str, str]) -> list[str]:
datetime_query = [
parser.isoparse(time_entries[0]).replace(tzinfo=timezone.utc),
parser.isoparse(time_entries[-1]).replace(tzinfo=timezone.utc),
]
if start := query.get("Start"):
datetime_query[0] = parser.isoparse(start).replace(tzinfo=timezone.utc)
if end := query.get("End"):
datetime_query[1] = parser.isoparse(end).replace(tzinfo=timezone.utc)
# filter times based on query Start/End
time_entries = [
datetime_str
for datetime_str in time_entries
if datetime_query[0] <= parser.isoparse(datetime_str) < datetime_query[1]
]
return time_entries

0 comments on commit 6be0a93

Please sign in to comment.