Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

spatial coordinates are lost with execute_local_udf #549

Closed
soxofaan opened this issue Mar 14, 2024 · 3 comments
Closed

spatial coordinates are lost with execute_local_udf #549

soxofaan opened this issue Mar 14, 2024 · 3 comments
Assignees

Comments

@soxofaan
Copy link
Member

from https://discuss.eodc.eu/t/how-to-export-udfdata/705

execute_local_udf does not allow access to georeferenced x/y coordinates

@soxofaan
Copy link
Member Author

example:

import openeo
from openeo.udf import execute_local_udf

udf = openeo.UDF("""
import xarray
def apply_datacube(cube: xarray.DataArray, context: dict) -> xarray.DataArray:
    print(f"{cube.coords['t']=}")
    print(f"{cube.coords['x']=}")
    print(f"{cube.coords['y']=}")
    return cube
""")

res = execute_local_udf(udf=udf, datacube="tmp.nc")

results in

cube.coords['t']=<xarray.DataArray 't' (t: 3)>
array(['2018-09-03T00:00:00.000000000', '2018-09-05T00:00:00.000000000',
       '2018-09-08T00:00:00.000000000'], dtype='datetime64[ns]')
Coordinates:
  * t        (t) datetime64[ns] 2018-09-03 2018-09-05 2018-09-08
Attributes:
    standard_name:  t
    long_name:      t
    axis:           T
cube.coords['x']=<xarray.DataArray 'x' (x: 219)>
array([  0,   1,   2, ..., 216, 217, 218])
Dimensions without coordinates: x
cube.coords['y']=<xarray.DataArray 'y' (y: 339)>
array([  0,   1,   2, ..., 336, 337, 338])
Dimensions without coordinates: y

Note how the x and y coordinates are just non-georeferenced ranges

@soxofaan
Copy link
Member Author

I found that the original coordinates are explicitly dropped here:

d = XarrayDataCube(d_array.transpose(*dims).astype(numpy.float64).drop(labels="x").drop(labels="y"))

Dropping the original coordinates was in the original implementation of execute_local_udf introduced in 0962e00 but I have no idea why this was done

@soxofaan
Copy link
Member Author

merged in eddfa77

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

No branches or pull requests

1 participant