Skip to content

Commit

Permalink
Add support for spatial_extent, temporal_extent and bands to `C…
Browse files Browse the repository at this point in the history
…onnection.load_result()`
  • Loading branch information
soxofaan committed Jan 6, 2022
1 parent 1ea3b5e commit f480815
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 2 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

### Added
- Add experimental support for `chunk_polygon` process ([Open-EO/openeo-processes#287](https://github.com/Open-EO/openeo-processes/issues/287))
- Add support for `spatial_extent`, `temporal_extent` and `bands` to `Connection.load_result()`

### Changed

Expand Down
22 changes: 20 additions & 2 deletions openeo/rest/connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -872,19 +872,37 @@ def load_collection(

imagecollection = legacy_alias(load_collection, name="imagecollection")

def load_result(self, id: str) -> DataCube:
def load_result(
self,
id: str,
spatial_extent: Optional[Dict[str, float]] = None,
temporal_extent: Optional[List[Union[str, datetime.datetime, datetime.date]]] = None,
bands: Optional[List[str]] = None,
) -> DataCube:
"""
Loads batch job results by job id from the server-side user workspace.
The job must have been stored by the authenticated user on the back-end currently connected to.
:param id: The id of a batch job with results.
:param spatial_extent: limit data to specified bounding box or polygons
:param temporal_extent: limit data to specified temporal interval
:param bands: only add the specified bands
:return: a :py:class:`DataCube`
"""
# TODO: add check that back-end supports `load_result` process?
if self._api_version.below("1.0.0"):
raise OpenEoClientException(
"This method requires support for at least version 1.0.0 in the openEO backend.")
return self.datacube_from_process(process_id="load_result", id=id)
return self.datacube_from_process(
process_id="load_result",
id=id,
**dict_no_none(
spatial_extent=spatial_extent,
temporal_extent=temporal_extent and DataCube._get_temporal_extent(temporal_extent),
bands=bands
)
)

def create_service(self, graph: dict, type: str, **kwargs) -> Service:
# TODO: type hint for graph: is it a nested or a flat one?
Expand Down
23 changes: 23 additions & 0 deletions tests/rest/test_connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -1348,6 +1348,29 @@ def test_load_result(requests_mock):
}


def test_load_result_filters(requests_mock):
requests_mock.get(API_URL, json={"api_version": "1.0.0"})
con = Connection(API_URL)
cube = con.load_result(
"j0bi6",
spatial_extent={"west": 3, "south": 4, "east": 5, "north": 6},
temporal_extent=["2021-10-01", "2021-12-12"],
bands=["red"],
)
assert cube.flat_graph() == {
"loadresult1": {
"process_id": "load_result",
"arguments": {
"id": "j0bi6",
"spatial_extent": {"west": 3, "south": 4, "east": 5, "north": 6},
"temporal_extent": ["2021-10-01", "2021-12-12"],
"bands": ["red"],
},
"result": True,
}
}


def test_list_file_formats(requests_mock):
requests_mock.get(API_URL, json={"api_version": "1.0.0"})
conn = Connection(API_URL)
Expand Down

0 comments on commit f480815

Please sign in to comment.