From a0263ac06282cf0a874be524ebf25d91162019f7 Mon Sep 17 00:00:00 2001 From: Brian Pondi Date: Tue, 21 May 2024 23:27:08 +0200 Subject: [PATCH] minor fixes --- DESCRIPTION | 1 + R/api.R | 1 + R/math-processes.R | 6 +++--- R/ml-processes.R | 6 ++++++ R/processes.R | 23 ++++++++++++----------- 5 files changed, 23 insertions(+), 14 deletions(-) create mode 100644 R/ml-processes.R diff --git a/DESCRIPTION b/DESCRIPTION index 5d22410..70d2ddf 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -33,6 +33,7 @@ Collate: 'Parameter-class.R' 'Process-class.R' 'processes.R' + 'ml-processes.R' 'math-processes.R' 'Router.R' 'api.R' diff --git a/R/api.R b/R/api.R index e4b929b..0a136cb 100644 --- a/R/api.R +++ b/R/api.R @@ -3,6 +3,7 @@ #' @include Session-Class.R #' @include Router.R #' @include math-processes.R +#' @include ml-processes.R #' @include processes.R #' @include api_job.R #' @include api_process_graphs.R diff --git a/R/math-processes.R b/R/math-processes.R index e7f0833..50f4cef 100644 --- a/R/math-processes.R +++ b/R/math-processes.R @@ -136,7 +136,7 @@ add = Process$new( operation = function(x, y, job) { classes = c("number", "null") - if(class(x) %in% names(classes) && class(y) %in% names(classes)) { + if (class(x) %in% names(classes) && class(y) %in% names(classes)) { return(x + y) } else { @@ -171,7 +171,7 @@ subtract = Process$new( operation = function(x, y, job) { classes = c("number", "null") - if(class(x) %in% names(classes) && class(y) %in% names(classes)) { + if (class(x) %in% names(classes) && class(y) %in% names(classes)) { return(x - y) } else { @@ -205,7 +205,7 @@ multiply = Process$new( schema = list(type = c("number", "null"))), operation = function(x, y, job) { classes = c("number", "null") - if(class(x) %in% names(classes) && class(y) %in% names(classes)) { + if (class(x) %in% names(classes) && class(y) %in% names(classes)) { return(x * y) } else { diff --git a/R/ml-processes.R b/R/ml-processes.R new file mode 100644 index 0000000..b8a2438 --- /dev/null +++ b/R/ml-processes.R @@ -0,0 +1,6 @@ +#' @include Process-class.R +#' @import gdalcubes +NULL + + +#' TO DO : Implement machine learning processes diff --git a/R/processes.R b/R/processes.R index 475e86a..cd301a2 100644 --- a/R/processes.R +++ b/R/processes.R @@ -149,12 +149,12 @@ load_collection <- Process$new( message("After default Spatial extent for stac..") if (crs != 4326) { message("crs is not 4326...") - min_pt <- sf::st_sfc(st_point(c(xmin, ymin)), crs = crs) + min_pt <- sf::st_sfc(sf::st_point(c(xmin, ymin)), crs = crs) min_pt <- sf::st_transform(min_pt, crs = 4326) min_bbx <- sf::st_bbox(min_pt) xmin_stac <- min_bbx$xmin ymin_stac <- min_bbx$ymin - max_pt <- sf::st_sfc(st_point(c(xmax, ymax)), crs = crs) + max_pt <- sf::st_sfc(sf::st_point(c(xmax, ymax)), crs = crs) max_pt <- sf::st_transform(max_pt, crs = 4326) max_bbx <- sf::st_bbox(max_pt) xmax_stac <- max_bbx$xmax @@ -181,16 +181,16 @@ load_collection <- Process$new( # Define cube view with monthly aggregation crs <- c("EPSG", crs) crs <- paste(crs, collapse = ":") - v.overview <- cube_view(srs = crs, dx = 30, dy = 30, dt = "P1M", + v.overview <- gdalcubes::cube_view(srs = crs, dx = 30, dy = 30, dt = "P1M", aggregation = "median", resampling = "average", extent = list(t0 = t0, t1 = t1, left = xmin, right = xmax, top = ymax, bottom = ymin)) # gdalcubes creation - cube <- raster_cube(img.col, v.overview) + cube <- gdalcubes::raster_cube(img.col, v.overview) if (!is.null(bands)) { - cube = select_bands(cube, bands) + cube = gdalcubes::select_bands(cube, bands) } message("data cube is created: ") message(as_json(cube)) @@ -1023,7 +1023,7 @@ run_udf <- Process$new( user_function <- eval(func_parse) # reducer udf message("reducer function -> time") - data <- reduce_time(data, names = context, FUN = user_function) + data <- gdalcubes::reduce_time(data, names = context, FUN = user_function) return(data) } else { # convert parsed string function to class function @@ -1031,12 +1031,12 @@ run_udf <- Process$new( func_parse <- parse(text = udf) user_function <- eval(func_parse) # apply per pixel udf - data <- apply_pixel(data, FUN = user_function) + data <- gdalcubes::apply_pixel(data, FUN = user_function) return(data) } } else { message("simple reducer udf") - data <- reduce_time(data, udf) + data <- gdalcubes::reduce_time(data, udf) return(data) } } @@ -1192,8 +1192,8 @@ array_interpolate_linear <- Process$new( ) ), returns = list( - description = "The value of the requested element.", - schema = list(description = "Any data type is allowed.") + description = "An array with no-data values being replaced with interpolated values. If not at least 2 numerical values are available in the array, the array stays the same.", + schema = list(type = "array") ), operation = function(data, job) { method <- "linear" @@ -1253,7 +1253,8 @@ save_result <- Process$new( schema = list(type = "boolean") ), operation = function(data, format, options = NULL, job) { - gdalcubes_options(parallel = 8) + CORES <- parallel::detectCores() + gdalcubes::gdalcubes_options(parallel = CORES) message("Data is being saved in format :") message(format) message("The above format is being saved")