Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add exclusion mask for sits_smooth #1241

Merged
merged 3 commits into from
Nov 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions R/api_smooth.R
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
band,
block,
overlap,
exclusion_mask,
smooth_fn,
output_dir,
version) {
Expand All @@ -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
Expand Down Expand Up @@ -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
}
Expand Down Expand Up @@ -124,6 +147,7 @@
window_size,
neigh_fraction,
smoothness,
exclusion_mask,
multicores,
memsize,
output_dir,
Expand All @@ -146,6 +170,7 @@
band = "bayes",
block = block,
overlap = overlap,
exclusion_mask = exclusion_mask,
smooth_fn = smooth_fn,
output_dir = output_dir,
version = version
Expand Down
10 changes: 10 additions & 0 deletions R/sits_smooth.R
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand All @@ -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,
Expand All @@ -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,
Expand All @@ -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,
Expand All @@ -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,
Expand Down
9 changes: 9 additions & 0 deletions man/sits_smooth.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading