send_udf: Test a UDF operation

Description Usage Arguments Details Value Note Examples

View source: R/udf.R

Description

This function is a testing function for UDF requests against a UDF service. If an openEO UDF service is available (external via an URL or a local setup) and if you can obtain sample data that fit the context of your UDF use case, you can use this function to send the code and the data to the UDF service. Depending on the state of the service (error or success) you can debug your code.

Usage

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
send_udf(
  data,
  code,
  host = "http://localhost",
  port = NULL,
  language = "R",
  debug = FALSE,
  user_context = NA,
  server_context = NA,
  download_info = FALSE,
  legacy = FALSE,
  ...
)

Arguments

data

file path or a list object with the UDF-API data object

code

a call object or a file path of the user defined code

host

URL to the UDF service

port

optional port of the UDF service host

language

programming language (R or Python) of the source code

debug

(optional) logical. Switch on / off debugging information for time taken

user_context

list. Context parameter that are shipped from the user into the udf_service

server_context

list. Context usually sent from the back-end to trigger certain settings.

download_info

(optional) logical. Whether or not to print the time taken separately for the download

legacy

logical. Whether or not the legacy endpoint shall be used (default: FALSE)

...

parameters passed on to httr::content or to be more precise to jsonlite::fromJSON

Details

If you use a local R UDF service you might want to debug using the 'browser()' function.

Value

the textual JSON representation of the result

Note

The debug options are only available for the R-UDF service. The R UDF-API version has to be of version 0.1.0 (not the old alpha version). You might want to check https://github.com/Open-EO/openeo-r-udf#running-the-api-locally for setting up a local service for debugging.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
## Not run: 
port = 5555
host = "http://localhost" 
script = quote({
  all_dim = names(dim(data))
  ndvi_result = st_apply(data, FUN = function(X,...) {
    (X[8]-X[4])/(X[8]+X[4])
  }, MARGIN = all_dim[-which(all_dim=="band")])

  all_dim = names(dim(ndvi_result))
  min_ndvi = st_apply(ndvi_result,FUN = min, MARGIN = all_dim[-which(all_dim=="t")])

  min_ndvi
})
result = send_udf(data = "hypercube.json",code = script,host=host,port=port)


## End(Not run)

flahn/openeo-r-client documentation built on Sept. 18, 2020, 5:16 a.m.