Open-EO / openeo-python-client

Python client API for OpenEO
https://open-eo.github.io/openeo-python-client/
Apache License 2.0
149 stars 38 forks source link

problems with UDF example (on backend) #168

Closed jonathom closed 3 years ago

jonathom commented 3 years ago

I was trying out the UDF example given in the documentation. The execution fails, a part of the error reads: AttributeError: 'DataArray' object has no attribute 'interpolare_na' at [...].

I can't tell where the problem lies here, any help would be very much appreciated. What went wrong?

Process graph: { "process_graph": { "apply1": { "arguments": { "data": { "from_node": "loadcollection2" }, "process": { "process_graph": { "neq1": { "arguments": { "x": { "from_parameter": "x" }, "y": 4 }, "process_id": "neq", "result": true } } } }, "process_id": "apply" }, "applydimension1": { "arguments": { "data": { "from_node": "mask1" }, "dimension": "t", "process": { "process_graph": { "runudf1": { "arguments": { "data": { "from_parameter": "data" }, "runtime": "Python", "udf": "from typing import Dict\nimport xarray\nfrom scipy.signal import savgol_filter\nfrom openeo_udf.api.datacube import DataCube\n\ndef apply_datacube(cube: DataCube, context: Dict) -> DataCube:\n \"\"\"\n Applies a savitzky-golay smoothing to a timeseries datacube.\n This UDF preserves dimensionality, and assumes a datacube with a temporal dimension 't' as input.\n \"\"\"\n array: xarray.DataArray = cube.get_array()\n filled = array.interpolare_na(dim=\"t\")\n smoothed_array = savgol_filter(filled.values, 5, 2, axis=0)\n return DataCube(xarray.DataArray(smoothed_array, dims=array.dims, coords=array.coords))", "version": "latest" }, "process_id": "run_udf", "result": true } } } }, "process_id": "apply_dimension" }, "loadcollection1": { "arguments": { "bands": [ "TOC-B02_10M", "TOC-B04_10M", "TOC-B08_10M" ], "id": "TERRASCOPE_S2_TOC_V2", "spatial_extent": { "crs": 4326, "east": 5.1533818244, "north": 51.18469636, "south": 51.181925592, "west": 5.151836872 }, "temporal_extent": [ "2016-01-01", "2016-03-10" ] }, "process_id": "load_collection" }, "loadcollection2": { "arguments": { "bands": [ "SCENECLASSIFICATION_20M" ], "id": "TERRASCOPE_S2_TOC_V2", "spatial_extent": { "crs": 4326, "east": 5.153381824493408, "north": 51.18469636040683, "south": 51.18192559252128, "west": 5.15183687210083 }, "temporal_extent": [ "2016-01-01", "2016-03-10" ] }, "process_id": "load_collection" }, "mask1": { "arguments": { "data": { "from_node": "reducedimension1" }, "mask": { "from_node": "resamplecubespatial1" } }, "process_id": "mask" }, "reducedimension1": { "arguments": { "data": { "from_node": "loadcollection1" }, "dimension": "bands", "reducer": { "process_graph": { "add1": { "arguments": { "x": { "from_node": "arrayelement1" }, "y": { "from_node": "multiply2" } }, "process_id": "add" }, "add2": { "arguments": { "x": { "from_node": "subtract2" }, "y": 1 }, "process_id": "add" }, "arrayelement1": { "arguments": { "data": { "from_parameter": "data" }, "index": 2 }, "process_id": "array_element" }, "arrayelement2": { "arguments": { "data": { "from_parameter": "data" }, "index": 1 }, "process_id": "array_element" }, "arrayelement3": { "arguments": { "data": { "from_parameter": "data" }, "index": 0 }, "process_id": "array_element" }, "divide1": { "arguments": { "x": { "from_node": "multiply1" }, "y": { "from_node": "add2" } }, "process_id": "divide", "result": true }, "multiply1": { "arguments": { "x": 2.5, "y": { "from_node": "subtract1" } }, "process_id": "multiply" }, "multiply2": { "arguments": { "x": 6, "y": { "from_node": "arrayelement2" } }, "process_id": "multiply" }, "multiply3": { "arguments": { "x": 7.5, "y": { "from_node": "arrayelement3" } }, "process_id": "multiply" }, "subtract1": { "arguments": { "x": { "from_node": "arrayelement1" }, "y": { "from_node": "arrayelement2" } }, "process_id": "subtract" }, "subtract2": { "arguments": { "x": { "from_node": "add1" }, "y": { "from_node": "multiply3" } }, "process_id": "subtract" } } } }, "process_id": "reduce_dimension" }, "resamplecubespatial1": { "arguments": { "data": { "from_node": "apply1" }, "method": "near", "target": { "from_node": "reducedimension1" } }, "process_id": "resample_cube_spatial" }, "saveresult1": { "arguments": { "data": { "from_node": "applydimension1" }, "format": "NetCDF", "options": {} }, "process_id": "save_result", "result": true } } }

soxofaan commented 3 years ago

I think you have a typo in your UDF code: should be interpolate_na instead of interpolare_na

jonathom commented 3 years ago

Yep, that's it. Thank you!