Skip to content
This repository has been archived by the owner on Oct 1, 2020. It is now read-only.

Commit

Permalink
Merge pull request #6 from Open-EO/develop
Browse files Browse the repository at this point in the history
  • Loading branch information
pramitghosh authored Jul 25, 2018
2 parents 8b0eace + d766797 commit 087e3ee
Show file tree
Hide file tree
Showing 16 changed files with 292 additions and 95 deletions.
9 changes: 6 additions & 3 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
Package: openEO.R.Backend
Title: Reference backend implementation for openEO conformant backend with a local filesystem
Version: 0.2.4
Authors@R: person("Florian", "Lahn", email = "[email protected]", role = c("aut", "cre"))
Version: 0.2.5
Authors@R: c(person("Florian", "Lahn", email = "[email protected]", role = c("aut", "cre")),
person("Pramit","Ghosh",email = "[email protected]", role = c("aut","ctb")))
Description: The package contains a backend solution in compliance with the openEO API. In this demonstration
the file backend solution is the local file system containing some raster data collections.
URL: https://github.com/Open-EO/openeo-r-backend
BugReports: https://github.com/Open-EO/openeo-r-backend/issues
Depends:
R (>= 3.3),
rgdal (>= 1.2-16),
Expand All @@ -27,7 +30,7 @@ Encoding: UTF-8
LazyData: true
RoxygenNote: 6.0.1
VignetteBuilder: knitr
License: Apache License
License: Apache License 2.0
Imports:
plumber,
jsonlite,
Expand Down
7 changes: 3 additions & 4 deletions DOCKERFILE
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
FROM openeo-baseserver:1.4
FROM openeo-baseserver:1.5
MAINTAINER Florian Lahn ([email protected])
LABEL version="0.2.4"
LABEL version="0.2.5"
LABEL description="A simple openeo (almost) conformant backend for frontend development"

# create the path for the user files
RUN mkdir -p /opt/dockerfiles/
RUN mkdir -p /var/openeo/workspace/
RUN mkdir -p /opt/dockerfiles/ && mkdir -p /var/openeo/workspace/

COPY ./ /opt/dockerfiles/

Expand Down
7 changes: 3 additions & 4 deletions DOCKERFILE-base
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
FROM r-base:3.4.4
FROM r-base:3.5.0
MAINTAINER Florian Lahn ([email protected])
LABEL version="1.4"
LABEL version="1.5"
LABEL description="The basic configuration of the openeo r server image"

# create the path for the user files
RUN mkdir -p /opt/dockerfiles/
RUN mkdir -p /var/openeo/workspace/
RUN mkdir -p /opt/dockerfiles/ && mkdir -p /var/openeo/workspace/

COPY ./ /opt/dockerfiles/

Expand Down
4 changes: 4 additions & 0 deletions Dockerfiles/install_package.R
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
library(devtools)

# install the R UDF package from github
install_github("pramitghosh/OpenEO.R.UDF",ref="v0.0.1",dependencies=TRUE)

# install the R back-end package
install("/opt/dockerfiles")
4 changes: 4 additions & 0 deletions Dockerfiles/install_package_dependencies.R
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,8 @@ library(devtools)

install_deps("/opt/dockerfiles",repos=cran.mirror)
installation = list.files("/opt/dockerfiles",recursive=TRUE,full.names = TRUE)

# packages for the R UDFs
install_github("r-spatial/stars", dependencies=TRUE)

removed = file.remove(installation)
4 changes: 4 additions & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,13 @@ export(is.Process)
export(is.Product)
export(is.Service)
export(is.User)
export(loadSentinel2Data)
export(raster_collection_export)
export(read_legend)
export(serializer_proxy)
export(udf_export)
export(write_generics)
exportMethods(crs)
exportMethods(extent)
import(DBI)
import(plumber)
Expand Down
34 changes: 23 additions & 11 deletions R/Collection-class.R
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,6 @@ Collection <- R6Class(
},

