-
Notifications
You must be signed in to change notification settings - Fork 3
UDF Runtimes in the R back end
Currently, the R-back-end supports two UDF runtimes with R:
- A "sourced" call on locally exported raster files (UDF Runtime: R-3.5.1-cmd)
- A JSON call to the r-udf-service (UDF Runtime: R-3.5.1-udf-service)
Both variants are described in more detail on the repository for r-udf. But to quickly summarize: the r udf implementation uses stars
objects as a mean for user interaction. The idea is that the data is exported from the back-end either as files (option 1) or as JSON objects for a webservice call (option 2) and read with additional metadata in the UDF implementation. There operations on the stars
object are performed in order to reduce dimensions or aggregate values on those dimensions. The third step in this transaction between back-end and r-udf implementation is the reimport of the UDF results. This is also done either file-based or as JSON response from the service.
In case 1) we need to load the library, define the function that will be applied on the data during st_apply
and trigger the execution of the UDF.
library(openEO.R.UDF)
custom_function = function(obj)
{
median(obj)
}
run_UDF(function_name = custom_function, drop_dim = 4)
In case 2) the script amount has been reduced to only providing the function that is applied in st_apply
or similar functions as one unnamed function.
function(obj)
{
median(obj)
}
The code has to be stored as a R script and uploaded to the r-back-end. In 1) it is also required to state which dimension is reduced (see the package documentation to find out the correct value). In the service version this will be set automatically by the process that was used in the process graph.