Skip to content
This repository has been archived by the owner on Oct 1, 2020. It is now read-only.

UDF Runtimes in the R back end

Florian Lahn edited this page Feb 6, 2019 · 1 revision

Overview over offered UDF runtimes (v0.3.1-3)

Currently, the R-back-end supports two UDF runtimes with R:

  1. A "sourced" call on locally exported raster files (UDF Runtime: R-3.5.1-cmd)
  2. 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.

UDF Runtime: R-3.5.1-cmd

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)

UDF Runtime: R-3.5.1-udf-service

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)
}

Note

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.