Skip to content

Commit

Permalink
remove messages in documentation mode
Browse files Browse the repository at this point in the history
  • Loading branch information
gilbertocamara committed Apr 29, 2023
1 parent 38ac57d commit 7df10d2
Show file tree
Hide file tree
Showing 18 changed files with 138 additions and 85 deletions.
13 changes: 8 additions & 5 deletions R/api_apply.R
Original file line number Diff line number Diff line change
Expand Up @@ -47,11 +47,14 @@
# # Callback final tile classification
# .callback(process = "Apply", event = "recovery",
# context = environment())
message("Recovery: band ",
paste0("'", out_band, "'", collapse = ", "),
" already exists.")
message("(If you want to produce a new image, please ",
"change 'output_dir' or 'version' parameters)")
if (.check_messages()) {
message("Recovery: band ",
paste0("'", out_band, "'", collapse = ", "),
" already exists.")
message("(If you want to produce a new image, please ",
"change 'output_dir' or 'version' parameters)")
}

# Create tile based on template
feature <- .tile_eo_from_files(
files = out_file, fid = .fi_fid(.fi(feature)),
Expand Down
14 changes: 14 additions & 0 deletions R/api_check.R
Original file line number Diff line number Diff line change
Expand Up @@ -2247,6 +2247,20 @@

return(progress)
}
#' @title Checks if messages should be displayed
#' @name .check_messages
#' @return TRUE/FALSE
#' @keywords internal
#' @noRd
.check_messages <- function() {
# if working on sits documentation mode, no progress bar
if (Sys.getenv("SITS_DOCUMENTATION_MODE") == "true" ||
Sys.getenv("SITS_DOCUMENTATION_MODE") == "TRUE") {
return(FALSE)
}
else
return(TRUE)
}

