Skip to content

Commit 20d24ce

Browse files
committed
do not attempt datetime filtering in case of netcdf with time dimension, doesn't work (yet)
stac-utils/stac-fastapi-elasticsearch-opensearch#183 #1093
1 parent 6441ddf commit 20d24ce

File tree

1 file changed

+22
-9
lines changed

1 file changed

+22
-9
lines changed

openeogeotrellis/load_stac.py

Lines changed: 22 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -204,6 +204,8 @@ def operator_value(criterion: Dict[str, object]) -> (str, object):
204204
collection = None
205205
metadata = None
206206

207+
netcdf_with_time_dimension = False
208+
207209
backend_config = get_backend_config()
208210
poll_interval_seconds = backend_config.job_dependencies_poll_interval_seconds
209211
max_poll_delay_seconds = backend_config.job_dependencies_max_poll_delay_seconds
@@ -277,6 +279,7 @@ def operator_value(criterion: Dict[str, object]) -> (str, object):
277279
intersecting_items = [item] if intersects_spatiotemporally(item) else []
278280
elif isinstance(stac_object, pystac.Collection) and supports_item_search(stac_object):
279281
collection = stac_object
282+
netcdf_with_time_dimension = contains_netcdf_with_time_dimension(collection)
280283
collection_id = collection.id
281284
metadata = GeopysparkCubeMetadata(
282285
metadata=collection.to_dict(include_self_link=False, transform_hrefs=False)
@@ -319,7 +322,7 @@ def operator_value(criterion: Dict[str, object]) -> (str, object):
319322
limit=20,
320323
datetime=(
321324
None
322-
if temporal_extent is DEFAULT_TEMPORAL_EXTENT
325+
if temporal_extent is (DEFAULT_TEMPORAL_EXTENT or netcdf_with_time_dimension)
323326
else f"{from_date.isoformat().replace('+00:00', 'Z')}/"
324327
f"{to_date.isoformat().replace('+00:00', 'Z')}" # end is inclusive
325328
),
@@ -347,6 +350,7 @@ def operator_value(criterion: Dict[str, object]) -> (str, object):
347350

348351
if isinstance(catalog, pystac.Collection):
349352
collection = catalog
353+
netcdf_with_time_dimension = contains_netcdf_with_time_dimension(collection)
350354

351355
band_names = [b["name"] for b in (catalog.summaries.lists if isinstance(catalog, pystac.Collection)
352356
else catalog.extra_fields.get("summaries", {})).get("eo:bands", [])]
@@ -417,14 +421,6 @@ def intersects_temporally(interval) -> bool:
417421
band_cell_size: Dict[str, Tuple[float, float]] = {} # assumes a band has the same resolution across features/assets
418422
band_epsgs: Dict[str, Set[int]] = {}
419423

420-
netcdf_with_time_dimension = False
421-
if collection is not None:
422-
# we found some collection level metadata
423-
item_assets = collection.extra_fields.get("item_assets", {})
424-
dimensions = set([tuple(v.get("dimensions")) for i in item_assets.values() if "cube:variables" in i for v in
425-
i.get("cube:variables", {}).values()])
426-
# this is one way to determine if a time dimension is used, but it does depend on the use of item_assets and datacube extension.
427-
netcdf_with_time_dimension = len(dimensions) == 1 and "time" in dimensions.pop()
428424

429425
for itm in intersecting_items:
430426
items_found = True
@@ -702,6 +698,23 @@ def intersects_temporally(interval) -> bool:
702698
return GeopysparkDataCube(pyramid=gps.Pyramid(levels), metadata=metadata)
703699

704700

701+
def contains_netcdf_with_time_dimension(collection):
702+
"""
703+
Checks if the STAC collection contains netcdf files with multiple time stamps.
704+
This collection organization is used for storing small patches of EO data, and requires special loading because the
705+
default readers will not handle this case properly.
706+
707+
"""
708+
if collection is not None:
709+
# we found some collection level metadata
710+
item_assets = collection.extra_fields.get("item_assets", {})
711+
dimensions = set([tuple(v.get("dimensions")) for i in item_assets.values() if "cube:variables" in i for v in
712+
i.get("cube:variables", {}).values()])
713+
# this is one way to determine if a time dimension is used, but it does depend on the use of item_assets and datacube extension.
714+
return len(dimensions) == 1 and "time" in dimensions.pop()
715+
return False
716+
717+
705718
def get_best_url(asset: pystac.Asset):
706719
"""
707720
Relevant doc: https://github.com/stac-extensions/alternate-assets

0 commit comments

Comments
 (0)