Skip to content

Commit 05b527f

Browse files
committed
Issue #737 assume presence of spatial dimensions in load_stac result
This is not perfect, but at least a quick fix for common use cases
1 parent d0a548e commit 05b527f

File tree

2 files changed

+45
-1
lines changed

2 files changed

+45
-1
lines changed

openeo/metadata.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -655,9 +655,16 @@ def is_band_asset(asset: pystac.Asset) -> bool:
655655
else:
656656
raise ValueError(stac_object)
657657

658+
# At least assume there are spatial dimensions
659+
# TODO: are there conditions in which we even should not assume the presence of spatial dimensions?
660+
dimensions = [
661+
SpatialDimension(name="x", extent=[None, None]),
662+
SpatialDimension(name="y", extent=[None, None]),
663+
]
664+
658665
# TODO: conditionally include band dimension when there was actual indication of band metadata?
659666
band_dimension = BandDimension(name="bands", bands=bands)
660-
dimensions = [band_dimension]
667+
dimensions.append(band_dimension)
661668

662669
# TODO: is it possible to derive the actual name of temporal dimension that the backend will use?
663670
temporal_dimension = _StacMetadataParser().get_temporal_dimension(stac_object)

tests/rest/datacube/test_datacube.py

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
"""
77

88
import contextlib
9+
import json
910
import pathlib
1011
import re
1112
from datetime import date, datetime
@@ -25,6 +26,7 @@
2526
from openeo.rest._testing import build_capabilities
2627
from openeo.rest.connection import Connection
2728
from openeo.rest.datacube import DataCube
29+
from openeo.testing.stac import StacDummyBuilder
2830
from openeo.util import dict_no_none
2931

3032
from .. import get_download_graph
@@ -312,6 +314,41 @@ def test_load_stac_spatial_extent_parameter(self, dummy_backend):
312314
"spatial_extent": {"from_parameter": "zpatial_extent"},
313315
}
314316

317+
@pytest.mark.parametrize(
318+
"stac_metadata",
319+
[
320+
StacDummyBuilder.item(),
321+
StacDummyBuilder.collection(),
322+
StacDummyBuilder.catalog(),
323+
],
324+
)
325+
def test_load_stac_resample_spatial(self, dummy_backend, tmp_path, stac_metadata):
326+
"""https://github.com/Open-EO/openeo-python-client/issues/737"""
327+
stac_path = tmp_path / "stac.json"
328+
# TODO #738 real request mocking of STAC resources compatible with pystac?
329+
stac_path.write_text(json.dumps(stac_metadata))
330+
cube = dummy_backend.connection.load_stac(str(stac_path))
331+
cube = cube.resample_spatial(resolution=10, projection=4326)
332+
cube.execute()
333+
assert dummy_backend.get_sync_pg() == {
334+
"loadstac1": {
335+
"process_id": "load_stac",
336+
"arguments": {"url": dirty_equals.IsStr(regex=".*/stac.json")},
337+
},
338+
"resamplespatial1": {
339+
"process_id": "resample_spatial",
340+
"arguments": {
341+
"data": {"from_node": "loadstac1"},
342+
"projection": 4326,
343+
"resolution": 10,
344+
"method": "near",
345+
"align": "upper-left",
346+
},
347+
"result": True,
348+
},
349+
}
350+
351+
315352
def test_filter_temporal_basic_positional_args(s2cube):
316353
im = s2cube.filter_temporal("2016-01-01", "2016-03-10")
317354
graph = _get_leaf_node(im)

0 commit comments

Comments
 (0)