Open-EO / openeo-processes-dask

Python implementations of many OpenEO processes, dask-friendly by default.
Apache License 2.0
19 stars 14 forks source link

tests for `apply_dimension` are invalid #213

Open clausmichele opened 10 months ago

clausmichele commented 10 months ago

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 commented 10 months ago

A common use case is a combination of apply_dimension + quantiles, which also fails. @m-mohr FYI related to this https://github.com/Open-EO/openeo-processes-dask/pull/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 commented 10 months ago

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