.check_stac_items <- function(items) {
.check_that(
Expand Down
11 changes: 5 additions & 6 deletions R/api_combine_predictions.R
Original file line number Diff line number Diff line change
Expand Up @@ -76,12 +76,11 @@
)
# Resume feature
if (file.exists(out_file)) {
# # Callback final tile classification
# .callback(process = "tile_classification", event = "recovery",
# context = environment())
message("Recovery: tile '", base_tile[["tile"]], "' already exists.")
message("(If you want to produce a new probability image, please ",
"change 'output_dir' or 'version' parameters)")
if (.check_messages()) {
message("Recovery: tile '", base_tile[["tile"]], "' already exists.")
message("(If you want to produce a new probability image, please ",
"change 'output_dir' or 'version' parameters)")
}
probs_tile <- .tile_probs_from_file(
file = out_file,
band = band,
Expand Down
11 changes: 5 additions & 6 deletions R/api_label_class.R
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,11 @@
)
# Resume feature
if (file.exists(out_file)) {
# # Callback final tile classification
# .callback(process = "tile_classification", event = "recovery",
# context = environment())
message("Recovery: tile '", tile[["tile"]], "' already exists.")
message("(If you want to produce a new image, please ",
"change 'output_dir' or 'version' parameters)")
if (.check_messages()) {
message("Recovery: tile '", tile[["tile"]], "' already exists.")
message("(If you want to produce a new image, please ",
"change 'output_dir' or 'version' parameters)")
}
class_tile <- .tile_class_from_file(
file = out_file, band = band, base_tile = tile
)
Expand Down
11 changes: 5 additions & 6 deletions R/api_reclassify.R
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,11 @@
)
# Resume feature
if (file.exists(out_file)) {
# # Callback final tile classification
# .callback(process = "tile_classification", event = "recovery",
# context = environment())
message("Recovery: tile '", tile[["tile"]], "' already exists.")
message("(If you want to produce a new image, please ",
"change 'output_dir' or 'version' parameters)")
if (.check_messages()) {
message("Recovery: tile '", tile[["tile"]], "' already exists.")
message("(If you want to produce a new image, please ",
"change 'output_dir' or 'version' parameters)")
}
class_tile <- .tile_class_from_file(
file = out_file, band = band, base_tile = tile
)
Expand Down
11 changes: 5 additions & 6 deletions R/api_smooth.R
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,11 @@
)
# Resume feature
if (file.exists(out_file)) {
# # Callback final tile classification
# .callback(process = "tile_classification", event = "recovery",
# context = environment())
message("Recovery: tile '", tile[["tile"]], "' already exists.")
message("(If you want to produce a new image, please ",
"change 'output_dir' or 'version' parameters)")
if (.check_messages()) {
message("Recovery: tile '", tile[["tile"]], "' already exists.")
message("(If you want to produce a new image, please ",
"change 'output_dir' or 'version' parameters)")
}
probs_tile <- .tile_probs_from_file(
file = out_file, band = band, base_tile = tile,
labels = .tile_labels(tile), update_bbox = FALSE
Expand Down
11 changes: 5 additions & 6 deletions R/api_uncertainty.R
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,11 @@
)
# Resume feature
if (file.exists(out_file)) {
# # Callback final tile classification
# .callback(process = "tile_classification", event = "recovery",
# context = environment())
message("Recovery: tile '", tile[["tile"]], "' already exists.")
message("(If you want to produce a new image, please ",
"change 'output_dir' or 'version' parameters)")
if (.check_messages()) {
message("Recovery: tile '", tile[["tile"]], "' already exists.")
message("(If you want to produce a new image, please ",
"change 'output_dir' or 'version' parameters)")
}
uncert_tile <- .tile_uncertainty_from_file(
file = out_file,
band = band,
Expand Down
11 changes: 5 additions & 6 deletions R/api_variance.R
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,11 @@
)
# Resume feature
if (file.exists(out_file)) {
# # Callback final tile classification
# .callback(process = "tile_classification", event = "recovery",
# context = environment())
message("Recovery: tile '", tile[["tile"]], "' already exists.")
message("(If you want to produce a new image, please ",
"change 'output_dir' or 'version' parameters)")
if (.check_messages()) {
message("Recovery: tile '", tile[["tile"]], "' already exists.")
message("(If you want to produce a new image, please ",
"change 'output_dir' or 'version' parameters)")
}
var_tile <- .tile_variance_from_file(
file = out_file, band = band, base_tile = tile,
labels = .tile_labels(tile), update_bbox = FALSE
Expand Down
11 changes: 5 additions & 6 deletions R/sits_classify_cube.R
Original file line number Diff line number Diff line change
Expand Up @@ -46,12 +46,11 @@
)
# Resume feature
if (file.exists(out_file)) {
# # Callback final tile classification
# .callback(process = "tile_classification", event = "recovery",
# context = environment())
message("Recovery: tile '", tile[["tile"]], "' already exists.")
message("(If you want to produce a new image, please ",
"change 'output_dir' or 'version' parameters)")
if (.check_messages()) {
message("Recovery: tile '", tile[["tile"]], "' already exists.")
message("(If you want to produce a new image, please ",
"change 'output_dir' or 'version' parameters)")
}
probs_tile <- .tile_probs_from_file(
file = out_file, band = band, base_tile = tile,
labels = .ml_labels(ml_model), update_bbox = TRUE
Expand Down
11 changes: 5 additions & 6 deletions R/sits_cube_copy.R
Original file line number Diff line number Diff line change
Expand Up @@ -102,12 +102,11 @@ sits_cube_copy <- function(cube,
)
# Resume feature
if (.raster_is_valid(out_file, output_dir = output_dir)) {
# # Callback final tile classification
# .callback(process = "tile_classification", event = "recovery",
# context = environment())
message("Recovery: file '", out_file, "' already exists.")
message("(If you want to get a new version, please ",
"change 'output_dir' parameter or delete the existing file)")
if (.check_messages()) {
message("Recovery: file '", out_file, "' already exists.")
message("(If you want to get a new version, please ",
"change 'output_dir' parameter or delete the existing file)")
}
asset <- .download_update_asset(
asset = asset, roi = roi, res = res, out_file = out_file
)
Expand Down
15 changes: 7 additions & 8 deletions R/sits_mixture_model.R
Original file line number Diff line number Diff line change
Expand Up @@ -254,14 +254,13 @@ sits_mixture_model.raster_cube <- function(data, endmembers, ...,
)
# Resume feature
if (.raster_is_valid(out_files, output_dir = output_dir)) {
# # Callback final tile classification
# .callback(process = "mixtureModel", event = "recovery",
# context = environment())
message("Recovery: fractions ",
paste0("'", out_fracs, "'", collapse = ", "),
" already exists.")
message("(If you want to produce a new image, please ",
"change 'output_dir' parameters)")
if (.check_messages()) {
message("Recovery: fractions ",
paste0("'", out_fracs, "'", collapse = ", "),
" already exists.")
message("(If you want to produce a new image, please ",
"change 'output_dir' parameters)")
}
# Create tile based on template
fracs_feature <- .tile_eo_from_files(
files = out_files,
Expand Down
16 changes: 10 additions & 6 deletions R/sits_mosaic.R
Original file line number Diff line number Diff line change
Expand Up @@ -223,9 +223,11 @@ sits_mosaic <- function(cube,
)
# Resume feature
if (.raster_is_valid(out_file, output_dir = output_dir)) {
message("Recovery: file '", out_file, "' already exists.")
message("(If you want to produce a new cropped image, please ",
"change 'version' or 'output_dir' parameter)")
if (.check_messages()) {
message("Recovery: file '", out_file, "' already exists.")
message("(If you want to produce a new cropped image, please ",
"change 'version' or 'output_dir' parameter)")
}
base_tile <- .tile_from_file(
file = out_file, base_tile = base_tile,
band = .tile_bands(base_tile), update_bbox = TRUE,
Expand Down Expand Up @@ -278,9 +280,11 @@ sits_mosaic <- function(cube,
)
# Resume feature
if (.raster_is_valid(out_file, output_dir = output_dir)) {
message("Recovery: file '", out_file, "' already exists.")
message("(If you want to produce a new cropped image, please ",
"change 'version' or 'output_dir' parameter)")
if (.check_messages()) {
message("Recovery: file '", out_file, "' already exists.")
message("(If you want to produce a new cropped image, please ",
"change 'version' or 'output_dir' parameter)")
}
asset <- .tile_from_file(
file = out_file, base_tile = asset,
band = .tile_bands(asset), update_bbox = TRUE,
Expand Down
7 changes: 1 addition & 6 deletions R/sits_summary.R
Original file line number Diff line number Diff line change
Expand Up @@ -129,8 +129,6 @@ summary.raster_cube <- function(
# change names
colnames(sum) <- bands
# print statistics
d <- as.character(lubridate::as_date(date))
cat("Statistics for tile ", tile$tile, " date ", d, "\n")
sum
}
#' @title Summarize data cubes
Expand Down Expand Up @@ -209,7 +207,6 @@ summary.probs_cube <- function(
offset <- .offset(band_conf)
sum <- summary(values*scale + offset)
colnames(sum) <- sits_labels(tile)
cat("Statistics for tile ", tile$tile, "\n")
sum
}
#' @title Summarize data cubes
Expand Down Expand Up @@ -288,7 +285,6 @@ summary.variance_cube <- function(
offset <- .offset(band_conf)
sum <- summary(values*scale + offset)
colnames(sum) <- sits_labels(tile)
cat("Statistics for tile ", tile$tile, "\n")
sum
}
#' @title Summarize data cubes
Expand Down Expand Up @@ -364,7 +360,6 @@ summary.class_cube <- function(
terra::expanse(unit = "km", byValue = TRUE)
# create a tibble
areas <- class_areas[,3]
# get t
cat("Class Areas for tile ", tile$tile, "\n")
# get the result
data.frame(class = sits_labels(tile), area_km2 = signif(areas, 4))
}
9 changes: 8 additions & 1 deletion tests/testthat/test-apply.R
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,11 @@ test_that("Kernel functions", {
median_2 <- v_obj_md[21,21]

expect_true(median_1 == median_2)

documentation <- FALSE
if (Sys.getenv("SITS_DOCUMENTATION_MODE") == "true") {
documentation <- TRUE
Sys.setenv("SITS_DOCUMENTATION_MODE" = "false")
}
# Recovery
out <- capture_messages({
expect_message({
Expand All @@ -147,6 +151,9 @@ test_that("Kernel functions", {
regexp = "Recovery"
)
})
if (documentation) {
Sys.setenv("SITS_DOCUMENTATION_MODE" = "true")
}
expect_true(grepl("output_dir", out[1]))
expect_true(grepl("Recovery", out[2]))
cube_mean <- sits_apply(
Expand Down
8 changes: 8 additions & 0 deletions tests/testthat/test-combine_predictions.R
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,11 @@ test_that("Combine predictions", {

# Recovery
# test Recovery
documentation <- FALSE
if (Sys.getenv("SITS_DOCUMENTATION_MODE") == "true") {
documentation <- TRUE
Sys.setenv("SITS_DOCUMENTATION_MODE" = "false")
}
out <- capture_messages({
expect_message(
object = { sits_combine_predictions(
Expand All @@ -67,6 +72,9 @@ test_that("Combine predictions", {
regexp = "Recovery"
)
})
if (documentation) {
Sys.setenv("SITS_DOCUMENTATION_MODE" = "true")
}
expect_true(grepl("output_dir", out[1]))

# combine predictions
Expand Down
26 changes: 24 additions & 2 deletions tests/testthat/test-raster.R
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,11 @@ test_that("Single core classification with rfor", {
)

# testing resume feature
documentation <- FALSE
if (Sys.getenv("SITS_DOCUMENTATION_MODE") == "true") {
documentation <- TRUE
Sys.setenv("SITS_DOCUMENTATION_MODE" = "false")
}
out <- capture_messages({
expect_message(
object = { sits_classify(
Expand All @@ -34,6 +39,9 @@ test_that("Single core classification with rfor", {
regexp = "Recovery: "
)
})
if (documentation) {
Sys.setenv("SITS_DOCUMENTATION_MODE" = "true")
}
expect_true(grepl("output_dir", out[1]))

sits_labels(sinop_probs) <- c(
Expand Down Expand Up @@ -476,7 +484,11 @@ test_that("Classification with post-processing", {
sinop_probs,
output_dir = output_dir,
)

documentation <- FALSE
if (Sys.getenv("SITS_DOCUMENTATION_MODE") == "true") {
documentation <- TRUE
Sys.setenv("SITS_DOCUMENTATION_MODE" = "false")
}
# testing resume feature
out <- capture_messages({
expect_message(
Expand All @@ -487,6 +499,9 @@ test_that("Classification with post-processing", {
regexp = "Recovery"
)
})
if (documentation) {
Sys.setenv("SITS_DOCUMENTATION_MODE" = "true")
}
expect_true(grepl("output_dir", out[1]))

expect_true(all(file.exists(unlist(sinop_class$file_info[[1]]$path))))
Expand All @@ -506,7 +521,11 @@ test_that("Classification with post-processing", {
memsize = 4,
multicores = 2
)

documentation <- FALSE
if (Sys.getenv("SITS_DOCUMENTATION_MODE") == "true") {
documentation <- TRUE
Sys.setenv("SITS_DOCUMENTATION_MODE" = "false")
}
# testing the recovery feature
out <- capture_messages({
expect_message(
Expand All @@ -519,6 +538,9 @@ test_that("Classification with post-processing", {
regexp = "Recovery"
)
})
if (documentation) {
Sys.setenv("SITS_DOCUMENTATION_MODE" = "true")
}
expect_true(grepl("output_dir", out[1]))

expect_true(all(file.exists(unlist(sinop_bayes$file_info[[1]]$path))))
Expand Down
Loading

0 comments on commit 7df10d2

Please sign in to comment.