From 6c20f3ad4e828b5a70cb6f5580fbb391d4c82ed6 Mon Sep 17 00:00:00 2001 From: ValentinaHutter Date: Wed, 20 Sep 2023 14:54:01 +0200 Subject: [PATCH 1/5] update openeo-processes --- openeo_processes_dask/specs/openeo-processes | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/openeo_processes_dask/specs/openeo-processes b/openeo_processes_dask/specs/openeo-processes index 730c13c5..6885090f 160000 --- a/openeo_processes_dask/specs/openeo-processes +++ b/openeo_processes_dask/specs/openeo-processes @@ -1 +1 @@ -Subproject commit 730c13c50fa9b0e3bd9525f950dc82bbe2799329 +Subproject commit 6885090f736092353a0558b14c1aedee03ce87c6 From 7c17706ae6fbb1f348195371f69561529accd96b Mon Sep 17 00:00:00 2001 From: ValentinaHutter Date: Wed, 20 Sep 2023 14:55:34 +0200 Subject: [PATCH 2/5] bump 2023.9.1 --- pyproject.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyproject.toml b/pyproject.toml index 8b4aecc4..44ff0e4a 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [tool.poetry] name = "openeo-processes-dask" -version = "2023.9.0" +version = "2023.9.1" description = "Python implementations of many OpenEO processes, dask-friendly by default." authors = ["Lukas Weidenholzer ", "Sean Hoyal ", "Valentina Hutter "] maintainers = ["EODC Staff "] From 4178cb34e0141eec62528c1d167a8cbf9952dac4 Mon Sep 17 00:00:00 2001 From: ValentinaHutter Date: Wed, 20 Sep 2023 14:56:25 +0200 Subject: [PATCH 3/5] bump 2023.9.0 --- pyproject.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyproject.toml b/pyproject.toml index 44ff0e4a..8b4aecc4 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [tool.poetry] name = "openeo-processes-dask" -version = "2023.9.1" +version = "2023.9.0" description = "Python implementations of many OpenEO processes, dask-friendly by default." authors = ["Lukas Weidenholzer ", "Sean Hoyal ", "Valentina Hutter "] maintainers = ["EODC Staff "] From 8fa74780fbcb4a54fe9dd687660eea6559edff3e Mon Sep 17 00:00:00 2001 From: ValentinaHutter Date: Fri, 13 Sep 2024 13:02:26 +0200 Subject: [PATCH 4/5] add array_apply process --- .../process_implementations/arrays.py | 14 ++++++++++++++ tests/test_arrays.py | 12 ++++++++++++ 2 files changed, 26 insertions(+) diff --git a/openeo_processes_dask/process_implementations/arrays.py b/openeo_processes_dask/process_implementations/arrays.py index a02de6f8..1d16ac44 100644 --- a/openeo_processes_dask/process_implementations/arrays.py +++ b/openeo_processes_dask/process_implementations/arrays.py @@ -32,6 +32,7 @@ "array_contains", "array_find", "array_labels", + "array_apply", "first", "last", "order", @@ -213,6 +214,19 @@ def array_labels(data: ArrayLike) -> ArrayLike: return np.arange(len(data)) +def array_apply(data: ArrayLike, process: Callable, context: Optional[Any] = None) -> ArrayLike: + if not context: + context = {} + positional_parameters = {"x": 0} + named_parameters = {"x": data, "context": context} + if callable(process): + process_to_apply = np.vectorize(process) + return process_to_apply(data, + positional_parameters = positional_parameters, + named_parameters = named_parameters, + ) + + def first( data: ArrayLike, ignore_nodata: Optional[bool] = True, diff --git a/tests/test_arrays.py b/tests/test_arrays.py index 1d3e0f4f..279bb4e3 100644 --- a/tests/test_arrays.py +++ b/tests/test_arrays.py @@ -10,6 +10,7 @@ from openeo_processes_dask.process_implementations.arrays import * from openeo_processes_dask.process_implementations.cubes.reduce import reduce_dimension +from openeo_processes_dask.process_implementations.math import add from openeo_processes_dask.process_implementations.exceptions import ( ArrayElementNotAvailable, TooManyDimensions, @@ -251,6 +252,17 @@ def test_array_labels(): array_labels(np.array([[1, 0, 3, 2], [5, 0, 6, 4]])) +def test_array_apply(process_registry): + _process = partial( + process_registry["add"].implementation, + y=1, + x=ParameterReference(from_parameter="x"), + ) + + output_cube = array_apply(data=np.array([1,2,3,4,5,6]), process=_process) + assert (output_cube == [2,3,4,5,6,7]).all() + + def test_first(): assert first(np.array([1, 0, 3, 2])) == 1 assert pd.isnull(first(np.array([np.nan, 2, 3]), ignore_nodata=False)) From aae0705b4eff36aea7233ed859d346435016abb0 Mon Sep 17 00:00:00 2001 From: ValentinaHutter Date: Fri, 13 Sep 2024 13:06:31 +0200 Subject: [PATCH 5/5] run pre-commit hook --- .../process_implementations/arrays.py | 11 +++++++---- tests/test_arrays.py | 6 +++--- 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/openeo_processes_dask/process_implementations/arrays.py b/openeo_processes_dask/process_implementations/arrays.py index 1d16ac44..c66b5546 100644 --- a/openeo_processes_dask/process_implementations/arrays.py +++ b/openeo_processes_dask/process_implementations/arrays.py @@ -214,16 +214,19 @@ def array_labels(data: ArrayLike) -> ArrayLike: return np.arange(len(data)) -def array_apply(data: ArrayLike, process: Callable, context: Optional[Any] = None) -> ArrayLike: +def array_apply( + data: ArrayLike, process: Callable, context: Optional[Any] = None +) -> ArrayLike: if not context: context = {} positional_parameters = {"x": 0} named_parameters = {"x": data, "context": context} if callable(process): process_to_apply = np.vectorize(process) - return process_to_apply(data, - positional_parameters = positional_parameters, - named_parameters = named_parameters, + return process_to_apply( + data, + positional_parameters=positional_parameters, + named_parameters=named_parameters, ) diff --git a/tests/test_arrays.py b/tests/test_arrays.py index 279bb4e3..0152ac09 100644 --- a/tests/test_arrays.py +++ b/tests/test_arrays.py @@ -10,11 +10,11 @@ from openeo_processes_dask.process_implementations.arrays import * from openeo_processes_dask.process_implementations.cubes.reduce import reduce_dimension -from openeo_processes_dask.process_implementations.math import add from openeo_processes_dask.process_implementations.exceptions import ( ArrayElementNotAvailable, TooManyDimensions, ) +from openeo_processes_dask.process_implementations.math import add from tests.general_checks import general_output_checks from tests.mockdata import create_fake_rastercube @@ -259,8 +259,8 @@ def test_array_apply(process_registry): x=ParameterReference(from_parameter="x"), ) - output_cube = array_apply(data=np.array([1,2,3,4,5,6]), process=_process) - assert (output_cube == [2,3,4,5,6,7]).all() + output_cube = array_apply(data=np.array([1, 2, 3, 4, 5, 6]), process=_process) + assert (output_cube == [2, 3, 4, 5, 6, 7]).all() def test_first():