Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

tests for apply_dimension are invalid #213

Closed
clausmichele opened this issue Dec 18, 2023 · 4 comments
Closed

tests for apply_dimension are invalid #213

clausmichele opened this issue Dec 18, 2023 · 4 comments

Comments

@clausmichele
Copy link
Member

From the apply_dimension definition:

process:
Process to be applied on all values along the given dimension. The specified process needs to accept an array and must return an array with at least one element. A process may consist of multiple sub-processes.

Currently, the internal tests are using processes like add, mean and order.
The add and mean processes can't be used since they do not return an array of values but a single number.

The order process should be ok, since it returns an array. However, I can't really use it in a normal process graph so probably the test is not testing it correctly.

from openeo.local import LocalConnection
local_conn = LocalConnection("./")

url = "https://stac.eurac.edu/collections/SENTINEL2_L2A_SAMPLE"

temporal_extent = ["2022-06-01T00:00:00Z", "2022-06-30T00:00:00Z"]

datacube = local_conn.load_stac(
    url=url,
    temporal_extent=temporal_extent,
)

from openeo.processes import order

cube = datacube.apply_dimension(
    process=lambda d: order(d),
    dimension="band",
)

cube.execute()

Returned error for the above example:
ValueError: order with nodata=None is not supported for arrays with more than one dimension, as this would result in sparse multi-dimensional arrays.

So I can try to set the nodata:

process=lambda d: order(d,nodata=True),

error:

ValueError: applied function returned data with an unexpected number of dimensions. Received 0 dimension(s) but expected 4 dimensions with names ('time', 'y', 'x', 'band'), from:

array(None, dtype=object)
@clausmichele
Copy link
Member Author

A common use case is a combination of apply_dimension + quantiles, which also fails.
@m-mohr FYI related to this #204

Sample tests for quantiles are here: https://github.com/Open-EO/openeo-test-suite/blob/main/src/openeo_test_suite/tests/workflows/test_apply_dimension.py

@m-mohr
Copy link
Member

m-mohr commented Dec 19, 2023

You can use mean and other reducers, you just need to convert the output to an array again using e.g. array_create. You can't use them standalone though, indeed.

Example: https://github.com/Open-EO/openeo-community-examples/blob/main/python/Sentinel1_Stats/Sentinel1_Stats.ipynb

I'm also working on example tests here: https://github.com/Open-EO/openeo-processes/blob/add-tests/tests/apply_dimension.json5

@ValentinaHutter
Copy link
Collaborator

added new tests for quantiles, interpolate, modify and filter: https://github.com/Open-EO/openeo-processes-dask/blob/main/tests/test_apply.py

@clausmichele
Copy link
Member Author

Thanks @ValentinaHutter, I will have a look and test them!

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants