diff --git a/CHANGELOG.md b/CHANGELOG.md index 25ad8d11f..f6a338bce 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/openeo/rest/datacube.py b/openeo/rest/datacube.py index 2e0ba56a1..1df0b757a 100644 --- a/openeo/rest/datacube.py +++ b/openeo/rest/datacube.py @@ -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 + """ + 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) diff --git a/tests/rest/datacube/test_datacube100.py b/tests/rest/datacube/test_datacube100.py index 40f7ef10f..839f41a58 100644 --- a/tests/rest/datacube/test_datacube100.py +++ b/tests/rest/datacube/test_datacube100.py @@ -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"}]})