diff --git a/NAMESPACE b/NAMESPACE index 6bb2b58a8..32b557e76 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -365,9 +365,8 @@ S3method(sits_to_csv,tbl_df) S3method(sits_to_xlsx,list) S3method(sits_to_xlsx,sits_accuracy) S3method(sits_uncertainty,default) -S3method(sits_uncertainty,entropy) -S3method(sits_uncertainty,least) -S3method(sits_uncertainty,margin) +S3method(sits_uncertainty,probs_cube) +S3method(sits_uncertainty,probs_vector_cube) S3method(sits_variance,default) S3method(sits_variance,derived_cube) S3method(sits_variance,probs_cube) diff --git a/R/api_check.R b/R/api_check.R index 72531c2f1..6a28feb76 100644 --- a/R/api_check.R +++ b/R/api_check.R @@ -255,7 +255,7 @@ #' @rdname check_functions #' @keywords internal #' @noRd -.check_cube_files <- function(x, ...) { +.check_raster_cube_files <- function(x, ...) { # check for data access robj <- tryCatch( .raster_open_rast(.tile_path(x)), diff --git a/R/api_plot_raster.R b/R/api_plot_raster.R index 5ee308569..95f4c272c 100644 --- a/R/api_plot_raster.R +++ b/R/api_plot_raster.R @@ -12,13 +12,14 @@ #' @param line_width Line width to plot the segments boundary #' @param palette A sequential RColorBrewer palette #' @param rev Reverse the color palette? -#' @param tmap_options List with optional tmap parameters -#' tmap max_cells (default: 1e+06) -#' tmap_graticules_labels_size (default: 0.7) -#' tmap_legend_title_size (default: 1.5) -#' tmap_legend_text_size (default: 1.2) -#' tmap_legend_bg_color (default: "white") -#' tmap_legend_bg_alpha (default: 0.5) +#' @param tmap_options Named vector with optional tmap parameters: +#' scale (default = 1.0) +#' max_cells (default: 1e+06) +#' graticules_labels_size (default: 0.7) +#' legend_title_size (default: 1.5) +#' legend_text_size (default: 1.2) +#' legend_bg_color (default: "white") +#' legend_bg_alpha (default: 0.5) #' #' @return A plot object #' @@ -104,7 +105,7 @@ #' @param tile Tile to be plotted. #' @param legend Legend for the classes #' @param palette A sequential RColorBrewer palette -#' @param tmap_options List with optional tmap parameters +#' @param tmap_options Named vector with optional tmap parameters #' max_cells (default: 1e+06) #' scale (default: 0.8) #' font_family (default: "plex_sans") @@ -193,14 +194,14 @@ #' @param labels_plot Labels to be plotted #' @param palette A sequential RColorBrewer palette #' @param rev Reverse the color palette? -#' @param tmap_options List with optional tmap parameters -#' tmap max_cells (default: 1e+06) -#' tmap_graticules_labels_size (default: 0.7) -#' tmap_legend_title_size (default: 1.5) -#' tmap_legend_text_size (default: 1.2) -#' tmap_legend_bg_color (default: "white") -#' tmap_legend_bg_alpha (default: 0.5) -#' +#' @param tmap_options Named vector with optional tmap parameters +#' max_cells (default: 1e+06) +#' graticules_labels_size (default: 0.7) +#' legend_title_size (default: 1.5) +#' legend_text_size (default: 1.2) +#' legend_bg_color (default: "white") +#' legend_bg_alpha (default: 0.5) +#' scale (default: 1.0) #' @return A plot object #' .plot_probs <- function(tile, @@ -260,7 +261,7 @@ bds <- as.numeric(names(labels[labels %in% labels_plot])) # set the tmap options - tmap_params <- .plot_tmap_params(tmap_options) + tmap_options <- .plot_tmap_params(tmap_options) p <- tmap::tm_shape(probs_st[, , , bds]) + tmap::tm_raster( @@ -274,10 +275,10 @@ tmap::tm_layout( legend.show = TRUE, legend.outside = FALSE, - legend.bg.color = tmap_params[["legend_bg_color"]], - legend.bg.alpha = tmap_params[["legend_bg_alpha"]], - legend.title.size = tmap_params[["legend_title_size"]], - legend.text.size = tmap_params[["legend_text_size"]], + legend.bg.color = tmap_options[["legend_bg_color"]], + legend.bg.alpha = tmap_options[["legend_bg_alpha"]], + legend.title.size = tmap_options[["legend_title_size"]], + legend.text.size = tmap_options[["legend_text_size"]], outer.margins = 0 ) @@ -362,14 +363,14 @@ #' @param sf_seg Segments (sf object) #' @param seg_color Color to use for segment borders #' @param line_width Line width to plot the segments boundary -#' @param tmap_options List with optional tmap parameters -#' tmap max_cells (default: 1e+06) -#' tmap_graticules_labels_size (default: 0.7) -#' tmap_legend_title_size (default: 1.5) -#' tmap_legend_text_size (default: 1.2) -#' tmap_legend_bg_color (default: "white") -#' tmap_legend_bg_alpha (default: 0.5) -#' +#' @param tmap_options Named vector with optional tmap parameters +#' max_cells (default: 1e+06) +#' graticules_labels_size (default: 0.7) +#' legend_title_size (default: 1.5) +#' legend_text_size (default: 1.2) +#' legend_bg_color (default: "white") +#' legend_bg_alpha (default: 0.5) +#' scale (default: 1.0) #' @return A plot object #' .plot_rgb <- function(tile, @@ -418,12 +419,12 @@ stretch = TRUE ) - tmap_params <- .plot_tmap_params(tmap_options) + tmap_options <- .plot_tmap_params(tmap_options) p <- tmap::tm_shape(rgb_st) + tmap::tm_raster() + tmap::tm_graticules( - labels.size = tmap_params[["graticules_labels_size"]] + labels.size = tmap_options[["graticules_labels_size"]] ) + tmap::tm_compass() @@ -442,26 +443,16 @@ #' @author Gilberto Camara, \email{gilberto.camara@@inpe.br} #' #' @param tile Tile to be plotted. -#' @param tmap_options List with optional tmap parameters -#' tmap max_cells (default: 1e+06) -#' tmap_graticules_labels_size (default: 0.7) -#' tmap_legend_title_size (default: 1.5) -#' tmap_legend_text_size (default: 1.2) -#' tmap_legend_bg_color (default: "white") -#' tmap_legend_bg_alpha (default: 0.5) +#' @param tmap_options Named vector with options #' @return Cell size for x and y coordinates. #' #' .plot_read_size <- function(tile, tmap_options) { # get the maximum number of bytes to be displayed - if (!purrr::is_null(tmap_options[["max_cells"]])) { - max_cells <- tmap_options[["max_cells"]] - } else { - max_cells <- as.numeric(.conf("tmap", "max_cells")) - } - max_raster <- c(plot = max_cells, view = max_cells) + max_cells <- 1e+07 + # max_raster <- c(plot = max_cells, view = max_cells) # set the options for tmap - tmap::tmap_options(max.raster = max_raster) + # tmap::tmap_options(max.raster = max_raster) # numbers of nrows and ncols nrows <- max(.tile_nrows(tile)) ncols <- max(.tile_ncols(tile)) @@ -487,86 +478,50 @@ #' @noRd #' @author Gilberto Camara, \email{gilberto.camara@@inpe.br} #' -#' @param tmap_options List with optional tmap parameters +#' @param tmap_user Named vector with optional tmap parameters #' @return Updated tmap params. #' -.plot_tmap_params <- function(tmap_options) { - # set the tmap options - graticules_labels_size <- as.numeric(.conf("tmap", "graticules_labels_size")) - legend_title_size <- as.numeric(.conf("tmap", "legend_title_size")) - legend_text_size <- as.numeric(.conf("tmap", "legend_text_size")) - legend_width <- as.numeric(.conf("tmap", "legend_width")) - legend_height <- as.numeric(.conf("tmap", "legend_height")) - legend_position <- .conf("tmap", "legend_position") - legend_outside <- .conf("tmap", "legend_outside") - legend_outside_position <- .conf("tmap", "legend_outside_position") - legend_bg_color <- .conf("tmap", "legend_bg_color") - legend_bg_alpha <- as.numeric(.conf("tmap", "legend_bg_alpha")) - scale <- as.numeric(.conf("tmap", "scale")) - font_family <- .conf("tmap", "font_family") - - # user specified tmap options - if (!purrr::is_null(tmap_options)) { - # scale - if (!purrr::is_null(tmap_options[["scale"]])) { - scale <- as.numeric(tmap_options[["scale"]]) - } - # font_family - if (!purrr::is_null(tmap_options[["font_family"]])) { - font_family <- as.numeric(tmap_options[["font_family"]]) - } - # graticules label size - if (!purrr::is_null(tmap_options[["graticules_labels_size"]])) { - graticules_labels_size <- as.numeric( - tmap_options[["graticules_labels_size"]]) - } - # legend title size - if (!purrr::is_null(tmap_options[["legend_title_size"]])) { - legend_title_size <- as.numeric(tmap_options[["legend_title_size"]]) - } - # legend text size - if (!purrr::is_null(tmap_options[["legend_text_size"]])) { - legend_text_size <- as.numeric(tmap_options[["legend_text_size"]]) - } - # tmap legend bg color - if (!purrr::is_null(tmap_options[["legend_bg_color"]])) { - legend_bg_color <- tmap_options[["legend_bg_color"]] - } - # tmap legend bg alpha - if (!purrr::is_null(tmap_options[["legend_bg_alpha"]])) { - legend_bg_alpha <- as.numeric(tmap_options[["legend_bg_alpha"]]) - } - # tmap legend height - if (!purrr::is_null(tmap_options[["legend_height"]])) { - legend_height <- as.numeric(tmap_options[["legend_height"]]) - } - if (!purrr::is_null(tmap_options[["legend_width"]])) { - legend_width <- as.numeric(tmap_options[["legend_width"]]) - } - if (!purrr::is_null(tmap_options[["legend_position"]])) { - legend_position <- tmap_options[["legend_position"]] - } - if (!purrr::is_null(tmap_options[["legend_outside"]])) { - legend_outside <- tmap_options[["legend_outside"]] - } - if (!purrr::is_null(tmap_options[["legend_outside_position"]])) { - legend_outside_position <- - tmap_options[["legend_outside_position"]] - } - } - tmap_params <- list( - "scale" = scale, - "font_family" = font_family, - "graticules_labels_size" = graticules_labels_size, - "legend_title_size" = legend_title_size, - "legend_text_size" = legend_text_size, - "legend_bg_color" = legend_bg_color, - "legend_bg_alpha" = legend_bg_alpha, - "legend_height" = legend_height, - "legend_width" = legend_width, - "legend_position" = legend_position, - "legend_outside" = legend_outside, - "legend_outside_position" = legend_outside_position +.plot_tmap_params <- function(tmap_user) { + # reset the tmap params + tmap::tmap_options_reset() + # get the tmap defaults + tmap_options <- list( + graticules_labels_size = + as.numeric(.conf("tmap", "graticules_labels_size")), + legend_title_size = as.numeric(.conf("tmap", "legend_title_size")), + legend_text_size = as.numeric(.conf("tmap", "legend_text_size")), + legend_width = as.numeric(.conf("tmap", "legend_width")), + legend_height = as.numeric(.conf("tmap", "legend_height")), + legend_position = .conf("tmap", "legend_position"), + legend_outside = .conf("tmap", "legend_outside"), + legend_outside_position = .conf("tmap", "legend_outside_position"), + legend_bg_color = .conf("tmap", "legend_bg_color"), + legend_bg_alpha = as.numeric(.conf("tmap", "legend_bg_alpha")), + scale = as.numeric(.conf("tmap", "scale")), + font_family = .conf("tmap", "font_family") ) - return(tmap_params) + if (!purrr::is_null(tmap_user)) { + keys <- unique(c(names(tmap_user), names(tmap_options))) + .check_that( + all(keys %in% names(tmap_options)), + msg = paste("invalid tmap params - valid params are ", + keys, collapse = " ") + ) + for (k in names(tmap_user)) + tmap_options <- tmap_user[[k]] + } + # set tmap options + tmap::tmap_options(scale = as.numeric(tmap_options[["scale"]]), + legend.title.size = as.numeric(tmap_options[["legend_title_size"]]), + legend.text.size = as.numeric(tmap_options[["legend_text_size"]]), + legend.width = as.numeric(tmap_options[["legend_width"]]), + legend.height = as.numeric(tmap_options[["legend_height"]]), + legend.position = tmap_options[["legend_position"]], + legend.outside = tmap_options[["legend_outside"]], + legend.outside.position = tmap_options[["legend_outside_position"]], + legend.bg.color = tmap_options[["legend_bg_color"]], + legend.bg.alpha = as.numeric(tmap_options[["legend_bg_alpha"]]), + fontfamily = tmap_options[["font_family"]] + ) + return(tmap_options) } diff --git a/R/api_plot_vector.R b/R/api_plot_vector.R index 608f7c3b6..2c4f0d00c 100644 --- a/R/api_plot_vector.R +++ b/R/api_plot_vector.R @@ -7,13 +7,12 @@ #' @param tile Tile to be plotted. #' @param legend Legend for the classes #' @param palette A sequential RColorBrewer palette -#' @param tmap_options List with optional tmap parameters -#' tmap max_cells (default: 1e+06) -#' tmap_graticules_labels_size (default: 0.7) -#' tmap_legend_title_size (default: 1.5) -#' tmap_legend_text_size (default: 1.2) -#' tmap_legend_bg_color (default: "white") -#' tmap_legend_bg_alpha (default: 0.5) +#' @param tmap_options Named vector with optional tmap parameters +#' graticules_labels_size (default: 0.7) +#' legend_title_size (default: 1.5) +#' legend_text_size (default: 1.2) +#' legend_bg_color (default: "white") +#' legend_bg_alpha (default: 0.5) #' #' @return A plot object #' @@ -42,7 +41,7 @@ rev = TRUE ) # set the tmap options - tmap_params <- .plot_tmap_params(tmap_options) + tmap_options <- .plot_tmap_params(tmap_options) # name the colors to match the labels names(colors) <- labels # join sf geometries @@ -56,20 +55,20 @@ palette = colors ) + tmap::tm_graticules( - labels.size = tmap_params[["graticules_labels_size"]] + labels.size = tmap_options[["graticules_labels_size"]] ) + tmap::tm_compass() + tmap::tm_layout( legend.show = TRUE, legend.outside = FALSE, - scale = tmap_params[["scale"]], - fontfamily = tmap_params[["font_family"]], - legend.bg.color = tmap_params[["legend_bg_color"]], - legend.bg.alpha = tmap_params[["legend_bg_alpha"]], - legend.title.size = tmap_params[["legend_title_size"]], - legend.text.size = tmap_params[["legend_text_size"]], - legend.width = tmap_params[["legend_width"]], - legend.position = tmap_params[["legend_position"]] + scale = tmap_options[["scale"]], + fontfamily = tmap_options[["font_family"]], + legend.bg.color = tmap_options[["legend_bg_color"]], + legend.bg.alpha = tmap_options[["legend_bg_alpha"]], + legend.title.size = tmap_options[["legend_title_size"]], + legend.text.size = tmap_options[["legend_text_size"]], + legend.width = tmap_options[["legend_width"]], + legend.position = tmap_options[["legend_position"]] ) + tmap::tm_borders(lwd = 0.2) return(p) @@ -84,13 +83,7 @@ #' @param labels_plot Labels to be plotted #' @param palette A sequential RColorBrewer palette #' @param rev Revert the color of the palette? -#' @param tmap_options List with optional tmap parameters -#' tmap max_cells (default: 1e+06) -#' tmap_graticules_labels_size (default: 0.7) -#' tmap_legend_title_size (default: 1.5) -#' tmap_legend_text_size (default: 1.2) -#' tmap_legend_bg_color (default: "white") -#' tmap_legend_bg_alpha (default: 0.5) +#' @param tmap_options Named vector with optional tmap parameters #' #' @return A plot object #' @@ -124,7 +117,7 @@ # get the segements to be plotted sf_seg <- .segments_read_vec(tile) # set the tmap options - tmap_params <- .plot_tmap_params(tmap_options) + tmap_options <- .plot_tmap_params(tmap_options) # set the mode to plot tmap::tmap_mode("plot") # plot the segments by facet @@ -138,17 +131,17 @@ tmap::tm_polygons(labels_plot) + tmap::tm_facets(sync = FALSE, ncol = 2, scale.factor = 1) + tmap::tm_graticules( - labels.size = tmap_params[["graticules_labels_size"]] + labels.size = tmap_options[["graticules_labels_size"]] ) + tmap::tm_compass() + tmap::tm_layout( - fontfamily = tmap_params[["font_family"]], - legend.bg.color = tmap_params[["legend_bg_color"]], - legend.bg.alpha = tmap_params[["legend_bg_alpha"]], - legend.title.size = tmap_params[["legend_title_size"]], - legend.text.size = tmap_params[["legend_text_size"]], - legend.width = tmap_params[["legend_width"]], - legend.height = tmap_params[["legend_height"]], + fontfamily = tmap_options[["font_family"]], + legend.bg.color = tmap_options[["legend_bg_color"]], + legend.bg.alpha = tmap_options[["legend_bg_alpha"]], + legend.title.size = tmap_options[["legend_title_size"]], + legend.text.size = tmap_options[["legend_text_size"]], + legend.width = tmap_options[["legend_width"]], + legend.height = tmap_options[["legend_height"]], outer.margins = c(0.00001, 0.00001, 0.00001, 0.00001), inner.margins = c(0, 0, 0, 0), between.margin = 0, diff --git a/R/api_segments.R b/R/api_segments.R index be19e0c2a..01784a770 100755 --- a/R/api_segments.R +++ b/R/api_segments.R @@ -1,3 +1,18 @@ +#' +#' @name .segments_tile +#' @keywords internal +#' @noRd +#' @description Extract the segments from a tile +#' +#' @param tile tile of regular data cube +#' @param seg_fn Segmentation function to be used +#' @param band Name of output band +#' @param block Block size +#' @param roi Region of interest +#' @param output_dir Directory for saving temporary segment files +#' @param version Version of the result +#' @param progress Show progress bar? +#' @return segments for the tile .segments_tile <- function(tile, seg_fn, band, @@ -67,7 +82,7 @@ values <- C_fill_na(values, 0) # Used to check values (below) input_pixels <- nrow(values) - # Apply segment function + # Apply segmentation function values <- seg_fn(values, block, bbox) # Check if the result values is a vector object .check_vector(values) @@ -92,8 +107,13 @@ # Return segments tile seg_tile } - - +#' @name .segments_is_valud +#' @keywords internal +#' @noRd +#' @description Check if segments file is valid +#' +#' @param file GKPG file containing the segments +#' @return TRUE/FALSE .segments_is_valid <- function(file) { # resume processing in case of failure if (!all(file.exists(file))) { @@ -115,7 +135,14 @@ } return(TRUE) } - +#' @name .segments_data_read +#' @keywords internal +#' @noRd +#' @description Extract the segments from a tile +#' +#' @param tile Tile of regular data cube +#' @param block Block size +#' @return values of the time series in the block .segments_data_read <- function(tile, block) { # For cubes that have a time limit to expire (MPC cubes only) tile <- .cube_token_generator(tile) @@ -149,54 +176,94 @@ values } -.get_segments_from_cube <- function(cube) { - slider::slide_dfr(cube, function(tile) { - .segments_read_vec(tile) - }) -} - +#' @name .segments_path +#' @keywords internal +#' @noRd +#' @description Find the path to the GPKG file with the segments +#' +#' @param cube Regular data cube +#' @return GPKG file name .segments_path <- function(cube) { slider::slide_chr(cube, function(tile) { tile[["vector_info"]][[1]][["path"]] }) } - +#' @name .segments_read_vec +#' @keywords internal +#' @noRd +#' @description Read the segments associated to a tile +#' @param cube Regular data cube +#' @return segment vectors (sf object) .segments_read_vec <- function(cube) { tile <- .tile(cube) vector_seg <- .vector_read_vec(.segments_path(tile)) return(vector_seg) } - +#' @name .segments_join_probs +#' @keywords internal +#' @noRd +#' @description Join the probabilities of time series inside each +#' segment to the segments vectors +#' @param data Classified time series +#' @param segments Segments object (sf object) +#' @return segment vectors (sf object) with the probabilities +#' .segments_join_probs <- function(data, segments) { # Select polygon_id and class for the time series tibble - data_id <- data |> + data <- data |> dplyr::select("polygon_id", "predicted") |> dplyr::mutate(polygon_id = as.numeric(.data[["polygon_id"]])) |> tidyr::unnest(cols = "predicted") |> dplyr::select(-"class") |> dplyr::group_by(.data[["polygon_id"]]) # Select just probability labels - labels <- setdiff(colnames(data_id), c("polygon_id", "from", "to", "class")) + labels <- setdiff(colnames(data), c("polygon_id", "from", "to", "class")) + # Calculate metrics + data <- dplyr::summarise( + data, + dplyr::across(.cols = dplyr::all_of(labels), + .names = "{.col}_mean", mean) + ) + # Summarize probabilities + data <- data |> + dplyr::rename_with(~ gsub("_mean$", "", .x)) |> + dplyr::rowwise() |> + dplyr::mutate(sum = sum(dplyr::c_across(cols = dplyr::all_of(labels)))) |> + dplyr::mutate(dplyr::across(.cols = dplyr::all_of(labels), ~ .x / .data[["sum"]])) |> + dplyr::select(-"sum") + + # join the data_id tibble with the segments (sf objects) + dplyr::left_join(segments, data, by = c("pol_id" = "polygon_id")) +} +#' @name .segments_join_probs_neigh +#' @keywords internal +#' @noRd +#' @description Join the probabilities of time series inside each +#' segment to the segments vectors +#' Include neighbour information +#' @param data Classified time series +#' @param segments Segments object (sf object) +#' @return segment vectors (sf object) with the probabilities +#' +.segments_join_probs_neigh <- function(data, segments) { + # Select polygon_id and class for the time series tibble + data <- data |> + dplyr::select("polygon_id", "predicted") |> + dplyr::mutate(polygon_id = as.numeric(.data[["polygon_id"]])) |> + tidyr::unnest(cols = "predicted") |> + dplyr::select(-"class") |> + dplyr::group_by(.data[["polygon_id"]]) + # Select just probability labels + labels <- setdiff(colnames(data), c("polygon_id", "from", "to", "class")) # Calculate metrics data_id <- dplyr::summarise( - data_id, + data, dplyr::across(.cols = dplyr::all_of(labels), .names = "{.col}_mean", mean), dplyr::across(.cols = dplyr::all_of(labels), - .names = "{.col}_mean_logit", function(x) { - x <- ifelse(x == 0, 0.00001, x) - x <- ifelse(x == 1, 0.99999, x) - mean(log(x / (1 - x))) - }), - dplyr::across(.cols = dplyr::all_of(labels), - .names = "{.col}_var_logit", function(x) { - x <- ifelse(x == 0, 0.00001, x) - x <- ifelse(x == 1, 0.99999, x) - var(log(x / (1 - x))) - }) + .names = "{.col}_var", stats::var) ) - # Summarize probabilities data_id <- data_id |> dplyr::rename_with(~ gsub("_mean$", "", .x)) |> @@ -205,10 +272,32 @@ dplyr::mutate(dplyr::across(.cols = dplyr::all_of(labels), ~ .x / .data[["sum"]])) |> dplyr::select(-"sum") + # Get the information about the neighbours + neighbors <- spdep::poly2nb(segments) + # ungroup the data tibble + data <- dplyr::ungroup(data) + # obtain neighborhood statistics for each polygon + neigh_stats <- purrr::map_dfr(unique(data$polygon_id), function(id){ + # get the ids of the neighbours of a polygon + ids <- neighbors[[id]] + # get mean and variance of the neighbours per class + neigh <- data |> + dplyr::filter(.data[["polygon_id"]] %in% ids) |> + dplyr::select(!!labels) |> + dplyr::summarise( + dplyr::across(.cols = dplyr::all_of(labels), + .names = "{.col}_nmean", mean), + dplyr::across(.cols = dplyr::all_of(labels), + .names = "{.col}_nvar", stats::var) + ) + return(neigh) + }) + # include neighborhood statistics in the results + data_id <- dplyr::bind_cols(data_id, neigh_stats) + # join the data_id tibble with the segments (sf objects) dplyr::left_join(segments, data_id, by = c("pol_id" = "polygon_id")) } - #' #' @name .segments_extract_data #' @keywords internal diff --git a/R/api_uncertainty.R b/R/api_uncertainty.R index 78b7172ef..db77958c3 100644 --- a/R/api_uncertainty.R +++ b/R/api_uncertainty.R @@ -1,6 +1,6 @@ #---- internal functions ---- -#' @title Create an uncertainty cube -#' @name .uncertainty_cube +#' @title Create an uncertainty raster cube +#' @name .uncertainty_raster_cube #' @keywords internal #' @noRd #' @param cube A cube @@ -9,7 +9,7 @@ #' @param output_dir directory where files will be saved #' @param version version name of resulting cube#' #' @return uncertainty cube -.uncertainty_cube <- function(cube, +.uncertainty_raster_cube <- function(cube, band, uncert_fn, output_dir, @@ -17,7 +17,7 @@ # Process each tile sequentially uncert_cube <- .cube_foreach_tile(cube, function(tile) { # Compute uncertainty - uncert_tile <- .uncertainty_tile( + uncert_tile <- .uncertainty_raster_tile( tile = tile, band = band, uncert_fn = uncert_fn, @@ -29,16 +29,16 @@ return(uncert_cube) } #' @title Create an uncertainty tile-band asset -#' @name .uncertainty_tile +#' @name .uncertainty_raster_tile #' @keywords internal #' @noRd #' @param tile tile of data cube #' @param band band name #' @param uncert_fn function to compute uncertainty #' @param output_dir directory where files will be saved -#' @param version version name of resulting cube#' +#' @param version version name of resulting cube #' @return uncertainty tile-band combination -.uncertainty_tile <- function(tile, +.uncertainty_raster_tile <- function(tile, band, uncert_fn, output_dir, @@ -53,7 +53,7 @@ # Resume feature if (file.exists(out_file)) { .check_recovery(tile[["tile"]]) - + # return the existing tile uncert_tile <- .tile_derived_from_file( file = out_file, band = band, @@ -62,6 +62,7 @@ ) return(uncert_tile) } + # If output file does not exist # Create chunks as jobs chunks <- .tile_chunks_create(tile = tile, overlap = 0) # Process jobs in parallel @@ -129,6 +130,89 @@ uncert_tile } +#---- internal functions ---- +#' @title Create an uncertainty raster cube +#' @name .uncertainty_vector_cube +#' @keywords internal +#' @noRd +#' @param cube A cube +#' @param band band name +#' @param output_dir directory where files will be saved +#' @param version version name of resulting cube#' +#' @return uncertainty cube +.uncertainty_vector_cube <- function(cube, + band, + output_dir, + version) { + # Process each tile sequentially + uncert_cube <- .cube_foreach_tile(cube, function(tile) { + # Compute uncertainty + uncert_tile <- .uncertainty_vector_tile( + tile = tile, + band = band, + output_dir = output_dir, + version = version + ) + return(uncert_tile) + }) + class(uncert_cube) <- c("uncertainty_vector_cube", class(cube)) + return(uncert_cube) +} +#' @title Create an uncertainty vector tile +#' @name .uncertainty_vector_tile +#' @keywords internal +#' @noRd +#' @param tile tile of data cube +#' @param band band name +#' @param output_dir directory where files will be saved +#' @param version version name of resulting cube +#' @return uncertainty tile-band combination +.uncertainty_vector_tile <- function(tile, + band, + output_dir, + version) { + # Output file + out_file <- .file_derived_name( + tile = tile, + band = band, + version = version, + output_dir = output_dir, + ext = "gpkg" + ) + # select uncertainty function + uncert_fn <- switch( + band, + "least" = .uncertainty_fn_least(), + "margin" = .uncertainty_fn_margin(), + "entropy" = .uncertainty_fn_entropy() + ) + # get the labels + labels <- unname(sits_labels(tile)) + # read the segments + sf_seg <- .segments_read_vec(tile) + # extract matrix values from segments + probs_matrix <- sf_seg |> + sf::st_drop_geometry() |> + dplyr::select(dplyr::all_of(labels)) |> + as.matrix() + # apply uncertainty function + uncert_values <- uncert_fn(probs_matrix) + colnames(uncert_values) <- band + uncert_values <- tibble::as_tibble(uncert_values) + # merge uncertainty values + sf_seg <- sf_seg |> + dplyr::bind_cols(uncert_values) |> + dplyr::relocate(dplyr::all_of(band), .before = "geom") + # Prepare and save results as vector + .vector_write_vec(v_obj = sf_seg, file_path = out_file) + # Set information on uncert_tile + uncert_tile <- tile + uncert_tile$vector_info[[1]]$band <- band + uncert_tile$vector_info[[1]]$path <- out_file + class(uncert_tile) <- c("uncertainty_vector_cube", class(uncert_tile)) + return(uncert_tile) +} + #---- uncertainty functions ---- #' @title Least uncertainty function #' @name .uncertainty_fn_least diff --git a/R/sits_accuracy.R b/R/sits_accuracy.R index b8727e4a4..536b5b058 100644 --- a/R/sits_accuracy.R +++ b/R/sits_accuracy.R @@ -129,8 +129,6 @@ sits_accuracy.sits <- function(data, ...) { #' @rdname sits_accuracy #' @export sits_accuracy.class_cube <- function(data, ..., validation) { - # check the cube is valid - .check_cube_files(data) # generic function # Is this a CSV file? if (is.character(validation)) { diff --git a/R/sits_clean.R b/R/sits_clean.R index 248e9bbf1..82cc0a32a 100644 --- a/R/sits_clean.R +++ b/R/sits_clean.R @@ -70,7 +70,7 @@ sits_clean.class_cube <- function(cube, window_size = 5L, memsize = 4L, version = "v1-clean", progress = TRUE) { # Preconditions # Check cube has files - .check_cube_files(cube) + .check_raster_cube_files(cube) # Check window size .check_window_size(window_size, min = 1, max = 15) # Check memsize diff --git a/R/sits_cube_copy.R b/R/sits_cube_copy.R index 015c1a164..dd0b62280 100644 --- a/R/sits_cube_copy.R +++ b/R/sits_cube_copy.R @@ -59,7 +59,7 @@ sits_cube_copy <- function(cube, progress = TRUE) { # Pre-conditions .check_is_raster_cube(cube) - .check_cube_files(cube) + .check_raster_cube_files(cube) if (.has(roi)) { sf_roi <- .roi_as_sf(roi, default_crs = cube$crs[[1]]) } else { diff --git a/R/sits_get_data.R b/R/sits_get_data.R index 825743acc..165ab7fa0 100644 --- a/R/sits_get_data.R +++ b/R/sits_get_data.R @@ -111,7 +111,7 @@ sits_get_data <- function(cube, # Pre-conditions .check_is_raster_cube(cube) .check_is_regular(cube) - .check_cube_files(cube) + .check_raster_cube_files(cube) .check_cube_bands(cube, bands = bands) .check_crs(crs) .check_multicores(multicores, min = 1, max = 2048) diff --git a/R/sits_label_classification.R b/R/sits_label_classification.R index 64c727851..e469767d0 100644 --- a/R/sits_label_classification.R +++ b/R/sits_label_classification.R @@ -53,8 +53,8 @@ #' } #' @export sits_label_classification <- function(cube, - memsize = 4, - multicores = 2, + memsize = 4L, + multicores = 2L, output_dir, version = "v1", progress = TRUE) { @@ -126,7 +126,7 @@ sits_label_classification.probs_vector_cube <- function(cube, ..., version = "v1", progress = TRUE) { # Pre-conditions - Check parameters - .check_cube_files(cube) + .check_raster_cube_files(cube) .check_output_dir(output_dir) version <- .check_version(version) # version is case-insensitive in sits diff --git a/R/sits_plot.R b/R/sits_plot.R index 020fb394f..755679de5 100644 --- a/R/sits_plot.R +++ b/R/sits_plot.R @@ -322,9 +322,9 @@ plot.predicted <- function(x, y, ..., #' @param date Date to be plotted. #' @param palette An RColorBrewer palette #' @param rev Reverse the color order in the palette? -#' @param tmap_options List with optional tmap parameters +#' @param tmap_options Named list with optional tmap parameters #' max_cells (default: 1e+06) -#' scale (default: 0.5) +#' scale (default: 1.0) #' graticules_labels_size (default: 0.7) #' legend_title_size (default: 1.0) #' legend_text_size (default: 1.0) @@ -452,13 +452,14 @@ plot.raster_cube <- function(x, ..., #' @param line_width Line width to plot the segments boundary (in pixels) #' @param palette An RColorBrewer palette #' @param rev Reverse the color order in the palette? -#' @param tmap_options List with optional tmap parameters -#' tmap_max_cells (default: 1e+06) -#' tmap_graticules_labels_size (default: 0.7) -#' tmap_legend_title_size (default: 1.5) -#' tmap_legend_text_size (default: 1.2) -#' tmap_legend_bg_color (default: "white") -#' tmap_legend_bg_alpha (default: 0.5) +#' @param tmap_options Named list with optional tmap parameters +#' max_cells (default: 1e+06) +#' scale (default: 1.0) +#' graticules_labels_size (default: 0.7) +#' legend_title_size (default: 1.0) +#' legend_text_size (default: 1.0) +#' legend_bg_color (default: "white") +#' legend_bg_alpha (default: 0.5) #' #' @return A plot object with an RGB image #' or a B/W image on a color @@ -582,13 +583,14 @@ plot.vector_cube <- function(x, ..., #' @param labels Labels to plot (optional). #' @param palette RColorBrewer palette #' @param rev Reverse order of colors in palette? -#' @param tmap_options List with optional tmap parameters -#' tmap_max_cells (default: 1e+06) -#' tmap_graticules_labels_size (default: 0.7) -#' tmap_legend_title_size (default: 1.5) -#' tmap_legend_text_size (default: 1.2) -#' tmap_legend_bg_color (default: "white") -#' tmap_legend_bg_alpha (default: 0.5) +#' @param tmap_options Named list with optional tmap parameters +#' max_cells (default: 1e+06) +#' scale (default: 1.0) +#' graticules_labels_size (default: 0.7) +#' legend_title_size (default: 1.0) +#' legend_text_size (default: 1.0) +#' legend_bg_color (default: "white") +#' legend_bg_alpha (default: 0.5) #' @return A plot containing probabilities associated #' to each class for each pixel. #' @@ -655,13 +657,14 @@ plot.probs_cube <- function(x, ..., #' @param labels Labels to plot (optional). #' @param palette RColorBrewer palette #' @param rev Reverse order of colors in palette? -#' @param tmap_options List with optional tmap parameters -#' tmap_max_cells (default: 1e+06) -#' tmap_graticules_labels_size (default: 0.7) -#' tmap_legend_title_size (default: 1.5) -#' tmap_legend_text_size (default: 1.2) -#' tmap_legend_bg_color (default: "white") -#' tmap_legend_bg_alpha (default: 0.5) +#' @param tmap_options Named list with optional tmap parameters +#' max_cells (default: 1e+06) +#' scale (default: 1.0) +#' graticules_labels_size (default: 0.7) +#' legend_title_size (default: 1.0) +#' legend_text_size (default: 1.0) +#' legend_bg_color (default: "white") +#' legend_bg_alpha (default: 0.5) #' @return A plot containing probabilities associated #' to each class for each pixel. #' @@ -747,13 +750,14 @@ plot.probs_vector_cube <- function(x, ..., #' @param palette RColorBrewer palette #' @param rev Reverse order of colors in palette? #' @param type Type of plot ("map" or "hist") -#' @param tmap_options List with optional tmap parameters -#' tmap_max_cells (default: 1e+06) -#' tmap_graticules_labels_size (default: 0.7) -#' tmap_legend_title_size (default: 1.5) -#' tmap_legend_text_size (default: 1.2) -#' tmap_legend_bg_color (default: "white") -#' tmap_legend_bg_alpha (default: 0.5) +#' @param tmap_options Named list with optional tmap parameters +#' max_cells (default: 1e+06) +#' scale (default: 1.0) +#' graticules_labels_size (default: 0.7) +#' legend_title_size (default: 1.0) +#' legend_text_size (default: 1.0) +#' legend_bg_color (default: "white") +#' legend_bg_alpha (default: 0.5) #' @return A plot containing probabilities associated #' to each class for each pixel. #' @@ -830,13 +834,14 @@ plot.variance_cube <- function(x, ..., #' @param tile Tiles to be plotted. #' @param palette An RColorBrewer palette #' @param rev Reverse the color order in the palette? -#' @param tmap_options List with optional tmap parameters -#' tmap_max_cells (default: 1e+06) -#' tmap_graticules_labels_size (default: 0.7) -#' tmap_legend_title_size (default: 1.5) -#' tmap_legend_text_size (default: 1.2) -#' tmap_legend_bg_color (default: "white") -#' tmap_legend_bg_alpha (default: 0.5) +#' @param tmap_options Named list with optional tmap parameters +#' max_cells (default: 1e+06) +#' scale (default: 1.0) +#' graticules_labels_size (default: 0.7) +#' legend_title_size (default: 1.0) +#' legend_text_size (default: 1.0) +#' legend_bg_color (default: "white") +#' legend_bg_alpha (default: 0.5) #' #' @return A plot object produced by the stars package #' with a map showing the uncertainty associated @@ -912,18 +917,14 @@ plot.uncertainty_cube <- function(x, ..., #' @param title Title of the plot. #' @param legend Named vector that associates labels to colors. #' @param palette Alternative RColorBrewer palette -#' @param tmap_options List with optional tmap parameters +#' @param tmap_options Named list with optional tmap parameters #' max_cells (default: 1e+06) +#' scale (default: 0.5) #' graticules_labels_size (default: 0.7) -#' scale (default = 0.8) -#' legend_title_size (default: 0.7) -#' legend_text_size (default: 0.7) +#' legend_title_size (default: 1.0) +#' legend_text_size (default: 1.0) #' legend_bg_color (default: "white") #' legend_bg_alpha (default: 0.5) -#' legend_width (default: 0.5) -#' legend_height (default: 0.7) -#' legend_position (default: c("left", "bottom")) -#' #' #' @return A color map, where each pixel has the color #' associated to a label, as defined by the legend @@ -1016,13 +1017,14 @@ plot.class_cube <- function(x, y, ..., #' @param seg_color Segment color. #' @param line_width Segment line width. #' @param palette Alternative RColorBrewer palette -#' @param tmap_options List with optional tmap parameters -#' tmap_max_cells (default: 1e+06) -#' tmap_graticules_labels_size (default: 0.7) -#' tmap_legend_title_size (default: 1.5) -#' tmap_legend_text_size (default: 1.2) -#' tmap_legend_bg_color (default: "white") -#' tmap_legend_bg_alpha (default: 0.5) +#' @param tmap_options Named list with optional tmap parameters +#' max_cells (default: 1e+06) +#' scale (default: 0.5) +#' graticules_labels_size (default: 0.7) +#' legend_title_size (default: 1.0) +#' legend_text_size (default: 1.0) +#' legend_bg_color (default: "white") +#' legend_bg_alpha (default: 0.5) #' #' @return A plot object with an RGB image #' or a B/W image on a color diff --git a/R/sits_reclassify.R b/R/sits_reclassify.R index 0b635de5a..0e8b59293 100644 --- a/R/sits_reclassify.R +++ b/R/sits_reclassify.R @@ -117,13 +117,13 @@ sits_reclassify <- function(cube, .check_valid(mask) # check cube .check_cube_is_class_cube(cube) - .check_cube_files(cube) + .check_raster_cube_files(cube) # # check mask .check_that( x = inherits(mask, "class_cube"), msg = "mask is not a classified data cube" ) - .check_cube_files(mask) + .check_raster_cube_files(mask) UseMethod("sits_reclassify", cube) } diff --git a/R/sits_regularize.R b/R/sits_regularize.R index 590dcb319..c647c3444 100644 --- a/R/sits_regularize.R +++ b/R/sits_regularize.R @@ -113,7 +113,7 @@ sits_regularize.raster_cube <- function(cube, multicores = 2L, progress = TRUE) { # Preconditions - .check_cube_files(cube) + .check_raster_cube_files(cube) .period_check(period) .check_num_parameter(res, exclusive_min = 0) output_dir <- .file_normalize(output_dir) @@ -165,7 +165,7 @@ sits_regularize.raster_cube <- function(cube, multicores = 2L, progress = TRUE) { # Preconditions - .check_cube_files(cube) + .check_raster_cube_files(cube) .period_check(period) .check_num_parameter(res, exclusive_min = 0) output_dir <- .file_normalize(output_dir) diff --git a/R/sits_sample_functions.R b/R/sits_sample_functions.R index 1b1cae6d2..40342d410 100644 --- a/R/sits_sample_functions.R +++ b/R/sits_sample_functions.R @@ -296,7 +296,7 @@ sits_sampling_design <- function(cube, std_err = 0.01, rare_class_prop = 0.1){ # check the cube is valid - .check_cube_files(cube) + .check_raster_cube_files(cube) # check cube is class cube .check_cube_is_class_cube(cube) # get the labels diff --git a/R/sits_select.R b/R/sits_select.R index d01d5e2ce..0ec93dafe 100644 --- a/R/sits_select.R +++ b/R/sits_select.R @@ -88,7 +88,7 @@ sits_select.raster_cube <- function(data, dates = NULL, tiles = NULL) { # Pre-condition - .check_cube_files(data) + .check_raster_cube_files(data) # Filter bands if (!purrr::is_null(bands) && !any(is.na(bands))) { bands <- .band_set_case(bands) diff --git a/R/sits_smooth.R b/R/sits_smooth.R index d594ae124..8ef350bb0 100644 --- a/R/sits_smooth.R +++ b/R/sits_smooth.R @@ -63,7 +63,7 @@ sits_smooth <- function(cube, window_size = 7L, neigh_fraction = 0.5, smoothness = 10L, memsize = 4L, multicores = 2L, output_dir, version = "v1") { # Check if cube has probability data - .check_cube_files(cube) + .check_raster_cube_files(cube) # check window size .check_window_size(window_size, min = 3, max = 33) # check neighborhood fraction diff --git a/R/sits_uncertainty.R b/R/sits_uncertainty.R index 301eb4de4..7c005a8a5 100644 --- a/R/sits_uncertainty.R +++ b/R/sits_uncertainty.R @@ -7,6 +7,7 @@ #' @author Alber Sanchez, \email{alber.ipia@@inpe.br} #' #' @param cube Probability data cube. +#' @param ... Other parameters for specific functions. #' @param type Method to measure uncertainty. See details. #' @param multicores Number of cores to run the function. #' @param memsize Maximum overall memory (in GB) to run the function. @@ -51,7 +52,18 @@ #' plot(uncert_cube) #' } #' @export -sits_uncertainty <- function( +sits_uncertainty <- function(cube, ..., + type = "entropy", + multicores = 2L, + memsize = 4L, + output_dir, + version = "v1") { + # Dispatch + UseMethod("sits_uncertainty", cube) +} +#' @rdname sits_uncertainty +#' @export +sits_uncertainty.probs_cube <- function( cube, type = "entropy", multicores = 2, @@ -59,8 +71,7 @@ sits_uncertainty <- function( output_dir, version = "v1") { # Check if cube has probability data - .check_cube_files(cube) - .check_cube_is_probs_cube(cube) + .check_raster_cube_files(cube) # Check memsize .check_memsize(memsize, min = 1, max = 16384) # Check multicores @@ -91,24 +102,17 @@ sits_uncertainty <- function( .parallel_start(workers = multicores) on.exit(.parallel_stop(), add = TRUE) # Define the class of the smoothing - class(type) <- c(type, class(type)) - UseMethod("sits_uncertainty", type) -} - -#' @rdname sits_uncertainty -#' @export -sits_uncertainty.least <- function( - cube, - type = "least", - multicores = 2, - memsize = 4, - output_dir, - version = "v1") { + uncert_fn <- switch( + type, + "least" = .uncertainty_fn_least(), + "margin" = .uncertainty_fn_margin(), + "entropy" = .uncertainty_fn_entropy() + ) # Compute uncertainty - uncert_cube <- .uncertainty_cube( + uncert_cube <- .uncertainty_raster_cube( cube = cube, - band = "least", - uncert_fn = .uncertainty_fn_least(), + band = type, + uncert_fn = uncert_fn, output_dir = output_dir, version = version ) @@ -116,38 +120,29 @@ sits_uncertainty.least <- function( } #' @rdname sits_uncertainty #' @export -sits_uncertainty.entropy <- function( +sits_uncertainty.probs_vector_cube <- function( cube, type = "entropy", multicores = 2, memsize = 4, output_dir, version = "v1") { + # Check if cube has probability data + .check_raster_cube_files(cube) + # Check memsize + .check_memsize(memsize, min = 1, max = 16384) + # Check multicores + .check_multicores(multicores, min = 1, max = 2048) + # check output dir + .check_output_dir(output_dir) + # check version + version <- .check_version(version) + # version is case-insensitive in sits + version <- tolower(version) # Compute uncertainty - uncert_cube <- .uncertainty_cube( - cube = cube, - band = "entropy", - uncert_fn = .uncertainty_fn_entropy(), - output_dir = output_dir, - version = version - ) - return(uncert_cube) -} - -#' @rdname sits_uncertainty -#' @export -sits_uncertainty.margin <- function( - cube, - type = "margin", - multicores = 2, - memsize = 4, - output_dir, - version = "v1") { - # Create uncertainty cube - uncert_cube <- .uncertainty_cube( + uncert_cube <- .uncertainty_vector_cube( cube = cube, - band = "margin", - uncert_fn = .uncertainty_fn_margin(), + band = type, output_dir = output_dir, version = version ) diff --git a/R/sits_variance.R b/R/sits_variance.R index 8ac0e4a4a..f308c17ef 100644 --- a/R/sits_variance.R +++ b/R/sits_variance.R @@ -57,7 +57,7 @@ sits_variance <- function( output_dir, version = "v1") { # Check if cube has data and metadata - .check_cube_files(cube) + .check_raster_cube_files(cube) # check window size .check_window_size(window_size, min = 3, max = 33) # check neighborhood fraction diff --git a/man/plot.class_cube.Rd b/man/plot.class_cube.Rd index 6fd553c51..41d9b466c 100644 --- a/man/plot.class_cube.Rd +++ b/man/plot.class_cube.Rd @@ -30,17 +30,14 @@ \item{palette}{Alternative RColorBrewer palette} -\item{tmap_options}{List with optional tmap parameters +\item{tmap_options}{Named vector with optional tmap parameters max_cells (default: 1e+06) +scale (default: 0.5) graticules_labels_size (default: 0.7) -scale (default = 0.8) -legend_title_size (default: 0.7) -legend_text_size (default: 0.7) +legend_title_size (default: 1.0) +legend_text_size (default: 1.0) legend_bg_color (default: "white") -legend_bg_alpha (default: 0.5) -legend_width (default: 0.5) -legend_height (default: 0.7) -legend_position (default: c("left", "bottom"))} +legend_bg_alpha (default: 0.5)} } \value{ A color map, where each pixel has the color diff --git a/man/plot.class_vector_cube.Rd b/man/plot.class_vector_cube.Rd index 2b819dfe7..4adbec3bc 100644 --- a/man/plot.class_vector_cube.Rd +++ b/man/plot.class_vector_cube.Rd @@ -30,13 +30,14 @@ \item{palette}{Alternative RColorBrewer palette} -\item{tmap_options}{List with optional tmap parameters -tmap_max_cells (default: 1e+06) -tmap_graticules_labels_size (default: 0.7) -tmap_legend_title_size (default: 1.5) -tmap_legend_text_size (default: 1.2) -tmap_legend_bg_color (default: "white") -tmap_legend_bg_alpha (default: 0.5)} +\item{tmap_options}{Named vector with optional tmap parameters +max_cells (default: 1e+06) +scale (default: 0.5) +graticules_labels_size (default: 0.7) +legend_title_size (default: 1.0) +legend_text_size (default: 1.0) +legend_bg_color (default: "white") +legend_bg_alpha (default: 0.5)} } \value{ A plot object with an RGB image diff --git a/man/plot.probs_cube.Rd b/man/plot.probs_cube.Rd index f4b7d36f8..16a94082c 100644 --- a/man/plot.probs_cube.Rd +++ b/man/plot.probs_cube.Rd @@ -27,13 +27,14 @@ \item{rev}{Reverse order of colors in palette?} -\item{tmap_options}{List with optional tmap parameters -tmap_max_cells (default: 1e+06) -tmap_graticules_labels_size (default: 0.7) -tmap_legend_title_size (default: 1.5) -tmap_legend_text_size (default: 1.2) -tmap_legend_bg_color (default: "white") -tmap_legend_bg_alpha (default: 0.5)} +\item{tmap_options}{Named vector with optional tmap parameters +max_cells (default: 1e+06) +scale (default: 0.5) +graticules_labels_size (default: 0.7) +legend_title_size (default: 1.0) +legend_text_size (default: 1.0) +legend_bg_color (default: "white") +legend_bg_alpha (default: 0.5)} } \value{ A plot containing probabilities associated diff --git a/man/plot.probs_vector_cube.Rd b/man/plot.probs_vector_cube.Rd index 5a0ac01b8..e758b446f 100644 --- a/man/plot.probs_vector_cube.Rd +++ b/man/plot.probs_vector_cube.Rd @@ -27,13 +27,14 @@ \item{rev}{Reverse order of colors in palette?} -\item{tmap_options}{List with optional tmap parameters -tmap_max_cells (default: 1e+06) -tmap_graticules_labels_size (default: 0.7) -tmap_legend_title_size (default: 1.5) -tmap_legend_text_size (default: 1.2) -tmap_legend_bg_color (default: "white") -tmap_legend_bg_alpha (default: 0.5)} +\item{tmap_options}{Named vector with optional tmap parameters +max_cells (default: 1e+06) +scale (default: 0.5) +graticules_labels_size (default: 0.7) +legend_title_size (default: 1.0) +legend_text_size (default: 1.0) +legend_bg_color (default: "white") +legend_bg_alpha (default: 0.5)} } \value{ A plot containing probabilities associated diff --git a/man/plot.raster_cube.Rd b/man/plot.raster_cube.Rd index f5ac2bc75..49b05ef40 100644 --- a/man/plot.raster_cube.Rd +++ b/man/plot.raster_cube.Rd @@ -39,7 +39,7 @@ \item{rev}{Reverse the color order in the palette?} -\item{tmap_options}{List with optional tmap parameters +\item{tmap_options}{Named vector with optional tmap parameters max_cells (default: 1e+06) scale (default: 0.5) graticules_labels_size (default: 0.7) diff --git a/man/plot.uncertainty_cube.Rd b/man/plot.uncertainty_cube.Rd index e2e21536a..f8f8d2a46 100644 --- a/man/plot.uncertainty_cube.Rd +++ b/man/plot.uncertainty_cube.Rd @@ -24,13 +24,14 @@ \item{rev}{Reverse the color order in the palette?} -\item{tmap_options}{List with optional tmap parameters -tmap_max_cells (default: 1e+06) -tmap_graticules_labels_size (default: 0.7) -tmap_legend_title_size (default: 1.5) -tmap_legend_text_size (default: 1.2) -tmap_legend_bg_color (default: "white") -tmap_legend_bg_alpha (default: 0.5)} +\item{tmap_options}{Named vector with optional tmap parameters +max_cells (default: 1e+06) +scale (default: 0.5) +graticules_labels_size (default: 0.7) +legend_title_size (default: 1.0) +legend_text_size (default: 1.0) +legend_bg_color (default: "white") +legend_bg_alpha (default: 0.5)} } \value{ A plot object produced by the stars package diff --git a/man/plot.variance_cube.Rd b/man/plot.variance_cube.Rd index 9de0f6784..455614c76 100644 --- a/man/plot.variance_cube.Rd +++ b/man/plot.variance_cube.Rd @@ -30,13 +30,14 @@ \item{type}{Type of plot ("map" or "hist")} -\item{tmap_options}{List with optional tmap parameters -tmap_max_cells (default: 1e+06) -tmap_graticules_labels_size (default: 0.7) -tmap_legend_title_size (default: 1.5) -tmap_legend_text_size (default: 1.2) -tmap_legend_bg_color (default: "white") -tmap_legend_bg_alpha (default: 0.5)} +\item{tmap_options}{Named vector with optional tmap parameters +max_cells (default: 1e+06) +scale (default: 0.5) +graticules_labels_size (default: 0.7) +legend_title_size (default: 1.0) +legend_text_size (default: 1.0) +legend_bg_color (default: "white") +legend_bg_alpha (default: 0.5)} } \value{ A plot containing probabilities associated diff --git a/man/plot.vector_cube.Rd b/man/plot.vector_cube.Rd index f4eb34f55..83a7f7435 100644 --- a/man/plot.vector_cube.Rd +++ b/man/plot.vector_cube.Rd @@ -45,13 +45,14 @@ \item{rev}{Reverse the color order in the palette?} -\item{tmap_options}{List with optional tmap parameters -tmap_max_cells (default: 1e+06) -tmap_graticules_labels_size (default: 0.7) -tmap_legend_title_size (default: 1.5) -tmap_legend_text_size (default: 1.2) -tmap_legend_bg_color (default: "white") -tmap_legend_bg_alpha (default: 0.5)} +\item{tmap_options}{Named vector with optional tmap parameters +max_cells (default: 1e+06) +scale (default: 0.5) +graticules_labels_size (default: 0.7) +legend_title_size (default: 1.0) +legend_text_size (default: 1.0) +legend_bg_color (default: "white") +legend_bg_alpha (default: 0.5)} } \value{ A plot object with an RGB image diff --git a/man/sits_label_classification.Rd b/man/sits_label_classification.Rd index f41e7dd06..991b42a2a 100644 --- a/man/sits_label_classification.Rd +++ b/man/sits_label_classification.Rd @@ -12,8 +12,8 @@ \usage{ sits_label_classification( cube, - memsize = 4, - multicores = 2, + memsize = 4L, + multicores = 2L, output_dir, version = "v1", progress = TRUE diff --git a/man/sits_uncertainty.Rd b/man/sits_uncertainty.Rd index 9dcf775c5..59e8ecb6c 100644 --- a/man/sits_uncertainty.Rd +++ b/man/sits_uncertainty.Rd @@ -2,31 +2,22 @@ % Please edit documentation in R/sits_uncertainty.R \name{sits_uncertainty} \alias{sits_uncertainty} -\alias{sits_uncertainty.least} -\alias{sits_uncertainty.entropy} -\alias{sits_uncertainty.margin} +\alias{sits_uncertainty.probs_cube} +\alias{sits_uncertainty.probs_vector_cube} \alias{sits_uncertainty.default} \title{Estimate classification uncertainty based on probs cube} \usage{ sits_uncertainty( cube, + ..., type = "entropy", - multicores = 2, - memsize = 4, + multicores = 2L, + memsize = 4L, output_dir, version = "v1" ) -\method{sits_uncertainty}{least}( - cube, - type = "least", - multicores = 2, - memsize = 4, - output_dir, - version = "v1" -) - -\method{sits_uncertainty}{entropy}( +\method{sits_uncertainty}{probs_cube}( cube, type = "entropy", multicores = 2, @@ -35,9 +26,9 @@ sits_uncertainty( version = "v1" ) -\method{sits_uncertainty}{margin}( +\method{sits_uncertainty}{probs_vector_cube}( cube, - type = "margin", + type = "entropy", multicores = 2, memsize = 4, output_dir, @@ -49,6 +40,8 @@ sits_uncertainty( \arguments{ \item{cube}{Probability data cube.} +\item{...}{Other parameters for specific functions.} + \item{type}{Method to measure uncertainty. See details.} \item{multicores}{Number of cores to run the function.}