diff --git a/R/api_smooth.R b/R/api_smooth.R index 07ac57d5d..7ae976ea0 100644 --- a/R/api_smooth.R +++ b/R/api_smooth.R @@ -16,6 +16,7 @@ band, block, overlap, + exclusion_mask, smooth_fn, output_dir, version) { @@ -39,6 +40,19 @@ } # Create chunks as jobs chunks <- .tile_chunks_create(tile = tile, overlap = overlap, block = block) + # Calculate exclusion mask + if (.has(exclusion_mask)) { + # Remove chunks within the exclusion mask + chunks <- .chunks_filter_mask( + chunks = chunks, + mask = exclusion_mask + ) + + exclusion_mask <- .chunks_crop_mask( + chunks = chunks, + mask = exclusion_mask + ) + } # Process jobs in parallel block_files <- .jobs_map_parallel_chr(chunks, function(chunk) { # Job block @@ -96,6 +110,15 @@ multicores = .jobs_multicores(), update_bbox = FALSE ) + # Exclude masked areas + probs_tile <- .crop( + cube = probs_tile, + roi = exclusion_mask, + output_dir = output_dir, + multicores = 1, + overwrite = TRUE, + progress = FALSE + ) # Return probs tile probs_tile } @@ -124,6 +147,7 @@ window_size, neigh_fraction, smoothness, + exclusion_mask, multicores, memsize, output_dir, @@ -146,6 +170,7 @@ band = "bayes", block = block, overlap = overlap, + exclusion_mask = exclusion_mask, smooth_fn = smooth_fn, output_dir = output_dir, version = version diff --git a/R/sits_smooth.R b/R/sits_smooth.R index 4843058ef..3afd49f9c 100644 --- a/R/sits_smooth.R +++ b/R/sits_smooth.R @@ -18,6 +18,9 @@ #' @param smoothness Estimated variance of logit of class probabilities #' (Bayesian smoothing parameter) #' (integer vector or scalar, min = 1, max = 200). +#' @param exclusion_mask Areas to be excluded from the classification +#' process. It can be defined as a sf object or a +#' shapefile. #' @param memsize Memory available for classification in GB #' (integer, min = 1, max = 16384). #' @param multicores Number of cores to be used for classification @@ -63,6 +66,7 @@ sits_smooth <- function(cube, window_size = 9L, neigh_fraction = 0.5, smoothness = 20L, + exclusion_mask = NULL, memsize = 4L, multicores = 2L, output_dir, @@ -100,6 +104,7 @@ sits_smooth.probs_cube <- function(cube, window_size = 9L, neigh_fraction = 0.5, smoothness = 20L, + exclusion_mask = NULL, memsize = 4L, multicores = 2L, output_dir, @@ -147,6 +152,7 @@ sits_smooth.probs_cube <- function(cube, window_size = window_size, neigh_fraction = neigh_fraction, smoothness = smoothness, + exclusion_mask = exclusion_mask, multicores = multicores, memsize = memsize, output_dir = output_dir, @@ -159,6 +165,7 @@ sits_smooth.raster_cube <- function(cube, window_size = 7L, neigh_fraction = 0.5, smoothness = 10L, + exclusion_mask = NULL, memsize = 4L, multicores = 2L, output_dir, @@ -170,6 +177,7 @@ sits_smooth.raster_cube <- function(cube, sits_smooth.derived_cube <- function(cube, window_size = 7L, neigh_fraction = 0.5, smoothness = 10L, + exclusion_mask = NULL, memsize = 4L, multicores = 2L, output_dir, @@ -182,6 +190,7 @@ sits_smooth.default <- function(cube, window_size = 7L, neigh_fraction = 0.5, smoothness = 10L, + exclusion_mask = NULL, memsize = 4L, multicores = 2L, output_dir, @@ -196,6 +205,7 @@ sits_smooth.default <- function(cube, window_size = 7L, neigh_fraction = 0.5, smoothness = 10L, + exclusion_mask = NULL, memsize = 4L, multicores = 2L, output_dir, diff --git a/man/sits_smooth.Rd b/man/sits_smooth.Rd index e3adecc11..e6d933bff 100644 --- a/man/sits_smooth.Rd +++ b/man/sits_smooth.Rd @@ -13,6 +13,7 @@ sits_smooth( window_size = 9L, neigh_fraction = 0.5, smoothness = 20L, + exclusion_mask = NULL, memsize = 4L, multicores = 2L, output_dir, @@ -24,6 +25,7 @@ sits_smooth( window_size = 9L, neigh_fraction = 0.5, smoothness = 20L, + exclusion_mask = NULL, memsize = 4L, multicores = 2L, output_dir, @@ -35,6 +37,7 @@ sits_smooth( window_size = 7L, neigh_fraction = 0.5, smoothness = 10L, + exclusion_mask = NULL, memsize = 4L, multicores = 2L, output_dir, @@ -46,6 +49,7 @@ sits_smooth( window_size = 7L, neigh_fraction = 0.5, smoothness = 10L, + exclusion_mask = NULL, memsize = 4L, multicores = 2L, output_dir, @@ -57,6 +61,7 @@ sits_smooth( window_size = 7L, neigh_fraction = 0.5, smoothness = 10L, + exclusion_mask = NULL, memsize = 4L, multicores = 2L, output_dir, @@ -77,6 +82,10 @@ to be used in Bayesian inference. (Bayesian smoothing parameter) (integer vector or scalar, min = 1, max = 200).} +\item{exclusion_mask}{Areas to be excluded from the classification +process. It can be defined as a sf object or a +shapefile.} + \item{memsize}{Memory available for classification in GB (integer, min = 1, max = 16384).}