Skip to content

Commit

Permalink
context in udf
Browse files Browse the repository at this point in the history
context in udf
  • Loading branch information
PondiB authored Nov 22, 2023
2 parents ef3eb75 + 2efa521 commit 71cdab8
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 14 deletions.
12 changes: 2 additions & 10 deletions R/processes.R
Original file line number Diff line number Diff line change
Expand Up @@ -900,14 +900,6 @@ run_udf <- Process$new(
subtype = "string"
)
),
Parameter$new(
name = "names",
description = "List of names to define outputs from a reducer UDF",
schema = list(
type = "string",
subtype = "string"
)
),
Parameter$new(
name = "runtime",
description = "A UDF runtime identifier available at the back-end.",
Expand Down Expand Up @@ -935,7 +927,7 @@ run_udf <- Process$new(
description = "The computed result.",
schema = list(type = c("number", "null"))
),
operation = function(data, udf, names = c("default"), runtime = "R", version = NULL, context = NULL, job) {
operation = function(data, udf, runtime = "R", version = NULL, context = NULL, job) {
if (runtime != "R") {
stop("Only R runtime is supported.")
}
Expand All @@ -953,7 +945,7 @@ run_udf <- Process$new(
user_function <- eval(func_parse)
# reducer udf
message("reducer function -> time")
data <- reduce_time(data, names = names, FUN = user_function)
data <- reduce_time(data, names = context, FUN = user_function)
return(data)
} else {
# convert parsed string function to class function
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@ change_detection = "function(x) {
}"

# run udf
datacube_udf = p$run_udf(data = datacube_filtered, udf = change_detection, names = c("change_date", "change_magnitude"))
datacube_udf = p$run_udf(data = datacube_filtered, udf = change.detection, context = c("change_date", "change_magnitude"))

# supported formats
formats = list_file_formats()
Expand All @@ -233,7 +233,7 @@ result = p$save_result(data = datacube_udf, format = formats$output$NetCDF)

# Process and download data synchronously
start.time <- Sys.time()
compute_result(graph = result, output_file = "change_detection.nc")
compute_result(graph = result, output_file = "detected_changes.nc")
end.time <- Sys.time()
time.taken <- end.time - start.time
time.taken
Expand Down
4 changes: 2 additions & 2 deletions examples/03-change-detection/R-Client-bfast-brandenburg.R
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ change.detection = 'function(x) {
}'

# run udf
datacube_udf = p$run_udf(data = datacube_filtered, udf = change.detection, names = c("change_date", "change_magnitude"))
datacube_udf = p$run_udf(data = datacube_filtered, udf = change.detection, context = c("change_date", "change_magnitude"))

# supported formats
formats = list_file_formats()
Expand All @@ -67,7 +67,7 @@ result = p$save_result(data = datacube_udf, format = formats$output$NetCDF)

# Process and download data synchronously
start.time <- Sys.time()
compute_result(graph = result, output_file = "change_detection.nc")
compute_result(graph = result, output_file = "detected_changes.nc")
end.time <- Sys.time()
time.taken <- end.time - start.time
time.taken
Expand Down
16 changes: 16 additions & 0 deletions man/load_stac.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 71cdab8

Please sign in to comment.