From 95b94f593e4b023ab3242a6a04d523cc10db545e Mon Sep 17 00:00:00 2001 From: michael_b Date: Fri, 9 Feb 2024 16:54:32 +0100 Subject: [PATCH] add new process --- DESCRIPTION | 1 + NAMESPACE | 1 + R/api.R | 3 ++ R/fill_missing_values.R | 59 ++++++++++++++++++++++++++++++++++++++ man/fill_missing_values.Rd | 16 +++++++++++ 5 files changed, 80 insertions(+) create mode 100644 R/fill_missing_values.R create mode 100644 man/fill_missing_values.Rd diff --git a/DESCRIPTION b/DESCRIPTION index 5536568..c9c89ca 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -43,5 +43,6 @@ Collate: 'ProcessGraph-class.R' 'SessionConfig-Class.R' 'error.R' + 'fill_missing_values.R' Depends: R (>= 4.3.0) diff --git a/NAMESPACE b/NAMESPACE index 4e3fba5..f374c38 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -9,6 +9,7 @@ export(ProcessGraph) export(SessionConfig) export(SessionInstance) export(createSessionInstance) +export(fill_missing_values_opp) export(getJobIdIndex) export(is.Collection) export(is.Job) diff --git a/R/api.R b/R/api.R index 56a6dec..e3e2f6b 100644 --- a/R/api.R +++ b/R/api.R @@ -316,4 +316,7 @@ addEndpoint = function() { Session$assignProcess(divide) Session$assignProcess(evi) + + Session$assignProcess(fill_missing_values) + } diff --git a/R/fill_missing_values.R b/R/fill_missing_values.R new file mode 100644 index 0000000..589520d --- /dev/null +++ b/R/fill_missing_values.R @@ -0,0 +1,59 @@ +#' @export +fill_missing_values_opp = function(data, method, job) { + message("Call parameters:") + message("\ndata:") + message(gdalcubes::as_json(data)) + + message("\nmethod:") + message(method) + + valid_methods <- c("near", "linear", "locf", "nocb") + if (!(method %in% valid_methods)) { + stop(paste("Invalid method. Please choose one of", toString(valid_methods))) + } + + tryCatch({ + message("\nFill NA values...") + + gdalcubes::fill_time(data, method) + + message("NA values filled!") + + }, + error = function(err) + { + message("An Error occured!") + message(toString(err)) + stop(toString(err$message)) + }) + + return(data) +} + + +#' fill_missing_values +fill_missing_values <- Process$new( + id = "fill_missing_values", + description = "Fill NA data cube pixels by simple time series interpolation.", + categories = as.array("cubes"), + summary = "Fill out missing values", + parameters = list( + Parameter$new( + name = "data", + description = "A data cube with bands.", + schema = list( + type = "object", + subtype = "raster-cube" + ) + ), + Parameter$new( + name = "method", + description = "Method of interpolation to fill NA values. Valid methods are: near,linear, locf, nocb. Look up the gdalcubes reference for further information.", + schema = list( + type = "string" + ), + ) + ), + returns = eo_datacube, + operation = fill_missing_values_opp +) diff --git a/man/fill_missing_values.Rd b/man/fill_missing_values.Rd new file mode 100644 index 0000000..d7b185f --- /dev/null +++ b/man/fill_missing_values.Rd @@ -0,0 +1,16 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/fill_missing_values.R +\docType{data} +\name{fill_missing_values} +\alias{fill_missing_values} +\title{fill_missing_values} +\format{ +An object of class \code{Process} (inherits from \code{R6}) of length 12. +} +\usage{ +fill_missing_values +} +\description{ +fill_missing_values +} +\keyword{datasets}