Skip to content

Commit 8806613

Browse files
committed
fixup! Issue #391/#651 add docs, changelog, review tweaks
1 parent 55ac5ae commit 8806613

File tree

3 files changed

+68
-5
lines changed

3 files changed

+68
-5
lines changed

docs/datacube_construction.rst

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -229,7 +229,7 @@ in a single entity that can be used to create or run batch jobs. For example:
229229
Moreover, it is not necessary to explicitly create such a
230230
:py:class:`~openeo.rest.multiresult.MultiResult` object,
231231
as the :py:meth:`Connection.create_job() <openeo.rest.connection.Connection.create_job>` method
232-
directly support passing multiple data cube objects in a list,
232+
directly supports passing multiple data cube objects in a list,
233233
which will be automatically grouped as a multi-result:
234234

235235
.. code-block:: python
@@ -241,7 +241,8 @@ which will be automatically grouped as a multi-result:
241241
242242
.. important::
243243

244-
Only a single :py:class:`~openeo.rest.connection.Connection` can be in play when working with multiple results.
244+
Only a single :py:class:`~openeo.rest.connection.Connection` can be in play
245+
when grouping multiple results like this.
245246
As everything is to be merged in a single process graph
246247
to be sent to a single backend,
247248
it is not possible to mix cubes created from different connections.

openeo/rest/_testing.py

Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
import collections
44
import json
55
import re
6-
from typing import Callable, Iterable, Iterator, Optional, Sequence, Union
6+
from typing import Callable, Iterable, Iterator, Optional, Sequence, Tuple, Union
77

88
from openeo import Connection, DataCube
99
from openeo.rest.vectorcube import VectorCube
@@ -92,12 +92,36 @@ def at_url(cls, root_url: str, *, requests_mock, capabilities: Optional[dict] =
9292
connection = Connection(root_url)
9393
return cls(requests_mock=requests_mock, connection=connection)
9494

95-
def setup_collection(self, collection_id: str):
95+
def setup_collection(
96+
self,
97+
collection_id: str,
98+
*,
99+
temporal: Union[bool, Tuple[str, str]] = True,
100+
bands: Sequence[str] = ("B1", "B2", "B3"),
101+
):
96102
# TODO: also mock `/collections` overview
103+
# TODO: option to override cube_dimensions as a whole, or override dimension names
104+
cube_dimensions = {
105+
"x": {"type": "spatial"},
106+
"y": {"type": "spatial"},
107+
}
108+
109+
if temporal:
110+
cube_dimensions["t"] = {
111+
"type": "temporal",
112+
"extent": temporal if isinstance(temporal, tuple) else [None, None],
113+
}
114+
if bands:
115+
cube_dimensions["bands"] = {"type": "bands", "values": list(bands)}
116+
97117
self._requests_mock.get(
98118
self.connection.build_url(f"/collections/{collection_id}"),
99119
# TODO: add more metadata?
100-
json={"id": collection_id},
120+
json={
121+
"id": collection_id,
122+
# define temporal and band dim
123+
"cube:dimensions": {"t": {"type": "temporal"}, "bands": {"type": "bands"}},
124+
},
101125
)
102126
return self
103127

tests/rest/test_connection.py

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3802,3 +3802,41 @@ def test_create_job_with_mixed_connections(self, con120, dummy_backend, another_
38023802

38033803
with pytest.raises(OpenEoClientException, match="Mixing different connections"):
38043804
other_connection.create_job([save1, save2])
3805+
3806+
def test_create_job_intermediate_resultst(self, con120, dummy_backend):
3807+
cube = con120.load_collection("S2")
3808+
save1 = cube.save_result(format="GTiff")
3809+
reduced = cube.reduce_temporal("mean")
3810+
save2 = reduced.save_result(format="GTiff")
3811+
con120.create_job([save1, save2])
3812+
assert dummy_backend.get_batch_pg() == {
3813+
"loadcollection1": {
3814+
"process_id": "load_collection",
3815+
"arguments": {"id": "S2", "spatial_extent": None, "temporal_extent": None},
3816+
},
3817+
"saveresult1": {
3818+
"process_id": "save_result",
3819+
"arguments": {"data": {"from_node": "loadcollection1"}, "format": "GTiff", "options": {}},
3820+
},
3821+
"reducedimension1": {
3822+
"process_id": "reduce_dimension",
3823+
"arguments": {
3824+
"data": {"from_node": "loadcollection1"},
3825+
"dimension": "t",
3826+
"reducer": {
3827+
"process_graph": {
3828+
"mean1": {
3829+
"arguments": {"data": {"from_parameter": "data"}},
3830+
"process_id": "mean",
3831+
"result": True,
3832+
}
3833+
}
3834+
},
3835+
},
3836+
},
3837+
"saveresult2": {
3838+
"process_id": "save_result",
3839+
"arguments": {"data": {"from_node": "reducedimension1"}, "format": "GTiff", "options": {}},
3840+
"result": True,
3841+
},
3842+
}

0 commit comments

Comments
 (0)