-
Notifications
You must be signed in to change notification settings - Fork 14
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
first implementation of local udf #308
base: main
Are you sure you want to change the base?
Conversation
@VincentVerelst there seem to be conflicts. Could you fix them before proceeding? |
@clausmichele , merge conflicts have been solved |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Some things to fix:
- There is a missing
__init__.py
file. It has to be inside theopeneo_processes_dask/process_implementations/udf
folder, with the following content:
from .udf import *
- The attributes are not maintained and with them the projection/CRS is also gone. It's necessary to keep it. You can test it with this MWE:
import openeo
from openeo.local import LocalConnection
local_conn = LocalConnection("./")
url = "https://earth-search.aws.element84.com/v1/collections/sentinel-2-l2a"
spatial_extent = {"east": 11.40, "north": 46.52, "south": 46.46, "west": 11.25}
temporal_extent = ["2022-06-01", "2022-06-10"]
bands = ["red", "nir"]
properties = {"eo:cloud_cover": dict(lt=80)}
s2_datacube = local_conn.load_stac(
url=url,
spatial_extent=spatial_extent,
temporal_extent=temporal_extent,
bands=bands,
properties=properties,
)
b04 = s2_datacube.band("red")
b08 = s2_datacube.band("nir")
ndvi = (b08 - b04) / (b08 + b04)
ndvi_median = ndvi.reduce_dimension(dimension="time", reducer="median")
result_ndvi_xr = ndvi_median.execute()
# Build a UDF object from an inline string with Python source code.
udf = openeo.UDF("""
from openeo.udf import XarrayDataCube
def apply_datacube(cube: XarrayDataCube, context: dict) -> XarrayDataCube:
array = cube.get_array()
print(array.shape)
array.values = 0.0001 * array.values
return cube
""")
# Apply the UDF to a cube.
rescaled_cube = ndvi_median.apply(process=udf)
rescaled_cube_xr = rescaled_cube.execute()
print(result_ndvi_xr.rio.crs)
print(rescaled_cube_xr.rio.crs)
>> EPSG:32632
>> None
This seems to be a broader problem in the |
@ValentinaHutter do you know if the attributes were not passed due to some technical reason? Maybe some edge case that would not work if we keep the attributes? |
It should be fine to set |
@clausmichele , two unit tests are failing because Let me know what you prefer. |
I'm not the author of that function and we are not using it at the moment. EODC developed it and probably @ValentinaHutter knows if the change could impact something on their side. |
thanks for adding the change to 0.4.3! from EODC's side it's fine to switch to this version. |
@ValentinaHutter , @clausmichele , @jdries , how do we proceed further? |
Looks like tests are failing because of a change in either the test data or a dependency in load_stac. I now created a PR to independently test the ndvi process #316 but for |
I will investigate! Something changed but I don't understand where. In fact, even the example in the docs now is failing: https://open-eo.github.io/openeo-python-client/cookbook/localprocessing.html |
So, the issue occurs with the latest version of pystac. With |
Did you mean pystac or pystac-client? |
|
Thanks for the clarification, I now merged the dependency into main, so you can pull from there 👍 |
No description provided.