Skip to content

Commit f932f5b

Browse files
committed
Issue #666 load_stac: fallback temporal dimension when no cube:dimensions
1 parent 37ba260 commit f932f5b

File tree

3 files changed

+37
-2
lines changed

3 files changed

+37
-2
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1717

1818
### Fixed
1919

20+
- `load_stac`: use fallback temporal dimension when no "cube:dimensions" in STAC Collection ([#666](https://github.com/Open-EO/openeo-python-client/issues/666))
2021

2122
## [0.35.0] - 2024-11-19
2223

openeo/metadata.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
import pystac.extensions.item_assets
1212

1313
from openeo.internal.jupyter import render_component
14-
from openeo.util import deep_get
14+
from openeo.util import Rfc3339, deep_get
1515

1616
_log = logging.getLogger(__name__)
1717

@@ -691,6 +691,11 @@ def get_temporal_dimension(self, stac_obj: pystac.STACObject) -> Union[TemporalD
691691
if len(temporal_dims) == 1:
692692
name, extent = temporal_dims[0]
693693
return TemporalDimension(name=name, extent=extent)
694+
elif isinstance(stac_obj, pystac.Collection) and stac_obj.extent.temporal:
695+
# No explicit "cube:dimensions": fallback from "extent"
696+
# and openEO API recommendation to use "t" as dimension name
697+
extent = [Rfc3339(propagate_none=True).normalize(d) for d in stac_obj.extent.temporal.intervals[0]]
698+
return TemporalDimension(name="t", extent=extent)
694699
else:
695700
if isinstance(stac_obj, pystac.Item):
696701
cube_dimensions = stac_obj.properties.get("cube:dimensions", {})

tests/rest/test_connection.py

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
import openeo
1919
from openeo.capabilities import ApiVersionException
2020
from openeo.internal.graph_building import FlatGraphableMixin, PGNode
21+
from openeo.metadata import TemporalDimension
2122
from openeo.rest import (
2223
CapabilitiesException,
2324
OpenEoApiError,
@@ -40,7 +41,7 @@
4041
)
4142
from openeo.rest.vectorcube import VectorCube
4243
from openeo.testing.stac import StacDummyBuilder
43-
from openeo.util import ContextTimer, dict_no_none
44+
from openeo.util import ContextTimer, deep_get, dict_no_none
4445

4546
from .auth.test_cli import auth_config, refresh_token_store
4647

@@ -2622,6 +2623,34 @@ def test_load_stac_reduce_temporal(self, con120, tmp_path, temporal_dim):
26222623
},
26232624
}
26242625

2626+
@pytest.mark.parametrize(
2627+
["collection_extent", "dim_extent"],
2628+
[
2629+
(
2630+
{"spatial": {"bbox": [[3, 4, 5, 6]]}, "temporal": {"interval": [["2024-01-01", "2024-05-05"]]}},
2631+
["2024-01-01T00:00:00Z", "2024-05-05T00:00:00Z"],
2632+
),
2633+
(
2634+
{"spatial": {"bbox": [[3, 4, 5, 6]]}, "temporal": {"interval": [[None, "2024-05-05"]]}},
2635+
[None, "2024-05-05T00:00:00Z"],
2636+
),
2637+
],
2638+
)
2639+
def test_load_stac_no_cube_extension_temporal_dimension(self, con120, tmp_path, collection_extent, dim_extent):
2640+
"""
2641+
Metadata detection when STAC metadata does not use "cube" extension
2642+
https://github.com/Open-EO/openeo-python-client/issues/666
2643+
"""
2644+
stac_path = tmp_path / "stac.json"
2645+
stac_data = StacDummyBuilder.collection(extent=collection_extent)
2646+
# No cube:dimensions, but at least "temporal" extent is set as indicator for having a temporal dimension
2647+
assert "cube:dimensions" not in stac_data
2648+
assert deep_get(stac_data, "extent", "temporal")
2649+
stac_path.write_text(json.dumps(stac_data))
2650+
2651+
cube = con120.load_stac(str(stac_path))
2652+
assert cube.metadata.temporal_dimension == TemporalDimension(name="t", extent=dim_extent)
2653+
26252654

26262655
@pytest.mark.parametrize(
26272656
"data",

0 commit comments

Comments
 (0)