Skip to content

dimension names not passed in UDFs #330

@clausmichele

Description

@clausmichele

In the current implementation, which is relying on the one included in the openeo package here: https://github.com/Open-EO/openeo-python-client/blob/master/openeo/udf/run_code.py

The current implementation doesn't pass the dimension names (it renames them to "dim_0", "dim_1", ...) nor the dimension labels (converts all of them to integer). It would be necessary to have access to dimension names and labels inside the UDF.

Sample code to reproduce the issue:

import openeo

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,
    bands=["B03","B04"]
)

# Build a UDF object from an inline string with Python source code.
udf = openeo.UDF(
"""
import xarray
import numpy as np

def apply_datacube(cube: xarray.DataArray, context: dict) -> xarray.DataArray:
    print(cube.dims)
    return cube
"""
)

# Apply the UDF to a cube.
datacube.apply_dimension(dimension="bands",process=udf).execute()

('dim_0', 'dim_1', 'dim_2', 'dim_3')

@jzvolensky @Yuvraj198920 this would be a nice thing to fix within EOEPCA+.

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions