From 6db9048e25ffcc8e274a96618fd46adcccc0008e Mon Sep 17 00:00:00 2001 From: Felipe Carlos Date: Tue, 19 Nov 2024 12:07:43 -0300 Subject: [PATCH 1/2] add exclusion mask for sits_smooth --- R/api_smooth.R | 25 +++++++++++++++++++++++++ R/sits_smooth.R | 10 ++++++++++ man/sits_smooth.Rd | 9 +++++++++ 3 files changed, 44 insertions(+) diff --git a/R/api_smooth.R b/R/api_smooth.R index d30d924f4..f4f27c258 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 90944da5d..ba53a3baf 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 = 7L, neigh_fraction = 0.5, smoothness = 10L, + exclusion_mask = NULL, memsize = 4L, multicores = 2L, output_dir, @@ -100,6 +104,7 @@ sits_smooth.probs_cube <- function(cube, window_size = 7L, neigh_fraction = 0.5, smoothness = 10L, + 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 c35a8c91d..9a6f290ab 100644 --- a/man/sits_smooth.Rd +++ b/man/sits_smooth.Rd @@ -13,6 +13,7 @@ sits_smooth( window_size = 7L, neigh_fraction = 0.5, smoothness = 10L, + exclusion_mask = NULL, memsize = 4L, multicores = 2L, output_dir, @@ -24,6 +25,7 @@ sits_smooth( window_size = 7L, neigh_fraction = 0.5, smoothness = 10L, + 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).} From 5d0a3025e3341e62c27937628dce447a4c55b56b Mon Sep 17 00:00:00 2001 From: Felipe Carlos Date: Tue, 19 Nov 2024 12:11:58 -0300 Subject: [PATCH 2/2] update sits_smooth docs --- man/sits_smooth.Rd | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/man/sits_smooth.Rd b/man/sits_smooth.Rd index fff939f9e..e6d933bff 100644 --- a/man/sits_smooth.Rd +++ b/man/sits_smooth.Rd @@ -12,7 +12,7 @@ sits_smooth( cube, window_size = 9L, neigh_fraction = 0.5, - smoothness = 10L, + smoothness = 20L, exclusion_mask = NULL, memsize = 4L, multicores = 2L, @@ -24,7 +24,7 @@ sits_smooth( cube, window_size = 9L, neigh_fraction = 0.5, - smoothness = 10L, + smoothness = 20L, exclusion_mask = NULL, memsize = 4L, multicores = 2L,