diff --git a/CHANGELOG.md b/CHANGELOG.md index dadd889db..77af2d694 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -17,6 +17,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Fixed +- When using `DataCube.load_collection()` without a connection, it is not necessary anymore to also explicitly set `fetch_metadata=False` ([#638](https://github.com/Open-EO/openeo-python-client/issues/638)) + ## [0.32.0] - 2024-09-27 diff --git a/openeo/rest/datacube.py b/openeo/rest/datacube.py index 7be11cc3c..fe80c79c0 100644 --- a/openeo/rest/datacube.py +++ b/openeo/rest/datacube.py @@ -152,7 +152,8 @@ def load_collection( Create a new Raster Data cube. :param collection_id: image collection identifier - :param connection: The connection to use to connect with the backend. + :param connection: The backend connection to use. + Can be ``None`` to work without connection and collection metadata. :param spatial_extent: limit data to specified bounding box or polygons :param temporal_extent: limit data to specified temporal interval. Typically, just a two-item list or tuple containing start and end date. @@ -191,7 +192,7 @@ def load_collection( if isinstance(collection_id, Parameter): fetch_metadata = False metadata: Optional[CollectionMetadata] = ( - connection.collection_metadata(collection_id) if fetch_metadata else None + connection.collection_metadata(collection_id) if connection and fetch_metadata else None ) if bands: if isinstance(bands, str): diff --git a/tests/rest/datacube/test_datacube.py b/tests/rest/datacube/test_datacube.py index 1b746beb1..32f9899f3 100644 --- a/tests/rest/datacube/test_datacube.py +++ b/tests/rest/datacube/test_datacube.py @@ -17,6 +17,7 @@ import shapely import shapely.geometry +from openeo import collection_property from openeo.api.process import Parameter from openeo.rest import BandMathException, OpenEoClientException from openeo.rest._testing import build_capabilities @@ -81,6 +82,60 @@ def _get_leaf_node(cube, force_flat=True) -> dict: raise ValueError(repr(cube)) +class TestDataCube: + def test_load_collection_connectionless_basic(self): + cube = DataCube.load_collection("T3") + assert cube.flat_graph() == { + "loadcollection1": { + "arguments": {"id": "T3", "spatial_extent": None, "temporal_extent": None}, + "process_id": "load_collection", + "result": True, + } + } + + def test_load_collection_connectionless_full(self): + cube = DataCube.load_collection( + "T3", + spatial_extent={"west": 1, "east": 2, "north": 3, "south": 4}, + temporal_extent=["2019-01-01", "2019-02-01"], + bands=["RED", "GREEN"], + properties=[collection_property("orbit") == "low"], + ) + assert cube.flat_graph() == { + "loadcollection1": { + "process_id": "load_collection", + "arguments": { + "id": "T3", + "spatial_extent": {"east": 2, "north": 3, "south": 4, "west": 1}, + "temporal_extent": ["2019-01-01", "2019-02-01"], + "bands": ["RED", "GREEN"], + "properties": { + "orbit": { + "process_graph": { + "eq1": { + "process_id": "eq", + "arguments": {"x": {"from_parameter": "value"}, "y": "low"}, + "result": True, + } + } + } + }, + }, + "result": True, + } + } + + def test_load_collection_connectionless_temporal_extent_shortcut(self): + cube = DataCube.load_collection("T3", temporal_extent="2024-09") + assert cube.flat_graph() == { + "loadcollection1": { + "arguments": {"id": "T3", "spatial_extent": None, "temporal_extent": ["2024-09-01", "2024-10-01"]}, + "process_id": "load_collection", + "result": True, + } + } + + def test_filter_temporal_basic_positional_args(s2cube): im = s2cube.filter_temporal("2016-01-01", "2016-03-10") graph = _get_leaf_node(im)