From 542192aa9e7448c03a086fc548ec03c8a232f124 Mon Sep 17 00:00:00 2001 From: Felipe Date: Sat, 7 Dec 2024 20:03:21 +0000 Subject: [PATCH 01/10] fix bug in time series classification images --- R/api_classify.R | 4 ++++ R/api_ml_model.R | 2 ++ R/sits_classify.R | 2 +- 3 files changed, 7 insertions(+), 1 deletion(-) diff --git a/R/api_classify.R b/R/api_classify.R index 5762c5f5..86f7b570 100755 --- a/R/api_classify.R +++ b/R/api_classify.R @@ -651,6 +651,8 @@ values <- .pred_features(pred_part) # Classify values <- ml_model(values) + # normalize and calibrate values + values <- .ml_normalize(ml_model, values) # Return classification values <- tibble::as_tibble(values) values @@ -691,6 +693,8 @@ values <- .pred_features(pred_part) # Classify values <- ml_model(values) + # normalize and calibrate values + values <- .ml_normalize(ml_model, values) # Return classification values <- tibble::tibble(data.frame(values)) # Clean GPU memory diff --git a/R/api_ml_model.R b/R/api_ml_model.R index 3d4df02b..d480f964 100644 --- a/R/api_ml_model.R +++ b/R/api_ml_model.R @@ -119,8 +119,10 @@ #' @export #' .ml_normalize.torch_model <- function(ml_model, values){ + column_names <- colnames(values) values[is.na(values)] <- 0 values <- softmax(values) + colnames(values) <- column_names return(values) } #' @export diff --git a/R/sits_classify.R b/R/sits_classify.R index ee603458..fd712ec6 100644 --- a/R/sits_classify.R +++ b/R/sits_classify.R @@ -437,7 +437,7 @@ sits_classify.segs_cube <- function(data, proc_bloat <- .conf("processing_bloat_gpu") } # avoid memory race in Apple MPS - if(.torch_mps_enabled(ml_model)){ + if (.torch_mps_enabled(ml_model)) { memsize <- 1 gpu_memory <- 1 } From 699baf0894ce33aed9e792f7cfd0b409468f4e62 Mon Sep 17 00:00:00 2001 From: Felipe Date: Sat, 7 Dec 2024 21:56:08 +0000 Subject: [PATCH 02/10] update .tile_extract message --- R/api_tile.R | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/R/api_tile.R b/R/api_tile.R index df41654f..26fe7e4b 100644 --- a/R/api_tile.R +++ b/R/api_tile.R @@ -1465,7 +1465,8 @@ NULL x = r_obj, y = segments, fun = NULL, - include_cols = "pol_id" + include_cols = "pol_id", + progress = FALSE ) values <- dplyr::bind_rows(values) values <- dplyr::select(values, -"coverage_fraction") From e39ae1359aed141cf136893ead69e6a483541fb5 Mon Sep 17 00:00:00 2001 From: Felipe Date: Mon, 9 Dec 2024 19:24:46 +0000 Subject: [PATCH 03/10] add FLT8S metadata --- inst/extdata/config_internals.yml | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/inst/extdata/config_internals.yml b/inst/extdata/config_internals.yml index 3da8d367..bc4a603c 100644 --- a/inst/extdata/config_internals.yml +++ b/inst/extdata/config_internals.yml @@ -125,6 +125,13 @@ default_values : maximum_value: 1.7014118346015974e+37 offset_value : 0 scale_factor : 1 + FLT8S : + data_type : "FLT8S" + missing_value: -3.402823466385288e+37 + minimum_value: -3.402823466385288e+37 + maximum_value: 1.7014118346015974e+37 + offset_value : 0 + scale_factor : 1 # Derived cube definitions derived_cube : From ae2e0eac005f1d81a5223c42536474ee773ba193 Mon Sep 17 00:00:00 2001 From: Felipe Date: Wed, 11 Dec 2024 20:33:51 +0000 Subject: [PATCH 04/10] fix bug in classify label's name with space --- R/api_classify.R | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/R/api_classify.R b/R/api_classify.R index 86f7b570..a7a4647e 100755 --- a/R/api_classify.R +++ b/R/api_classify.R @@ -596,7 +596,8 @@ prediction <- .classify_ts_gpu( pred = pred, ml_model = ml_model, - gpu_memory = gpu_memory) + gpu_memory = gpu_memory + ) else prediction <- .classify_ts_cpu( pred = pred, @@ -696,7 +697,7 @@ # normalize and calibrate values values <- .ml_normalize(ml_model, values) # Return classification - values <- tibble::tibble(data.frame(values)) + values <- tibble::as_tibble(values) # Clean GPU memory .ml_gpu_clean(ml_model) return(values) From ef975f0d4672c5d0a8fe4bfd79839d103c366456 Mon Sep 17 00:00:00 2001 From: Felipe Carvalho Date: Thu, 12 Dec 2024 16:54:16 +0000 Subject: [PATCH 05/10] fix bug in plot segment with RGB --- R/sits_plot.R | 2 ++ 1 file changed, 2 insertions(+) diff --git a/R/sits_plot.R b/R/sits_plot.R index dcfae4a2..4bcf0b8a 100644 --- a/R/sits_plot.R +++ b/R/sits_plot.R @@ -836,6 +836,8 @@ plot.vector_cube <- function(x, ..., sf_seg = sf_seg, seg_color = seg_color, line_width = line_width, + first_quantile = first_quantile, + last_quantile = last_quantile, scale = scale, max_cog_size = max_cog_size, tmap_params = tmap_params From ced2f92c3d9f40dab87a169cf7ab4902698d1530 Mon Sep 17 00:00:00 2001 From: gilbertocamara Date: Thu, 12 Dec 2024 22:19:49 -0300 Subject: [PATCH 06/10] add function to export time series to CSV --- NAMESPACE | 1 + R/api_csv.R | 19 +++++++++++++ R/sits_classify.R | 8 ++++-- R/sits_csv.R | 50 +++++++++++++++++++++++++++++------ man/sits_timeseries_to_csv.Rd | 33 +++++++++++++++++++++++ 5 files changed, 101 insertions(+), 10 deletions(-) create mode 100644 man/sits_timeseries_to_csv.Rd diff --git a/NAMESPACE b/NAMESPACE index 754f776d..a8b4414c 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -601,6 +601,7 @@ export(sits_tae) export(sits_tempcnn) export(sits_tiles_to_roi) export(sits_timeline) +export(sits_timeseries_to_csv) export(sits_to_csv) export(sits_to_xlsx) export(sits_train) diff --git a/R/api_csv.R b/R/api_csv.R index 48af7ad5..8f5d6a9f 100644 --- a/R/api_csv.R +++ b/R/api_csv.R @@ -81,3 +81,22 @@ ) return(samples) } +#' @title Get samples metadata as CSV +#' @name .csv_metadata_from_samples +#' @author Gilberto Camara +#' @keywords internal +#' @noRd +#' @param data A sits tibble. +#' @return A tibble with metadata +#' +.csv_metadata_from_samples <- function(data) { + # select the parts of the tibble to be saved + csv_columns <- .conf("df_sample_columns") + csv <- dplyr::select(data, dplyr::all_of(csv_columns)) + # create a column with the id + n_rows_csv <- nrow(csv) + id <- tibble::tibble(id = 1:n_rows_csv) + # join the two tibbles + csv <- dplyr::bind_cols(id, csv) + return(csv) +} diff --git a/R/sits_classify.R b/R/sits_classify.R index f81094c4..b5787ca7 100644 --- a/R/sits_classify.R +++ b/R/sits_classify.R @@ -299,14 +299,18 @@ sits_classify.raster_cube <- function(data, msg = .conf("messages", ".check_gpu_memory") ) # Calculate available memory from GPU - memsize <- floor(gpu_memory - .torch_mem_info()) - .check_int_parameter(memsize, min = 1, + gpu_available_memory <- floor(gpu_memory - .torch_mem_info()) + .check_int_parameter(gpu_available_memory, min = 1, msg = .conf("messages", ".check_gpu_memory_size") ) proc_bloat <- .conf("processing_bloat_gpu") } # avoid memory race in Apple MPS if (.torch_mps_enabled(ml_model)) { + .check_int_parameter(gpu_memory, min = 1, max = 16384, + msg = .conf("messages", ".check_gpu_memory") + ) + warning(.conf("messages", "sits_classify_mps"), call. = FALSE ) diff --git a/R/sits_csv.R b/R/sits_csv.R index c8a73008..d0e2ae1a 100644 --- a/R/sits_csv.R +++ b/R/sits_csv.R @@ -39,14 +39,8 @@ sits_to_csv.sits <- function(data, file = NULL) { extensions = "csv", file_exists = FALSE ) - # select the parts of the tibble to be saved - csv_columns <- .conf("df_sample_columns") - csv <- dplyr::select(data, dplyr::all_of(csv_columns)) - # create a column with the id - n_rows_csv <- nrow(csv) - id <- tibble::tibble(id = 1:n_rows_csv) - # join the two tibbles - csv <- dplyr::bind_cols(id, csv) + # get metadata + csv <- .csv_metadata_from_samples(data) # write the CSV file if (.has(file)) utils::write.csv(csv, file, row.names = FALSE, quote = FALSE) @@ -68,3 +62,43 @@ sits_to_csv.tbl_df <- function(data, file) { sits_to_csv.default <- function(data, file) { stop(.conf("messages", "sits_to_csv_default")) } + +#' @title Export a a full sits tibble to the CSV format +#' +#' @name sits_timeseries_to_csv +#' +#' @author Gilberto Camara, \email{gilberto.camara@@inpe.br} +#' +#' @description Converts metadata and data from a sits tibble to a CSV file. +#' The CSV file will not contain the actual time +#' series. Its columns will be the same as those of a +#' CSV file used to retrieve data from +#' ground information ("latitude", "longitude", "start_date", +#' "end_date", "cube", "label"), plus the all the time series for +#' each data +#' @param data Time series (tibble of class "sits"). +#' @param file Full path of the exported CSV file +#' (valid file name with extension ".csv"). +#' @return Return data.frame with CSV columns (optional) +#' +#' @examples +#' csv_file <- paste0(tempdir(), "/cerrado_2classes_ts.csv") +#' sits_timeseries_to_csv(cerrado_2classes, file = csv_file) +#' @export +#' +sits_timeseries_to_csv <- function(data, file = NULL) { + # check the samples are valid + data <- .check_samples(data) + csv_1 <- .csv_metadata_from_samples(data) + csv_2 <- .predictors(data)[-2:0] + csv_combined <- dplyr::bind_cols(csv_1, csv_2) + + # write the CSV file + if (.has(file)) + utils::write.csv(csv_combined, + file, + row.names = FALSE, + quote = FALSE) + + return(csv_combined) +} diff --git a/man/sits_timeseries_to_csv.Rd b/man/sits_timeseries_to_csv.Rd new file mode 100644 index 00000000..6854f79d --- /dev/null +++ b/man/sits_timeseries_to_csv.Rd @@ -0,0 +1,33 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/sits_csv.R +\name{sits_timeseries_to_csv} +\alias{sits_timeseries_to_csv} +\title{Export a a full sits tibble to the CSV format} +\usage{ +sits_timeseries_to_csv(data, file = NULL) +} +\arguments{ +\item{data}{Time series (tibble of class "sits").} + +\item{file}{Full path of the exported CSV file +(valid file name with extension ".csv").} +} +\value{ +Return data.frame with CSV columns (optional) +} +\description{ +Converts metadata and data from a sits tibble to a CSV file. + The CSV file will not contain the actual time + series. Its columns will be the same as those of a + CSV file used to retrieve data from + ground information ("latitude", "longitude", "start_date", + "end_date", "cube", "label"), plus the all the time series for + each data +} +\examples{ +csv_file <- paste0(tempdir(), "/cerrado_2classes_ts.csv") +sits_timeseries_to_csv(cerrado_2classes, file = csv_file) +} +\author{ +Gilberto Camara, \email{gilberto.camara@inpe.br} +} From 1747bdfcf76bf20a6680339afdb21479d0f12283 Mon Sep 17 00:00:00 2001 From: Felipe Date: Mon, 16 Dec 2024 17:18:18 +0000 Subject: [PATCH 07/10] add support to multi tiles in summary variance cube --- R/sits_summary.R | 81 +++++++++++++++++++----------------- man/summary.variance_cube.Rd | 7 ++-- 2 files changed, 47 insertions(+), 41 deletions(-) diff --git a/R/sits_summary.R b/R/sits_summary.R index bf4453b8..9b91ee2a 100644 --- a/R/sits_summary.R +++ b/R/sits_summary.R @@ -267,11 +267,12 @@ summary.derived_cube <- function(object, ..., tile = NULL) { #' @author Gilberto Camara, \email{gilberto.camara@@inpe.br} #' @description This is a generic function. Parameters depend on the specific #' type of input. -#' @param object Object of class "class_cube" -#' @param ... Further specifications for \link{summary}. -#' @param tile Tile to be summarized -#' @param intervals Intervals to calculate the quantiles -#' @param quantiles Quantiles to be shown +#' @param object Object of class "class_cube" +#' @param ... Further specifications for \link{summary}. +#' @param sample_size The size of samples will be extracted from the variance +#' cube. +#' @param intervals Intervals to calculate the quantiles +#' @param quantiles Quantiles to be shown #' #' @return A summary of a variance cube #' @@ -299,42 +300,46 @@ summary.derived_cube <- function(object, ..., tile = NULL) { #' @export summary.variance_cube <- function( object, ..., - tile = NULL, intervals = 0.05, - quantiles = c ("75%", "80%", "85%", "90%", "95%", "100%")) { + sample_size = 10000, + quantiles = c("75%", "80%", "85%", "90%", "95%", "100%")) { .check_set_caller("summary_variance_cube") - # Pre-conditional check - .check_chr_parameter(tile, allow_null = TRUE) - # Extract the chosen tile - if (!is.null(tile)) { - object <- .summary_check_tile(object, tile) - } - # get sample size - sample_size <- .conf("summary_sample_size") - # Get tile name - tile <- .default(tile, .cube_tiles(object)[[1]]) - tile <- .cube_filter_tiles(object, tile) - # get the bands - band <- .tile_bands(tile) - # extract the file paths - files <- .tile_paths(tile) - # read the files with terra - r <- .raster_open_rast(files) - # get the a sample of the values - values <- r |> - .raster_sample(size = sample_size, na.rm = TRUE) - # scale the values - band_conf <- .tile_band_conf(tile, band) - scale <- .scale(band_conf) - offset <- .offset(band_conf) - values <- values * scale + offset - # calculate the quantiles - mat <- apply(values, 2, function(x){ - stats::quantile(x, probs = seq(0, 1, intervals)) + # Get cube labels + labels <- .cube_labels(object) + # Extract variance values for each tiles using a sample size + var_values <- slider::slide(data, function(tile) { + # get the bands + band <- .tile_bands(tile) + # extract the file path + file <- .tile_paths(tile) + # read the files with terra + r <- .raster_open_rast(file) + # get the a sample of the values + values <- r |> + .raster_sample(size = sample_size, na.rm = TRUE) + # scale the values + band_conf <- .tile_band_conf(tile, band) + scale <- .scale(band_conf) + offset <- .offset(band_conf) + values <- values * scale + offset + values }) - colnames(mat) <- .tile_labels(tile) - - return(mat[quantiles, ]) + # Combine variance values + var_values <- dplyr::bind_rows(var_values) + # Update columns name + colnames(var_values) <- labels + # Extract quantile for each column + var_values <- dplyr::reframe( + var_values, + dplyr::across(.cols = dplyr::all_of(labels), function(x) { + stats::quantile(x, probs = seq(0, 1, intervals)) + }) + ) + # Update row names + percent_intervals <- paste0(seq(from = 0, to = 1, by = intervals)*100, "%") + rownames(var_values) <- percent_intervals + # Return variance values filtered by quantiles + return(var_values[quantiles, ]) } #' #' diff --git a/man/summary.variance_cube.Rd b/man/summary.variance_cube.Rd index c0ca3405..c713bf95 100644 --- a/man/summary.variance_cube.Rd +++ b/man/summary.variance_cube.Rd @@ -7,8 +7,8 @@ \method{summary}{variance_cube}( object, ..., - tile = NULL, intervals = 0.05, + sample_size = 10000, quantiles = c("75\%", "80\%", "85\%", "90\%", "95\%", "100\%") ) } @@ -17,10 +17,11 @@ \item{...}{Further specifications for \link{summary}.} -\item{tile}{Tile to be summarized} - \item{intervals}{Intervals to calculate the quantiles} +\item{sample_size}{The size of samples will be extracted from the variance +cube.} + \item{quantiles}{Quantiles to be shown} } \value{ From 311291006c18b4c359007e9b7039f17820b6c0a4 Mon Sep 17 00:00:00 2001 From: Felipe Date: Mon, 16 Dec 2024 17:27:19 +0000 Subject: [PATCH 08/10] update sits_summary code --- R/sits_summary.R | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/R/sits_summary.R b/R/sits_summary.R index 9b91ee2a..35d13e20 100644 --- a/R/sits_summary.R +++ b/R/sits_summary.R @@ -305,9 +305,9 @@ summary.variance_cube <- function( quantiles = c("75%", "80%", "85%", "90%", "95%", "100%")) { .check_set_caller("summary_variance_cube") # Get cube labels - labels <- .cube_labels(object) + labels <- unname(.cube_labels(object)) # Extract variance values for each tiles using a sample size - var_values <- slider::slide(data, function(tile) { + var_values <- slider::slide(object, function(tile) { # get the bands band <- .tile_bands(tile) # extract the file path From 8c8bf45454f950058db59da3a4593b6598b429cf Mon Sep 17 00:00:00 2001 From: Felipe Date: Mon, 16 Dec 2024 17:35:28 +0000 Subject: [PATCH 09/10] update summary --- R/sits_summary.R | 67 ++++++++++++++++++++++-------------------------- 1 file changed, 31 insertions(+), 36 deletions(-) diff --git a/R/sits_summary.R b/R/sits_summary.R index 9b91ee2a..184aaea5 100644 --- a/R/sits_summary.R +++ b/R/sits_summary.R @@ -195,9 +195,10 @@ summary.raster_cube <- function(object, ..., tile = NULL, date = NULL) { #' @title Summary of a derived cube #' @author Felipe Souza, \email{felipe.souza@@inpe.br} #' @noRd -#' @param object data cube +#' @param object data cube #' @param ... Further specifications for \link{summary}. -#' @param tile A \code{tile}. +#' @param sample_size The size of samples will be extracted from the variance +#' cube. #' @return Summary of a derived cube #' #' @examples @@ -225,41 +226,35 @@ summary.raster_cube <- function(object, ..., tile = NULL, date = NULL) { #' } #' #' @export -summary.derived_cube <- function(object, ..., tile = NULL) { +summary.derived_cube <- function(object, ..., sample_size = 10000) { .check_set_caller("summary_derived_cube") - # Pre-conditional check - .check_chr_parameter(tile, allow_null = TRUE) - # Extract the chosen tile - if (!is.null(tile)) { - object <- .summary_check_tile(object, tile) - } - # get sample size - sample_size <- .conf("summary_sample_size") - # Get tile name - tile <- .default(tile, .cube_tiles(object)[[1]]) - tile <- .cube_filter_tiles(object, tile) - # get the bands - band <- .tile_bands(tile) - .check_num( - x = length(band), - min = 1, - max = 1, - is_integer = TRUE - ) - # extract the file paths - files <- .tile_paths(tile) - # read the files with terra - r <- .raster_open_rast(files) - # get the a sample of the values - values <- r |> - .raster_sample(size = sample_size, na.rm = TRUE) - # scale the values - band_conf <- .tile_band_conf(tile, band) - scale <- .scale(band_conf) - offset <- .offset(band_conf) - sum <- summary(values * scale + offset) - colnames(sum) <- .tile_labels(tile) - return(sum) + # Get cube labels + labels <- unname(.cube_labels(object)) + # Extract variance values for each tiles using a sample size + var_values <- slider::slide(object, function(tile) { + # get the bands + band <- .tile_bands(tile) + # extract the file path + file <- .tile_paths(tile) + # read the files with terra + r <- .raster_open_rast(file) + # get the a sample of the values + values <- r |> + .raster_sample(size = sample_size, na.rm = TRUE) + # scale the values + band_conf <- .tile_band_conf(tile, band) + scale <- .scale(band_conf) + offset <- .offset(band_conf) + values <- values * scale + offset + values + }) + # Combine variance values + var_values <- dplyr::bind_rows(var_values) + var_values <- summary(var_values) + # Update columns name + colnames(var_values) <- labels + # Return summary values + return(var_values) } #' @title Summarise variance cubes #' @method summary variance_cube From 803aed0025aa3bfead270f2abbaeae50d1c09905 Mon Sep 17 00:00:00 2001 From: Felipe Date: Mon, 16 Dec 2024 20:47:01 +0000 Subject: [PATCH 10/10] update summary of class_cube --- R/sits_summary.R | 89 ++++++++++++++++++++------------------- man/summary.class_cube.Rd | 4 +- 2 files changed, 46 insertions(+), 47 deletions(-) diff --git a/R/sits_summary.R b/R/sits_summary.R index 15f2efaf..15ad0f91 100644 --- a/R/sits_summary.R +++ b/R/sits_summary.R @@ -336,8 +336,6 @@ summary.variance_cube <- function( # Return variance values filtered by quantiles return(var_values[quantiles, ]) } -#' -#' #' @title Summarize data cubes #' @method summary class_cube #' @name summary.class_cube @@ -346,7 +344,6 @@ summary.variance_cube <- function( #' type of input. #' @param object Object of class "class_cube" #' @param ... Further specifications for \link{summary}. -#' @param tile Tile to be summarized #' #' @return A summary of a classified cube #' @@ -373,46 +370,50 @@ summary.variance_cube <- function( #' summary(label_cube) #' } #' @export -#' -summary.class_cube <- function(object, ..., tile = NULL) { +summary.class_cube <- function(object, ...) { .check_set_caller("summary_class_cube") - # Pre-conditional check - .check_chr_parameter(tile, allow_null = TRUE) - # Extract the chosen tile - if (!is.null(tile)) { - object <- .summary_check_tile(object, tile) - } - # Get tile name - tile <- .default(tile, .cube_tiles(object)[[1]]) - tile <- .cube_filter_tiles(object, tile) - # get the bands - bands <- .tile_bands(tile) - .check_chr_parameter(bands, len_min = 1, len_max = 1) - # extract the file paths - files <- .tile_paths(tile) - # read raster files - r <- .raster_open_rast(files) - # get a frequency of values - class_areas <- .raster_freq(r) - # transform to km^2 - cell_size <- .tile_xres(tile) * .tile_yres(tile) - class_areas[["area"]] <- (class_areas[["count"]] * cell_size) / 10^6 - # change value to character - class_areas <- dplyr::mutate(class_areas, - value = as.character(.data[["value"]]) - ) - # create a data.frame with the labels - labels <- .tile_labels(tile) - df1 <- tibble::tibble(value = names(labels), class = unname(labels)) - # join the labels with the areas - sum <- dplyr::full_join(df1, class_areas, by = "value") - sum <- dplyr::mutate(sum, - area_km2 = signif(.data[["area"]], 2), - .keep = "unused" - ) - # remove layer information - sum_clean <- sum[, -3] |> - tidyr::replace_na(list(layer = 1, count = 0, area_km2 = 0)) - # show the result - return(sum_clean) + # Get cube labels + labels <- unname(.cube_labels(object)) + # Extract classes values for each tiles using a sample size + classes_areas <- slider::slide(object, function(tile) { + # get the bands + band <- .tile_bands(tile) + # extract the file path + file <- .tile_paths(tile) + # read the files with terra + r <- .raster_open_rast(file) + # get a frequency of values + class_areas <- .raster_freq(r) + # transform to km^2 + cell_size <- .tile_xres(tile) * .tile_yres(tile) + class_areas[["area"]] <- (class_areas[["count"]] * cell_size) / 10^6 + # change value to character + class_areas <- dplyr::mutate( + class_areas, value = as.character(.data[["value"]]) + ) + # create a data.frame with the labels + labels <- .tile_labels(tile) + df1 <- tibble::tibble(value = names(labels), class = unname(labels)) + # join the labels with the areas + sum <- dplyr::full_join(df1, class_areas, by = "value") + sum <- dplyr::mutate(sum, + area_km2 = signif(.data[["area"]], 2), + .keep = "unused" + ) + # remove layer information + sum_clean <- sum[, -3] |> + tidyr::replace_na(list(layer = 1, count = 0, area_km2 = 0)) + + sum_clean + }) + # Combine tiles areas + classes_areas <- dplyr::bind_rows(classes_areas) |> + dplyr::group_by(.data[["value"]], .data[["class"]]) |> + dplyr::summarise( + count = sum(.data[["count"]]), + area_km2 = sum(.data[["area_km2"]]), + .groups = "keep") |> + dplyr::ungroup() + # Return classes areas + return(classes_areas) } diff --git a/man/summary.class_cube.Rd b/man/summary.class_cube.Rd index bdaf6a9d..21f93251 100644 --- a/man/summary.class_cube.Rd +++ b/man/summary.class_cube.Rd @@ -4,14 +4,12 @@ \alias{summary.class_cube} \title{Summarize data cubes} \usage{ -\method{summary}{class_cube}(object, ..., tile = NULL) +\method{summary}{class_cube}(object, ...) } \arguments{ \item{object}{Object of class "class_cube"} \item{...}{Further specifications for \link{summary}.} - -\item{tile}{Tile to be summarized} } \value{ A summary of a classified cube