From 436cf79201e600a57df0f4b069e5d999367d6f45 Mon Sep 17 00:00:00 2001 From: CalvinKuo Date: Fri, 3 Jul 2026 09:13:26 +0800 Subject: [PATCH 1/3] add datacube inspect helper --- openeo/rest/datacube.py | 19 ++++++++++ tests/rest/datacube/test_datacube100.py | 49 +++++++++++++++++++++++++ 2 files changed, 68 insertions(+) diff --git a/openeo/rest/datacube.py b/openeo/rest/datacube.py index 2e0ba56a1..f1f592bce 100644 --- a/openeo/rest/datacube.py +++ b/openeo/rest/datacube.py @@ -137,6 +137,25 @@ 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 + """ + 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..a6ccc8259 100644 --- a/tests/rest/datacube/test_datacube100.py +++ b/tests/rest/datacube/test_datacube100.py @@ -2896,6 +2896,55 @@ 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 res.flat_graph() == { + "loadcollection1": { + "process_id": "load_collection", + "arguments": { + "id": "S2", + "spatial_extent": None, + "temporal_extent": None, + }, + }, + "inspect1": { + "process_id": "inspect", + "arguments": { + "data": {"from_node": "loadcollection1"}, + "message": "debug cube", + "code": "Debug", + "level": "warning", + }, + "result": True, + }, + } + + +def test_inspect_without_log_fields(con100: Connection): + cube = con100.load_collection("S2") + res = cube.inspect() + + assert res.flat_graph() == { + "loadcollection1": { + "process_id": "load_collection", + "arguments": { + "id": "S2", + "spatial_extent": None, + "temporal_extent": None, + }, + }, + "inspect1": { + "process_id": "inspect", + "arguments": { + "data": {"from_node": "loadcollection1"}, + }, + "result": True, + }, + } + + @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"}]}) From 20bbc6f0df805e38fee3e46abf87467d4dd8db31 Mon Sep 17 00:00:00 2001 From: CalvinKuo Date: Fri, 3 Jul 2026 22:50:49 +0800 Subject: [PATCH 2/3] address inspect review feedback --- CHANGELOG.md | 1 + openeo/rest/datacube.py | 2 ++ tests/rest/datacube/test_datacube100.py | 22 ++-------------------- 3 files changed, 5 insertions(+), 20 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 25ad8d11f..8c3ceab91 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,6 +9,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Added +- Add `DataCube.inspect()` helper for the openEO `inspect` process. ([#795](https://github.com/Open-EO/openeo-python-client/issues/795)) - `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)) diff --git a/openeo/rest/datacube.py b/openeo/rest/datacube.py index f1f592bce..1df0b757a 100644 --- a/openeo/rest/datacube.py +++ b/openeo/rest/datacube.py @@ -146,6 +146,8 @@ def inspect(self, message=_UNSET, code=_UNSET, level=_UNSET) -> DataCube: 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: diff --git a/tests/rest/datacube/test_datacube100.py b/tests/rest/datacube/test_datacube100.py index a6ccc8259..839f41a58 100644 --- a/tests/rest/datacube/test_datacube100.py +++ b/tests/rest/datacube/test_datacube100.py @@ -2900,15 +2900,7 @@ def test_inspect(con100: Connection): cube = con100.load_collection("S2") res = cube.inspect(message="debug cube", code="Debug", level="warning") - assert res.flat_graph() == { - "loadcollection1": { - "process_id": "load_collection", - "arguments": { - "id": "S2", - "spatial_extent": None, - "temporal_extent": None, - }, - }, + assert get_download_graph(res, drop_save_result=True, drop_load_collection=True) == { "inspect1": { "process_id": "inspect", "arguments": { @@ -2917,7 +2909,6 @@ def test_inspect(con100: Connection): "code": "Debug", "level": "warning", }, - "result": True, }, } @@ -2926,21 +2917,12 @@ def test_inspect_without_log_fields(con100: Connection): cube = con100.load_collection("S2") res = cube.inspect() - assert res.flat_graph() == { - "loadcollection1": { - "process_id": "load_collection", - "arguments": { - "id": "S2", - "spatial_extent": None, - "temporal_extent": None, - }, - }, + assert get_download_graph(res, drop_save_result=True, drop_load_collection=True) == { "inspect1": { "process_id": "inspect", "arguments": { "data": {"from_node": "loadcollection1"}, }, - "result": True, }, } From 73621c001474207a04150fe40e4e467b706ccbf7 Mon Sep 17 00:00:00 2001 From: CalvinKuo Date: Fri, 3 Jul 2026 23:30:20 +0800 Subject: [PATCH 3/3] move inspect changelog entry --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 8c3ceab91..f6a338bce 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,10 +9,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Added -- Add `DataCube.inspect()` helper for the openEO `inspect` process. ([#795](https://github.com/Open-EO/openeo-python-client/issues/795)) - `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