Skip to content

Commit

Permalink
allow creating a vectorcube from uploaded files
Browse files Browse the repository at this point in the history
  • Loading branch information
jdries authored and soxofaan committed Nov 23, 2022
1 parent 9c39c44 commit b1b5474
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 0 deletions.
14 changes: 14 additions & 0 deletions openeo/rest/connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
from openeo.rest.rest_capabilities import RESTCapabilities
from openeo.rest.service import Service
from openeo.rest.udp import RESTUserDefinedProcess, Parameter
from openeo.rest.vectorcube import VectorCube
from openeo.util import ensure_list, dict_no_none, rfc3339, load_json_resource, LazyLoadCache, \
ContextTimer, str_truncate

Expand Down Expand Up @@ -899,6 +900,19 @@ def _api_version(self) -> ComparableVersion:
# TODO make this a public property (it's also useful outside the Connection class)
return self.capabilities().api_version_check

def vectorcube_from_paths(self, paths:List[str], format:str, options:dict={}) -> VectorCube:
"""
Loads one or more files referenced by url or path that is accessible by the backend.
:param paths: The files to read.
:param format: The file format to read from. It must be one of the values that the server reports as supported input file formats.
:param options: The file format parameters to be used to read the files. Must correspond to the parameters that the server reports as supported parameters for the chosen format.
:return: A :py:class:`VectorCube`.
"""
graph = PGNode("load_uploaded_files", arguments=dict(paths=paths,format=format,options=options))
return VectorCube(graph=graph, connection=self)

def datacube_from_process(self, process_id: str, namespace: str = None, **kwargs) -> DataCube:
"""
Load a data cube from a (custom) process.
Expand Down
10 changes: 10 additions & 0 deletions tests/rest/test_connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -2402,6 +2402,16 @@ def test_version_info(requests_mock, capabilities, expected):
con = Connection(API_URL)
assert con.version_info() == expected

def test_vectorcube_from_paths(requests_mock):
requests_mock.get("https://oeo.test/", json={"api_version": "1.1.0"})
con = Connection(API_URL)
vc = con.vectorcube_from_paths(["mydata.pq"],format="parquet")
assert {'loaduploadedfiles1': {'arguments': {'format': 'parquet',
'options': {},
'paths': ['mydata.pq']},
'process_id': 'load_uploaded_files',
'result': True}} == vc.flat_graph()


class TestExecute:
# Dummy process graphs
Expand Down

0 comments on commit b1b5474

Please sign in to comment.