Commit 2b7e90b8 authored by Romulo Pereira Goncalves's avatar Romulo Pereira Goncalves
Browse files

Only pass one raster, and the one that is in memory.

parent f5b1bf63
...@@ -112,7 +112,7 @@ sample_nb <- function(raster, ...@@ -112,7 +112,7 @@ sample_nb <- function(raster,
res <- parallel::mclapply( res <- parallel::mclapply(
1:nb_mean, 1:nb_mean,
model_opt_r, model_opt_r,
raster = raster, raster = rast,
sample_type = sample_type, sample_type = sample_type,
buffer = buffer, buffer = buffer,
model = model, model = model,
...@@ -124,7 +124,6 @@ sample_nb <- function(raster, ...@@ -124,7 +124,6 @@ sample_nb <- function(raster,
mtry = mtry, mtry = mtry,
mod.error = mod.error, mod.error = mod.error,
pbtn1 = pbtn1, pbtn1 = pbtn1,
rast = rast,
max_samples_per_class = max_samples_per_class, max_samples_per_class = max_samples_per_class,
mc.cores = cores, mc.cores = cores,
mc.preschedule = TRUE, mc.preschedule = TRUE,
...@@ -138,7 +137,7 @@ sample_nb <- function(raster, ...@@ -138,7 +137,7 @@ sample_nb <- function(raster,
} else { } else {
for (k in 1:nb_mean) { for (k in 1:nb_mean) {
res <- model_opt_r( res <- model_opt_r(
raster = raster, raster = rast,
sample_type = sample_type, sample_type = sample_type,
buffer = buffer, buffer = buffer,
model = model, model = model,
...@@ -151,7 +150,6 @@ sample_nb <- function(raster, ...@@ -151,7 +150,6 @@ sample_nb <- function(raster,
mtry = mtry, mtry = mtry,
mod.error = mod.error, mod.error = mod.error,
pbtn1 = pbtn1, pbtn1 = pbtn1,
rast = rast,
max_samples_per_class = max_samples_per_class max_samples_per_class = max_samples_per_class
) )
points_list[[k]] <- res$points points_list[[k]] <- res$points
......
...@@ -15,7 +15,6 @@ ...@@ -15,7 +15,6 @@
#' @param mtry number of predictor used at random forest splitting nodes (mtry << n predictors) #' @param mtry number of predictor used at random forest splitting nodes (mtry << n predictors)
#' @param mod.error threshold for model error until which iteration is being executed #' @param mod.error threshold for model error until which iteration is being executed
#' @param pbtn1 matrix for points #' @param pbtn1 matrix for points
#' @param rast raster
#' @param max_samples_per_class maximum number of samples per class #' @param max_samples_per_class maximum number of samples per class
#' #'
#' @return a list with 4 elements: #' @return a list with 4 elements:
...@@ -37,12 +36,11 @@ model_opt_r <- function(k, ...@@ -37,12 +36,11 @@ model_opt_r <- function(k,
mtry, mtry,
mod.error, mod.error,
pbtn1, pbtn1,
rast,
max_samples_per_class) { max_samples_per_class) {
points <- NULL points <- NULL
models <- NULL models <- NULL
oobe <- matrix(NA, nrow = n, ncol = 1) oobe <- matrix(NA, nrow = n, ncol = 1)
rast <- raster::mask(rast, raster::calc(rast, fun = sum)) rast <- raster::mask(raster, raster::calc(raster, fun = sum))
for (j in 1:n) { for (j in 1:n) {
###Vorbereitung Klassifizierung ###Vorbereitung Klassifizierung
if (j == 1) { if (j == 1) {
...@@ -152,7 +150,7 @@ model_opt_r <- function(k, ...@@ -152,7 +150,7 @@ model_opt_r <- function(k,
nam <- nam <-
as.vector(fasterize::fasterize(sf::st_as_sf(poly), rast[[1]], field = "V1"))[-attr(test1, "na.action")] as.vector(fasterize::fasterize(sf::st_as_sf(poly), rast[[1]], field = "V1"))[-attr(test1, "na.action")]
co<-raster::xyFromCell(rast, c(1:raster::ncell(rast))[-attr(test1,"na.action")]) co <- raster::xyFromCell(rast, c(1:raster::ncell(rast))[-attr(test1,"na.action")])
pbtn1 <- as.data.frame(cbind(nam, co)) pbtn1 <- as.data.frame(cbind(nam, co))
sp::coordinates(pbtn1) <- c("x", "y") sp::coordinates(pbtn1) <- c("x", "y")
......
...@@ -18,7 +18,6 @@ model_opt_r( ...@@ -18,7 +18,6 @@ model_opt_r(
mtry, mtry,
mod.error, mod.error,
pbtn1, pbtn1,
rast,
max_samples_per_class max_samples_per_class
) )
} }
...@@ -49,8 +48,6 @@ model_opt_r( ...@@ -49,8 +48,6 @@ model_opt_r(
\item{pbtn1}{matrix for points} \item{pbtn1}{matrix for points}
\item{rast}{raster}
\item{max_samples_per_class}{maximum number of samples per class} \item{max_samples_per_class}{maximum number of samples per class}
} }
\value{ \value{
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment