diff --git a/DESCRIPTION b/DESCRIPTION index 90a05b4ab..8d3640eb5 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -102,7 +102,7 @@ Suggests: RcppArmadillo (>= 0.12), scales, spdep, - stars (>= 0.6), + stars (>= 0.6-5), stringr, supercells (>= 1.0.0), testthat (>= 3.1.3), @@ -137,9 +137,7 @@ Collate: 'api_cube.R' 'api_data.R' 'api_debug.R' - 'api_detect_changes.R' 'api_download.R' - 'api_dtw.R' 'api_environment.R' 'api_factory.R' 'api_file_info.R' @@ -202,6 +200,7 @@ Collate: 'api_tile.R' 'api_timeline.R' 'api_tmap.R' + 'api_tmap_v3.R' 'api_torch.R' 'api_torch_psetae.R' 'api_ts.R' @@ -231,9 +230,6 @@ Collate: 'sits_cube_copy.R' 'sits_clean.R' 'sits_cluster.R' - 'sits_detect_change.R' - 'sits_detect_change_method.R' - 'sits_dtw.R' 'sits_factory.R' 'sits_filters.R' 'sits_geo_dist.R' diff --git a/NAMESPACE b/NAMESPACE index 67061e53e..741cf6547 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -10,6 +10,11 @@ S3method("sits_labels<-",class_cube) S3method("sits_labels<-",default) S3method("sits_labels<-",probs_cube) S3method("sits_labels<-",sits) +S3method(.accuracy_get_validation,csv) +S3method(.accuracy_get_validation,data.frame) +S3method(.accuracy_get_validation,gpkg) +S3method(.accuracy_get_validation,sf) +S3method(.accuracy_get_validation,shp) S3method(.band_rename,raster_cube) S3method(.band_rename,sits) S3method(.check_samples,default) diff --git a/NEWS.md b/NEWS.md index 12557665c..e860e130e 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,13 +1,22 @@ # SITS Release History -# What's new in SITS version 1.5 - -### Hotfix version 1.5.0-1 +# What's new in SITS version 1.5.1 + +* Support for ESA World Cover map +* Support for many Digital Earth Australia products +* Support for Digital Earth Africa geomedian products +* Improve .netrc access to Harmonized Landsat-Sentinel cubes +* Use ROI to cut data cube after mosaic operation +* Support for raster and vector classification using DEM as base cubes +* Convert from 'httr' package to 'httr2' package +* Remove deprecated class to purrr::map_dfc, purrr::map_dfr and similar +* Fix tuning for torch models +* Add geometry validation when extracting time series * Add multicores processing support for active learning sampling methods * Remove tapply from `.reg_cube_split_assets()` for R 4.X compatibility * Fix `sits_merge()` function that was not merging `SAR` and `OPTICAL` cubes * Rename n_input_pixels back to input_pixels for compatibility with models trained in old versions of the package -* Fix torch usage in Apple M3 by turning off MPS technology +* Fix torch usage in Apple M3 * Fix date parameter usage in `sits_view()` * Improve `plot()` performance using raster overviews * Include support for PLANET Mosaic product diff --git a/R/api_accuracy.R b/R/api_accuracy.R index 0d873e994..e457d8ff7 100644 --- a/R/api_accuracy.R +++ b/R/api_accuracy.R @@ -119,3 +119,71 @@ ) ) } +#' @title Get validation samples +#' @name .accuracy_get_validation +#' @description Retrieves and checks validation data +#' @keywords internal +#' @noRd +#' @param validation validation (CSV file, SHP file, SF object, data.frame) +#' @return samples for validation +#' +.accuracy_get_validation <- function(validation){ + # handle validation data as files + if (is.character(validation)) { + val_class <- tolower(.file_ext(validation)) + class(validation) <- c(val_class, validation) + } + UseMethod(".accuracy_get_validation", validation) +} +#' @export +.accuracy_get_validation.csv <- function(validation){ + # Read sample information from CSV file and put it in a tibble + valid_samples <- .csv_get_validation_samples(validation) + return(valid_samples) +} +#' @export +.accuracy_get_validation.shp <- function(validation){ + validation_sf <- sf::st_read(validation) + .check_that(all(sf::st_geometry_type(validation_sf) == "POINT")) + valid_samples <- .accuracy_get_validation(validation_sf) + return(valid_samples) +} +#' @export +.accuracy_get_validation.gpkg <- function(validation){ + validation_sf <- sf::st_read(validation) + .check_that(all(sf::st_geometry_type(validation_sf) == "POINT")) + valid_samples <- .accuracy_get_validation(validation_sf) + return(valid_samples) +} +#' @export +.accuracy_get_validation.sf <- function(validation){ + # Pre-condition - check for the required columns + .check_chr_contains(colnames(validation), c("label")) + # transform the `sf` object in a valid + valid_samples <- validation |> + dplyr::mutate( + geom = sf::st_geometry(validation) + ) |> + dplyr::mutate( + geom = sf::st_centroid(.data[["geom"]]) + ) |> + dplyr::mutate( + coords = sf::st_coordinates(.data[["geom"]]) + ) |> + dplyr::mutate( + longitude = .data[["coords"]][, 1], + latitude = .data[["coords"]][, 2] + ) |> + dplyr::select( + "label", "longitude", "latitude" + ) + return(valid_samples) +} +#' @export +`.accuracy_get_validation.data.frame` <- function(validation){ + # handle data frames + .check_chr_contains(colnames(validation), + c("label", "longitude", "latitude") + ) + return(validation) +} diff --git a/R/api_csv.R b/R/api_csv.R index 410e87dd3..f531d5e15 100644 --- a/R/api_csv.R +++ b/R/api_csv.R @@ -30,3 +30,30 @@ class(samples) <- c("sits", class(samples)) return(samples) } + +#' @title Transform a CSV with labelled points for accuracy assessmentinto a samples file +#' @name .csv_get_validation_samples +#' @author Gilberto Camara +#' @keywords internal +#' @noRd +#' @param csv_file CSV that describes the data to be retrieved. +#' @return A tibble with information the samples to be retrieved +#' +.csv_get_validation_samples <- function(csv_file) { + # read sample information from CSV file and put it in a tibble + samples <- tibble::as_tibble( + utils::read.csv( + file = csv_file, + stringsAsFactors = FALSE + ) + ) + # pre-condition - check if CSV file is correct + .check_samples(samples) + # select valid columns + samples <- dplyr::select( + samples, + c("longitude", "latitude", "label") + ) + class(samples) <- c("sits", class(samples)) + return(samples) +} diff --git a/R/api_samples.R b/R/api_samples.R index 7588aaddc..53da2b89d 100644 --- a/R/api_samples.R +++ b/R/api_samples.R @@ -350,6 +350,8 @@ dplyr::filter(.data[["label"]] == lab) |> dplyr::slice_sample(n = samples_label) }) + # transform to sf object + samples <- sf::st_as_sf(samples) return(samples) } diff --git a/R/api_tmap.R b/R/api_tmap.R index b4461b946..cfdc86198 100644 --- a/R/api_tmap.R +++ b/R/api_tmap.R @@ -30,51 +30,6 @@ class(st) <- "tmap_v3" UseMethod(".tmap_false_color", st) } -#' @export -.tmap_false_color.tmap_v3 <- function(st, - band, - sf_seg, - seg_color, - line_width, - palette, - rev, - scale, - tmap_params){ - - # reverse the color palette? - if (rev || palette == "Greys") - palette <- paste0("-", palette) - - # generate plot - p <- tmap::tm_shape(st, raster.downsample = FALSE) + - tmap::tm_raster( - palette = palette, - title = band, - midpoint = NA, - style = "cont", - style.args = list(na.rm = TRUE) - ) + - tmap::tm_graticules( - labels.size = tmap_params[["graticules_labels_size"]] - ) + - tmap::tm_compass() + - tmap::tm_layout( - 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.height = tmap_params[["legend_height"]], - legend.width = tmap_params[["legend_width"]], - legend.position = tmap_params[["legend_position"]], - scale = scale - ) - # include segments - if (.has(sf_seg)) { - p <- p + tmap::tm_shape(sf_seg) + - tmap::tm_borders(col = seg_color, lwd = line_width) - } - return(p) -} #' @title Plot a DEM #' @name .tmap_dem_map #' @author Gilberto Camara, \email{gilberto.camara@@inpe.br} @@ -97,39 +52,7 @@ class(r) <- "tmap_v3" UseMethod(".tmap_dem_map", r) } -# -#' @export -.tmap_dem_map.tmap_v3 <- function(r, band, - palette, rev, - scale, tmap_params){ - # reverse order of colors? - if (rev) - palette <- paste0("-", palette) - # generate plot - p <- tmap::tm_shape(r, raster.downsample = FALSE) + - tmap::tm_raster( - palette = palette, - title = band, - midpoint = NA, - style = "cont", - style.args = list(na.rm = TRUE) - ) + - tmap::tm_graticules( - labels.size = tmap_params[["graticules_labels_size"]] - ) + - tmap::tm_compass() + - tmap::tm_layout( - 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.height = tmap_params[["legend_height"]], - legend.width = tmap_params[["legend_width"]], - legend.position = tmap_params[["legend_position"]], - scale = scale - ) - return(p) -} + #' @title Plot a RGB color image with tmap #' @name .tmap_rgb_color #' @author Gilberto Camara, \email{gilberto.camara@@inpe.br} @@ -153,33 +76,6 @@ class(rgb_st) <- "tmap_v3" UseMethod(".tmap_rgb_color", rgb_st) } -#' @export -.tmap_rgb_color.tmap_v3 <- function(rgb_st, - sf_seg, seg_color, line_width, - scale, tmap_params) { - - # tmap params - labels_size <- tmap_params[["graticules_labels_size"]] - - p <- tmap::tm_shape(rgb_st, raster.downsample = FALSE) + - tmap::tm_raster() + - tmap::tm_graticules( - labels.size = labels_size - ) + - tmap::tm_layout( - scale = scale - ) + - tmap::tm_compass() - - # include segments - if (.has(sf_seg)) { - p <- p + tmap::tm_shape(sf_seg) + - tmap::tm_borders(col = seg_color, lwd = line_width) - } - - return(p) -} - #' @title Plot a probs image #' @name .tmap_probs_map #' @author Gilberto Camara, \email{gilberto.camara@@inpe.br} @@ -208,45 +104,24 @@ UseMethod(".tmap_probs_map", probs_st) } # -#' @export -#' -.tmap_probs_map.tmap_v3 <- function(probs_st, - labels, - labels_plot, - palette, - rev, - scale, - tmap_params){ - # revert the palette - if (rev) { - palette <- paste0("-", palette) - } - # select stars bands to be plotted - bds <- as.numeric(names(labels[labels %in% labels_plot])) +#' @title Plot a color image with legend +#' @name .tmap_class_map +#' @author Gilberto Camara, \email{gilberto.camara@@inpe.br} +#' @description plots a RGB color image +#' @keywords internal +#' @noRd +#' @param st Stars object. +#' @param colors Named vector with colors to be displayed +#' @param scale Scale to plot map (0.4 to 1.0) +#' @param tmap_params List with tmap params for detailed plot control +#' @return A plot object +.tmap_class_map <- function(st, colors, scale, tmap_params) { - p <- tmap::tm_shape(probs_st[, , , bds]) + - tmap::tm_raster( - style = "cont", - palette = palette, - midpoint = NA, - title = labels[labels %in% labels_plot] - ) + - tmap::tm_facets(sync = FALSE) + - tmap::tm_graticules( - labels.size = tmap_params[["graticules_labels_size"]] - ) + - tmap::tm_compass() + - 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.position = tmap_params[["legend_position"]], - scale = scale - ) - return(p) + if (as.numeric_version(utils::packageVersion("tmap")) < "3.9") + class(st) <- "tmap_v3" + else + class(st) <- "tmap_v3" + UseMethod(".tmap_class_map", st) } #' @title Plot a vector probs map @@ -272,84 +147,9 @@ class(sf_seg) <- "tmap_v3" UseMethod(".tmap_vector_probs", sf_seg) } -#' @export -.tmap_vector_probs.tmap_v3 <- function(sf_seg, palette, rev, - labels, labels_plot, - scale, tmap_params){ - # revert the palette? - if (rev) { - palette <- paste0("-", palette) - } - # plot the segments - p <- tmap::tm_shape(sf_seg) + - tmap::tm_fill( - labels_plot, - style = "cont", - palette = palette, - midpoint = NA, - title = labels[labels %in% labels_plot]) + - tmap::tm_graticules( - labels.size = tmap_params[["graticules_labels_size"]] - ) + - tmap::tm_compass() + - tmap::tm_layout( - legend.show = TRUE, - 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.position = tmap_params[["legend_position"]], - scale = scale - ) + - tmap::tm_borders(lwd = 0.1) - return(p) -} -#' @title Plot a color image with legend -#' @name .tmap_class_map -#' @author Gilberto Camara, \email{gilberto.camara@@inpe.br} -#' @description plots a RGB color image -#' @keywords internal -#' @noRd -#' @param st Stars object. -#' @param colors Named vector with colors to be displayed -#' @param scale Scale to plot map (0.4 to 1.0) -#' @param tmap_params List with tmap params for detailed plot control -#' @return A plot object -.tmap_class_map <- function(st, colors, scale, tmap_params) { - if (as.numeric_version(utils::packageVersion("tmap")) < "3.9") - class(st) <- "tmap_v3" - else - class(st) <- "tmap_v3" - UseMethod(".tmap_class_map", st) -} -#' @export -.tmap_class_map.tmap_v3 <- function(st, colors, scale, tmap_params) { - - # plot using tmap - p <- tmap::tm_shape(st, raster.downsample = FALSE) + - tmap::tm_raster( - style = "cat", - labels = colors[["label"]], - palette = colors[["color"]] - ) + - tmap::tm_graticules( - labels.size = tmap_params[["graticules_labels_size"]], - ndiscr = 50 - ) + - tmap::tm_compass() + - tmap::tm_layout( - 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.position = tmap_params[["legend_position"]], - scale = scale - ) - return(p) -} #' @title Plot a vector class map #' @name .tmap_vector_class #' @author Gilberto Camara, \email{gilberto.camara@@inpe.br} @@ -368,36 +168,7 @@ class(sf_seg) <- "tmap_v3" UseMethod(".tmap_vector_class", sf_seg) } -# -#' @export -.tmap_vector_class.tmap_v3 <- function(sf_seg, - colors, - scale, - tmap_params){ - # plot the data using tmap - p <- tmap::tm_shape(sf_seg) + - tmap::tm_fill( - col = "class", - palette = colors - ) + - tmap::tm_graticules( - labels.size = tmap_params[["graticules_labels_size"]] - ) + - tmap::tm_compass() + - tmap::tm_layout( - 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.height = tmap_params[["legend_height"]], - legend.width = tmap_params[["legend_width"]], - legend.position = tmap_params[["legend_position"]], - scale = scale - ) + - tmap::tm_borders(lwd = 0.2) - return(p) -} #' @title Plot a vector uncertainty map #' @name .tmap_vector_uncert #' @author Gilberto Camara, \email{gilberto.camara@@inpe.br} @@ -420,36 +191,6 @@ UseMethod(".tmap_vector_uncert", sf_seg) } -.tmap_vector_uncert.tmap_v3 <- function(sf_seg, palette, rev, - type, scale, tmap_params){ - # revert the palette - if (rev) { - palette <- paste0("-", palette) - } - # plot - p <- tmap::tm_shape(sf_seg) + - tmap::tm_fill( - col = type, - palette = palette - ) + - tmap::tm_graticules( - labels.size = tmap_params[["graticules_labels_size"]] - ) + - tmap::tm_compass() + - tmap::tm_layout( - 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.height = tmap_params[["legend_height"]], - legend.width = tmap_params[["legend_width"]], - legend.position = tmap_params[["legend_position"]], - scale = scale - ) + - tmap::tm_borders(lwd = 0.2) - - return(suppressWarnings(p)) -} #' @title Prepare tmap params for dots value #' @name .tmap_params_set #' @author Gilberto Camara, \email{gilberto.camara@@inpe.br} @@ -466,9 +207,7 @@ #' \item \code{legend_text_size}: relative size of legend text (default = 1.0) #' \item \code{legend_bg_color}: color of legend background (default = "white") #' \item \code{legend_bg_alpha}: legend opacity (default = 0.5) -#' \item \code{legend_width}: relative width of legend (default = 1.0) #' \item \code{legend_position}: 2D position of legend (default = c("left", "bottom")) -#' \item \code{legend_height}: relative height of legend (default = 1.0) #' } .tmap_params_set <- function(dots){ @@ -478,8 +217,6 @@ legend_bg_alpha <- as.numeric(.conf("plot", "legend_bg_alpha")) legend_title_size <- as.numeric(.conf("plot", "legend_title_size")) legend_text_size <- as.numeric(.conf("plot", "legend_text_size")) - legend_height <- as.numeric(.conf("plot", "legend_height")) - legend_width <- as.numeric(.conf("plot", "legend_width")) legend_position <- .conf("plot", "legend_position") if ("graticules_labels_size" %in% names(dots)) @@ -492,10 +229,6 @@ legend_title_size <- dots[["legend_title_size"]] if ("legend_text_size" %in% names(dots)) legend_text_size <- dots[["legend_text_size"]] - if ("legend_height" %in% names(dots)) - legend_height <- dots[["legend_height"]] - if ("legend_width" %in% names(dots)) - legend_width <- dots[["legend_width"]] if ("legend_position" %in% names(dots)) legend_position <- dots[["legend_position"]] @@ -505,8 +238,6 @@ "legend_bg_alpha" = legend_bg_alpha, "legend_title_size" = legend_title_size, "legend_text_size" = legend_text_size, - "legend_height" = legend_height, - "legend_width" = legend_width, "legend_position" = legend_position ) return(tmap_params) diff --git a/R/api_tmap_v3.R b/R/api_tmap_v3.R new file mode 100644 index 000000000..d994dbde6 --- /dev/null +++ b/R/api_tmap_v3.R @@ -0,0 +1,251 @@ +#' @export +.tmap_false_color.tmap_v3 <- function(st, + band, + sf_seg, + seg_color, + line_width, + palette, + rev, + scale, + tmap_params){ + if (rev || palette == "Greys") + cols4all_name <- paste0("-", palette) + + # generate plot + p <- tmap::tm_shape(st, raster.downsample = FALSE) + + tmap::tm_raster( + palette = palette, + title = band, + midpoint = NA, + style = "cont", + style.args = list(na.rm = TRUE) + ) + + tmap::tm_graticules( + labels.size = tmap_params[["graticules_labels_size"]] + ) + + tmap::tm_compass() + + tmap::tm_layout( + 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.position = tmap_params[["legend_position"]], + scale = scale + ) + # include segments + if (.has(sf_seg)) { + p <- p + tmap::tm_shape(sf_seg) + + tmap::tm_borders(col = seg_color, lwd = line_width) + } + return(p) +} +# +#' @export +.tmap_dem_map.tmap_v3 <- function(r, band, + palette, rev, + scale, tmap_params){ + # reverse the color palette? + if (rev || palette == "Greys") + cols4all_name <- paste0("-", palette) + # generate plot + p <- tmap::tm_shape(r, raster.downsample = FALSE) + + tmap::tm_raster( + palette = palette, + title = band, + midpoint = NA, + style = "cont", + style.args = list(na.rm = TRUE) + ) + + tmap::tm_graticules( + labels.size = tmap_params[["graticules_labels_size"]] + ) + + tmap::tm_compass() + + tmap::tm_layout( + 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.position = tmap_params[["legend_position"]], + scale = scale + ) + return(p) +} +#' @export +.tmap_rgb_color.tmap_v3 <- function(rgb_st, + sf_seg, seg_color, line_width, + scale, tmap_params) { + + # tmap params + labels_size <- tmap_params[["graticules_labels_size"]] + + p <- tmap::tm_shape(rgb_st, raster.downsample = FALSE) + + tmap::tm_raster() + + tmap::tm_graticules( + labels.size = labels_size + ) + + tmap::tm_layout( + scale = scale + ) + + tmap::tm_compass() + + # include segments + if (.has(sf_seg)) { + p <- p + tmap::tm_shape(sf_seg) + + tmap::tm_borders(col = seg_color, lwd = line_width) + } + + return(p) +} +#' @export +#' +.tmap_probs_map.tmap_v3 <- function(probs_st, + labels, + labels_plot, + palette, + rev, + scale, + tmap_params){ + # reverse the color palette? + if (rev || palette == "Greys") + cols4all_name <- paste0("-", palette) + + # select stars bands to be plotted + bds <- as.numeric(names(labels[labels %in% labels_plot])) + + p <- tmap::tm_shape(probs_st[, , , bds]) + + tmap::tm_raster( + style = "cont", + palette = palette, + midpoint = NA, + title = labels[labels %in% labels_plot] + ) + + tmap::tm_facets(sync = FALSE) + + tmap::tm_graticules( + labels.size = tmap_params[["graticules_labels_size"]] + ) + + tmap::tm_compass() + + 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.position = tmap_params[["legend_position"]], + scale = scale + ) + return(p) +} +#' @export +.tmap_class_map.tmap_v3 <- function(st, colors, scale, tmap_params) { + + # plot using tmap + p <- tmap::tm_shape(st, raster.downsample = FALSE) + + tmap::tm_raster( + style = "cat", + labels = colors[["label"]], + palette = colors[["color"]] + ) + + tmap::tm_graticules( + labels.size = tmap_params[["graticules_labels_size"]], + ndiscr = 50 + ) + + tmap::tm_compass() + + tmap::tm_layout( + 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.position = tmap_params[["legend_position"]], + scale = scale + ) + return(p) +} +#' @export +.tmap_vector_probs.tmap_v3 <- function(sf_seg, palette, rev, + labels, labels_plot, + scale, tmap_params){ + if (rev || palette == "Greys") + cols4all_name <- paste0("-", palette) + + # plot the segments + p <- tmap::tm_shape(sf_seg) + + tmap::tm_fill( + labels_plot, + style = "cont", + palette = palette, + midpoint = NA, + title = labels[labels %in% labels_plot]) + + tmap::tm_graticules( + labels.size = tmap_params[["graticules_labels_size"]] + ) + + tmap::tm_compass() + + tmap::tm_layout( + legend.show = TRUE, + 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.position = tmap_params[["legend_position"]], + scale = scale + ) + + tmap::tm_borders(lwd = 0.1) + + return(p) +} +# +#' @export +.tmap_vector_class.tmap_v3 <- function(sf_seg, + colors, + scale, + tmap_params){ + # plot the data using tmap + p <- tmap::tm_shape(sf_seg) + + tmap::tm_fill( + col = "class", + palette = colors + ) + + tmap::tm_graticules( + labels.size = tmap_params[["graticules_labels_size"]] + ) + + tmap::tm_compass() + + tmap::tm_layout( + 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.position = tmap_params[["legend_position"]], + scale = scale + ) + + tmap::tm_borders(lwd = 0.2) + + return(p) +} +.tmap_vector_uncert.tmap_v3 <- function(sf_seg, palette, rev, + type, scale, tmap_params){ + # revert the palette + if (rev) { + palette <- paste0("-", palette) + } + # plot + p <- tmap::tm_shape(sf_seg) + + tmap::tm_fill( + col = type, + palette = palette + ) + + tmap::tm_graticules( + labels.size = tmap_params[["graticules_labels_size"]] + ) + + tmap::tm_compass() + + tmap::tm_layout( + 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.position = tmap_params[["legend_position"]], + scale = scale + ) + + tmap::tm_borders(lwd = 0.2) + + return(suppressWarnings(p)) +} diff --git a/R/sits_accuracy.R b/R/sits_accuracy.R index 65b6ae1c5..29f77249f 100644 --- a/R/sits_accuracy.R +++ b/R/sits_accuracy.R @@ -136,45 +136,9 @@ sits_accuracy.sits <- function(data, ...) { #' @export sits_accuracy.class_cube <- function(data, ..., validation) { .check_set_caller("sits_accuracy_class_cube") - # handle sample files in CSV format - if (is.character(validation)) { - if (tolower(.file_ext(validation)) == "csv") { - # Read sample information from CSV file and put it in a tibble - validation <- .csv_get_samples(validation) - } else if (tolower(.file_ext(validation)) == "shp") { - validation <- sf::st_read(validation) - .check_that(all(sf::st_geometry_type(validation) == "POINT")) - } else { - stop(.conf("messages", "sits_accuracy_class_cube_validation")) - } - } - # handle `sf` objects - if (inherits(validation, "sf")) { - # Pre-condition - check for the required columns - .check_chr_contains(colnames(validation), c( - "label", "start_date", "end_date" - )) - # transform the `sf` object in a valid - validation <- validation |> - dplyr::mutate( - geom = sf::st_geometry(validation) - ) |> - dplyr::mutate( - geom = sf::st_centroid(.data[["geom"]]) - ) |> - dplyr::mutate( - coords = sf::st_coordinates(.data[["geom"]]) - ) |> - dplyr::mutate( - longitude = .data[["coords"]][, 1], - latitude = .data[["coords"]][, 2] - ) |> - dplyr::select( - "start_date", "end_date", "label", "longitude", "latitude" - ) - } - # Pre-condition - check if validation samples are OK - validation <- .check_samples(validation) + # get the validation samples + valid_samples <- .accuracy_get_validation(validation) + # Find the labels of the cube labels_cube <- .cube_labels(data) # Create a list of (predicted, reference) values @@ -186,12 +150,12 @@ sits_accuracy.class_cube <- function(data, ..., validation) { .check_that(length(labelled_band) == 1) # get xy in cube projection xy_tb <- .proj_from_latlong( - longitude = validation[["longitude"]], - latitude = validation[["latitude"]], + longitude = valid_samples[["longitude"]], + latitude = valid_samples[["latitude"]], crs = .crs(tile) ) # join samples with XY values in a single tibble - points <- dplyr::bind_cols(validation, xy_tb) + points <- dplyr::bind_cols(valid_samples, xy_tb) # are there points to be retrieved from the cube? .check_that(nrow(points) != 0) # Filter the points inside the tile @@ -245,12 +209,12 @@ sits_accuracy.class_cube <- function(data, ..., validation) { # Create the error matrix error_matrix <- table( factor(pred_ref[["predicted"]], - levels = labels_cube, - labels = labels_cube + levels = labels_cube, + labels = labels_cube ), factor(pred_ref[["reference"]], - levels = labels_cube, - labels = labels_cube + levels = labels_cube, + labels = labels_cube ) ) # Get area for each class of the cube diff --git a/R/sits_active_learning.R b/R/sits_active_learning.R index c7b514578..2cdac8106 100644 --- a/R/sits_active_learning.R +++ b/R/sits_active_learning.R @@ -237,7 +237,7 @@ sits_uncertainty_sampling <- function(uncert_cube, #' data_dir <- system.file("extdata/raster/mod13q1", package = "sits") #' cube <- sits_cube( #' source = "BDC", -#' collection = "MOD13Q1-6", +#' collection = "MOD13Q1-6.1", #' data_dir = data_dir #' ) #' # build a random forest model diff --git a/R/sits_classify.R b/R/sits_classify.R index 250b1e544..435bcf9ae 100644 --- a/R/sits_classify.R +++ b/R/sits_classify.R @@ -25,12 +25,12 @@ #' named lat/long values #' ("lon_min", "lat_min", "lon_max", "lat_max"). #' @param filter_fn Smoothing filter to be applied - optional -#' (clousure containing object of class "function"). +#' (closure containing object of class "function"). #' @param impute_fn Imputation function to remove NA. #' @param start_date Start date for the classification #' (Date in YYYY-MM-DD format). #' @param end_date End date for the classification -#' (Date im YYYY-MM-DD format). +#' (Date in YYYY-MM-DD format). #' @param memsize Memory available for classification in GB #' (integer, min = 1, max = 16384). #' @param multicores Number of cores to be used for classification diff --git a/R/sits_combine_predictions.R b/R/sits_combine_predictions.R index c8186d88a..2eded9d5b 100644 --- a/R/sits_combine_predictions.R +++ b/R/sits_combine_predictions.R @@ -45,7 +45,7 @@ #' data = cube, ml_model = rfor_model, output_dir = tempdir(), #' version = "rfor" #' ) -#' # create an XGBoost model +#' # create an SVM model #' svm_model <- sits_train(samples_modis_ndvi, sits_svm()) #' # classify a data cube using SVM model #' probs_svm_cube <- sits_classify( diff --git a/R/sits_config.R b/R/sits_config.R index 5c014af93..06553fac0 100644 --- a/R/sits_config.R +++ b/R/sits_config.R @@ -136,7 +136,7 @@ sits_list_collections <- function(source = NULL) { #' @title List the cloud collections supported by sits #' @name sits_config_user_file #' @param file_path file to store the user configuration file -#' @param overwrite replace current configurarion file? +#' @param overwrite replace current configuration file? #' @description #' Creates a user configuration file. #' diff --git a/R/sits_cube.R b/R/sits_cube.R index d93be3120..e72bd6e30 100755 --- a/R/sits_cube.R +++ b/R/sits_cube.R @@ -225,10 +225,11 @@ #' lat_min = -33.85777, #' lat_max = -32.56690 #' ), -#' start_date = "2016-01-01", -#' end_date = "2017-01-01" +#' start_date = "2018-01-01", +#' end_date = "2018-12-31" #' ) #' # --- Access to CDSE open data Sentinel 2/2A level 2 collection +#' # --- remember to set the appropriate environmental variables #' # It is recommended that `multicores` be used to accelerate the process. #' s2_cube <- sits_cube( #' source = "CDSE", @@ -240,6 +241,7 @@ #' ) #' #' ## --- Sentinel-1 SAR from CDSE +#' # --- remember to set the appropriate environmental variables #' roi_sar <- c("lon_min" = 33.546, "lon_max" = 34.999, #' "lat_min" = 1.427, "lat_max" = 3.726) #' s1_cube_open <- sits_cube( diff --git a/R/sits_mlp.R b/R/sits_mlp.R index 51da192d9..c2241ba08 100644 --- a/R/sits_mlp.R +++ b/R/sits_mlp.R @@ -66,7 +66,7 @@ #' data_dir <- system.file("extdata/raster/mod13q1", package = "sits") #' cube <- sits_cube( #' source = "BDC", -#' collection = "MOD13Q1-6", +#' collection = "MOD13Q1-6.1", #' data_dir = data_dir #' ) #' # classify a data cube diff --git a/R/sits_plot.R b/R/sits_plot.R index 54df72195..0e087ba5f 100644 --- a/R/sits_plot.R +++ b/R/sits_plot.R @@ -687,7 +687,7 @@ plot.dem_cube <- function(x, ..., #' @param max_cog_size Maximum size of COG overviews (lines or columns) #' @return A plot object with an RGB image #' or a B/W image on a color -#' scale using the pallete +#' scale using the palette #' #' @note The following optional parameters are available to allow for detailed #' control over the plot output: @@ -1345,7 +1345,7 @@ plot.class_cube <- function(x, y, ..., #' #' @return A plot object with an RGB image #' or a B/W image on a color -#' scale using the pallete +#' scale using the chosen palette #' #' @note To see which color palettes are supported, please run #' @examples diff --git a/R/sits_sample_functions.R b/R/sits_sample_functions.R index 3441bcecc..b626701dd 100644 --- a/R/sits_sample_functions.R +++ b/R/sits_sample_functions.R @@ -240,6 +240,7 @@ sits_reduce_imbalance <- function(samples, #' #' @param cube Classified cube #' @param expected_ua Expected values of user's accuracy +#' @param alloc_options Fixed sample allocation for rare classes #' @param std_err Standard error we would like to achieve #' @param rare_class_prop Proportional area limit for rare classes #' @@ -288,6 +289,7 @@ sits_reduce_imbalance <- function(samples, #' @export sits_sampling_design <- function(cube, expected_ua = 0.75, + alloc_options = c(100, 75, 50), std_err = 0.01, rare_class_prop = 0.1) { .check_set_caller("sits_sampling_design") @@ -325,18 +327,16 @@ sits_sampling_design <- function(cube, # find out the classes which are rare rare_classes <- prop[prop <= rare_class_prop] # Determine allocation possibilities - # allocate a sample size of 50–100 for rare classes # Given each allocation for rare classes (e.g, 100 samples) # allocate the rest of the sample size proportionally # to the other more frequent classes - alloc_three <- c(100, 75, 50) - alloc_options_lst <- purrr::map(alloc_three, function(al) { + alloc_options_lst <- purrr::map(alloc_options, function(al) { # determine the number of samples to be allocated # to more frequent classes samples_rare_classes <- al * length(rare_classes) remaining_samples <- sample_size - samples_rare_classes # allocate samples per class - # rare classes are given a fixed value (100, 75, 50) + # rare classes are given a fixed value (e.g., 100, 75, 50) # other classes are allocated proportionally to area alloc_class_lst <- purrr::map(prop, function(p) { if (p <= rare_class_prop) { @@ -462,7 +462,7 @@ sits_stratified_sampling <- function(cube, y = labels, by = "labels" ) |> - dplyr::select("labels", "label_id", alloc) |> + dplyr::select("labels", "label_id", dplyr::all_of(alloc)) |> dplyr::rename("label" = "labels") # include overhead samples_class[alloc] <- ceiling(unlist(samples_class[[alloc]]) * overhead) diff --git a/R/sits_select.R b/R/sits_select.R index 28a257119..39d9aa818 100644 --- a/R/sits_select.R +++ b/R/sits_select.R @@ -11,7 +11,7 @@ #' @param dates Character vector with sparse dates to select. #' #' @description Filter only the selected bands and dates -#' from a set of time series or froam a data cube. +#' from a set of time series or from a data cube. #' #' @return Tibble with time series or data cube. #' diff --git a/R/sits_summary.R b/R/sits_summary.R index 3bbe280ae..1da48693d 100644 --- a/R/sits_summary.R +++ b/R/sits_summary.R @@ -6,7 +6,7 @@ #' @description This is a generic function. Parameters depend on the specific #' type of input. #' -#' @param object Object of classes "sits". +#' @param object Object of class "sits". #' @param ... Further specifications for \link{summary}. #' #' @return A summary of the sits tibble. @@ -37,7 +37,7 @@ summary.sits <- function(object, ...) { #' @description This is a generic function. Parameters depend on the specific #' type of input. #' -#' @param object Object of classe "sits_accuracy". +#' @param object Object of class "sits_accuracy". #' @param ... Further specifications for \link{summary}. #' #' @return A summary of the sample accuracy diff --git a/README.Rmd b/README.Rmd index d6ada3c68..b659bfc52 100644 --- a/README.Rmd +++ b/README.Rmd @@ -37,7 +37,7 @@ torch::torch_manual_seed(1234) `sits` is an open source R package for satellite image time series analysis. It enables users to apply machine learning techniques for classifying image time series obtained from earth observation data cubes. The basic workflow in `sits` is: -1. Select an image collection available on cloud providers AWS, Microsoft Planetary Computer, Digital Earth Africa, Swiss Data Cube, NASA Harmonized Landsat/Sentinel and Brazil Data Cube. +1. Select an image collection available on cloud providers AWS, Brazil Data Cube, Digital Earth Africa, Copernicus Data Space, Digital Earth Australia, Microsoft Planetary Computer, NASA Harmonized Landsat/Sentinel, and Swiss Data Cube. 2. Build a regular data cube from analysis-ready image collections. 3. Extract labelled time series from data cubes to be used as training samples. 4. Perform samples quality control using self-organised maps. @@ -54,13 +54,14 @@ torch::torch_manual_seed(1234) knitr::include_graphics("inst/extdata/markdown/figures/sits_general_view.jpg") ``` + ## Documentation Detailed documentation on how to use `sits` is available in the e-book ["Satellite Image Time Series Analysis on Earth Observation Data Cubes"](https://e-sensing.github.io/sitsbook/). ## `sits` on Kaggle -Those that want to evaluate the `sits` package before installing are invited to run the examples available on [Kaggle](https://www.kaggle.com/esensing/code). If you are new on kaggle, please follow the [instructions](https://gist.github.com/OldLipe/814089cc5792c9c0c989d870a22910f4) to set up your account. These examples provide a fast-track introduction to the package. We recommend running them in the following order: +Those that want to evaluate the `sits` package before installing are invited to run the examples available on [Kaggle](https://www.kaggle.com/esensing/code). If you are new to Kaggle, please follow the [instructions](https://gist.github.com/OldLipe/814089cc5792c9c0c989d870a22910f4) to set up your account. These examples provide a fast-track introduction to the package. We recommend running them in the following order: 1. [Introduction to SITS](https://www.kaggle.com/esensing/introduction-to-sits) 2. [Working with time series in SITS](https://www.kaggle.com/esensing/working-with-time-series-in-sits) @@ -109,13 +110,15 @@ Classification using torch-based deep learning models in `sits` uses CUDA compat Users create data cubes from analysis-ready data (ARD) image collections available in cloud services. The collections accessible in `sits` `r packageVersion("sits")` are: -1. Brazil Data Cube ([BDC](http://brazildatacube.org/en/home-page-2/#dataproducts)): Open data collections of Sentinel-2, Landsat-8 and CBERS-4 images. -2. Microsoft Planetary Computer ([MPC](https://planetarycomputer.microsoft.com/catalog)): Open data collection of Sentinel-2/2A and Landsat-8 -3. Earth on AWS ([AWS](https://aws.amazon.com/earth/)): Sentinel-2/2A level 2A collections. -4. Digital Earth Africa ([DEAFRICA](https://www.digitalearthafrica.org/)): Open data collection of Sentinel-2/2A and Landsat-8 for Africa. -5. [USGS](https://landsatlook.usgs.gov/stac-browser): Landsat-4/5/7/8 collections, which are not open data. -6. Swiss Data Cube ([SDC](https://www.swissdatacube.org/)): Open data collection of Sentinel-2/2A and Landsat-8. -7. NASA Harmonized Landsat/Sentinel Collection [HLS](https://hls.gsfc.nasa.gov/). +- Brazil Data Cube - [BDC](https://data.inpe.br/bdc/web/en/home-page-2/): Open data collections of Sentinel-2, Landsat-8 and CBERS-4 images. +- Copernicus Data Space Environment [CDSE](https://dataspace.copernicus.eu/): Open data collections from the EU Copernicus programme. +- Earth on AWS - [AWS](https://aws.amazon.com/earth/): Sentinel-2/2A level 2A collections. +- Digital Earth Africa - [DEAFRICA](https://www.digitalearthafrica.org/): Open data collection of Sentinel-2/2A and Landsat-8 for Africa. +- Digital Earth Australia - [DEAUSTRALIA](https://www.ga.gov.au/scientific-topics/dea): Open data collections for the Australian subcontinent. +- Microsoft Planetary Computer - [MPC](https://planetarycomputer.microsoft.com/catalog): Open data collection of Sentinel-2/2A and Landsat-8. +- NASA Harmonized Landsat/Sentinel Collection [HLS](https://hls.gsfc.nasa.gov/). +- Swiss Data Cube ([SDC](https://www.swissdatacube.org/)): Open data collection of Sentinel-2/2A and Landsat-8. +- [USGS](https://landsatlook.usgs.gov/stac-browser): Landsat-4/5/7/8 collections, which are not open data. Open data collections do not require payment of access fees. Except for those in the Brazil Data Cube, these collections are not regular. Irregular collections require further processing before they can be used for classification using machine learning models. @@ -206,10 +209,9 @@ available in `sits`: - Random forests (`sits_rfor()`) - Extreme gradient boosting (`sits_xgboost()`) - Multi-layer perceptrons (`sits_mlp()`) -- Deep Residual Networks (`sits_resnet()`) (see ref. [8]) -- 1D convolution neural networks (`sits_tempcnn()`) (see ref. [9]) -- Temporal self-attention encoder (`sits_tae()`) (see ref. [10]) -- Lightweight temporal attention encoder (`sits_lighttae()`) (see ref. [11] and [12]) +- 1D convolution neural networks (`sits_tempcnn()`) +- Temporal self-attention encoder (`sits_tae()`) +- Lightweight temporal attention encoder (`sits_lighttae()`) The following example illustrate how to train a dataset and classify an individual time series. First we use the `sits_train()` function with two @@ -279,58 +281,57 @@ plot(label_cube, ``` -## Additional information - -Since version 1.4.2, `sits` support OBIA analysis of image time series, using an extension of R package `supercells`. - -The package is described in detail in on-line book ["SITS: Data analysis and machine learning for data cubes using satellite image time series"](https://e-sensing.github.io/sitsbook/). - - ### References #### Citable papers for sits If you use `sits`, please cite the following paper: -- [1] Rolf Simoes, Gilberto Camara, Gilberto Queiroz, Felipe Souza, Pedro R. Andrade, Lorena Santos, Alexandre Carvalho, and Karine Ferreira. “Satellite Image Time Series Analysis for Big Earth Observation Data”. Remote Sensing, 13: 2428, 2021. . +- Rolf Simoes, Gilberto Camara, Gilberto Queiroz, Felipe Souza, Pedro R. Andrade, Lorena Santos, Alexandre Carvalho, and Karine Ferreira. “Satellite Image Time Series Analysis for Big Earth Observation Data”. Remote Sensing, 13: 2428, 2021. . Additionally, the sample quality control methods that use self-organized maps are described in the following reference: -- [2] Lorena Santos, Karine Ferreira, Gilberto Camara, Michelle Picoli, Rolf Simoes, “Quality control and class noise reduction of satellite image time series”. ISPRS Journal of Photogrammetry and Remote Sensing, 177:75-88, 2021. . +- Lorena Santos, Karine Ferreira, Gilberto Camara, Michelle Picoli, Rolf Simoes, “Quality control and class noise reduction of satellite image time series”. ISPRS Journal of Photogrammetry and Remote Sensing, 177:75-88, 2021. . #### Papers that use sits to produce LUCC maps -- [3] Rolf Simoes, Michelle Picoli, et al., "Land use and cover maps for Mato Grosso State in Brazil from 2001 to 2017". Sci Data 7(34), 2020. . +- Rolf Simoes, Michelle Picoli, et al., "Land use and cover maps for Mato Grosso State in Brazil from 2001 to 2017". Sci Data 7(34), 2020. . -- [4] Michelle Picoli, Gilberto Camara, et al., “Big Earth Observation Time Series Analysis for Monitoring Brazilian Agriculture”. ISPRS Journal of Photogrammetry and Remote Sensing, 2018. . +- Michelle Picoli, Gilberto Camara, et al., “Big Earth Observation Time Series Analysis for Monitoring Brazilian Agriculture”. ISPRS Journal of Photogrammetry and Remote Sensing, 2018. . -- [5] Karine Ferreira, Gilberto Queiroz et al., "Earth Observation Data Cubes for Brazil: Requirements, Methodology and Products". Remote Sens. 12:4033, 2020. . +- Karine Ferreira, Gilberto Queiroz et al., "Earth Observation Data Cubes for Brazil: Requirements, Methodology and Products". Remote Sens. 12:4033, 2020. . -#### Papers that describe software used in sits +- Hadi, Firman, Laode Muhammad Sabri, Yudo Prasetyo, and Bambang Sudarsono. [Leveraging Time-Series Imageries and Open Source Tools for Enhanced Land Cover Classification](https://doi.org/10.1088/1755-1315/1276/1/012035). In IOP Conference Series: Earth and Environmental Science, 1276:012035. IOP Publishing, 2023. -We thank the authors of these papers for making their code available to be used in connection with sits. +- Bruno Adorno, Thales Körting, and Silvana Amaral, [Contribution of time-series data cubes to classify urban vegetation types by remote sensing](https://doi.org/10.1016/j.ufug.2022.127817). Urban Forest & Urban Greening, 79, 127817, 2023. -- [6] Marius Appel and Edzer Pebesma, “On-Demand Processing of Data Cubes from Satellite Image Collections with the Gdalcubes Library.” Data 4 (3): 1–16, 2020. . +- Giuliani, Gregory. [Time-First Approach for Land Cover Mapping Using Big Earth Observation Data Time-Series in a Data Cube – a Case Study from the Lake Geneva Region (Switzerland)](https://doi.org/10.1080/20964471.2024.2323241). Big Earth Data, 2024. -- [7] Ron Wehrens and Johannes Kruisselbrink, "Flexible Self-Organising Maps in kohonen 3.0". Journal of Statistical Software, 87(7), 2018. . +- Werner, João, Mariana Belgiu et al., [Mapping Integrated Crop–Livestock Systems Using Fused Sentinel-2 and PlanetScope Time Series and Deep Learning](https://doi.org/10.3390/rs16081421). Remote Sensing 16, no. 8 (January 2024): 1421. -- [8] Hassan Fawaz, Germain Forestier, Jonathan Weber, Lhassane Idoumghar, and Pierre-Alain Muller, "Deep learning for time series classification: a review". Data Mining and Knowledge Discovery, 33(4): 917--963, 2019. . +#### Papers that describe software used by the sits package -- [9] Charlotte Pelletier, Geoffrey I. Webb, and Francois Petitjean. “Temporal Convolutional Neural Network for the Classification of Satellite Image Time Series.” Remote Sensing 11 (5), 2019. . +We thank the authors of these papers for making their code available to be used in connection with sits. + +- Marius Appel and Edzer Pebesma, “On-Demand Processing of Data Cubes from Satellite Image Collections with the Gdalcubes Library.” Data 4 (3): 1–16, 2020. . + +- Ron Wehrens and Johannes Kruisselbrink, "Flexible Self-Organising Maps in kohonen 3.0". Journal of Statistical Software, 87(7), 2018. . -- [10] Vivien Garnot, Loic Landrieu, Sebastien Giordano, and Nesrine Chehata, "Satellite Image Time Series Classification with Pixel-Set Encoders and Temporal Self-Attention", Conference on Computer Vision and Pattern Recognition, 2020. . +- Charlotte Pelletier, Geoffrey I. Webb, and Francois Petitjean. “Temporal Convolutional Neural Network for the Classification of Satellite Image Time Series.” Remote Sensing 11 (5), 2019. . -- [11] Vivien Garnot, Loic Landrieu, "Lightweight Temporal Self-Attention for Classifying Satellite Images Time Series", 2020. . +- Vivien Garnot, Loic Landrieu, Sebastien Giordano, and Nesrine Chehata, "Satellite Image Time Series Classification with Pixel-Set Encoders and Temporal Self-Attention", Conference on Computer Vision and Pattern Recognition, 2020. . -- [12] Maja Schneider, Marco Körner, "[Re] Satellite Image Time Series Classification with Pixel-Set Encoders and Temporal Self-Attention." ReScience C 7 (2), 2021. . +- Vivien Garnot, Loic Landrieu, "Lightweight Temporal Self-Attention for Classifying Satellite Images Time Series", 2020. . -- [13] Jakub Nowosad, Tomasz Stepinski, "Extended SLIC superpixels algorithm for applications to non-imagery geospatial rasters". International Journal of Applied Earth Observation and Geoinformation, 112, 102935, 2022. +- Maja Schneider, Marco Körner, "[Re] Satellite Image Time Series Classification with Pixel-Set Encoders and Temporal Self-Attention." ReScience C 7 (2), 2021. . -- [14] Martin Tennekes, “tmap: Thematic Maps in R.” Journal of Statistical Software, 84(6), 1–39, 2018. +- Jakub Nowosad, Tomasz Stepinski, "Extended SLIC superpixels algorithm for applications to non-imagery geospatial rasters". International Journal of Applied Earth Observation and Geoinformation, 112, 102935, 2022. + +- Martin Tennekes, “tmap: Thematic Maps in R.” Journal of Statistical Software, 84(6), 1–39, 2018. ### Acknowledgements for community support -The authors are thankful for the contributions of Edzer Pebesma, Jakub Novosad. Marius Appel, Martin Tennekes, Robert Hijmans, Ron Wehrens, and Tim Appelhans, respectively chief developers of the packages `sf`/`stars`, `supercells`, `gdalcubes`, `tmap`, `terra`, `kohonen`, and `leafem`. The `sits` package is also much indebted to the work of the RStudio team, including the `tidyverse`. We are indepted to Daniel Falbel for his great work in the `torch` and `luz` packages. We thank Charlotte Pelletier and Hassan Fawaz for sharing the python code that has been reused for the TempCNN and ResNet machine learning models. We would like to thank Maja Schneider for sharing the python code that helped the implementation of the `sits_lighttae()` and `sits_tae()` model. We recognise the importance of the work by Chris Holmes and Mattias Mohr on the STAC specification and API. +The authors are thankful for the contributions of Edzer Pebesma, Jakub Nowosad. Marius Appel, Martin Tennekes, Robert Hijmans, Ron Wehrens, and Tim Appelhans, respectively chief developers of the packages `sf`/`stars`, `supercells`, `gdalcubes`, `tmap`, `terra`, `kohonen`, and `leafem`. The `sits` package recognises the great work of the RStudio team, including the `tidyverse`. Many thanks to Daniel Falbel for his great work in the `torch` and `luz` packages. Charlotte Pelletier shared the python code that has been reused for the TempCNN machine learning model. We would like to thank Maja Schneider for sharing the python code that helped the implementation of the `sits_lighttae()` and `sits_tae()` model. We recognise the importance of the work by Chris Holmes and Mattias Mohr on the STAC specification and API. ### Acknowledgements for Financial and Material Support @@ -346,9 +347,9 @@ We acknowledge and thank the project funders that provided financial and materia 5. Microsoft Planetary Computer under the GEO-Microsoft Cloud Computer Grants Programme. -6. The Open-Earth-Monitor Cyberinfratructure project, which has received - funding from the European Union's Horizon Europe research and innovation programme - under [grant agreement No. 101059548](https://cordis.europa.eu/project/id/101059548). +6. The Open-Earth-Monitor Cyberinfratructure project, which has received funding from the European Union's Horizon Europe research and innovation programme under [grant agreement No. 101059548](https://cordis.europa.eu/project/id/101059548). + +7. [FAO-EOSTAT](https://www.fao.org/in-action/eostat) initiative, which uses next generation Earth observation tools to produce land cover and land use statistics. ### How to contribute diff --git a/README.md b/README.md index 74d9aad81..029e7a9e0 100644 --- a/README.md +++ b/README.md @@ -29,9 +29,10 @@ analysis. It enables users to apply machine learning techniques for classifying image time series obtained from earth observation data cubes. The basic workflow in `sits` is: -1. Select an image collection available on cloud providers AWS, - Microsoft Planetary Computer, Digital Earth Africa, Swiss Data Cube, - NASA Harmonized Landsat/Sentinel and Brazil Data Cube. +1. Select an image collection available on cloud providers AWS, Brazil + Data Cube, Digital Earth Africa, Copernicus Data Space, Digital + Earth Australia, Microsoft Planetary Computer, NASA Harmonized + Landsat/Sentinel, and Swiss Data Cube. 2. Build a regular data cube from analysis-ready image collections. 3. Extract labelled time series from data cubes to be used as training samples. @@ -67,8 +68,8 @@ Cubes”](https://e-sensing.github.io/sitsbook/). Those that want to evaluate the `sits` package before installing are invited to run the examples available on -[Kaggle](https://www.kaggle.com/esensing/code). If you are new on -kaggle, please follow the +[Kaggle](https://www.kaggle.com/esensing/code). If you are new to +Kaggle, please follow the [instructions](https://gist.github.com/OldLipe/814089cc5792c9c0c989d870a22910f4) to set up your account. These examples provide a fast-track introduction to the package. We recommend running them in the following order: @@ -121,7 +122,7 @@ devtools::install_github("e-sensing/sits", dependencies = TRUE) # load the sits library library(sits) #> SITS - satellite image time series analysis. -#> Loaded sits v1.5.0. +#> Loaded sits v1.5.1. #> See ?sits for help, citation("sits") for use in publication. #> Documentation avaliable in https://e-sensing.github.io/sitsbook/. ``` @@ -139,26 +140,32 @@ more information on how to install the required drivers. ### Image Collections Accessible by `sits` Users create data cubes from analysis-ready data (ARD) image collections -available in cloud services. The collections accessible in `sits` 1.5.0 +available in cloud services. The collections accessible in `sits` 1.5.1 are: -1. Brazil Data Cube - ([BDC](http://brazildatacube.org/en/home-page-2/#dataproducts)): - Open data collections of Sentinel-2, Landsat-8 and CBERS-4 images. -2. Microsoft Planetary Computer - ([MPC](https://planetarycomputer.microsoft.com/catalog)): Open data - collection of Sentinel-2/2A and Landsat-8 -3. Earth on AWS ([AWS](https://aws.amazon.com/earth/)): Sentinel-2/2A - level 2A collections. -4. Digital Earth Africa - ([DEAFRICA](https://www.digitalearthafrica.org/)): Open data - collection of Sentinel-2/2A and Landsat-8 for Africa. -5. [USGS](https://landsatlook.usgs.gov/stac-browser): Landsat-4/5/7/8 - collections, which are not open data. -6. Swiss Data Cube ([SDC](https://www.swissdatacube.org/)): Open data - collection of Sentinel-2/2A and Landsat-8. -7. NASA Harmonized Landsat/Sentinel Collection - [HLS](https://hls.gsfc.nasa.gov/). +- Brazil Data Cube - + [BDC](https://data.inpe.br/bdc/web/en/home-page-2/): Open data + collections of Sentinel-2, Landsat-8 and CBERS-4 images. +- Copernicus Data Space Environment + [CDSE](https://dataspace.copernicus.eu/): Open data collections from + the EU Copernicus programme. +- Earth on AWS - [AWS](https://aws.amazon.com/earth/): Sentinel-2/2A + level 2A collections. +- Digital Earth Africa - + [DEAFRICA](https://www.digitalearthafrica.org/): Open data collection + of Sentinel-2/2A and Landsat-8 for Africa. +- Digital Earth Australia - + [DEAUSTRALIA](https://www.ga.gov.au/scientific-topics/dea): Open data + collections for the Australian subcontinent. +- Microsoft Planetary Computer - + [MPC](https://planetarycomputer.microsoft.com/catalog): Open data + collection of Sentinel-2/2A and Landsat-8. +- NASA Harmonized Landsat/Sentinel Collection + [HLS](https://hls.gsfc.nasa.gov/). +- Swiss Data Cube ([SDC](https://www.swissdatacube.org/)): Open data + collection of Sentinel-2/2A and Landsat-8. +- [USGS](https://landsatlook.usgs.gov/stac-browser): Landsat-4/5/7/8 + collections, which are not open data. Open data collections do not require payment of access fees. Except for those in the Brazil Data Cube, these collections are not regular. @@ -176,13 +183,13 @@ similar ways. ``` r s2_cube <- sits_cube( - source = "MPC", - collection = "SENTINEL-2-L2A", - tiles = c("20LKP", "20LLP"), - bands = c("B03", "B08", "B11", "SCL"), - start_date = as.Date("2018-07-01"), - end_date = as.Date("2019-06-30"), - progress = FALSE + source = "MPC", + collection = "SENTINEL-2-L2A", + tiles = c("20LKP", "20LLP"), + bands = c("B03", "B08", "B11", "SCL"), + start_date = as.Date("2018-07-01"), + end_date = as.Date("2019-06-30"), + progress = FALSE ) ``` @@ -210,11 +217,11 @@ Pebesma, 2019](https://www.mdpi.com/2306-5729/4/3/92). ``` r gc_cube <- sits_regularize( - cube = s2_cube, - output_dir = tempdir(), - period = "P15D", - res = 60, - multicores = 4 + cube = s2_cube, + output_dir = tempdir(), + period = "P15D", + res = 60, + multicores = 4 ) ``` @@ -249,16 +256,16 @@ library(sits) data_dir <- system.file("extdata/raster/mod13q1", package = "sits") # create a cube from downloaded files raster_cube <- sits_cube( - source = "BDC", - collection = "MOD13Q1-6", - data_dir = data_dir, - delim = "_", - parse_info = c("X1", "X2", "tile", "band", "date"), - progress = FALSE + source = "BDC", + collection = "MOD13Q1-6", + data_dir = data_dir, + delim = "_", + parse_info = c("X1", "X2", "tile", "band", "date"), + progress = FALSE ) # obtain a set of samples defined by a CSV file csv_file <- system.file("extdata/samples/samples_sinop_crop.csv", - package = "sits" + package = "sits" ) # retrieve the time series associated with the samples from the data cube points <- sits_get_data(raster_cube, samples = csv_file) @@ -292,11 +299,9 @@ available in `sits`: - Random forests (`sits_rfor()`) - Extreme gradient boosting (`sits_xgboost()`) - Multi-layer perceptrons (`sits_mlp()`) -- Deep Residual Networks (`sits_resnet()`) (see ref. \[8\]) -- 1D convolution neural networks (`sits_tempcnn()`) (see ref. \[9\]) -- Temporal self-attention encoder (`sits_tae()`) (see ref. \[10\]) -- Lightweight temporal attention encoder (`sits_lighttae()`) (see ref. - \[11\] and \[12\]) +- 1D convolution neural networks (`sits_tempcnn()`) +- Temporal self-attention encoder (`sits_tae()`) +- Lightweight temporal attention encoder (`sits_lighttae()`) The following example illustrate how to train a dataset and classify an individual time series. First we use the `sits_train()` function with @@ -313,16 +318,16 @@ data("samples_modis_ndvi") data("point_mt_6bands") # Train a deep learning model tempcnn_model <- sits_train( - samples = samples_modis_ndvi, - ml_method = sits_tempcnn() + samples = samples_modis_ndvi, + ml_method = sits_tempcnn() ) # Select NDVI band of the point to be classified # Classify using TempCNN model # Plot the result -point_mt_6bands |> - sits_select(bands = "NDVI") |> - sits_classify(tempcnn_model) |> - plot() +point_mt_6bands |> + sits_select(bands = "NDVI") |> + sits_classify(tempcnn_model) |> + plot() #> | | | 0% | |=================================== | 50% | |======================================================================| 100% ``` @@ -344,36 +349,44 @@ using `sits_view()`. # Cube is composed of MOD13Q1 images from the Sinop region in Mato Grosso (Brazil) data_dir <- system.file("extdata/raster/mod13q1", package = "sits") sinop <- sits_cube( - source = "BDC", - collection = "MOD13Q1-6", - data_dir = data_dir, - delim = "_", - parse_info = c("X1", "X2", "tile", "band", "date"), - progress = FALSE + source = "BDC", + collection = "MOD13Q1-6", + data_dir = data_dir, + delim = "_", + parse_info = c("X1", "X2", "tile", "band", "date"), + progress = FALSE ) # Classify the raster cube, generating a probability file # Filter the pixels in the cube to remove noise probs_cube <- sits_classify( - data = sinop, - ml_model = tempcnn_model, - output_dir = tempdir() + data = sinop, + ml_model = tempcnn_model, + output_dir = tempdir() ) #> | | | 0% | |======================================================================| 100% # apply a bayesian smoothing to remove outliers bayes_cube <- sits_smooth( - cube = probs_cube, - output_dir = tempdir() + cube = probs_cube, + output_dir = tempdir() ) # generate a thematic map label_cube <- sits_label_classification( - cube = bayes_cube, - output_dir = tempdir() + cube = bayes_cube, + output_dir = tempdir() ) #> | | | 0% | |======================================================================| 100% # plot the the labelled cube plot(label_cube, - title = "Land use and Land cover in Sinop, MT, Brazil in 2018" + title = "Land use and Land cover in Sinop, MT, Brazil in 2018" ) +#> The legacy packages maptools, rgdal, and rgeos, underpinning the sp package, +#> which was just loaded, will retire in October 2023. +#> Please refer to R-spatial evolution reports for details, especially +#> https://r-spatial.org/r/2023/05/15/evolution4.html. +#> It may be desirable to make the sf package available; +#> package maintainers should consider adding sf to Suggests:. +#> The sp package is now running under evolution status 2 +#> (status 2 uses the sf package in place of rgdal) ```
@@ -385,109 +398,113 @@ Land use and Land cover in Sinop, MT, Brazil in 2018
-## Additional information - -Since version 1.4.2, `sits` support OBIA analysis of image time series, -using an extension of R package `supercells`. - -The package is described in detail in on-line book [“SITS: Data analysis -and machine learning for data cubes using satellite image time -series”](https://e-sensing.github.io/sitsbook/). - ### References #### Citable papers for sits If you use `sits`, please cite the following paper: -- \[1\] Rolf Simoes, Gilberto Camara, Gilberto Queiroz, Felipe Souza, - Pedro R. Andrade, Lorena Santos, Alexandre Carvalho, and Karine - Ferreira. “Satellite Image Time Series Analysis for Big Earth - Observation Data”. Remote Sensing, 13: 2428, 2021. - . +- Rolf Simoes, Gilberto Camara, Gilberto Queiroz, Felipe Souza, Pedro R. + Andrade, Lorena Santos, Alexandre Carvalho, and Karine Ferreira. + “Satellite Image Time Series Analysis for Big Earth Observation Data”. + Remote Sensing, 13: 2428, 2021. . Additionally, the sample quality control methods that use self-organized maps are described in the following reference: -- \[2\] Lorena Santos, Karine Ferreira, Gilberto Camara, Michelle - Picoli, Rolf Simoes, “Quality control and class noise reduction of - satellite image time series”. ISPRS Journal of Photogrammetry and - Remote Sensing, 177:75-88, 2021. - . +- Lorena Santos, Karine Ferreira, Gilberto Camara, Michelle Picoli, Rolf + Simoes, “Quality control and class noise reduction of satellite image + time series”. ISPRS Journal of Photogrammetry and Remote Sensing, + 177:75-88, 2021. . #### Papers that use sits to produce LUCC maps -- \[3\] Rolf Simoes, Michelle Picoli, et al., “Land use and cover maps - for Mato Grosso State in Brazil from 2001 to 2017”. Sci Data - 7(34), 2020. . +- Rolf Simoes, Michelle Picoli, et al., “Land use and cover maps for + Mato Grosso State in Brazil from 2001 to 2017”. Sci Data 7(34), 2020. + . -- \[4\] Michelle Picoli, Gilberto Camara, et al., “Big Earth Observation - Time Series Analysis for Monitoring Brazilian Agriculture”. ISPRS - Journal of Photogrammetry and Remote Sensing, 2018. +- Michelle Picoli, Gilberto Camara, et al., “Big Earth Observation Time + Series Analysis for Monitoring Brazilian Agriculture”. ISPRS Journal + of Photogrammetry and Remote Sensing, 2018. . -- \[5\] Karine Ferreira, Gilberto Queiroz et al., “Earth Observation - Data Cubes for Brazil: Requirements, Methodology and Products”. Remote +- Karine Ferreira, Gilberto Queiroz et al., “Earth Observation Data + Cubes for Brazil: Requirements, Methodology and Products”. Remote Sens. 12:4033, 2020. . -#### Papers that describe software used in sits +- Hadi, Firman, Laode Muhammad Sabri, Yudo Prasetyo, and Bambang + Sudarsono. [Leveraging Time-Series Imageries and Open Source Tools for + Enhanced Land Cover + Classification](https://doi.org/10.1088/1755-1315/1276/1/012035). In + IOP Conference Series: Earth and Environmental Science, 1276:012035. + IOP Publishing, 2023. + +- Bruno Adorno, Thales Körting, and Silvana Amaral, [Contribution of + time-series data cubes to classify urban vegetation types by remote + sensing](https://doi.org/10.1016/j.ufug.2022.127817). Urban Forest & + Urban Greening, 79, 127817, 2023. + +- Giuliani, Gregory. [Time-First Approach for Land Cover Mapping Using + Big Earth Observation Data Time-Series in a Data Cube – a Case Study + from the Lake Geneva Region + (Switzerland)](https://doi.org/10.1080/20964471.2024.2323241). Big + Earth Data, 2024. + +- Werner, João, Mariana Belgiu et al., [Mapping Integrated + Crop–Livestock Systems Using Fused Sentinel-2 and PlanetScope Time + Series and Deep Learning](https://doi.org/10.3390/rs16081421). Remote + Sensing 16, no. 8 (January 2024): 1421. + +#### Papers that describe software used by the sits package We thank the authors of these papers for making their code available to be used in connection with sits. -- \[6\] Marius Appel and Edzer Pebesma, “On-Demand Processing of Data - Cubes from Satellite Image Collections with the Gdalcubes Library.” - Data 4 (3): 1–16, 2020. . +- Marius Appel and Edzer Pebesma, “On-Demand Processing of Data Cubes + from Satellite Image Collections with the Gdalcubes Library.” Data 4 + (3): 1–16, 2020. . -- \[7\] Ron Wehrens and Johannes Kruisselbrink, “Flexible - Self-Organising Maps in kohonen 3.0”. Journal of Statistical Software, - 87(7), 2018. . +- Ron Wehrens and Johannes Kruisselbrink, “Flexible Self-Organising Maps + in kohonen 3.0”. Journal of Statistical Software, 87(7), 2018. + . -- \[8\] Hassan Fawaz, Germain Forestier, Jonathan Weber, Lhassane - Idoumghar, and Pierre-Alain Muller, “Deep learning for time series - classification: a review”. Data Mining and Knowledge Discovery, 33(4): - 917–963, 2019. \. - -- \[9\] Charlotte Pelletier, Geoffrey I. Webb, and Francois Petitjean. +- Charlotte Pelletier, Geoffrey I. Webb, and Francois Petitjean. “Temporal Convolutional Neural Network for the Classification of Satellite Image Time Series.” Remote Sensing 11 (5), 2019. . -- \[10\] Vivien Garnot, Loic Landrieu, Sebastien Giordano, and Nesrine - Chehata, “Satellite Image Time Series Classification with Pixel-Set - Encoders and Temporal Self-Attention”, Conference on Computer Vision - and Pattern Recognition, 2020. \. +- Vivien Garnot, Loic Landrieu, Sebastien Giordano, and Nesrine Chehata, + “Satellite Image Time Series Classification with Pixel-Set Encoders + and Temporal Self-Attention”, Conference on Computer Vision and + Pattern Recognition, 2020. \. -- \[11\] Vivien Garnot, Loic Landrieu, “Lightweight Temporal - Self-Attention for Classifying Satellite Images Time Series”, 2020. - \. +- Vivien Garnot, Loic Landrieu, “Lightweight Temporal Self-Attention for + Classifying Satellite Images Time Series”, 2020. \. -- \[12\] Maja Schneider, Marco Körner, “\[Re\] Satellite Image Time - Series Classification with Pixel-Set Encoders and Temporal - Self-Attention.” ReScience C 7 (2), 2021. - . +- Maja Schneider, Marco Körner, “\[Re\] Satellite Image Time Series + Classification with Pixel-Set Encoders and Temporal Self-Attention.” + ReScience C 7 (2), 2021. . -- \[13\] Jakub Nowosad, Tomasz Stepinski, “Extended SLIC superpixels - algorithm for applications to non-imagery geospatial rasters”. - International Journal of Applied Earth Observation and Geoinformation, - 112, 102935, 2022. +- Jakub Nowosad, Tomasz Stepinski, “Extended SLIC superpixels algorithm + for applications to non-imagery geospatial rasters”. International + Journal of Applied Earth Observation and Geoinformation, 112, 102935, + 2022. -- \[14\] Martin Tennekes, “tmap: Thematic Maps in R.” Journal of - Statistical Software, 84(6), 1–39, 2018. +- Martin Tennekes, “tmap: Thematic Maps in R.” Journal of Statistical + Software, 84(6), 1–39, 2018. ### Acknowledgements for community support The authors are thankful for the contributions of Edzer Pebesma, Jakub -Novosad. Marius Appel, Martin Tennekes, Robert Hijmans, Ron Wehrens, and +Nowosad. Marius Appel, Martin Tennekes, Robert Hijmans, Ron Wehrens, and Tim Appelhans, respectively chief developers of the packages `sf`/`stars`, `supercells`, `gdalcubes`, `tmap`, `terra`, `kohonen`, and -`leafem`. The `sits` package is also much indebted to the work of the -RStudio team, including the `tidyverse`. We are indepted to Daniel -Falbel for his great work in the `torch` and `luz` packages. We thank -Charlotte Pelletier and Hassan Fawaz for sharing the python code that -has been reused for the TempCNN and ResNet machine learning models. We -would like to thank Maja Schneider for sharing the python code that -helped the implementation of the `sits_lighttae()` and `sits_tae()` +`leafem`. The `sits` package recognises the great work of the RStudio +team, including the `tidyverse`. Many thanks to Daniel Falbel for his +great work in the `torch` and `luz` packages. Charlotte Pelletier shared +the python code that has been reused for the TempCNN machine learning +model. We would like to thank Maja Schneider for sharing the python code +that helped the implementation of the `sits_lighttae()` and `sits_tae()` model. We recognise the importance of the work by Chris Holmes and Mattias Mohr on the STAC specification and API. @@ -524,6 +541,10 @@ material support: and innovation programme under [grant agreement No. 101059548](https://cordis.europa.eu/project/id/101059548). +7. [FAO-EOSTAT](https://www.fao.org/in-action/eostat) initiative, which + uses next generation Earth observation tools to produce land cover + and land use statistics. + ### How to contribute The `sits` project is released with a [Contributor Code of diff --git a/demo/00Index b/demo/00Index index 4974010e6..6145bbf1b 100644 --- a/demo/00Index +++ b/demo/00Index @@ -1,7 +1,4 @@ classify_cbers_bdc Classify a set of CBERS AWFI images in the Brazil Data Cube classify_deeplearning Classify MODIS image using deep learning -classify_raster_rfor Classify MODIS image using SVM -classify_ts Classify a time series using SVM -evaluate_samples_Kohonen Clustering and evaluation of samples using self-organizing maps ml_comparison Comparison of machine learning methods dl_comparison Comparison of deep learning methods diff --git a/demo/classify_cbers_bdc.R b/demo/classify_cbers_bdc.R index 70395cd3e..554db27e1 100644 --- a/demo/classify_cbers_bdc.R +++ b/demo/classify_cbers_bdc.R @@ -36,7 +36,7 @@ end_date <- timeline_samples[length(timeline_samples)] # define a CBERS data cube using the Brazil Data Cube cbers_cube <- sits_cube( source = "BDC", - collection = "CB4-16D-2", + collection = "CBERS-WFI-16D", bands = bands, tiles = "007004", start_date = start_date, diff --git a/demo/classify_deeplearning.R b/demo/classify_deeplearning.R index 273dd674a..eec2810e7 100644 --- a/demo/classify_deeplearning.R +++ b/demo/classify_deeplearning.R @@ -30,7 +30,7 @@ dl_model <- sits_train( data_dir <- system.file("extdata/sinop", package = "sitsdata") sinop <- sits_cube( source = "BDC", - collection = "MOD13Q1-6", + collection = "MOD13Q1-6.1", data_dir = data_dir ) @@ -55,8 +55,5 @@ sinop_label <- sits_label_classification( output_dir = tempdir() ) -# plot the smoothed image -plot(sinop_bayes) - # plot the classified image plot(sinop_label) diff --git a/demo/classify_raster_rfor.R b/demo/classify_raster_rfor.R deleted file mode 100644 index 49bc7962c..000000000 --- a/demo/classify_raster_rfor.R +++ /dev/null @@ -1,90 +0,0 @@ -# This is a demonstration of classification of a raster area -# The raster image is a MODIS data set covering the municipality of Sinop -# with two bands (NDVI and EVI) using MODIS collection 5 data - -# load the sitsdata library -if (!requireNamespace("sitsdata", quietly = TRUE)) { - stop("Please install package sitsdata\n", - "Please call devtools::install_github('e-sensing/sitsdata')", - call. = FALSE - ) -} - -# load the sitsdata library -library(sitsdata) - -data("samples_matogrosso_mod13q1") - -samples_ndvi_evi <- sits_select( - data = samples_matogrosso_mod13q1, - bands = c("NDVI", "EVI") -) - -# build the classification model -rfor_model <- sits_train( - samples_ndvi_evi, - ml_method = sits_rfor() -) - -# Read ndvi and evi data from the sitsdata package -# create a data cube to be classified -# Cube MOD13Q1 images from the Sinop region in Mato Grosso (Brazil) -data_dir <- system.file("extdata/sinop", package = "sitsdata") -sinop <- sits_cube( - source = "BDC", - collection = "MOD13Q1-6", - data_dir = data_dir, - delim = "_", - parse_info = c("X1", "tile", "band", "date") -) - -# classify the raster image -sinop_probs <- sits_classify( - data = sinop, - ml_model = rfor_model, - memsize = 8, - multicores = 2, - output_dir = tempdir() -) - -# smoothen with bayesian filter -sinop_bayes <- sits_smooth( - cube = sinop_probs, - memsize = 8, - multicores = 2, - output_dir = tempdir() -) -# calculate uncertainty -sinop_uncert <- sits_uncertainty( - cube = sinop_bayes, - type = "entropy", - memsize = 8, - multicores = 2, - output_dir = tempdir() -) -# calculate uncertainty -sinop_uncert_m <- sits_uncertainty( - cube = sinop_bayes, - type = "least", - memsize = 8, - multicores = 2, - output_dir = tempdir() -) -# calculate uncertainty -sinop_uncert_margin <- sits_uncertainty( - cube = sinop_bayes, - type = "margin", - memsize = 8, - multicores = 2, - output_dir = tempdir() -) -# label the classified image -sinop_label <- sits_label_classification( - cube = sinop_bayes, - memsize = 8, - multicores = 2, - output_dir = tempdir() -) - -# plot the smoothened image -plot(sinop_label) diff --git a/demo/classify_ts.R b/demo/classify_ts.R deleted file mode 100644 index 10ef52288..000000000 --- a/demo/classify_ts.R +++ /dev/null @@ -1,31 +0,0 @@ -# satellite image time series package (SITS) -# example of the classification of a time series -library(sits) - -# In this example, we are going to train a ML model -# and then will classify a point - -# use a sample with the bands "ndvi", "evi", "nir", and "mir" -# select a random forest model -rfor_model <- sits_train( - samples = samples_modis_ndvi, - ml_method = sits_rfor() -) - -# Retrieve a time series -data("point_mt_6bands") - -# select the bands "ndvi", "evi", "nir", and "mir" -point_tb <- sits_select( - data = point_mt_6bands, - bands = "NDVI" -) - -# classify the point -class_tb <- sits_classify( - data = point_tb, - ml_model = rfor_model -) - -# plot the classification -plot(class_tb, bands = "NDVI") diff --git a/demo/dl_comparison.R b/demo/dl_comparison.R index 6dd4e654f..9b8dda58b 100644 --- a/demo/dl_comparison.R +++ b/demo/dl_comparison.R @@ -39,15 +39,4 @@ acc_tc[["name"]] <- "TempCNN" results[[length(results) + 1]] <- acc_tc -# Deep Learning - ResNet -print("== Accuracy Assessment = ResNet =======================") -acc_rn <- sits_kfold_validate( - samples_matogrosso_mod13q1, - folds = 5, - ml_method = sits_resnet() -) -acc_rn[["name"]] <- "ResNet" - -results[[length(results) + 1]] <- acc_rn - sits_to_xlsx(results, file = file.path(tempdir(), "/accuracy_mato_grosso_dl.xlsx")) diff --git a/demo/evaluate_samples_Kohonen.R b/demo/evaluate_samples_Kohonen.R deleted file mode 100644 index 0b4c47266..000000000 --- a/demo/evaluate_samples_Kohonen.R +++ /dev/null @@ -1,31 +0,0 @@ -# satellite image time series package (SITS) -# example of clustering using self-organizin maps -library(sits) - -# load the sitsdata library -if (!requireNamespace("sitsdata", quietly = TRUE)) { - stop("Please install package sitsdata\n", - "Please call devtools::install_github('e-sensing/sitsdata')", - call. = FALSE - ) -} -library(sitsdata) -data("samples_cerrado_mod13q1") - -# Clustering time series samples using self-organizing maps -som_map <- - sits_som_map( - samples_cerrado_mod13q1, - grid_xdim = 12, - grid_ydim = 12, - alpha = 1, - distance = "euclidean" - ) - -plot(som_map) - -# Remove samples that have bad quality -new_samples <- sits_som_clean_samples(som_map) - -cluster_purity <- sits_som_evaluate_cluster(som_map) -plot(cluster_purity) diff --git a/inst/WORDLIST b/inst/WORDLIST index 924e5175e..5777428a3 100644 --- a/inst/WORDLIST +++ b/inst/WORDLIST @@ -1,8 +1,10 @@ ARD +Achanta Acknowledgements Alain Alexandre Alves +ALOS Amazonia Aperfeiçoamento Appel @@ -20,6 +22,7 @@ Bowyer Brasil BreizhCrops CBERS +CDSE CMASK CNPq CRS @@ -28,6 +31,7 @@ Cartaxo Carvalho Cerrado Chawla +Chebyshev Chehata Científico Citable @@ -37,6 +41,7 @@ Convolutional Coordenação DEAFRICA DEAfrica +DEM DOI DTW Datetime @@ -58,11 +63,13 @@ Francesco François GDAL GEOTIFF +GRD GTiff Garnot Garnot's Gdalcubes GeoJSON +Geospatial GeoTiff Geoinformation Geoscience @@ -70,10 +77,12 @@ Germain Giordano Golay Grosso +GPUs Guestrin HCL Hassan Herold +HLS Hijmans Hotfix IJCNN @@ -83,6 +92,8 @@ ISSN Idoumghar JSTARS Jaccard +Jakob +Jakub KDD Kaggle Kegelmeyer @@ -100,6 +111,9 @@ LZW Landrieu Lhassane Loic +Lemire's +Lucchi +MGRS MLP MODIS MSPC @@ -112,17 +126,21 @@ Mato Mattias Maus Mohr +Nasa NDVI Nacional NatNonForest Nesrine Ng NoClass +Nowosad Nível +OBIA Oguiza Olofsson Organising Oversample +PALSAR PROJ PSE Paulo @@ -136,6 +154,10 @@ Picoli Pre Preprocess Programme +QGIS +QML +Rasters +RColorBrewer README ROI RSpatial @@ -145,22 +167,32 @@ Relu Reproject ResNet Rmd +RStoolbox +RTC Russwurm +SAR SCL +SDC SGD SHP SIG +SLIC SOM STAC STK Sainte Sao +Sakoe Savitzky Schuster +Schwalb Sebastien Sevcikova +Shaji Siriseriwan +Spatio Stehman +Stepinski TAE TWDTW Tecnológico @@ -204,6 +236,7 @@ bayesian bbox bboxes biome +bleutner brazil brazildatacube bzip @@ -243,6 +276,7 @@ gdalcubes gdalwarp geo geojson +geospatial ggplot github gmail @@ -266,6 +300,8 @@ labelled labelling landsat latlong +lbi +lbk lineshape lintr logref @@ -274,11 +310,13 @@ lon lr lubridate luz +mcquitty maja mem memsize metatype microsoft +mlp modis msg mth @@ -291,21 +329,27 @@ neighbours nrows onwards opendata +organised overfit oversample oversampled +parallelization params perceptron perceptrons pid planetarycomputer pre +pred preprint probs +programme +proj psetae py pytorch randomForest +rasters rds rebalance recognise @@ -316,11 +360,18 @@ relu repo reweight rfor +rf roi +rOpenSci rowwise +rse rstac scutr sd +seg +segmentations +segs +setenv serialisation sgolay shp @@ -328,9 +379,11 @@ sigmoid sitsbook smotefamily som +spatio spatiotemporal stac subimage +supercells svm tempCNN tempdir diff --git a/inst/extdata/cran/check_package_cran.R b/inst/extdata/cran/check_package_cran.R index 46b392765..8af7acf16 100644 --- a/inst/extdata/cran/check_package_cran.R +++ b/inst/extdata/cran/check_package_cran.R @@ -26,7 +26,8 @@ urlchecker::url_update() # check on other distributions # _rhub devtools::check_rhub() -rhub::check_for_cran() +rhub::rhub_doctor("https://github.com/e-sensing/sits") +rhub::rhub_check() # _win devel devtools::check_win_devel() devtools::check_win_release() diff --git a/R/api_detect_changes.R b/inst/extdata/detect_change/api_detect_changes.R similarity index 100% rename from R/api_detect_changes.R rename to inst/extdata/detect_change/api_detect_changes.R diff --git a/R/api_dtw.R b/inst/extdata/detect_change/api_dtw.R similarity index 100% rename from R/api_dtw.R rename to inst/extdata/detect_change/api_dtw.R diff --git a/R/sits_detect_change.R b/inst/extdata/detect_change/sits_detect_change.R similarity index 98% rename from R/sits_detect_change.R rename to inst/extdata/detect_change/sits_detect_change.R index 9bf7ffa0a..94c8db73a 100644 --- a/R/sits_detect_change.R +++ b/inst/extdata/detect_change/sits_detect_change.R @@ -18,12 +18,12 @@ #' named lat/long values #' ("lon_min", "lat_min", "lon_max", "lat_max"). #' @param filter_fn Smoothing filter to be applied - optional -#' (clousure containing object of class "function"). +#' (closure containing object of class "function"). #' @param impute_fn Imputation function to remove NA. #' @param start_date Start date for the classification #' (Date in YYYY-MM-DD format). #' @param end_date End date for the classification -#' (Date im YYYY-MM-DD format). +#' (Date in YYYY-MM-DD format). #' @param memsize Memory available for classification in GB #' (integer, min = 1, max = 16384). #' @param multicores Number of cores to be used for classification diff --git a/R/sits_detect_change_method.R b/inst/extdata/detect_change/sits_detect_change_method.R similarity index 100% rename from R/sits_detect_change_method.R rename to inst/extdata/detect_change/sits_detect_change_method.R diff --git a/R/sits_dtw.R b/inst/extdata/detect_change/sits_dtw.R similarity index 100% rename from R/sits_dtw.R rename to inst/extdata/detect_change/sits_dtw.R diff --git a/inst/extdata/tmap/api_tmap_v3.R b/inst/extdata/tmap/api_tmap_v3.R deleted file mode 100644 index b4461b946..000000000 --- a/inst/extdata/tmap/api_tmap_v3.R +++ /dev/null @@ -1,514 +0,0 @@ -#' @title Plot a false color image with tmap -#' @name .tmap_false_color -#' @author Gilberto Camara, \email{gilberto.camara@@inpe.br} -#' @description plots a set of false color image -#' @keywords internal -#' @noRd -#' @param st stars object. -#' @param band Band to be plotted. -#' @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 palette A sequential RColorBrewer palette -#' @param rev Reverse the color palette? -#' @param scale Scale to plot map (0.4 to 1.0) -#' @param tmap_params List with tmap params for detailed plot control -#' @return A list of plot objects -.tmap_false_color <- function(st, - band, - sf_seg, - seg_color, - line_width, - palette, - rev, - scale, - tmap_params){ - - if (as.numeric_version(utils::packageVersion("tmap")) < "3.9") - class(st) <- "tmap_v3" - else - class(st) <- "tmap_v3" - UseMethod(".tmap_false_color", st) -} -#' @export -.tmap_false_color.tmap_v3 <- function(st, - band, - sf_seg, - seg_color, - line_width, - palette, - rev, - scale, - tmap_params){ - - # reverse the color palette? - if (rev || palette == "Greys") - palette <- paste0("-", palette) - - # generate plot - p <- tmap::tm_shape(st, raster.downsample = FALSE) + - tmap::tm_raster( - palette = palette, - title = band, - midpoint = NA, - style = "cont", - style.args = list(na.rm = TRUE) - ) + - tmap::tm_graticules( - labels.size = tmap_params[["graticules_labels_size"]] - ) + - tmap::tm_compass() + - tmap::tm_layout( - 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.height = tmap_params[["legend_height"]], - legend.width = tmap_params[["legend_width"]], - legend.position = tmap_params[["legend_position"]], - scale = scale - ) - # include segments - if (.has(sf_seg)) { - p <- p + tmap::tm_shape(sf_seg) + - tmap::tm_borders(col = seg_color, lwd = line_width) - } - return(p) -} -#' @title Plot a DEM -#' @name .tmap_dem_map -#' @author Gilberto Camara, \email{gilberto.camara@@inpe.br} -#' @description plots a RGB color image -#' @keywords internal -#' @noRd -#' @param r Raster object. -#' @param band Band of DEM cube -#' @param palette A sequential RColorBrewer palette -#' @param rev Reverse the color palette? -#' @param scale Scale to plot map (0.4 to 1.0) -#' @param tmap_params List with tmap params for detailed plot control -#' @return A plot object -.tmap_dem_map <- function(r, band, - palette, rev, - scale, tmap_params){ - if (as.numeric_version(utils::packageVersion("tmap")) < "3.9") - class(r) <- "tmap_v3" - else - class(r) <- "tmap_v3" - UseMethod(".tmap_dem_map", r) -} -# -#' @export -.tmap_dem_map.tmap_v3 <- function(r, band, - palette, rev, - scale, tmap_params){ - # reverse order of colors? - if (rev) - palette <- paste0("-", palette) - # generate plot - p <- tmap::tm_shape(r, raster.downsample = FALSE) + - tmap::tm_raster( - palette = palette, - title = band, - midpoint = NA, - style = "cont", - style.args = list(na.rm = TRUE) - ) + - tmap::tm_graticules( - labels.size = tmap_params[["graticules_labels_size"]] - ) + - tmap::tm_compass() + - tmap::tm_layout( - 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.height = tmap_params[["legend_height"]], - legend.width = tmap_params[["legend_width"]], - legend.position = tmap_params[["legend_position"]], - scale = scale - ) - return(p) -} -#' @title Plot a RGB color image with tmap -#' @name .tmap_rgb_color -#' @author Gilberto Camara, \email{gilberto.camara@@inpe.br} -#' @description plots a RGB color image -#' @keywords internal -#' @noRd -#' @param st Stars object. -#' @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 scale Scale to plot map (0.4 to 1.0) -#' @param tmap_params List with tmap params for detailed plot control -#' @return A list of plot objects -.tmap_rgb_color <- function(rgb_st, - sf_seg, seg_color, line_width, - scale, tmap_params) { - - if (as.numeric_version(utils::packageVersion("tmap")) < "3.9") - class(rgb_st) <- "tmap_v3" - else - class(rgb_st) <- "tmap_v3" - UseMethod(".tmap_rgb_color", rgb_st) -} -#' @export -.tmap_rgb_color.tmap_v3 <- function(rgb_st, - sf_seg, seg_color, line_width, - scale, tmap_params) { - - # tmap params - labels_size <- tmap_params[["graticules_labels_size"]] - - p <- tmap::tm_shape(rgb_st, raster.downsample = FALSE) + - tmap::tm_raster() + - tmap::tm_graticules( - labels.size = labels_size - ) + - tmap::tm_layout( - scale = scale - ) + - tmap::tm_compass() - - # include segments - if (.has(sf_seg)) { - p <- p + tmap::tm_shape(sf_seg) + - tmap::tm_borders(col = seg_color, lwd = line_width) - } - - return(p) -} - -#' @title Plot a probs image -#' @name .tmap_probs_map -#' @author Gilberto Camara, \email{gilberto.camara@@inpe.br} -#' @description plots a RGB color image -#' @keywords internal -#' @noRd -#' @param st Stars object. -#' @param labels Class labels -#' @param labels_plot Class labels to be plotted -#' @param palette A sequential RColorBrewer palette -#' @param rev Reverse the color palette? -#' @param scale Scale to plot map (0.4 to 1.0) -#' @param tmap_params List with tmap params for detailed plot control -#' @return A plot object -.tmap_probs_map <- function(probs_st, - labels, - labels_plot, - palette, - rev, - scale, - tmap_params){ - if (as.numeric_version(utils::packageVersion("tmap")) < "3.9") - class(probs_st) <- "tmap_v3" - else - class(probs_st) <- "tmap_v3" - UseMethod(".tmap_probs_map", probs_st) -} -# -#' @export -#' -.tmap_probs_map.tmap_v3 <- function(probs_st, - labels, - labels_plot, - palette, - rev, - scale, - tmap_params){ - # revert the palette - if (rev) { - palette <- paste0("-", palette) - } - # select stars bands to be plotted - bds <- as.numeric(names(labels[labels %in% labels_plot])) - - p <- tmap::tm_shape(probs_st[, , , bds]) + - tmap::tm_raster( - style = "cont", - palette = palette, - midpoint = NA, - title = labels[labels %in% labels_plot] - ) + - tmap::tm_facets(sync = FALSE) + - tmap::tm_graticules( - labels.size = tmap_params[["graticules_labels_size"]] - ) + - tmap::tm_compass() + - 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.position = tmap_params[["legend_position"]], - scale = scale - ) - return(p) -} - -#' @title Plot a vector probs map -#' @name .tmap_vector_probs -#' @author Gilberto Camara, \email{gilberto.camara@@inpe.br} -#' @description plots a RGB color image -#' @keywords internal -#' @noRd -#' @param sf_seg sf -#' @param palette A sequential RColorBrewer palette -#' @param rev Reverse the color palette? -#' @param labels Class labels -#' @param labels_plot Class labels to be plotted -#' @param scale Scale to plot map (0.4 to 1.0) -#' @param tmap_params Tmap parameters -#' @return A plot object -.tmap_vector_probs <- function(sf_seg, palette, rev, - labels, labels_plot, - scale, tmap_params){ - if (as.numeric_version(utils::packageVersion("tmap")) < "3.9") - class(sf_seg) <- "tmap_v3" - else - class(sf_seg) <- "tmap_v3" - UseMethod(".tmap_vector_probs", sf_seg) -} -#' @export -.tmap_vector_probs.tmap_v3 <- function(sf_seg, palette, rev, - labels, labels_plot, - scale, tmap_params){ - # revert the palette? - if (rev) { - palette <- paste0("-", palette) - } - - # plot the segments - p <- tmap::tm_shape(sf_seg) + - tmap::tm_fill( - labels_plot, - style = "cont", - palette = palette, - midpoint = NA, - title = labels[labels %in% labels_plot]) + - tmap::tm_graticules( - labels.size = tmap_params[["graticules_labels_size"]] - ) + - tmap::tm_compass() + - tmap::tm_layout( - legend.show = TRUE, - 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.position = tmap_params[["legend_position"]], - scale = scale - ) + - tmap::tm_borders(lwd = 0.1) - - return(p) -} -#' @title Plot a color image with legend -#' @name .tmap_class_map -#' @author Gilberto Camara, \email{gilberto.camara@@inpe.br} -#' @description plots a RGB color image -#' @keywords internal -#' @noRd -#' @param st Stars object. -#' @param colors Named vector with colors to be displayed -#' @param scale Scale to plot map (0.4 to 1.0) -#' @param tmap_params List with tmap params for detailed plot control -#' @return A plot object -.tmap_class_map <- function(st, colors, scale, tmap_params) { - - if (as.numeric_version(utils::packageVersion("tmap")) < "3.9") - class(st) <- "tmap_v3" - else - class(st) <- "tmap_v3" - UseMethod(".tmap_class_map", st) -} -#' @export -.tmap_class_map.tmap_v3 <- function(st, colors, scale, tmap_params) { - - # plot using tmap - p <- tmap::tm_shape(st, raster.downsample = FALSE) + - tmap::tm_raster( - style = "cat", - labels = colors[["label"]], - palette = colors[["color"]] - ) + - tmap::tm_graticules( - labels.size = tmap_params[["graticules_labels_size"]], - ndiscr = 50 - ) + - tmap::tm_compass() + - tmap::tm_layout( - 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.position = tmap_params[["legend_position"]], - scale = scale - ) - return(p) -} -#' @title Plot a vector class map -#' @name .tmap_vector_class -#' @author Gilberto Camara, \email{gilberto.camara@@inpe.br} -#' @description plots a RGB color image -#' @keywords internal -#' @noRd -#' @param sf_seg sf object. -#' @param colors Named vector with colors to be displayed -#' @param scale Scale to plot map (0.4 to 1.0) -#' @param tmap_params Parameters to control tmap output -#' @return A plot object -.tmap_vector_class <- function(sf_seg, colors, scale, tmap_params){ - if (as.numeric_version(utils::packageVersion("tmap")) < "3.9") - class(sf_seg) <- "tmap_v3" - else - class(sf_seg) <- "tmap_v3" - UseMethod(".tmap_vector_class", sf_seg) -} -# -#' @export -.tmap_vector_class.tmap_v3 <- function(sf_seg, - colors, - scale, - tmap_params){ - # plot the data using tmap - p <- tmap::tm_shape(sf_seg) + - tmap::tm_fill( - col = "class", - palette = colors - ) + - tmap::tm_graticules( - labels.size = tmap_params[["graticules_labels_size"]] - ) + - tmap::tm_compass() + - tmap::tm_layout( - 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.height = tmap_params[["legend_height"]], - legend.width = tmap_params[["legend_width"]], - legend.position = tmap_params[["legend_position"]], - scale = scale - ) + - tmap::tm_borders(lwd = 0.2) - - return(p) -} -#' @title Plot a vector uncertainty map -#' @name .tmap_vector_uncert -#' @author Gilberto Camara, \email{gilberto.camara@@inpe.br} -#' @description plots a RGB color image -#' @keywords internal -#' @noRd -#' @param sf_seg sf -#' @param palette A sequential RColorBrewer palette -#' @param rev Reverse the color palette? -#' @param type Uncertainty type -#' @param scale Scale to plot map (0.4 to 1.0) -#' @param tmap_params Tmap parameters -#' @return A plot object -.tmap_vector_uncert <- function(sf_seg, palette, rev, - type, scale, tmap_params){ - if (as.numeric_version(utils::packageVersion("tmap")) < "3.9") - class(sf_seg) <- "tmap_v3" - else - class(sf_seg) <- "tmap_v3" - UseMethod(".tmap_vector_uncert", sf_seg) - -} -.tmap_vector_uncert.tmap_v3 <- function(sf_seg, palette, rev, - type, scale, tmap_params){ - # revert the palette - if (rev) { - palette <- paste0("-", palette) - } - # plot - p <- tmap::tm_shape(sf_seg) + - tmap::tm_fill( - col = type, - palette = palette - ) + - tmap::tm_graticules( - labels.size = tmap_params[["graticules_labels_size"]] - ) + - tmap::tm_compass() + - tmap::tm_layout( - 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.height = tmap_params[["legend_height"]], - legend.width = tmap_params[["legend_width"]], - legend.position = tmap_params[["legend_position"]], - scale = scale - ) + - tmap::tm_borders(lwd = 0.2) - - return(suppressWarnings(p)) -} -#' @title Prepare tmap params for dots value -#' @name .tmap_params_set -#' @author Gilberto Camara, \email{gilberto.camara@@inpe.br} -#' @noRd -#' @keywords internal -#' @param dots params passed on dots -#' @description The following optional parameters are available to allow for detailed -#' control over the plot output: -#' \itemize{ -#' \item \code{first_quantile}: 1st quantile for stretching images (default = 0.05) -#' \item \code{last_quantile}: last quantile for stretching images (default = 0.95) -#' \item \code{graticules_labels_size}: size of coordinates labels (default = 0.8) -#' \item \code{legend_title_size}: relative size of legend title (default = 1.0) -#' \item \code{legend_text_size}: relative size of legend text (default = 1.0) -#' \item \code{legend_bg_color}: color of legend background (default = "white") -#' \item \code{legend_bg_alpha}: legend opacity (default = 0.5) -#' \item \code{legend_width}: relative width of legend (default = 1.0) -#' \item \code{legend_position}: 2D position of legend (default = c("left", "bottom")) -#' \item \code{legend_height}: relative height of legend (default = 1.0) -#' } -.tmap_params_set <- function(dots){ - - # tmap params - graticules_labels_size <- as.numeric(.conf("plot", "graticules_labels_size")) - legend_bg_color <- .conf("plot", "legend_bg_color") - legend_bg_alpha <- as.numeric(.conf("plot", "legend_bg_alpha")) - legend_title_size <- as.numeric(.conf("plot", "legend_title_size")) - legend_text_size <- as.numeric(.conf("plot", "legend_text_size")) - legend_height <- as.numeric(.conf("plot", "legend_height")) - legend_width <- as.numeric(.conf("plot", "legend_width")) - legend_position <- .conf("plot", "legend_position") - - if ("graticules_labels_size" %in% names(dots)) - graticules_labels_size <- dots[["graticules_labels_size"]] - if ("legend_bg_color" %in% names(dots)) - legend_bg_color <- dots[["legend_bg_color"]] - if ("legend_bg_alpha" %in% names(dots)) - legend_bg_alpha <- dots[["legend_bg_alpha"]] - if ("legend_title_size" %in% names(dots)) - legend_title_size <- dots[["legend_title_size"]] - if ("legend_text_size" %in% names(dots)) - legend_text_size <- dots[["legend_text_size"]] - if ("legend_height" %in% names(dots)) - legend_height <- dots[["legend_height"]] - if ("legend_width" %in% names(dots)) - legend_width <- dots[["legend_width"]] - if ("legend_position" %in% names(dots)) - legend_position <- dots[["legend_position"]] - - tmap_params <- list( - "graticules_labels_size" = graticules_labels_size, - "legend_bg_color" = legend_bg_color, - "legend_bg_alpha" = legend_bg_alpha, - "legend_title_size" = legend_title_size, - "legend_text_size" = legend_text_size, - "legend_height" = legend_height, - "legend_width" = legend_width, - "legend_position" = legend_position - ) - return(tmap_params) -} - diff --git a/inst/extdata/tmap/api_tmap_v4.R b/inst/extdata/tmap/api_tmap_v4.R index 4b3c87ae8..9a46be692 100644 --- a/inst/extdata/tmap/api_tmap_v4.R +++ b/inst/extdata/tmap/api_tmap_v4.R @@ -1,80 +1,3 @@ -#' @title Plot a false color image with tmap -#' @name .tmap_false_color -#' @author Gilberto Camara, \email{gilberto.camara@@inpe.br} -#' @description plots a set of false color image -#' @keywords internal -#' @noRd -#' @param st stars object. -#' @param band Band to be plotted. -#' @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 palette A sequential RColorBrewer palette -#' @param rev Reverse the color palette? -#' @param scale Scale to plot map (0.4 to 1.0) -#' @param tmap_params List with tmap params for detailed plot control -#' @return A list of plot objects -.tmap_false_color <- function(st, - band, - sf_seg, - seg_color, - line_width, - palette, - rev, - scale, - tmap_params){ - - if (as.numeric_version(utils::packageVersion("tmap")) < "3.9") - class(st) <- "tmap_v3" - else - class(st) <- "tmap_v4" - UseMethod(".tmap_false_color", st) -} -#' @export -.tmap_false_color.tmap_v3 <- function(st, - band, - sf_seg, - seg_color, - line_width, - palette, - rev, - scale, - tmap_params){ - - # reverse the color palette? - if (rev || palette == "Greys") - palette <- paste0("-", palette) - - # generate plot - p <- tmap::tm_shape(st, raster.downsample = FALSE) + - tmap::tm_raster( - palette = palette, - title = band, - midpoint = NA, - style = "cont", - style.args = list(na.rm = TRUE) - ) + - tmap::tm_graticules( - labels.size = tmap_params[["graticules_labels_size"]] - ) + - tmap::tm_compass() + - tmap::tm_layout( - 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.height = tmap_params[["legend_height"]], - legend.width = tmap_params[["legend_width"]], - legend.position = tmap_params[["legend_position"]], - scale = scale - ) - # include segments - if (.has(sf_seg)) { - p <- p + tmap::tm_shape(sf_seg) + - tmap::tm_borders(col = seg_color, lwd = line_width) - } - return(p) -} #' @export .tmap_false_color.tmap_v4 <- function(st, band, @@ -122,61 +45,6 @@ return(p) } -#' @title Plot a DEM -#' @name .tmap_dem_map -#' @author Gilberto Camara, \email{gilberto.camara@@inpe.br} -#' @description plots a RGB color image -#' @keywords internal -#' @noRd -#' @param r Raster object. -#' @param band Band of DEM cube -#' @param palette A sequential RColorBrewer palette -#' @param rev Reverse the color palette? -#' @param scale Scale to plot map (0.4 to 1.0) -#' @param tmap_params List with tmap params for detailed plot control -#' @return A plot object -.tmap_dem_map <- function(r, band, - palette, rev, - scale, tmap_params){ - if (as.numeric_version(utils::packageVersion("tmap")) < "3.9") - class(r) <- "tmap_v3" - else - class(r) <- "tmap_v4" - UseMethod(".tmap_dem_map", r) -} -# -#' @export -.tmap_dem_map.tmap_v3 <- function(r, band, - palette, rev, - scale, tmap_params){ - # reverse order of colors? - if (rev) - palette <- paste0("-", palette) - # generate plot - p <- tmap::tm_shape(r, raster.downsample = FALSE) + - tmap::tm_raster( - palette = palette, - title = band, - midpoint = NA, - style = "cont", - style.args = list(na.rm = TRUE) - ) + - tmap::tm_graticules( - labels.size = tmap_params[["graticules_labels_size"]] - ) + - tmap::tm_compass() + - tmap::tm_layout( - 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.height = tmap_params[["legend_height"]], - legend.width = tmap_params[["legend_width"]], - legend.position = tmap_params[["legend_position"]], - scale = scale - ) - return(p) -} #' @export #' .tmap_dem_map.tmap_v4 <- function(r, band, @@ -212,55 +80,6 @@ ) return(p) } -#' @title Plot a RGB color image with tmap -#' @name .tmap_rgb_color -#' @author Gilberto Camara, \email{gilberto.camara@@inpe.br} -#' @description plots a RGB color image -#' @keywords internal -#' @noRd -#' @param st Stars object. -#' @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 scale Scale to plot map (0.4 to 1.0) -#' @param tmap_params List with tmap params for detailed plot control -#' @return A list of plot objects -.tmap_rgb_color <- function(rgb_st, - sf_seg, seg_color, line_width, - scale, tmap_params) { - - if (as.numeric_version(utils::packageVersion("tmap")) < "3.9") - class(rgb_st) <- "tmap_v3" - else - class(rgb_st) <- "tmap_v4" - UseMethod(".tmap_rgb_color", rgb_st) -} -#' @export -.tmap_rgb_color.tmap_v3 <- function(rgb_st, - sf_seg, seg_color, line_width, - scale, tmap_params) { - - # tmap params - labels_size <- tmap_params[["graticules_labels_size"]] - - p <- tmap::tm_shape(rgb_st, raster.downsample = FALSE) + - tmap::tm_raster() + - tmap::tm_graticules( - labels.size = labels_size - ) + - tmap::tm_layout( - scale = scale - ) + - tmap::tm_compass() - - # include segments - if (.has(sf_seg)) { - p <- p + tmap::tm_shape(sf_seg) + - tmap::tm_borders(col = seg_color, lwd = line_width) - } - - return(p) -} #' @export .tmap_rgb_color.tmap_v4 <- function(rgb_st, sf_seg, seg_color, line_width, @@ -283,74 +102,6 @@ } return(p) } - -#' @title Plot a probs image -#' @name .tmap_probs_map -#' @author Gilberto Camara, \email{gilberto.camara@@inpe.br} -#' @description plots a RGB color image -#' @keywords internal -#' @noRd -#' @param st Stars object. -#' @param labels Class labels -#' @param labels_plot Class labels to be plotted -#' @param palette A sequential RColorBrewer palette -#' @param rev Reverse the color palette? -#' @param scale Scale to plot map (0.4 to 1.0) -#' @param tmap_params List with tmap params for detailed plot control -#' @return A plot object -.tmap_probs_map <- function(probs_st, - labels, - labels_plot, - palette, - rev, - scale, - tmap_params){ - if (as.numeric_version(utils::packageVersion("tmap")) < "3.9") - class(probs_st) <- "tmap_v3" - else - class(probs_st) <- "tmap_v4" - UseMethod(".tmap_probs_map", probs_st) -} -# -#' @export -#' -.tmap_probs_map.tmap_v3 <- function(probs_st, - labels, - labels_plot, - palette, - rev, - scale, - tmap_params){ - # revert the palette - if (rev) { - palette <- paste0("-", palette) - } - # select stars bands to be plotted - bds <- as.numeric(names(labels[labels %in% labels_plot])) - - p <- tmap::tm_shape(probs_st[, , , bds]) + - tmap::tm_raster( - style = "cont", - palette = palette, - midpoint = NA, - title = labels[labels %in% labels_plot] - ) + - tmap::tm_facets(sync = FALSE) + - tmap::tm_graticules( - labels.size = tmap_params[["graticules_labels_size"]] - ) + - tmap::tm_compass() + - 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"]], - scale = scale - ) - return(p) -} # #' @export #' @@ -396,64 +147,6 @@ scale = scale ) } -#' @title Plot a vector probs map -#' @name .tmap_vector_probs -#' @author Gilberto Camara, \email{gilberto.camara@@inpe.br} -#' @description plots a RGB color image -#' @keywords internal -#' @noRd -#' @param sf_seg sf -#' @param palette A sequential RColorBrewer palette -#' @param rev Reverse the color palette? -#' @param labels Class labels -#' @param labels_plot Class labels to be plotted -#' @param scale Scale to plot map (0.4 to 1.0) -#' @param tmap_params Tmap parameters -#' @return A plot object -.tmap_vector_probs <- function(sf_seg, palette, rev, - labels, labels_plot, - scale, tmap_params){ - if (as.numeric_version(utils::packageVersion("tmap")) < "3.9") - class(sf_seg) <- "tmap_v3" - else - class(sf_seg) <- "tmap_v4" - UseMethod(".tmap_vector_probs", sf_seg) -} -#' @export -.tmap_vector_probs.tmap_v3 <- function(sf_seg, palette, rev, - labels, labels_plot, - scale, tmap_params){ - # revert the palette? - if (rev) { - palette <- paste0("-", palette) - } - - # plot the segments - p <- tmap::tm_shape(sf_seg) + - tmap::tm_fill( - labels_plot, - style = "cont", - palette = palette, - midpoint = NA, - title = labels[labels %in% labels_plot]) + - tmap::tm_graticules( - labels.size = tmap_params[["graticules_labels_size"]] - ) + - tmap::tm_facets(sync = FALSE) + - tmap::tm_compass() + - tmap::tm_layout( - legend.show = TRUE, - 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.position = tmap_params[["legend_position"]], - scale = scale - ) + - tmap::tm_borders(lwd = 0.1) - - return(p) -} #' @export .tmap_vector_probs.tmap_v4 <- function(sf_seg, palette, rev, labels, labels_plot, @@ -489,50 +182,6 @@ ) return(p) } -#' @title Plot a color image with legend -#' @name .tmap_class_map -#' @author Gilberto Camara, \email{gilberto.camara@@inpe.br} -#' @description plots a RGB color image -#' @keywords internal -#' @noRd -#' @param st Stars object. -#' @param colors Named vector with colors to be displayed -#' @param scale Scale to plot map (0.4 to 1.0) -#' @param tmap_params List with tmap params for detailed plot control -#' @return A plot object -.tmap_class_map <- function(st, colors, scale, tmap_params) { - - if (as.numeric_version(utils::packageVersion("tmap")) < "3.9") - class(st) <- "tmap_v3" - else - class(st) <- "tmap_v4" - UseMethod(".tmap_class_map", st) -} -#' @export -.tmap_class_map.tmap_v3 <- function(st, colors, scale, tmap_params) { - - # plot using tmap - p <- tmap::tm_shape(st, raster.downsample = FALSE) + - tmap::tm_raster( - style = "cat", - labels = colors[["label"]], - palette = colors[["color"]] - ) + - tmap::tm_graticules( - labels.size = tmap_params[["graticules_labels_size"]], - ndiscr = 50 - ) + - tmap::tm_compass() + - tmap::tm_layout( - 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.position = tmap_params[["legend_position"]], - scale = scale - ) - return(p) -} #' @export .tmap_class_map.tmap_v4 <- function(st, colors, scale, tmap_params) { @@ -561,54 +210,6 @@ ) return(p) } -#' @title Plot a vector class map -#' @name .tmap_vector_class -#' @author Gilberto Camara, \email{gilberto.camara@@inpe.br} -#' @description plots a RGB color image -#' @keywords internal -#' @noRd -#' @param sf_seg sf object. -#' @param colors Named vector with colors to be displayed -#' @param scale Scale to plot map (0.4 to 1.0) -#' @param tmap_params Parameters to control tmap output -#' @return A plot object -.tmap_vector_class <- function(sf_seg, colors, scale, tmap_params){ - if (as.numeric_version(utils::packageVersion("tmap")) < "3.9") - class(sf_seg) <- "tmap_v3" - else - class(sf_seg) <- "tmap_v4" - UseMethod(".tmap_vector_class", sf_seg) -} -# -#' @export -.tmap_vector_class.tmap_v3 <- function(sf_seg, - colors, - scale, - tmap_params){ - # plot the data using tmap - p <- tmap::tm_shape(sf_seg) + - tmap::tm_fill( - col = "class", - palette = colors - ) + - tmap::tm_graticules( - labels.size = tmap_params[["graticules_labels_size"]] - ) + - tmap::tm_compass() + - tmap::tm_layout( - 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.height = tmap_params[["legend_height"]], - legend.width = tmap_params[["legend_width"]], - legend.position = tmap_params[["legend_position"]], - scale = scale - ) + - tmap::tm_borders(lwd = 0.2) - - return(p) -} #' @export .tmap_vector_class.tmap_v4 <- function(sf_seg, colors, @@ -645,59 +246,7 @@ return(p) } - -#' @title Plot a vector uncertainty map -#' @name .tmap_vector_uncert -#' @author Gilberto Camara, \email{gilberto.camara@@inpe.br} -#' @description plots a RGB color image -#' @keywords internal -#' @noRd -#' @param sf_seg sf -#' @param palette A sequential RColorBrewer palette -#' @param rev Reverse the color palette? -#' @param type Uncertainty type -#' @param scale Scale to plot map (0.4 to 1.0) -#' @param tmap_params Tmap parameters -#' @return A plot object -.tmap_vector_uncert <- function(sf_seg, palette, rev, - type, scale, tmap_params){ - if (as.numeric_version(utils::packageVersion("tmap")) < "3.9") - class(sf_seg) <- "tmap_v3" - else - class(sf_seg) <- "tmap_v4" - UseMethod(".tmap_vector_uncert", sf_seg) - -} -.tmap_vector_uncert.tmap_v3 <- function(sf_seg, palette, rev, - type, scale, tmap_params){ - # revert the palette - if (rev) { - palette <- paste0("-", palette) - } - # plot - p <- tmap::tm_shape(sf_seg) + - tmap::tm_fill( - col = type, - palette = palette - ) + - tmap::tm_graticules( - labels.size = tmap_params[["graticules_labels_size"]] - ) + - tmap::tm_compass() + - tmap::tm_layout( - 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.height = tmap_params[["legend_height"]], - legend.width = tmap_params[["legend_width"]], - legend.position = tmap_params[["legend_position"]], - scale = scale - ) + - tmap::tm_borders(lwd = 0.2) - - return(suppressWarnings(p)) -} +#' @export .tmap_vector_uncert.tmap_v4 <- function(sf_seg, palette, rev, type, scale, tmap_params){ # recover palette name used by cols4all @@ -746,9 +295,7 @@ #' \item \code{legend_text_size}: relative size of legend text (default = 1.0) #' \item \code{legend_bg_color}: color of legend background (default = "white") #' \item \code{legend_bg_alpha}: legend opacity (default = 0.5) -#' \item \code{legend_width}: relative width of legend (default = 1.0) #' \item \code{legend_position}: 2D position of legend (default = c("left", "bottom")) -#' \item \code{legend_height}: relative height of legend (default = 1.0) #' } .tmap_params_set <- function(dots){ @@ -758,8 +305,6 @@ legend_bg_alpha <- as.numeric(.conf("plot", "legend_bg_alpha")) legend_title_size <- as.numeric(.conf("plot", "legend_title_size")) legend_text_size <- as.numeric(.conf("plot", "legend_text_size")) - legend_height <- as.numeric(.conf("plot", "legend_height")) - legend_width <- as.numeric(.conf("plot", "legend_width")) legend_position <- .conf("plot", "legend_position") if ("graticules_labels_size" %in% names(dots)) @@ -772,10 +317,6 @@ legend_title_size <- dots[["legend_title_size"]] if ("legend_text_size" %in% names(dots)) legend_text_size <- dots[["legend_text_size"]] - if ("legend_height" %in% names(dots)) - legend_height <- dots[["legend_height"]] - if ("legend_width" %in% names(dots)) - legend_width <- dots[["legend_width"]] if ("legend_position" %in% names(dots)) legend_position <- dots[["legend_position"]] @@ -785,8 +326,6 @@ "legend_bg_alpha" = legend_bg_alpha, "legend_title_size" = legend_title_size, "legend_text_size" = legend_text_size, - "legend_height" = legend_height, - "legend_width" = legend_width, "legend_position" = legend_position ) return(tmap_params) diff --git a/man/plot.class_vector_cube.Rd b/man/plot.class_vector_cube.Rd index 07ad65112..6572590ee 100644 --- a/man/plot.class_vector_cube.Rd +++ b/man/plot.class_vector_cube.Rd @@ -35,7 +35,7 @@ \value{ A plot object with an RGB image or a B/W image on a color - scale using the pallete + scale using the chosen palette } \description{ Plot vector classified cube diff --git a/man/plot.vector_cube.Rd b/man/plot.vector_cube.Rd index 668c4cce1..b520f665e 100644 --- a/man/plot.vector_cube.Rd +++ b/man/plot.vector_cube.Rd @@ -59,7 +59,7 @@ \value{ A plot object with an RGB image or a B/W image on a color - scale using the pallete + scale using the palette } \description{ Plot RGB raster cube diff --git a/man/sits_classify.Rd b/man/sits_classify.Rd index a29d80c07..bec267e5f 100644 --- a/man/sits_classify.Rd +++ b/man/sits_classify.Rd @@ -82,7 +82,7 @@ sits_classify( \item{...}{Other parameters for specific functions.} \item{filter_fn}{Smoothing filter to be applied - optional -(clousure containing object of class "function").} +(closure containing object of class "function").} \item{multicores}{Number of cores to be used for classification (integer, min = 1, max = 2048).} @@ -103,7 +103,7 @@ named lat/long values (Date in YYYY-MM-DD format).} \item{end_date}{End date for the classification -(Date im YYYY-MM-DD format).} +(Date in YYYY-MM-DD format).} \item{memsize}{Memory available for classification in GB (integer, min = 1, max = 16384).} diff --git a/man/sits_combine_predictions.Rd b/man/sits_combine_predictions.Rd index 3d6ef43fa..ef0775a39 100644 --- a/man/sits_combine_predictions.Rd +++ b/man/sits_combine_predictions.Rd @@ -93,7 +93,7 @@ if (sits_run_examples()) { data = cube, ml_model = rfor_model, output_dir = tempdir(), version = "rfor" ) - # create an XGBoost model + # create an SVM model svm_model <- sits_train(samples_modis_ndvi, sits_svm()) # classify a data cube using SVM model probs_svm_cube <- sits_classify( diff --git a/man/sits_confidence_sampling.Rd b/man/sits_confidence_sampling.Rd index 4a76bed20..9f67c5fe6 100644 --- a/man/sits_confidence_sampling.Rd +++ b/man/sits_confidence_sampling.Rd @@ -62,7 +62,7 @@ if (sits_run_examples()) { data_dir <- system.file("extdata/raster/mod13q1", package = "sits") cube <- sits_cube( source = "BDC", - collection = "MOD13Q1-6", + collection = "MOD13Q1-6.1", data_dir = data_dir ) # build a random forest model diff --git a/man/sits_config_user_file.Rd b/man/sits_config_user_file.Rd index 5f816633c..85ed51708 100644 --- a/man/sits_config_user_file.Rd +++ b/man/sits_config_user_file.Rd @@ -9,7 +9,7 @@ sits_config_user_file(file_path, overwrite = FALSE) \arguments{ \item{file_path}{file to store the user configuration file} -\item{overwrite}{replace current configurarion file?} +\item{overwrite}{replace current configuration file?} } \value{ Called for side effects diff --git a/man/sits_cube.Rd b/man/sits_cube.Rd index 88b604f22..e36618694 100644 --- a/man/sits_cube.Rd +++ b/man/sits_cube.Rd @@ -303,10 +303,11 @@ if (sits_run_examples()) { lat_min = -33.85777, lat_max = -32.56690 ), - start_date = "2016-01-01", - end_date = "2017-01-01" + start_date = "2018-01-01", + end_date = "2018-12-31" ) # --- Access to CDSE open data Sentinel 2/2A level 2 collection + # --- remember to set the appropriate environmental variables # It is recommended that `multicores` be used to accelerate the process. s2_cube <- sits_cube( source = "CDSE", @@ -318,6 +319,7 @@ if (sits_run_examples()) { ) ## --- Sentinel-1 SAR from CDSE + # --- remember to set the appropriate environmental variables roi_sar <- c("lon_min" = 33.546, "lon_max" = 34.999, "lat_min" = 1.427, "lat_max" = 3.726) s1_cube_open <- sits_cube( diff --git a/man/sits_detect_change.Rd b/man/sits_detect_change.Rd deleted file mode 100644 index 27ea46345..000000000 --- a/man/sits_detect_change.Rd +++ /dev/null @@ -1,104 +0,0 @@ -% Generated by roxygen2: do not edit by hand -% Please edit documentation in R/sits_detect_change.R -\name{sits_detect_change} -\alias{sits_detect_change} -\alias{sits_detect_change.sits} -\alias{sits_detect_change.raster_cube} -\alias{sits_detect_change.default} -\title{Detect changes in time series} -\usage{ -sits_detect_change( - data, - cd_method, - ..., - filter_fn = NULL, - multicores = 2L, - progress = TRUE -) - -\method{sits_detect_change}{sits}( - data, - cd_method, - ..., - filter_fn = NULL, - multicores = 2L, - progress = TRUE -) - -\method{sits_detect_change}{raster_cube}( - data, - cd_method, - ..., - roi = NULL, - filter_fn = NULL, - impute_fn = impute_linear(), - start_date = NULL, - end_date = NULL, - memsize = 8L, - multicores = 2L, - output_dir, - version = "v1", - verbose = FALSE, - progress = TRUE -) - -\method{sits_detect_change}{default}(data, cd_method, ...) -} -\arguments{ -\item{data}{Set of time series.} - -\item{cd_method}{Change detection method (with parameters).} - -\item{...}{Other parameters for specific functions.} - -\item{filter_fn}{Smoothing filter to be applied - optional -(clousure containing object of class "function").} - -\item{multicores}{Number of cores to be used for classification -(integer, min = 1, max = 2048).} - -\item{progress}{Logical: Show progress bar?} - -\item{roi}{Region of interest (either an sf object, shapefile, -or a numeric vector with named XY values -("xmin", "xmax", "ymin", "ymax") or -named lat/long values -("lon_min", "lat_min", "lon_max", "lat_max").} - -\item{impute_fn}{Imputation function to remove NA.} - -\item{start_date}{Start date for the classification -(Date in YYYY-MM-DD format).} - -\item{end_date}{End date for the classification -(Date im YYYY-MM-DD format).} - -\item{memsize}{Memory available for classification in GB -(integer, min = 1, max = 16384).} - -\item{output_dir}{Valid directory for output file. -(character vector of length 1).} - -\item{version}{Version of the output -(character vector of length 1).} - -\item{verbose}{Logical: print information about processing time?} -} -\value{ -Time series with detection labels for - each point (tibble of class "sits") - or a data cube indicating detections in each pixel - (tibble of class "detections_cube"). -} -\description{ -Given a set of time series or an image, this function compares -each time series with a set of change/no-change patterns, and indicates -places and dates where change has been detected. -} -\author{ -Gilberto Camara, \email{gilberto.camara@inpe.br} - -Felipe Carlos, \email{efelipecarlos@gmail.com} - -Felipe Carvalho, \email{felipe.carvalho@inpe.br} -} diff --git a/man/sits_detect_change_method.Rd b/man/sits_detect_change_method.Rd deleted file mode 100644 index c5279f886..000000000 --- a/man/sits_detect_change_method.Rd +++ /dev/null @@ -1,27 +0,0 @@ -% Generated by roxygen2: do not edit by hand -% Please edit documentation in R/sits_detect_change_method.R -\name{sits_detect_change_method} -\alias{sits_detect_change_method} -\title{Create detect change method.} -\usage{ -sits_detect_change_method(samples, cd_method = sits_dtw()) -} -\arguments{ -\item{samples}{Time series with the training samples.} - -\item{cd_method}{Change detection method.} -} -\value{ -Change detection method prepared - to be passed to - \code{\link[sits]{sits_detect_change}} -} -\description{ -Prepare detection change method. Currently, sits supports the -following methods: 'dtw' (see \code{\link[sits]{sits_dtw}}) -} -\author{ -Gilberto Camara, \email{gilberto.camara@inpe.br} - -Felipe Carlos, \email{efelipecarlos@gmail.com} -} diff --git a/man/sits_dtw.Rd b/man/sits_dtw.Rd deleted file mode 100644 index e894ed778..000000000 --- a/man/sits_dtw.Rd +++ /dev/null @@ -1,55 +0,0 @@ -% Generated by roxygen2: do not edit by hand -% Please edit documentation in R/sits_dtw.R -\name{sits_dtw} -\alias{sits_dtw} -\title{Dynamic Time Warping for Detect changes.} -\usage{ -sits_dtw( - samples = NULL, - ..., - threshold = NULL, - start_date = NULL, - end_date = NULL, - window = NULL, - patterns = NULL -) -} -\arguments{ -\item{samples}{Time series with the training samples.} - -\item{...}{Other relevant parameters.} - -\item{threshold}{Threshold used to define if an event was detected.} - -\item{start_date}{Initial date of the interval used to extract the -patterns from the samples.} - -\item{end_date}{Final date of the interval used to extract the -patterns from the samples.} - -\item{window}{ISO8601-compliant time period used to define the -DTW moving window, with number and unit, -where "D", "M" and "Y" stands for days, month and -year; e.g., "P16D" for 16 days. This parameter is not -used in operations with data cubes.} - -\item{patterns}{Temporal patterns of the each label available in -`samples`.} -} -\value{ -Change detection method prepared to be passed to - \code{\link[sits]{sits_detect_change_method}} -} -\description{ -Create a Dynamic Time Warping (DTW) method for the -\code{\link[sits]{sits_detect_change_method}}. -} -\author{ -Felipe Carlos, \email{efelipecarlos@gmail.com} - -Felipe Carvalho, \email{felipe.carvalho@inpe.br} - -Gilberto Camara, \email{gilberto.camara@inpe.br} - -Rolf Simoes, \email{rolf.simoes@inpe.br} -} diff --git a/man/sits_mlp.Rd b/man/sits_mlp.Rd index 5a8d3a3c8..608ae4de1 100644 --- a/man/sits_mlp.Rd +++ b/man/sits_mlp.Rd @@ -90,7 +90,7 @@ if (sits_run_examples()) { data_dir <- system.file("extdata/raster/mod13q1", package = "sits") cube <- sits_cube( source = "BDC", - collection = "MOD13Q1-6", + collection = "MOD13Q1-6.1", data_dir = data_dir ) # classify a data cube diff --git a/man/sits_sampling_design.Rd b/man/sits_sampling_design.Rd index 93dc99bc1..19af8bf63 100644 --- a/man/sits_sampling_design.Rd +++ b/man/sits_sampling_design.Rd @@ -7,6 +7,7 @@ sits_sampling_design( cube, expected_ua = 0.75, + alloc_options = c(100, 75, 50), std_err = 0.01, rare_class_prop = 0.1 ) @@ -16,6 +17,8 @@ sits_sampling_design( \item{expected_ua}{Expected values of user's accuracy} +\item{alloc_options}{Fixed sample allocation for rare classes} + \item{std_err}{Standard error we would like to achieve} \item{rare_class_prop}{Proportional area limit for rare classes} diff --git a/man/sits_select.Rd b/man/sits_select.Rd index dc732d7b4..23b86ba77 100644 --- a/man/sits_select.Rd +++ b/man/sits_select.Rd @@ -46,7 +46,7 @@ Tibble with time series or data cube. } \description{ Filter only the selected bands and dates - from a set of time series or froam a data cube. + from a set of time series or from a data cube. } \examples{ # Retrieve a set of time series with 2 classes diff --git a/man/summary.sits.Rd b/man/summary.sits.Rd index 42ef25cd0..5f8f4acbf 100644 --- a/man/summary.sits.Rd +++ b/man/summary.sits.Rd @@ -7,7 +7,7 @@ \method{summary}{sits}(object, ...) } \arguments{ -\item{object}{Object of classes "sits".} +\item{object}{Object of class "sits".} \item{...}{Further specifications for \link{summary}.} } diff --git a/man/summary.sits_accuracy.Rd b/man/summary.sits_accuracy.Rd index 54c095d5c..bc4ddafba 100644 --- a/man/summary.sits_accuracy.Rd +++ b/man/summary.sits_accuracy.Rd @@ -7,7 +7,7 @@ \method{summary}{sits_accuracy}(object, ...) } \arguments{ -\item{object}{Object of classe "sits_accuracy".} +\item{object}{Object of class "sits_accuracy".} \item{...}{Further specifications for \link{summary}.} } diff --git a/tests/testthat/test-accuracy.R b/tests/testthat/test-accuracy.R index 05c90f490..f629f6548 100644 --- a/tests/testthat/test-accuracy.R +++ b/tests/testthat/test-accuracy.R @@ -109,8 +109,6 @@ test_that("Accuracy areas", { multicores = 1, progress = FALSE ) - - expect_true(all(file.exists(unlist(probs_cube$file_info[[1]]$path)))) tc_obj <- .raster_open_rast(probs_cube$file_info[[1]]$path[[1]]) expect_true(nrow(tc_obj) == .tile_nrows(probs_cube)) diff --git a/tests/testthat/test-samples.R b/tests/testthat/test-samples.R index 12244e73e..a6b22f27b 100644 --- a/tests/testthat/test-samples.R +++ b/tests/testthat/test-samples.R @@ -49,7 +49,7 @@ test_that("Sampling design", { expect_true(all(c("prop", "expected_ua", "std_dev", "equal", "alloc_100", "alloc_75", "alloc_50", "alloc_prop") - %in% colnames(sampling_design))) + %in% colnames(sampling_design))) # select samples shp_file <- paste0(tempdir(),"/strata.shp")