Skip to content

Commit

Permalink
Devel (#202)
Browse files Browse the repository at this point in the history
Small fixes and test improving
  • Loading branch information
ranghetti authored Sep 6, 2019
1 parent 55c7434 commit bc614a5
Show file tree
Hide file tree
Showing 42 changed files with 412 additions and 418 deletions.
1 change: 1 addition & 0 deletions .Rbuildignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,4 @@
^index\.R?md$
^utils$
^LICENSE\.md$
^cran\-comments\.md$
6 changes: 2 additions & 4 deletions NAMESPACE
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
# Generated by roxygen2: do not edit by hand

export(abs2rel)
export(check_gdal)
export(check_scihub_connection)
export(check_scihub_login)
export(check_sen2r_deps)
export(clean_traces)
export(comsub)
export(expand_path)
export(gdal_abs2rel)
export(gdal_rel2abs)
export(gdal_warp)
export(init_python)
export(install_aria2)
export(install_sen2cor)
export(list_indices)
export(load_binpaths)
export(mountpoint)
export(normalize_path)
export(projname)
Expand All @@ -40,12 +40,10 @@ export(safe_shortname)
export(sen2cor)
export(sen2r)
export(sen2r_getElements)
export(smooth_mask)
export(st_crs2)
export(stack2rgb)
export(str_pad2)
export(tiles_intersects)
export(trace_function)
export(write_scihub_login)
import(data.table)
import(mapedit)
Expand Down
38 changes: 22 additions & 16 deletions R/check_gdal.R
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
#' @note License: GPL 3.0
#' @importFrom gdalUtils gdal_setInstallation gdal_chooseInstallation
#' @importFrom jsonlite fromJSON
#' @export
#' @examples
#' \dontrun{
#'
Expand Down Expand Up @@ -122,8 +123,25 @@ check_gdal <- function(abort = TRUE, gdal_path = NULL, force = FALSE, ignore.ful
gdalinfo_paths <- gdalinfo_paths[order(gdal_versions, decreasing = TRUE)]
gdal_versions <- sort(gdal_versions, decreasing = TRUE)

# in Windows, prefer (filter, from v. 1.1.0) default OSGeo version
if (Sys.info()["sysname"] == "Windows") {
gdal_order <- c(
grep("^C:\\\\OSGEO4~1", gdal_dirs), # 1: C:\OSGeo4W64
grep("^(?!C:\\\\OSGEO4~1).*OSGEO4", gdal_dirs, perl=TRUE)#, # 2: other paths containing OSGEO4~1
# grep("^((?!OSGEO4).)*$", gdal_dirs, perl=TRUE) # 3: all other paths
# other paths were disabled to avoid selecting other installations
)
gdal_dirs <- gdal_dirs[gdal_order]
gdalinfo_paths <- gdalinfo_paths[gdal_order]
gdal_versions <- gdal_versions[gdal_order]
}

# check requisite 2: JP2 support
gdal_formats <- sapply(paste(gdalinfo_paths, "--formats"), system, intern = TRUE, simplify = FALSE)
gdal_formats <- if (length(gdalinfo_paths) > 0) {
sapply(paste(gdalinfo_paths, "--formats"), system, intern = TRUE, simplify = FALSE)
} else {
character(0)
}
gdal_JP2support <- sapply(gdal_formats, function(x) {length(grepl("JP2OpenJPEG", x)) > 0})
if (all(!gdal_JP2support)) {
print_message(
Expand All @@ -132,11 +150,11 @@ check_gdal <- function(abort = TRUE, gdal_path = NULL, force = FALSE, ignore.ful
"Please install JP2OpenJPEG support and recompile GDAL.",
if (Sys.info()["sysname"] == "Windows" & message_type=="error") {
paste0(
"\nWe recommend to use the OSGeo4W installer ",
"\nUsing the OSGeo4W installer ",
"(http://download.osgeo.org/osgeo4w/osgeo4w-setup-x86",
if (Sys.info()["machine"]=="x86-64") {"_64"},".exe), ",
"to choose the \"Advanced install\" and ",
"to check the packages \"gdal-python\" and \"openjpeg\"."
"choose the \"Advanced install\" and ",
"check the packages \"gdal-python\" and \"openjpeg\"."
)
}
)
Expand All @@ -147,18 +165,6 @@ check_gdal <- function(abort = TRUE, gdal_path = NULL, force = FALSE, ignore.ful
gdalinfo_paths <- gdalinfo_paths[gdal_JP2support]
gdal_versions <- gdal_versions[gdal_JP2support]

# in Windows, prefer default OSGeo version
if (Sys.info()["sysname"] == "Windows") {
gdal_order <- c(
grep("^C:\\\\OSGEO4~1", gdal_dirs), # 1: C:\OSGeo4W64
grep("^(?!C:\\\\OSGEO4~1).*OSGEO4", gdal_dirs, perl=TRUE), # 2: other paths containing OSGEO4~1
grep("^((?!OSGEO4).)*$", gdal_dirs, perl=TRUE) # 3: all other paths
)
gdal_dirs <- gdal_dirs[gdal_order]
gdalinfo_paths <- gdalinfo_paths[gdal_order]
gdal_versions <- gdal_versions[gdal_order]
}


# filter basing on the GDAL installation path defined with gdal_path
if (!is.null(gdal_path)) {
Expand Down
2 changes: 1 addition & 1 deletion R/check_param_list.R
Original file line number Diff line number Diff line change
Expand Up @@ -365,7 +365,7 @@ check_param_list <- function(pm, type = "string", check_paths = FALSE, correct =

# -- rgb_ranges --
if (all(is.array(pm$rgb_ranges), length(dim(pm$rgb_ranges)) > 2)) {
pm$rgb_ranges <- asplit(pm$rgb_ranges, 1)
pm$rgb_ranges <- split(pm$rgb_ranges, nrow(pm$rgb_ranges))
}
if (is.matrix(pm$rgb_ranges)) {
pm$rgb_ranges <- list(pm$rgb_ranges)
Expand Down
28 changes: 20 additions & 8 deletions R/check_sen2r_deps.R
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,16 @@ check_sen2r_deps <- function() {
helpText(em(
"GDAL is a mandatory dependency of the package:",
"it is needed for all the processing operations",
"and to retrieve metadata from SAFE products"
"and to retrieve metadata from SAFE products.",
if (Sys.info()["sysname"] == "Windows") {span(
"Starting from version 1.1.0, on Windows",
strong("it is strictly required to install GDAL using OSGeo4W"),
"in order to avoid errors.",
"To satisfy this requirement, click on \"Check GDAL\" and,",
"whenever the search of a valid installation will finish, download",
"the OSGeo4W installer and install it in the default directory",
"(or, in any case, maintain the directory name \"OSGeo4W64\")."
)}
)),
span(style="display:inline-block;vertical-align:center;padding-top:5px;",
actionButton("check_gdal", "Check GDAL", width=200),
Expand Down Expand Up @@ -157,13 +166,16 @@ check_sen2r_deps <- function() {
div(
p(style="text-align:center;font-size:500%;color:red;",
icon("times-circle")),
p("GDAL needs to be installed.",
"To do it, download the OSGeo4W installer using the button below:",
"then, give the administrator rules when required,",
"choose the \"Advanced install\" and",
"continue clicking \"Next\";",
"when the window to chose the packages to install will appear,",
"check the package \"gdal-python\" and install it."),
p(HTML(
"GDAL needs to be installed. To do it:<ol>",
"<li>download the OSGeo4W installer using the button below;</li>",
"<li>when the file will be automatically opened,",
"give the administrator rules when required;</li>",
"<li>choose the \"Advanced install\";</li>",
"<li>continue clicking \"Next\";</li>",
"<li>when the window for choosing the packages to install will appear,",
"check the package \"gdal-python\" and install it.</li></ol>"
)),
hr(style="margin-top: 0.75em; margin-bottom: 0.75em;"),
div(style="text-align:right;",
actionButton("install_gdal_button", strong("\u2000Download"), icon=icon("download")),
Expand Down
1 change: 0 additions & 1 deletion R/init_python.R
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
#' @note License: GPL 3.0
#' @importFrom reticulate import import_from_path import_builtins
#' use_python py_module_available py_discover_config
#' @export

init_python <- function() {

Expand Down
14 changes: 11 additions & 3 deletions R/install_sen2cor.R
Original file line number Diff line number Diff line change
Expand Up @@ -132,10 +132,18 @@ install_sen2cor <- function(sen2cor_dir=NA, version="2.8.0", force = FALSE) {
unzip = "internal"
))
unlink(sen2cor_installer)
sen2cor_bin <- system.file(
"sen2cor", gsub("\\.zip$","",basename(sen2cor_installer)), "L2A_Process.bat",
package="sen2r"
sen2cor_bin <- file.path(
sen2cor_dir,
gsub("\\.zip$","",basename(sen2cor_installer)),
"L2A_Process.bat"
)
if (!file.exists(sen2cor_bin)) {
print_message(
type = "error",
"Something went wrong during the installation of Sen2Cor, ",
"try reinstalling it or contact the package maintainer."
)
}
}

# fix bug #71
Expand Down
1 change: 1 addition & 0 deletions R/load_binpaths.R
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#' @author Luigi Ranghetti, phD (2018) \email{ranghetti.l@@irea.cnr.it}
#' @note License: GPL 3.0
#' @importFrom jsonlite fromJSON
#' @export
#' @examples
#' \dontrun{
#'
Expand Down
3 changes: 2 additions & 1 deletion R/raster_metadata.R
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
#' @importFrom stars read_stars st_dimensions
#' @importFrom sf st_bbox st_crs
#' @importFrom methods is
#' @examples
#' @examples \dontrun{
#' # Define product names
#' examplenames <- c(
#' system.file("tif/L7_ETMs.tif", package="stars"),
Expand All @@ -34,6 +34,7 @@
#' # Output with an invalid raster
#' examplenames <- c(examplenames, system.file("extdata/gdal_formats.json", package="sen2r"))
#' raster_metadata(examplenames)
#' }

raster_metadata <- function(raster_paths, meta = "all", format = "data.table") {

Expand Down
5 changes: 1 addition & 4 deletions R/s2_calcindices.R
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,7 @@
#' @param indices Character vector with the names of the required
#' indices. Values should be included in names corresponding to the
#' Abbreviations of the following indices:
#' [IDB](http://www.indexdatabase.de/db/is.php?sensor_id=96)
#' FIXME the list of the accepted values is a subset; this reference
#' will be replaced with an internal html page integrated in the
#' shiny interface).
#' [IDB](http://www.indexdatabase.de/db/is.php?sensor_id=96).
#' @param outdir (optional) Full name of the output directory where
#' the files should be created (default: current directory).
#' `outdir` can bot be an existing or non-existing directory (in the
Expand Down
5 changes: 4 additions & 1 deletion R/s2_download.R
Original file line number Diff line number Diff line change
Expand Up @@ -108,11 +108,14 @@ s2_download <- function(s2_prodlist = NULL,
} else if (grepl("^aria2c?$", downloader)) {

binpaths <- load_binpaths("aria2")
if (Sys.info()["sysname"] != "Windows") {
link <- gsub("/\\$value", "/\\\\$value", link)
}
aria_string <- paste0(
binpaths$aria2c, " -x 2 --check-certificate=false -d ",
dirname(zip_path),
" -o ", basename(zip_path),
" ", "\"", as.character(gsub("/\\$value", "/\\\\$value", link)), "\"",
" ", "\"", as.character(link), "\"",
" --allow-overwrite --file-allocation=none --retry-wait=2",
" --http-user=", "\"", creds[1], "\"",
" --http-passwd=", "\"", creds[2], "\"",
Expand Down
46 changes: 45 additions & 1 deletion R/s2_gui.R
Original file line number Diff line number Diff line change
Expand Up @@ -3746,7 +3746,10 @@ s2_gui <- function(param_list = NULL,
type = "error"
)

} else if (input$path_out_textin == "") {
} else if (
length(input$list_prods[!input$list_prods %in% c("indices","rgbimages")]) > 0 &
input$path_out_textin == ""
) {

# directory missing
sendSweetAlert(
Expand All @@ -3755,6 +3758,47 @@ s2_gui <- function(param_list = NULL,
type = "error"
)

} else if (
length(input$list_indices) > 0 &
input$path_out_textin == "" &
input$path_indices_textin == ""
) {

# directory missing
sendSweetAlert(
session, NULL,
span("Please specify at least one among the directories for spectral",
"indices and for output products before continuing."),
type = "error"
)

} else if (
length(input$list_rgb) > 0 &
input$path_out_textin == "" &
input$path_rgb_textin == ""
) {

# directory missing
sendSweetAlert(
session, NULL,
span("Please specify at least one among the directories for RGB",
"images and for output products before continuing."),
type = "error"
)

} else if (all(
input$online == TRUE,
length(nn(rv$extent)) == 0,
length(nn(input$tiles_checkbox)) == 0
)) {

# directory missing
sendSweetAlert(
session, NULL,
"Please specify the extent.",
type = "error"
)

} else {

# if all checks passed, exit from GUI and return values
Expand Down
2 changes: 1 addition & 1 deletion R/s2_rgb.R
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
#' Default is to use c(0,2500) for bands 1-5; c(0,7500) bands 6-12.
#' @param outdir (optional) Full name of the existing output directory
#' where the files should be created. Default is the same directory of
#' input reflectance files. # FIXME use a subdir with product name
#' input reflectance files.
#' @param subdirs (optional) Logical: if TRUE, different indices are
#' placed in separated `outfile` subdirectories; if FALSE, they are placed in
#' `outfile` directory; if NA (default), subdirectories are created only if
Expand Down
1 change: 0 additions & 1 deletion R/smooth_mask.R
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
#' smoothed / buffered).
#' Default (NULL) means that no NA values are present.
#' @return The path of the smoothed mask.
#' @export
#' @importFrom methods is
#' @author Luigi Ranghetti, phD (2018) \email{ranghetti.l@@irea.cnr.it}
#' @note License: GPL 3.0
Expand Down
2 changes: 0 additions & 2 deletions R/trace_functions.R
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,6 @@ clean_trace <- function(tracename) {

#' @name trace_function
#' @rdname trace_function
#' @export
trace_function <- function(trace_fun, trace_files, trace_funname=NA, ...) {

# Start tracing
Expand Down Expand Up @@ -131,7 +130,6 @@ trace_function <- function(trace_fun, trace_files, trace_funname=NA, ...) {

#' @name clean_traces
#' @rdname trace_function
#' @export
clean_traces <- function(trace_funname=NA) {

# import the content of the path in which trace txt files are placed
Expand Down
9 changes: 4 additions & 5 deletions _pkgdown.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ reference:
- '`s2_list`'
- '`s2_download`'
- '`sen2cor`'
- '`scihub_login`'
- title: Read and convert SAFE format
desc: ~
contents:
Expand All @@ -29,6 +30,7 @@ reference:
contents:
- '`safe_getMetadata`'
- '`safe_shortname`'
- '`raster_metadata`'
- '`sen2r_getElements`'
- '`s2_dop`'
- '`s2_tiles`'
Expand All @@ -39,24 +41,21 @@ reference:
- '`load_binpaths`'
- '`install_sen2cor`'
- '`install_aria2`'
- '`init_python`'
- '`check_gdal`'
- title: Accessory functions
desc: ~
contents:
- '`s2_gui`'
- '`list_indices`'
- '`stack2rgb`'
- '`raster2rgb`'
- '`expand_path`'
- '`comsub`'
- '`projname`'
- '`abs2rel`'
- '`gdal_abs2rel`'
- '`mountpoint`'
- '`trace_function`'
- '`st_crs2`'
- '`str_pad2`'
- '`normalize_path`'
- '`smooth_mask`'
- '`tiles_intersects`'
navbar:
type: inverse
Expand Down
12 changes: 12 additions & 0 deletions cran-comments.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# sen2r v. 1.1.0

## Test environments
* [local installation] Ubuntu 18.04, 64 bit, R 3.6.1
* [local installation] Archlinux, 64 bit, R 3.6.1
* [travis-ci] Ubuntu 16.04.6 LTS, 64 bit, R 3.6.1
* [R-hub] Windows Server 2008 R2 SP1, R-release, 32/64 bit
* [R-hub] macOS 10.11 El Capitan, R-release (experimental)

## R CMD check results
There were no ERRORs, WARNINGs or NOTEs.

Loading

0 comments on commit bc614a5

Please sign in to comment.