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}