Skip to content

Commit

Permalink
minor fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
PondiB committed May 21, 2024
1 parent 1e531fb commit a0263ac
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 14 deletions.
1 change: 1 addition & 0 deletions DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ Collate:
'Parameter-class.R'
'Process-class.R'
'processes.R'
'ml-processes.R'
'math-processes.R'
'Router.R'
'api.R'
Expand Down
1 change: 1 addition & 0 deletions R/api.R
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 3 additions & 3 deletions R/math-processes.R
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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 {
Expand Down
6 changes: 6 additions & 0 deletions R/ml-processes.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#' @include Process-class.R
#' @import gdalcubes
NULL


#' TO DO : Implement machine learning processes
23 changes: 12 additions & 11 deletions R/processes.R
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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))
Expand Down Expand Up @@ -1023,20 +1023,20 @@ 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
message("apply per pixel function")
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)
}
}
Expand Down Expand Up @@ -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"
Expand Down Expand Up @@ -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")
Expand Down

0 comments on commit a0263ac

Please sign in to comment.