Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- `DataCube.resample_spatial()` now supports parameterized `resolution` and `projection` arguments. ([#897](https://github.com/Open-EO/openeo-python-client/issues/897))
- Sanitize asset download filenames (e.g. strip slashes, (semi)colon, hash, ...), instead of blindly using the asset key as filename. ([#820](https://github.com/Open-EO/openeo-python-client/issues/820))
- Support parameters in `DataCube` apply- and band-math operations ([#903](https://github.com/Open-EO/openeo-python-client/issues/903))
- Add `DataCube.inspect()` helper for the openEO `inspect` process. ([#795](https://github.com/Open-EO/openeo-python-client/issues/795))

### Changed

Expand Down
21 changes: 21 additions & 0 deletions openeo/rest/datacube.py
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,27 @@ def process(

graph_add_node = legacy_alias(process, "graph_add_node", since="0.1.1")

def inspect(self, message=_UNSET, code=_UNSET, level=_UNSET) -> DataCube:
"""
Add information to the logs for this data cube.

:param message: A message to send in addition to the data.
:param code: A label to help identify one or more log entries originating from this process in the list
of all log entries. It can help to group or filter log entries and is usually not unique.
:param level: The severity level of this message, defaults to `info`.
:return: new DataCube instance

.. versionadded:: 0.51.0
"""
Comment thread
soxofaan marked this conversation as resolved.
arguments = {"data": self}
if message is not _UNSET:
arguments["message"] = message
if code is not _UNSET:
arguments["code"] = code
if level is not _UNSET:
arguments["level"] = level
return self.process(process_id="inspect", arguments=arguments)

def process_with_node(self, pg: PGNode, metadata: Optional[CollectionMetadata] = None) -> DataCube:
"""
Generic helper to create a new DataCube by applying a process (given as process graph node)
Expand Down
31 changes: 31 additions & 0 deletions tests/rest/datacube/test_datacube100.py
Original file line number Diff line number Diff line change
Expand Up @@ -2896,6 +2896,37 @@ def test_custom_process_arguments_namespacd(con100: Connection, test_data):
assert res.flat_graph() == expected


def test_inspect(con100: Connection):
cube = con100.load_collection("S2")
res = cube.inspect(message="debug cube", code="Debug", level="warning")

assert get_download_graph(res, drop_save_result=True, drop_load_collection=True) == {
"inspect1": {
"process_id": "inspect",
"arguments": {
"data": {"from_node": "loadcollection1"},
"message": "debug cube",
"code": "Debug",
"level": "warning",
},
},
}


def test_inspect_without_log_fields(con100: Connection):
cube = con100.load_collection("S2")
res = cube.inspect()

assert get_download_graph(res, drop_save_result=True, drop_load_collection=True) == {
"inspect1": {
"process_id": "inspect",
"arguments": {
"data": {"from_node": "loadcollection1"},
},
},
}


@pytest.mark.parametrize("api_capabilities", [{"udp": True}])
def test_save_user_defined_process(con100, requests_mock, test_data):
requests_mock.get(API_URL + "/processes", json={"processes": [{"id": "add"}]})
Expand Down