addGranule = function(space=NULL,time=NULL, band=NULL, data, ..., meta_band = NULL) {

dot_args = list(...)

if (is.character(data)) {
Expand Down Expand Up @@ -188,15 +187,19 @@ Collection <- R6Class(
}


if (!is.null(band) && length(band) > 1) {
if (!is.null(band) && length(band) >= 1) { #unstack also one banded images
# add multiple bands
bands = unstack(data)
adding = tibble(band = band)
if (self$dimensions$time) {
adding = add_column(adding,time = time)
}

layer = unstack(data)
if (class(data) != "RasterLayer") {
layer = unstack(data)
} else {
layer = list(data)
}

adding = add_column(adding,data=layer)

if (self$dimensions$space) {
Expand Down Expand Up @@ -326,9 +329,6 @@ Collection <- R6Class(
if (self$dimensions$time) {
# order by bands if present, stack single bands into one file

# space is fixed (for now)
# TODO rework the holding of spatial extents in a spatial* data.frame where we store the feature and
# state the IDs in the table
if (self$dimensions$band) {
private$data_table = private$data_table %>%
group_by(time,space) %>%
Expand Down Expand Up @@ -433,7 +433,6 @@ Collection <- R6Class(
}

if (self$dimensions$time) {
# TODO group also by band! currently assuming that we have only one attribute--hmm maybe it doesn't matter
out = private$data_table %>% dplyr::group_by(space) %>% dplyr::arrange(time) %>% dplyr::summarise(data=tibble(band,time,data) %>% (function(x, ...){
values = unlist(x$data)
names = paste(x$band,as.character(x$time), sep=".")
Expand Down Expand Up @@ -626,12 +625,10 @@ read_legend = function(legend.path,code, ...) {
# prepareBands
parentFolder = dirname(legend.path)

bandinfo = table %>% group_by(band_index) %>% summarise(band = first(band), data = first(filename)) %>% arrange(band_index)
bandinfo = table %>% group_by(band_index) %>% dplyr::summarise(band = first(band), data = first(filename)) %>% dplyr::arrange(band_index)
# use band as band_index
dots$band_id = bandinfo$band



for (i in 1:nrow(table)) {
row = table[i,]
if (as.integer(row$whether_raster) == 1) {
Expand All @@ -645,3 +642,18 @@ read_legend = function(legend.path,code, ...) {

return(collection)
}

#' @export
setMethod("crs", signature="Collection", function(x, ...) {
return(crs.Collection(x,...))
})

crs.Collection = function(x, ...) {
if (x$dimensions$space) {
return(x$getGlobalSRS())
} else {
stop("Try to select a spatial reference system without a spatial dimension defined.")
}

}

19 changes: 15 additions & 4 deletions R/Server-class.R
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,11 @@ OpenEOServer <- R6Class(
workspaces.path = NULL,
sqlite.path = NULL,

udf_transactions.path = NULL,

api.port = NULL,
host = NULL,
baseserver.url = "http:localhost:8000/api/",
mapserver.url = NULL, #assuming here a url, if not specified the backend is probably started with docker-compose

processes = NULL,
Expand Down Expand Up @@ -195,13 +198,21 @@ OpenEOServer <- R6Class(
if (is.null(self$workspaces.path)) {
self$workspaces.path <- getwd()
}

if (is.null(self$data.path)) {
self$data.path <- paste(self$workspaces.path,"data",sep="/")

if (!dir.exists(self$data.path)) {
dir.create(self$data.path,recursive = TRUE)
}
}
if (!dir.exists(self$data.path)) {
dir.create(self$data.path,recursive = TRUE)
}

if (is.null(self$udf_transactions.path)) {
self$udf_transactions.path = paste(self$workspaces.path,"udf",sep="/")
}
if (!dir.exists(self$udf_transactions.path)) {
dir.create(self$udf_transactions.path, recursive = TRUE)
}

if (is.null(self$secret.key)) {
self$secret.key <- sha256(charToRaw("openEO-R"))
}
Expand Down
28 changes: 16 additions & 12 deletions R/api.R
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
"/data/",
"/data/{product_id}",
"/jobs/",
"/jobs/{job_id}",
"/jobs/{job_id}/download",
"/jobs/{job_id}/queue",
"/processes/",
Expand Down Expand Up @@ -112,7 +113,7 @@
}
},
error=function(e) {
error(res,403,"Login failed.")
openEO.R.Backend:::error(res,403,"Login failed.")
}
)
}
Expand Down Expand Up @@ -144,16 +145,19 @@

}

job = Job$new(process_graph=process_graph,user_id = req$user$user_id)

job = job$run()

result = job$result
if (is.null(result)) {
openEO.R.Backend:::error(res,status = 500,msg = "The result was NULL due to an internal error during processing.")
}

return(.create_output(res = res,result = job$results, format = format))
tryCatch({
job = Job$new(process_graph=process_graph,user_id = req$user$user_id)

job = job$run()

if (is.null(job$results)) {
return(openEO.R.Backend:::error(res,status = 500,msg = "The result was NULL due to an internal error during processing."))
}

return(.create_output(res = res,result = job$results, format = format))
}, error= function(e) {
return(openEO.R.Backend:::error(res=res, status = 500, msg = e))
})
}

.ogrExtension = function(format) {
Expand Down Expand Up @@ -236,7 +240,7 @@
}
},
error = function(e) {
error(res,401,"Unauthorized")
openEO.R.Backend:::error(res,401,"Unauthorized")
}
)
}
Expand Down
2 changes: 1 addition & 1 deletion R/api_job.R
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ createJobsEndpoint = function() {
} else {
job_results = paste(openeo.server$workspaces.path,"jobs",job_id,sep="/")

base_url = paste("http://",openeo.server$host,":",openeo.server$api.port,"/api/result/",job_id,sep="")
base_url = paste(openeo.server$baseserver.url,"result/",job_id,sep="")

#get files in outputfolder but not the log file
paste(base_url,list.files(job_results,pattern="[^process\\.log]"),sep="/")
Expand Down
Loading

0 comments on commit 087e3ee

Please sign in to comment.