diff --git a/R-package/DESCRIPTION b/R-package/DESCRIPTION index 5e716eeb2248a6bd9073a8de4ac68908a511279a..805ff3c23aaef33389f22753cf7f7a999aa4a915 100644 --- a/R-package/DESCRIPTION +++ b/R-package/DESCRIPTION @@ -1,6 +1,6 @@ Package: HaSa Title: Autonomous Image Sampling and Probability Mapping -Version: 1.2.0 +Version: 1.3.0 Authors@R: person(given = "Carsten", family = "Neumann", @@ -15,6 +15,7 @@ Imports: sp (<= 1.4-1), rgdal (<= 1.4-8), raster, + geojsonio, maptools, rgeos, spatialEco, @@ -24,6 +25,7 @@ Imports: velox, leaflet, leafem, + IRdisplay, htmlwidgets Remotes:url::https://cran.r-project.org/src/contrib/Archive/velox/velox_0.2.0.tar.gz Encoding: UTF-8 diff --git a/R-package/R/inner_procedure.r b/R-package/R/inner_procedure.r index c0e16163959adde9781f2df815a17bd1f565c433..8baadfc4b42b597d8a5053434f519c4d472a7aaf 100644 --- a/R-package/R/inner_procedure.r +++ b/R-package/R/inner_procedure.r @@ -15,19 +15,21 @@ #' @param last only true for one class classifier c("FALSE", TRUE") #' @param seed set seed for reproducable results #' @param init.seed "sample" for new or use run1@seeds to reproduce previous steps -#' @param parallel_mode run loops using all available cores +#' @param save_runs if the user wants to save the runs, if TRUE the complete Habitat Class object is returned +#' @param parallel_mode run loops in parallel +#' @param max_num_cores maximum number of cores for parallelism #' #' @return a list with 3 elements: #' 1) An index #' 2) Accuracy vector #' 3) A vector with a Habitat objects, each consisting of 7 slots: \cr -#' run1@models - list of selected classifiers \cr -#' run1@ref_samples - list of SpatialPointsDataFrames with same length as run1@models holding reference labels [1,2] for each selected model \cr -#' run1@switch - vector of length run1@models indicating if target class equals 2, if not NA the labels need to be switched \cr +#' run1@models - list of selected classifiers (only if save_runs is TRUE) \cr +#' run1@ref_samples - list of SpatialPointsDataFrames with same length as run1@models holding reference labels [1,2] for each selected model (only if save_runs is TRUE) \cr +#' run1@switch - vector of length run1@models indicating if target class equals 2, if not NA the labels need to be switched (only if save_runs is TRUE) \cr #' run1@layer - raster map of habitat type probability \cr -#' run1@mod_all - list of all classifiers (equals nb_models) \cr -#' run1@class_ind - vector of predictive distance measure for all habitats \cr -#' run1@seeds - vector of seeds for random sampling \cr +#' run1@mod_all - list of all classifiers (equals nb_models) (only if save_runs is TRUE) \cr +#' run1@class_ind - vector of predictive distance measure for all habitats (only if save_runs is TRUE) \cr +#' run1@seeds - vector of seeds for random sampling (only if save_runs is TRUE) \cr #' all files are saved with step number, the *.tif file is additionally saved with class names #' @keywords internal @@ -46,7 +48,9 @@ sample_nb <- function(raster, last, seed, init.seed, - parallel_mode) { + save_runs, + parallel_mode, + max_num_cores) { ### n_channel <- length(names(raster)) ###velox @@ -74,8 +78,8 @@ sample_nb <- function(raster, seed2 <- init.seed } oobe <- matrix(NA, nrow = n, ncol = nb_mean) - models <- list() - points <- list() + models_list <- list() + points_list <- list() dif <- matrix(NA, nrow = nb_mean, ncol = nrow(reference)) channel <- matrix(NA, nrow = nb_mean, ncol = nrow(reference)) switch <- matrix(NA, nrow = nb_mean, ncol = nrow(reference)) @@ -85,6 +89,12 @@ sample_nb <- function(raster, if (parallel_mode == TRUE) { cores = parallel::detectCores( logical = TRUE) + if (cores > max_num_cores) { + cores <- max_num_cores + } else { + cores <- cores - 1 + } + res <- parallel::mclapply( 1:nb_mean, model_opt_r, @@ -103,11 +113,13 @@ sample_nb <- function(raster, pbtn2 = pbtn2, ras_vx = ras.vx, max_samples_per_class = max_samples_per_class, - mc.cores = cores + mc.cores = cores, + mc.preschedule = TRUE, + mc.cleanup = TRUE ) for (k in 1:nb_mean) { - points[[k]] <- res[["k" = k]][["points"]] - models[[k]] <- res[["k" = k]][["models"]] + points_list[[k]] <- res[["k" = k]][["points"]] + models_list[[k]] <- res[["k" = k]][["models"]] oobe[, k] <- res[["k" = k]][["oobe"]][, 1] } } else { @@ -130,22 +142,29 @@ sample_nb <- function(raster, ras_vx = ras.vx, max_samples_per_class = max_samples_per_class ) - points[[k]] <- res$points - models[[k]] <- res$models + points_list[[k]] <- res$points + models_list[[k]] <- res$models oobe[, k] <- res$oobe[, 1] setTxtProgressBar(pb, k) } } #which_models_null <- which(models == "NULL") - which_models_null <- vapply(models, is.not.null <- function(x){!is.null(x)}, FALSE) - if (length(models) == 0 | - length(which_models_null[which_models_null == FALSE]) == length(models)) { + which_models_null <- vapply(models_list, is.not.null <- function(x){!is.null(x)}, FALSE) + if (length(models_list) == 0 | + length(which_models_null[which_models_null == FALSE]) == length(models_list)) { + remove(points_list) + remove(models_list) + remove(ooe) stop("No Models - would you be so kind to increase init.samples, please") } if (length(which_models_null[which_models_null == FALSE]) > 0) { - models <- models[which_models_null] + models <- models_list[which_models_null] + } else { + models <- models_list } + remove(models_list) + for (jj in 1:nrow(reference)) { ref <- jj rr = 3 @@ -204,11 +223,16 @@ sample_nb <- function(raster, } close(pb) - mod_all <- models + if (save_runs == TRUE) { + mod_all <- models + } else { + mod_all = list() + } models <- models[ch] print(paste("n_models =", length(models))) switch <- switch[ch, index] - points <- points[ch] + points <- points_list[ch] + remove(points_list) dif <- dif[2,] ############################################################################## ###Vohersage @@ -241,16 +265,38 @@ sample_nb <- function(raster, dummy <- raster::calc(dummy, fun = sum) layer[[1]] <- dummy - obj <- new( - "Habitat", - models = models, - ref_samples = points, - switch = switch, - layer = layer, - mod_all = mod_all, - class_ind = dif, - seeds = seed2 - ) + if (save_runs == TRUE) { + obj <- new( + "Habitat", + models = models, + ref_samples = points, + switch = switch, + layer = layer, + mod_all = mod_all, + class_ind = dif, + seeds = seed2 + ) + } else { + obj <- new( + "Habitat", + models = list(), + ref_samples = list(), + switch = vector(), + layer = layer, + mod_all = list(), + class_ind = 0, + seeds = 0 + ) + } + remove(models) + remove(points) + remove(switch) + remove(layer) + remove(mod_all) + remove(dif) + remove(seed2) + gc(full = TRUE) + out <- list(index = index, acc = acc, obj = obj) return(out) } diff --git a/R-package/R/model_opt.r b/R-package/R/model_opt.r index 394663f255be3ba9fcf5e97c88b88b6301f81568..c9c674dc0f2f8c1a8833de9205563f92909ade5e 100644 --- a/R-package/R/model_opt.r +++ b/R-package/R/model_opt.r @@ -120,10 +120,7 @@ model_opt_r <- function(k, break } } - model_pre <- model1 - pbtn1_pre <- pbtn1 - pbtn2_pre <- pbtn2 - oobe <- oobe + ######################################################################## if (model == "rf") { correct <- @@ -138,8 +135,6 @@ model_opt_r <- function(k, if (length(which_classes_correct) == 0) { if (j == 1) { break - } else{ - pbtn1 <- pbtn1 } } else { d1 <- correct[which_classes_correct] @@ -149,7 +144,8 @@ model_opt_r <- function(k, pbtn1 <- as.data.frame(cbind(classes[d1], matrix(p1, ncol = 2))) sp::coordinates(pbtn1) <- c("V2", "V3") - sp::proj4string(pbtn1) <- sp::proj4string(pbt) + #sp::proj4string(pbtn1) <- sp::proj4string(pbt) + crs(pbtn1) <- crs(pbt) poly <- rgeos::gBuffer(spgeom = pbtn1, width = buffer, @@ -201,8 +197,6 @@ model_opt_r <- function(k, if (length(which_classes_correct_2) == 0) { if (j == 1) { break - } else{ - pbtn2 <- pbtn2 } } else { d2 <- correct[which_classes_correct_2] @@ -212,7 +206,8 @@ model_opt_r <- function(k, pbtn2 <- as.data.frame(cbind(classes[d2], matrix(p2, ncol = 2))) sp::coordinates(pbtn2) <- c("V2", "V3") - sp::proj4string(pbtn2) <- sp::proj4string(pbt) + #sp::proj4string(pbtn2) <- sp::proj4string(pbt) + crs(pbtn2) <- crs(pbt) poly <- rgeos::gBuffer(spgeom = pbtn2, width = buffer, @@ -298,6 +293,8 @@ model_opt_r <- function(k, classes <- data$classes pbt <- rbind(pbtn1, pbtn2) } + remove(pbt) + return(list( "k" = k, "models" = models, diff --git a/R-package/R/outer_procedure.r b/R-package/R/outer_procedure.r index eb81359d618e8111f9172ca7e11f96da7275841f..781f9cb873440a57cd31ff3d452018c0989bb27a 100644 --- a/R-package/R/outer_procedure.r +++ b/R-package/R/outer_procedure.r @@ -20,13 +20,15 @@ #' @param n_classes total number of classes (habitat types) to be separated #' @param multiTest number of test runs to compare different probability outputs #' @param RGB rgb channel numbers for image plot -#' @param overwrite overwrite the results file -#' @param parallel_mode run loops using all available cores - +#' @param overwrite overwrite the KML and raster files from previous runs (default TRUE) +#' @param save_runs an Habitat object and extra info (to restart a run) is saved (default TRUE) +#' @param parallel_mode run loops using all available cores (default FALSE) +#' @param max_num_cores maximum number of cores for parallelism (default 5) +#' @param plot_on_browser plot on the browser or inline in a notebook (default TRUE) #' #' @return 4 files per step: #' 1) Habitat type probability map as geocoded *.kml layer and *.tif raster files and *.png image output -#' 2) A Habitat object consisting of 7 slots: \cr +#' 2) A Habitat object (only if save_runs is set to TRUE) consisting of 7 slots: \cr #' run1@models - list of selcted classifiers \cr #' run1@ref_samples - list of SpatialPointsDataFrames with same length as run1@models holding reference labels [1,2] for each selected model \cr #' run1@switch - vector of lenght run1@models indicating if target class equals 2, if not NA the labels need to be switched \cr @@ -83,7 +85,10 @@ multi_Class_Sampling <- function(in.raster, multiTest = 1, RGB = c(19, 20, 21), overwrite = TRUE, - parallel_mode = FALSE) { + save_runs = TRUE, + parallel_mode = FALSE, + max_num_cores = 5, + plot_on_browser = TRUE) { ###first steps: data preparation if (class(reference) == "SpatialPointsDataFrame") { reference <- as.data.frame(raster::extract(in.raster, reference)) @@ -92,7 +97,8 @@ multi_Class_Sampling <- function(in.raster, input_raster <- in.raster area <- as(raster::extent(in.raster), 'SpatialPolygons') area <- sp::SpatialPolygonsDataFrame(area, data.frame(ID = 1:length(area))) - sp::proj4string(area) <- sp::proj4string(in.raster) + #sp::proj4string(area) <- sp::proj4string(in.raster) + crs(area) <- crs(in.raster) col <- colorRampPalette(c("lightgrey", "orange", @@ -151,7 +157,9 @@ multi_Class_Sampling <- function(in.raster, last = last, seed = seed, init.seed = init.seed, - parallel_mode = parallel_mode + save_runs = save_runs, + parallel_mode = parallel_mode, + max_num_cores = max_num_cores ) index <- maFo_rf$index @@ -182,6 +190,9 @@ multi_Class_Sampling <- function(in.raster, maFo_rf <- maFo[[as.numeric(decision)]] index <- new.names[[as.numeric(decision)]] acc <- new.acc[[as.numeric(decision)]] + remove(maFo) + remove(new.names) + remove(new.acc) ########################################################################## } else{ ######################## @@ -199,7 +210,9 @@ multi_Class_Sampling <- function(in.raster, last = last, seed = seed, init.seed = init.seed, - parallel_mode = parallel_mode + save_runs = save_runs, + parallel_mode = parallel_mode, + max_num_cores = max_num_cores ) index <- maFo_rf$index @@ -217,7 +230,8 @@ multi_Class_Sampling <- function(in.raster, g = RGB[2], b = RGB[3], acc = acc, - outPath = outPath + outPath = outPath, + plot_on_browser = plot_on_browser ) decision <- @@ -226,6 +240,7 @@ multi_Class_Sampling <- function(in.raster, sample2 <- init.samples models2 <- nb_models while (decision == "0") { + remove(maFo_rf) decision2 <- readline("Adjust init.samples/nb.models or auto [../.. or 0]: ") if (decision2 != "0") { @@ -253,7 +268,9 @@ multi_Class_Sampling <- function(in.raster, last = last, seed = seed, init.seed = init.seed, - parallel_mode = parallel_mode + save_runs = save_runs, + parallel_mode = parallel_mode, + max_num_cores = max_num_cores ) index <- maFo_rf$index @@ -270,20 +287,25 @@ multi_Class_Sampling <- function(in.raster, g = RGB[2], b = RGB[3], acc = acc, - outPath = outPath + outPath = outPath, + plot_on_browser = plot_on_browser ) decision <- readline("Threshold for Habitat Extraction or Sample Again [../0]: ") } - run1 <- maFo_rf if (i < 10) { ni <- paste("0", i, sep = "") } else{ ni <- i } - save(run1, file = paste(outPath, paste("Run", ni, sep = ""), sep = "")) + + if ( save_runs == TRUE) { + run1 <- maFo_rf + save(run1, file = paste(outPath, paste("Run", ni, sep = ""), sep = "")) + remove(run1) + } ###rgdal version issue not_good_workaround <- comment(dummy@crs) comment(dummy@crs) <- "" @@ -312,12 +334,16 @@ multi_Class_Sampling <- function(in.raster, dummy <- maFo_rf@layer[[1]] dummy[dummy < thres] <- 1 dummy[dummy >= thres] <- NA + in.raster <- in.raster * dummy reference <- reference[-index,] - out.reference <<- reference classNames <- classNames[-index] - out.names <<- classNames - in.raster <- in.raster * dummy - out.raster <<- in.raster + if (save_runs) { + out.reference <<- reference + out.names <<- classNames + out.raster <<- in.raster + } + remove(dummy) + remove(maFo_rf) print(paste(paste("Habitat", i), "Done")) @@ -335,6 +361,8 @@ multi_Class_Sampling <- function(in.raster, paste("threshold_step_", ni, sep = ""), sep = "")) } + # Release memory + gc(full = TRUE) if (i == r) { print("Congratulation - you finally made it towards the last habitat") diff --git a/R-package/R/plot_interactive.r b/R-package/R/plot_interactive.r index 17c63efbb161a04b13327e80ae68c5f36b68deaf..7edb98876ce9c302bb72a1110ce5f8a268ef93f2 100644 --- a/R-package/R/plot_interactive.r +++ b/R-package/R/plot_interactive.r @@ -10,9 +10,10 @@ #' @param b blue channel (integer) #' @param acc predictive accuracy (integer) #' @param outPath file path for '.html export (character) +#' @param plot_on_browser plot on the browser or inline in a notebook (default TRUE) #' #' @export -iplot <- function(x, y, HaTy, r, g, b, acc, outPath) { +iplot <- function(x, y, HaTy, r, g, b, acc, outPath, plot_on_browser = TRUE) { #x=layerInfo, y=RGB Image ############################################################################## if (exists("color") == F) { @@ -165,18 +166,35 @@ iplot <- function(x, y, HaTy, r, g, b, acc, outPath) { file = paste(outPath, 'leaflet.html', sep = ""), append = TRUE ) - utils::browseURL(paste(outPath, 'leaflet.html', sep = - ""), browser = "firefox") + rm(mv) + if (plot_on_browser == TRUE) { + utils::browseURL(paste(outPath, 'leaflet.html', sep = ""), + browser = "firefox") + } else { + html_code = sprintf( + '', + paste(outPath, 'leaflet.html', sep = "") + ) + IRdisplay::display_html(html_code) + } } else { htmlwidgets::saveWidget(mv, selfcontained = FALSE, paste(outPath, 'leaflet.html', sep = "")) + rm(mv) cat( "", file = paste(outPath, 'leaflet.html', sep = ""), append = TRUE ) - utils::browseURL(paste(outPath, 'leaflet.html', sep = "")) + if (plot_on_browser == TRUE) { + utils::browseURL(paste(outPath, 'leaflet.html', sep = "")) + } else { + html_code = sprintf( + '', + paste(outPath, 'leaflet.html', sep = "")) + IRdisplay::display_html(html_code) + } } #cat("", # file = "leaflet.html", diff --git a/R-package/man/iplot.Rd b/R-package/man/iplot.Rd index 48a16ae341f9039530014eeeef775da6b59af324..8ff53f5a10f70f491cc75e00ed43de33a0921154 100644 --- a/R-package/man/iplot.Rd +++ b/R-package/man/iplot.Rd @@ -4,7 +4,7 @@ \alias{iplot} \title{Plot Habitat Types} \usage{ -iplot(x, y, HaTy, r, g, b, acc, outPath) +iplot(x, y, HaTy, r, g, b, acc, outPath, plot_on_browser = TRUE) } \arguments{ \item{x}{probability image (*rasterObject)} @@ -22,6 +22,8 @@ iplot(x, y, HaTy, r, g, b, acc, outPath) \item{acc}{predictive accuracy (integer)} \item{outPath}{file path for '.html export (character)} + +\item{plot_on_browser}{plot on the browser or inline in a notebook (default TRUE)} } \description{ A quick wrapper to produce an interactive raster map of habitat type probability in a web browser using leaflet diff --git a/R-package/man/multi_Class_Sampling.Rd b/R-package/man/multi_Class_Sampling.Rd index 55a288b8f1558261f8e7a16df97d4c3b94a3188c..e9ee9a47a204a8dbf5e53ff579ed233be2557b3f 100644 --- a/R-package/man/multi_Class_Sampling.Rd +++ b/R-package/man/multi_Class_Sampling.Rd @@ -24,7 +24,10 @@ multi_Class_Sampling( multiTest = 1, RGB = c(19, 20, 21), overwrite = TRUE, - parallel_mode = FALSE + save_runs = TRUE, + parallel_mode = FALSE, + max_num_cores = 5, + plot_on_browser = TRUE ) } \arguments{ @@ -64,15 +67,21 @@ multi_Class_Sampling( \item{RGB}{rgb channel numbers for image plot} -\item{overwrite}{overwrite the results file} +\item{overwrite}{overwrite the KML and raster files from previous runs (default TRUE)} -\item{parallel_mode}{run loops using all available cores} +\item{save_runs}{an Habitat object and extra info (to restart a run) is saved (default TRUE)} + +\item{parallel_mode}{run loops using all available cores (default FALSE)} + +\item{max_num_cores}{maximum number of cores for parallelism (default 5)} + +\item{plot_on_browser}{plot on the browser or inline in a notebook (default TRUE)} } \value{ 4 files per step: \enumerate{ \item Habitat type probability map as geocoded *.kml layer and *.tif raster files and *.png image output -\item A Habitat object consisting of 7 slots: \cr +\item A Habitat object (only if save_runs is set to TRUE) consisting of 7 slots: \cr run1@models - list of selcted classifiers \cr run1@ref_samples - list of SpatialPointsDataFrames with same length as run1@models holding reference labels \link{1,2} for each selected model \cr run1@switch - vector of lenght run1@models indicating if target class equals 2, if not NA the labels need to be switched \cr diff --git a/R-package/man/sample_nb.Rd b/R-package/man/sample_nb.Rd index da32d5d1e6f0efab1e89f94185fb4c75058e9e51..43c7a8061da411830401b098584d1cb6b217faed 100644 --- a/R-package/man/sample_nb.Rd +++ b/R-package/man/sample_nb.Rd @@ -18,7 +18,9 @@ sample_nb( last, seed, init.seed, - parallel_mode + save_runs, + parallel_mode, + max_num_cores ) } \arguments{ @@ -46,7 +48,11 @@ sample_nb( \item{init.seed}{"sample" for new or use run1@seeds to reproduce previous steps} -\item{parallel_mode}{run loops using all available cores} +\item{save_runs}{if the user wants to save the runs, if TRUE the complete Habitat Class object is returned} + +\item{parallel_mode}{run loops in parallel} + +\item{max_num_cores}{maximum number of cores for parallelism} \item{nb_models}{number of models (independent classifiers) to collect} } @@ -56,13 +62,13 @@ a list with 3 elements: \item An index \item Accuracy vector \item A vector with a Habitat objects, each consisting of 7 slots: \cr -run1@models - list of selected classifiers \cr -run1@ref_samples - list of SpatialPointsDataFrames with same length as run1@models holding reference labels \link{1,2} for each selected model \cr -run1@switch - vector of length run1@models indicating if target class equals 2, if not NA the labels need to be switched \cr +run1@models - list of selected classifiers (only if save_runs is TRUE) \cr +run1@ref_samples - list of SpatialPointsDataFrames with same length as run1@models holding reference labels \link{1,2} for each selected model (only if save_runs is TRUE) \cr +run1@switch - vector of length run1@models indicating if target class equals 2, if not NA the labels need to be switched (only if save_runs is TRUE) \cr run1@layer - raster map of habitat type probability \cr -run1@mod_all - list of all classifiers (equals nb_models) \cr -run1@class_ind - vector of predictive distance measure for all habitats \cr -run1@seeds - vector of seeds for random sampling \cr +run1@mod_all - list of all classifiers (equals nb_models) (only if save_runs is TRUE) \cr +run1@class_ind - vector of predictive distance measure for all habitats (only if save_runs is TRUE) \cr +run1@seeds - vector of seeds for random sampling (only if save_runs is TRUE) \cr all files are saved with step number, the *.tif file is additionally saved with class names } } diff --git a/demo/HabitatSampler.ipynb b/demo/HabitatSampler.ipynb index 67852415ae29aae2d89f56416892677c87986360..df023cfeca04ff5c5ed84281df2e8623af5a721f 100644 --- a/demo/HabitatSampler.ipynb +++ b/demo/HabitatSampler.ipynb @@ -27,31 +27,23 @@ "cell_type": "code", "execution_count": 1, "metadata": {}, - "outputs": [ - { - "name": "stderr", - "output_type": "stream", - "text": [ - "Installing package into ‘/home/romulo/R/x86_64-pc-linux-gnu-library/3.6’\n", - "(as ‘lib’ is unspecified)\n", - "\n", - "Installing package into ‘/home/romulo/R/x86_64-pc-linux-gnu-library/3.6’\n", - "(as ‘lib’ is unspecified)\n", - "\n", - "Installing package into ‘/home/romulo/R/x86_64-pc-linux-gnu-library/3.6’\n", - "(as ‘lib’ is unspecified)\n", - "\n", - "Installing package into ‘/home/romulo/R/x86_64-pc-linux-gnu-library/3.6’\n", - "(as ‘lib’ is unspecified)\n", - "\n" - ] - } - ], + "outputs": [], "source": [ - "install.packages(\"https://cran.r-project.org/src/contrib/Archive/BH/BH_1.69.0-1.tar.gz\", repos=NULL, type=\"source\")\n", - "install.packages(\"https://cran.r-project.org/src/contrib/Archive/sf/sf_0.8-1.tar.gz\", repos=NULL, type=\"source\")\n", - "install.packages(\"https://cran.r-project.org/src/contrib/Archive/sp/sp_1.4-1.tar.gz\", repos=NULL, type=\"source\")\n", - "install.packages(\"https://cran.r-project.org/src/contrib/Archive/rgdal/rgdal_1.4-8.tar.gz\", repos=NULL, type=\"source\") " + "install_dependencies <- FALSE" + ] + }, + { + "cell_type": "code", + "execution_count": 2, + "metadata": {}, + "outputs": [], + "source": [ + "if (install_dependencies == TRUE) {\n", + " install.packages(\"https://cran.r-project.org/src/contrib/Archive/BH/BH_1.69.0-1.tar.gz\", repos=NULL, type=\"source\")\n", + " install.packages(\"https://cran.r-project.org/src/contrib/Archive/sf/sf_0.8-1.tar.gz\", repos=NULL, type=\"source\")\n", + " install.packages(\"https://cran.r-project.org/src/contrib/Archive/sp/sp_1.4-1.tar.gz\", repos=NULL, type=\"source\")\n", + " install.packages(\"https://cran.r-project.org/src/contrib/Archive/rgdal/rgdal_1.4-8.tar.gz\", repos=NULL, type=\"source\") \n", + "}" ] }, { @@ -65,89 +57,18 @@ }, { "cell_type": "code", - "execution_count": 2, + "execution_count": 3, "metadata": {}, "outputs": [], "source": [ - "from_sources <- FALSE" + "from_sources <- TRUE" ] }, { "cell_type": "code", "execution_count": 4, "metadata": {}, - "outputs": [ - { - "name": "stderr", - "output_type": "stream", - "text": [ - "Downloading git repo https://git.gfz-potsdam.de/habitat-sampler/HabitatSampler.git\n", - "\n", - "'/usr/bin/git' clone --depth 1 --no-hardlinks https://git.gfz-potsdam.de/habitat-sampler/HabitatSampler.git /tmp/RtmpLaI3S7/filede3c1ec5d7e\n", - "\n", - "'/usr/bin/git' fetch origin performance\n", - "\n", - "'/usr/bin/git' checkout FETCH_HEAD\n", - "\n", - "Downloading package from url: https://cran.r-project.org/src/contrib/Archive/velox/velox_0.2.0.tar.gz\n", - "\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "text": [ - "\u001b[32m✔\u001b[39m \u001b[38;5;247mchecking for file ‘/tmp/RtmpLaI3S7/remotesde3c5959756f/velox/DESCRIPTION’\u001b[39m\u001b[36m\u001b[39m\n", - "\u001b[38;5;247m─\u001b[39m\u001b[38;5;247m \u001b[39m\u001b[38;5;247mpreparing ‘velox’:\u001b[39m\u001b[36m\u001b[39m\n", - "\u001b[32m✔\u001b[39m \u001b[38;5;247mchecking DESCRIPTION meta-information\u001b[39m\u001b[36m\u001b[39m\n", - "\u001b[38;5;247m─\u001b[39m\u001b[38;5;247m \u001b[39m\u001b[38;5;247mcleaning src\u001b[39m\u001b[36m\u001b[39m\n", - "\u001b[38;5;247m─\u001b[39m\u001b[38;5;247m \u001b[39m\u001b[38;5;247mchecking for LF line-endings in source and make files and shell scripts\u001b[39m\u001b[36m\u001b[39m\n", - "\u001b[38;5;247m─\u001b[39m\u001b[38;5;247m \u001b[39m\u001b[38;5;247mchecking for empty or unneeded directories\u001b[39m\u001b[36m\u001b[39m\n", - "\u001b[38;5;247m─\u001b[39m\u001b[38;5;247m \u001b[39m\u001b[38;5;247mbuilding ‘velox_0.2.0.tar.gz’\u001b[39m\u001b[36m\u001b[39m\n", - " \n", - "\r" - ] - }, - { - "name": "stderr", - "output_type": "stream", - "text": [ - "Installing package into ‘/home/romulo/R/x86_64-pc-linux-gnu-library/3.6’\n", - "(as ‘lib’ is unspecified)\n", - "\n", - "Downloading package from url: https://cran.r-project.org/src/contrib/Archive/velox/velox_0.2.0.tar.gz\n", - "\n", - "Skipping velox, it is already being installed\n", - "\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "text": [ - "\u001b[32m✔\u001b[39m \u001b[38;5;247mchecking for file ‘/tmp/RtmpLaI3S7/filede3c1ec5d7e/R-package/DESCRIPTION’\u001b[39m\u001b[36m\u001b[39m\n", - "\u001b[38;5;247m─\u001b[39m\u001b[38;5;247m \u001b[39m\u001b[38;5;247mpreparing ‘HaSa’:\u001b[39m\u001b[36m\u001b[39m\n", - "\u001b[32m✔\u001b[39m \u001b[38;5;247mchecking DESCRIPTION meta-information\u001b[39m\u001b[36m\u001b[39m\n", - "\u001b[38;5;247m─\u001b[39m\u001b[38;5;247m \u001b[39m\u001b[38;5;247minstalling the package to build vignettes\u001b[39m\u001b[36m\u001b[39m\n", - "\u001b[32m✔\u001b[39m \u001b[38;5;247mcreating vignettes\u001b[39m\u001b[36m\u001b[36m (1.5s)\u001b[36m\u001b[39m\n", - "\u001b[38;5;247m─\u001b[39m\u001b[38;5;247m \u001b[39m\u001b[38;5;247mchecking for LF line-endings in source and make files and shell scripts\u001b[39m\u001b[36m\u001b[39m\n", - "\u001b[38;5;247m─\u001b[39m\u001b[38;5;247m \u001b[39m\u001b[38;5;247mchecking for empty or unneeded directories\u001b[39m\u001b[36m\u001b[39m\n", - "\u001b[38;5;247m─\u001b[39m\u001b[38;5;247m \u001b[39m\u001b[38;5;247mlooking to see if a ‘data/datalist’ file should be added\u001b[39m\u001b[36m\u001b[39m\n", - "\u001b[38;5;247m─\u001b[39m\u001b[38;5;247m \u001b[39m\u001b[38;5;247mbuilding ‘HaSa_1.1.0.tar.gz’\u001b[39m\u001b[36m\u001b[39m\n", - " \n", - "\r" - ] - }, - { - "name": "stderr", - "output_type": "stream", - "text": [ - "Installing package into ‘/home/romulo/R/x86_64-pc-linux-gnu-library/3.6’\n", - "(as ‘lib’ is unspecified)\n", - "\n" - ] - } - ], + "outputs": [], "source": [ "if (from_sources == TRUE) {\n", " wd<-\"./\"\n", @@ -247,15 +168,6 @@ " Linking to sp version: 1.4-5 \n", " Polygon checking: TRUE \n", "\n", - "\n", - "\n", - "Attaching package: ‘HaSa’\n", - "\n", - "\n", - "The following object is masked from ‘package:graphics’:\n", - "\n", - " clip\n", - "\n", "\n" ] }, @@ -345,7 +257,7 @@ ".list-inline>li {display: inline-block}\n", ".list-inline>li:not(:last-child)::after {content: \"\\00b7\"; padding: 0 .5ex}\n", "\n", - "
  1. 'HaSa'
  2. 'htmlwidgets'
  3. 'leaflet'
  4. 'rgeos'
  5. 'velox'
  6. 'devtools'
  7. 'usethis'
  8. 'e1071'
  9. 'randomForest'
  10. 'spatialEco'
  11. 'maptools'
  12. 'raster'
  13. 'rgdal'
  14. 'sp'
  15. 'stats'
  16. 'graphics'
  17. 'grDevices'
  18. 'utils'
  19. 'datasets'
  20. 'methods'
  21. 'base'
\n", + "
  1. 'IRdisplay'
  2. 'htmlwidgets'
  3. 'leaflet'
  4. 'rgeos'
  5. 'velox'
  6. 'devtools'
  7. 'usethis'
  8. 'e1071'
  9. 'randomForest'
  10. 'spatialEco'
  11. 'maptools'
  12. 'raster'
  13. 'rgdal'
  14. 'sp'
  15. 'stats'
  16. 'graphics'
  17. 'grDevices'
  18. 'utils'
  19. 'datasets'
  20. 'methods'
  21. 'base'
\n", "\n", "\n" ], @@ -544,7 +456,7 @@ "\\end{enumerate*}\n", "\n", "\\item \\begin{enumerate*}\n", - "\\item 'HaSa'\n", + "\\item 'IRdisplay'\n", "\\item 'htmlwidgets'\n", "\\item 'leaflet'\n", "\\item 'rgeos'\n", @@ -762,7 +674,7 @@ "\n", "\n", "\n", - "12. 1. 'HaSa'\n", + "12. 1. 'IRdisplay'\n", "2. 'htmlwidgets'\n", "3. 'leaflet'\n", "4. 'rgeos'\n", @@ -848,7 +760,7 @@ "[16] \"grDevices\" \"utils\" \"datasets\" \"methods\" \"base\" \n", "\n", "[[12]]\n", - " [1] \"HaSa\" \"htmlwidgets\" \"leaflet\" \"rgeos\" \"velox\" \n", + " [1] \"IRdisplay\" \"htmlwidgets\" \"leaflet\" \"rgeos\" \"velox\" \n", " [6] \"devtools\" \"usethis\" \"e1071\" \"randomForest\" \"spatialEco\" \n", "[11] \"maptools\" \"raster\" \"rgdal\" \"sp\" \"stats\" \n", "[16] \"graphics\" \"grDevices\" \"utils\" \"datasets\" \"methods\" \n", @@ -860,10 +772,11 @@ } ], "source": [ + "options(\"rgdal_show_exportToProj4_warnings\"=\"none\")\n", "if (from_sources == TRUE) {\n", - " libraries <- c(\"rgdal\",\"raster\",\"maptools\",\"spatialEco\",\"randomForest\",\"e1071\",\"devtools\",\"velox\",\"rgeos\",\"leaflet\",\"htmlwidgets\")\n", + " libraries <- c(\"rgdal\",\"raster\",\"maptools\",\"spatialEco\",\"randomForest\",\"e1071\",\"devtools\",\"velox\",\"rgeos\",\"leaflet\",\"htmlwidgets\", \"IRdisplay\")\n", "} else {\n", - " libraries <- c(\"rgdal\",\"raster\",\"maptools\",\"spatialEco\",\"randomForest\",\"e1071\",\"devtools\",\"velox\",\"rgeos\",\"leaflet\",\"htmlwidgets\", \"HaSa\")\n", + " libraries <- c(\"rgdal\",\"raster\",\"maptools\",\"spatialEco\",\"randomForest\",\"e1071\",\"devtools\",\"velox\",\"rgeos\",\"leaflet\",\"htmlwidgets\", \"IRdisplay\", \"HaSa\")\n", "}\n", "lapply(libraries, library, character.only = TRUE)" ] @@ -1071,6 +984,15 @@ "classNames<-c(\"deciduous\",\"coniferous\",\"heather_young\",\"heather_old\",\"heather_shrub\",\"bare_ground\",\"xeric_grass\")" ] }, + { + "cell_type": "code", + "execution_count": 14, + "metadata": {}, + "outputs": [], + "source": [ + "library(profvis)" + ] + }, { "cell_type": "markdown", "metadata": {}, @@ -1080,30 +1002,39 @@ }, { "cell_type": "code", - "execution_count": 14, + "execution_count": 15, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ - "[1] \"init.samples = 50 models = 200\"\n", - "[1] \"class=4 difference=0.84\"\n", + "[1] \"init.samples = 75 models = 220\"\n", + "[1] \"class=5 difference=0.8\"\n", "\n" ] }, + { + "data": { + "text/html": [ + "" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, { "name": "stdin", "output_type": "stream", "text": [ - "Threshold for Habitat Extraction or Sample Again [../0]: 16\n" + "Threshold for Habitat Extraction or Sample Again [../0]: 15\n" ] }, { "name": "stdout", "output_type": "stream", "text": [ - "[1] \"n_models = 9\"\n", + "[1] \"n_models = 8\"\n", "[1] 1\n", "[1] 2\n", "[1] 3\n", @@ -1111,8 +1042,7 @@ "[1] 5\n", "[1] 6\n", "[1] 7\n", - "[1] 8\n", - "[1] 9\n" + "[1] 8\n" ] }, { @@ -1127,23 +1057,32 @@ "output_type": "stream", "text": [ "[1] \"Habitat 1 Done\"\n", - "[1] \"init.samples = 100 models = 215\"\n", - "[1] \"class=4 difference=0.8\"\n", + "[1] \"init.samples = 125 models = 235\"\n", + "[1] \"class=4 difference=0.88\"\n", "\n" ] }, + { + "data": { + "text/html": [ + "" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, { "name": "stdin", "output_type": "stream", "text": [ - "Threshold for Habitat Extraction or Sample Again [../0]: 32\n" + "Threshold for Habitat Extraction or Sample Again [../0]: 24\n" ] }, { "name": "stdout", "output_type": "stream", "text": [ - "[1] \"n_models = 17\"\n", + "[1] \"n_models = 13\"\n", "[1] 1\n", "[1] 2\n", "[1] 3\n", @@ -1156,11 +1095,7 @@ "[1] 10\n", "[1] 11\n", "[1] 12\n", - "[1] 13\n", - "[1] 14\n", - "[1] 15\n", - "[1] 16\n", - "[1] 17\n" + "[1] 13\n" ] }, { @@ -1175,23 +1110,32 @@ "output_type": "stream", "text": [ "[1] \"Habitat 2 Done\"\n", - "[1] \"init.samples = 150 models = 230\"\n", - "[1] \"class=2 difference=0.92\"\n", + "[1] \"init.samples = 175 models = 250\"\n", + "[1] \"class=3 difference=0.84\"\n", "\n" ] }, + { + "data": { + "text/html": [ + "" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, { "name": "stdin", "output_type": "stream", "text": [ - "Threshold for Habitat Extraction or Sample Again [../0]: 44\n" + "Threshold for Habitat Extraction or Sample Again [../0]: 40\n" ] }, { "name": "stdout", "output_type": "stream", "text": [ - "[1] \"n_models = 25\"\n", + "[1] \"n_models = 22\"\n", "[1] 1\n", "[1] 2\n", "[1] 3\n", @@ -1213,10 +1157,7 @@ "[1] 19\n", "[1] 20\n", "[1] 21\n", - "[1] 22\n", - "[1] 23\n", - "[1] 24\n", - "[1] 25\n" + "[1] 22\n" ] }, { @@ -1231,23 +1172,32 @@ "output_type": "stream", "text": [ "[1] \"Habitat 3 Done\"\n", - "[1] \"init.samples = 200 models = 245\"\n", - "[1] \"class=1 difference=0.96\"\n", + "[1] \"init.samples = 225 models = 265\"\n", + "[1] \"class=3 difference=0.92\"\n", "\n" ] }, + { + "data": { + "text/html": [ + "" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, { "name": "stdin", "output_type": "stream", "text": [ - "Threshold for Habitat Extraction or Sample Again [../0]: 110\n" + "Threshold for Habitat Extraction or Sample Again [../0]: 55\n" ] }, { "name": "stdout", "output_type": "stream", "text": [ - "[1] \"n_models = 61\"\n", + "[1] \"n_models = 30\"\n", "[1] 1\n", "[1] 2\n", "[1] 3\n", @@ -1277,38 +1227,7 @@ "[1] 27\n", "[1] 28\n", "[1] 29\n", - "[1] 30\n", - "[1] 31\n", - "[1] 32\n", - "[1] 33\n", - "[1] 34\n", - "[1] 35\n", - "[1] 36\n", - "[1] 37\n", - "[1] 38\n", - "[1] 39\n", - "[1] 40\n", - "[1] 41\n", - "[1] 42\n", - "[1] 43\n", - "[1] 44\n", - "[1] 45\n", - "[1] 46\n", - "[1] 47\n", - "[1] 48\n", - "[1] 49\n", - "[1] 50\n", - "[1] 51\n", - "[1] 52\n", - "[1] 53\n", - "[1] 54\n", - "[1] 55\n", - "[1] 56\n", - "[1] 57\n", - "[1] 58\n", - "[1] 59\n", - "[1] 60\n", - "[1] 61\n" + "[1] 30\n" ] }, { @@ -1323,23 +1242,32 @@ "output_type": "stream", "text": [ "[1] \"Habitat 4 Done\"\n", - "[1] \"init.samples = 250 models = 260\"\n", - "[1] \"class=1 difference=0.96\"\n", + "[1] \"init.samples = 275 models = 280\"\n", + "[1] \"class=2 difference=0.96\"\n", "\n" ] }, + { + "data": { + "text/html": [ + "" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, { "name": "stdin", "output_type": "stream", "text": [ - "Threshold for Habitat Extraction or Sample Again [../0]: 120\n" + "Threshold for Habitat Extraction or Sample Again [../0]: 85\n" ] }, { "name": "stdout", "output_type": "stream", "text": [ - "[1] \"n_models = 67\"\n", + "[1] \"n_models = 47\"\n", "[1] 1\n", "[1] 2\n", "[1] 3\n", @@ -1386,27 +1314,7 @@ "[1] 44\n", "[1] 45\n", "[1] 46\n", - "[1] 47\n", - "[1] 48\n", - "[1] 49\n", - "[1] 50\n", - "[1] 51\n", - "[1] 52\n", - "[1] 53\n", - "[1] 54\n", - "[1] 55\n", - "[1] 56\n", - "[1] 57\n", - "[1] 58\n", - "[1] 59\n", - "[1] 60\n", - "[1] 61\n", - "[1] 62\n", - "[1] 63\n", - "[1] 64\n", - "[1] 65\n", - "[1] 66\n", - "[1] 67\n" + "[1] 47\n" ] }, { @@ -1421,23 +1329,32 @@ "output_type": "stream", "text": [ "[1] \"Habitat 5 Done\"\n", - "[1] \"init.samples = 300 models = 275\"\n", - "[1] \"class=1 difference=0.96\"\n", + "[1] \"init.samples = 325 models = 295\"\n", + "[1] \"class=1 difference=1\"\n", "\n" ] }, + { + "data": { + "text/html": [ + "" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, { "name": "stdin", "output_type": "stream", "text": [ - "Threshold for Habitat Extraction or Sample Again [../0]: 150\n" + "Threshold for Habitat Extraction or Sample Again [../0]: 270\n" ] }, { "name": "stdout", "output_type": "stream", "text": [ - "[1] \"n_models = 81\"\n", + "[1] \"n_models = 144\"\n", "[1] 1\n", "[1] 2\n", "[1] 3\n", @@ -1518,7 +1435,70 @@ "[1] 78\n", "[1] 79\n", "[1] 80\n", - "[1] 81\n" + "[1] 81\n", + "[1] 82\n", + "[1] 83\n", + "[1] 84\n", + "[1] 85\n", + "[1] 86\n", + "[1] 87\n", + "[1] 88\n", + "[1] 89\n", + "[1] 90\n", + "[1] 91\n", + "[1] 92\n", + "[1] 93\n", + "[1] 94\n", + "[1] 95\n", + "[1] 96\n", + "[1] 97\n", + "[1] 98\n", + "[1] 99\n", + "[1] 100\n", + "[1] 101\n", + "[1] 102\n", + "[1] 103\n", + "[1] 104\n", + "[1] 105\n", + "[1] 106\n", + "[1] 107\n", + "[1] 108\n", + "[1] 109\n", + "[1] 110\n", + "[1] 111\n", + "[1] 112\n", + "[1] 113\n", + "[1] 114\n", + "[1] 115\n", + "[1] 116\n", + "[1] 117\n", + "[1] 118\n", + "[1] 119\n", + "[1] 120\n", + "[1] 121\n", + "[1] 122\n", + "[1] 123\n", + "[1] 124\n", + "[1] 125\n", + "[1] 126\n", + "[1] 127\n", + "[1] 128\n", + "[1] 129\n", + "[1] 130\n", + "[1] 131\n", + "[1] 132\n", + "[1] 133\n", + "[1] 134\n", + "[1] 135\n", + "[1] 136\n", + "[1] 137\n", + "[1] 138\n", + "[1] 139\n", + "[1] 140\n", + "[1] 141\n", + "[1] 142\n", + "[1] 143\n", + "[1] 144\n" ] }, { @@ -1533,23 +1513,32 @@ "output_type": "stream", "text": [ "[1] \"Habitat 6 Done\"\n", - "[1] \"init.samples = 350 models = 290\"\n", + "[1] \"init.samples = 375 models = 310\"\n", "[1] \"class=1 difference=0.92\"\n", "\n" ] }, + { + "data": { + "text/html": [ + "" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, { "name": "stdin", "output_type": "stream", "text": [ - "Threshold for Habitat Extraction or Sample Again [../0]: 65\n" + "Threshold for Habitat Extraction or Sample Again [../0]: 72\n" ] }, { "name": "stdout", "output_type": "stream", "text": [ - "[1] \"n_models = 37\"\n", + "[1] \"n_models = 39\"\n", "[1] 1\n", "[1] 2\n", "[1] 3\n", @@ -1587,17 +1576,19 @@ "[1] 35\n", "[1] 36\n", "[1] 37\n", + "[1] 38\n", + "[1] 39\n", "[1] \"Habitat 7 Done\"\n", "[1] \"Congratulation - you finally made it towards the last habitat\"\n" ] } ], "source": [ - "multi_Class_Sampling(\n", + "pros <- profvis(multi_Class_Sampling(\n", " in.raster = a1,\n", - " init.samples = 50,\n", + " init.samples = 75,\n", " sample_type = \"regular\",\n", - " nb_models = 200,\n", + " nb_models = 220,\n", " nb_it = 10,\n", " buffer = 15,\n", " reference = ref,\n", @@ -1612,8 +1603,108 @@ " n_classes = 7,\n", " multiTest = 1,\n", " RGB = c(19,20,21),\n", - " overwrite=TRUE,\n", - " parallel_mode=TRUE)" + " overwrite = TRUE,\n", + " save_runs = FALSE,\n", + " parallel_mode = TRUE,\n", + " max_num_cores = 7,\n", + " plot_on_browser = FALSE))" + ] + }, + { + "cell_type": "code", + "execution_count": 16, + "metadata": {}, + "outputs": [ + { + "data": { + "text/html": [ + "\n", + "\n", + "\t\n", + "\t\t\n", + "\t\t\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\t\n", + "\t\n", + "\t\t
\n", + "