From 7a3f7e9db0d15aa9ccfecc7b8728590fb5a92c8c Mon Sep 17 00:00:00 2001 From: gilbertocamara Date: Sun, 4 Aug 2024 20:15:33 -0300 Subject: [PATCH] band names for DEAUSTRALIA collections --- .../sources/config_source_deaustralia.yml | 102 +++++++++--------- inst/extdata/tmap/api_tmap_v3.R | 21 ++-- man/plot.probs_vector_cube.Rd | 2 +- tests/testthat/test-plot.R | 2 +- 4 files changed, 64 insertions(+), 63 deletions(-) diff --git a/inst/extdata/sources/config_source_deaustralia.yml b/inst/extdata/sources/config_source_deaustralia.yml index b22d2ba5..ee39f991 100644 --- a/inst/extdata/sources/config_source_deaustralia.yml +++ b/inst/extdata/sources/config_source_deaustralia.yml @@ -10,7 +10,7 @@ sources: collections : GA_LS5T_ARD_3 : bands : - NBART_BLUE : &deaustralia_ls5_tm_30m + BLUE : &deaustralia_ls5_tm_30m missing_value : -999 minimum_value : 0 maximum_value : 65536 @@ -20,19 +20,19 @@ sources: resolution : 30 band_name : "nbart_blue" data_type : "INT2S" - NBART_GREEN : + GREEN : <<: *deaustralia_ls5_tm_30m band_name: "nbart_green" - NBART_RED : + RED : <<: *deaustralia_ls5_tm_30m band_name: "nbart_red" - NBART_NIR : + NIR : <<: *deaustralia_ls5_tm_30m band_name: "nbart_nir" - NBART_SWIR_1 : + SWIR_1 : <<: *deaustralia_ls5_tm_30m band_name: "nbart_swir_1" - NBART_SWIR_2 : + SWIR_2 : <<: *deaustralia_ls5_tm_30m band_name: "nbart_swir_2" CLOUD : @@ -63,7 +63,7 @@ sources: grid_system : "WRS-2" GA_LS7E_ARD_3 : bands : - NBART_BLUE : &deaustralia_ls7_etm_30m + BLUE : &deaustralia_ls7_etm_30m missing_value : -999 minimum_value : 0 maximum_value : 65536 @@ -73,22 +73,22 @@ sources: resolution : 30 band_name : "nbart_blue" data_type : "INT2S" - NBART_GREEN : + GREEN : <<: *deaustralia_ls7_etm_30m band_name: "nbart_green" - NBART_RED : + RED : <<: *deaustralia_ls7_etm_30m band_name: "nbart_red" - NBART_NIR : + NIR : <<: *deaustralia_ls7_etm_30m band_name: "nbart_nir" - NBART_SWIR_1 : + SWIR_1 : <<: *deaustralia_ls7_etm_30m band_name: "nbart_swir_1" - NBART_SWIR_2 : + SWIR_2 : <<: *deaustralia_ls7_etm_30m band_name: "nbart_swir_2" - NBART_PANCHROMATIC : + PANCHROMATIC : <<: *deaustralia_ls7_etm_30m resolution : 15 band_name: "nbart_panchromatic" @@ -121,7 +121,7 @@ sources: GA_LS8C_ARD_3 : bands : - NBART_COASTAL_AEROSOL : &deaustralia_ls8_oli_30m + COASTAL-AEROSOL : &deaustralia_ls8_oli_30m missing_value : -999 minimum_value : 0 maximum_value : 65536 @@ -131,25 +131,25 @@ sources: resolution : 30 band_name : "nbart_coastal_aerosol" data_type : "INT2U" - NBART_BLUE : + BLUE : <<: *deaustralia_ls8_oli_30m band_name : "nbart_blue" - NBART_GREEN : + GREEN : <<: *deaustralia_ls8_oli_30m band_name : "nbart_green" - NBART_RED : + RED : <<: *deaustralia_ls8_oli_30m band_name : "nbart_red" - NBART_NIR : + NIR : <<: *deaustralia_ls8_oli_30m band_name : "nbart_nir" - NBART_SWIR_1 : + SWIR-1 : <<: *deaustralia_ls8_oli_30m band_name : "nbart_swir_1" - NBART_SWIR_2 : + SWIR-2 : <<: *deaustralia_ls8_oli_30m band_name : "nbart_swir_2" - NBART_PANCHROMATIC: + PANCHROMATIC: <<: *deaustralia_ls8_oli_30m resolution : 15 band_name : "nbart_panchromatic" @@ -181,7 +181,7 @@ sources: grid_system : "WRS-2" GA_LS9C_ARD_3 : bands : - NBART_COASTAL_AEROSOL : &deaustralia_ls9_oli_30m + COASTAL-AEROSOL : &deaustralia_ls9_oli_30m missing_value : -999 minimum_value : 0 maximum_value : 65536 @@ -191,25 +191,25 @@ sources: resolution : 30 band_name : "nbart_coastal_aerosol" data_type : "INT2U" - NBART_BLUE : + BLUE : <<: *deaustralia_ls9_oli_30m band_name : "nbart_blue" - NBART_GREEN : + GREEN : <<: *deaustralia_ls9_oli_30m band_name : "nbart_green" - NBART_RED : + RED : <<: *deaustralia_ls9_oli_30m band_name : "nbart_red" - NBART_NIR : + NIR : <<: *deaustralia_ls9_oli_30m band_name : "nbart_nir" - NBART_SWIR_1 : + SWIR-1 : <<: *deaustralia_ls9_oli_30m band_name : "nbart_swir_1" - NBART_SWIR_2 : + SWIR-2 : <<: *deaustralia_ls9_oli_30m band_name : "nbart_swir_2" - NBART_PANCHROMATIC: + PANCHROMATIC: <<: *deaustralia_ls9_oli_30m resolution : 15 band_name : "nbart_panchromatic" @@ -242,7 +242,7 @@ sources: GA_S2AM_ARD_3 : bands : - NBART_COASTAL_AEROSOL : &deaustralia_s2a_msi_60m + COASTAL-AEROSOL : &deaustralia_s2a_msi_60m missing_value : -999 minimum_value : 0 maximum_value : 10000 @@ -251,7 +251,7 @@ sources: resolution : 60 band_name : "nbart_coastal_aerosol" data_type : "INT2S" - NBART_BLUE : &deaustralia_s2a_msi_10m + BLUE : &deaustralia_s2a_msi_10m missing_value : -999 minimum_value : 0 maximum_value : 10000 @@ -260,13 +260,13 @@ sources: resolution : 10 band_name : "nbart_blue" data_type : "INT2S" - NBART_GREEN : + GREEN : <<: *deaustralia_s2a_msi_10m band_name : "nbart_green" - NBART_RED : + RED : <<: *deaustralia_s2a_msi_10m band_name : "nbart_red" - NBART_RED_EDGE_1 : &deaustralia_s2a_msi_20m + RED-EDGE-1 : &deaustralia_s2a_msi_20m missing_value : -999 minimum_value : 0 maximum_value : 10000 @@ -275,22 +275,22 @@ sources: resolution : 20 band_name : "nbart_red_edge_1" data_type : "INT2S" - NBART_RED_EDGE_2 : + RED_EDGE_2 : <<: *deaustralia_s2a_msi_20m band_name : "nbart_red_edge_2" - NBART_RED_EDGE_3 : + RED_EDGE_3 : <<: *deaustralia_s2a_msi_20m band_name : "nbart_red_edge_3" - NBART_NIR_1 : + NIR-1 : <<: *deaustralia_s2a_msi_10m band_name : "nbart_nir_1" - NBART_NIR_2 : + NIR-2 : <<: *deaustralia_s2a_msi_20m band_name : "nbart_nir_2" - NBART_SWIR_2 : + SWIR-2 : <<: *deaustralia_s2a_msi_20m band_name : "nbart_swir_2" - NBART_SWIR_3 : + SWIR-3 : <<: *deaustralia_s2a_msi_20m band_name : "nbart_swir_3" CLOUD : @@ -323,7 +323,7 @@ sources: grid_system : "MGRS" GA_S2BM_ARD_3 : bands : - NBART_COASTAL_AEROSOL : &deaustralia_s2a_msi_60m + COASTAL-AEROSOL : &deaustralia_s2a_msi_60m missing_value : -999 minimum_value : 0 maximum_value : 10000 @@ -332,7 +332,7 @@ sources: resolution : 60 band_name : "nbart_coastal_aerosol" data_type : "INT2U" - NBART_BLUE : &deaustralia_s2a_msi_10m + BLUE : &deaustralia_s2a_msi_10m missing_value : -999 minimum_value : 0 maximum_value : 10000 @@ -341,13 +341,13 @@ sources: resolution : 10 band_name : "nbart_blue" data_type : "INT2S" - NBART_GREEN : + GREEN : <<: *deaustralia_s2a_msi_10m band_name : "nbart_green" - NBART_RED : + RED : <<: *deaustralia_s2a_msi_10m band_name : "nbart_red" - NBART_RED_EDGE_1 : &deaustralia_s2a_msi_20m + RED-EDGE-1 : &deaustralia_s2a_msi_20m missing_value : -999 minimum_value : 0 maximum_value : 10000 @@ -356,22 +356,22 @@ sources: resolution : 20 band_name : "nbart_red_edge_1" data_type : "INT2S" - NBART_RED_EDGE_2 : + RED-EDGE-2 : <<: *deaustralia_s2a_msi_20m band_name : "nbart_red_edge_2" - NBART_RED_EDGE_3 : + RED-EDGE-3 : <<: *deaustralia_s2a_msi_20m band_name : "nbart_red_edge_3" - NBART_NIR_1 : + NIR-1 : <<: *deaustralia_s2a_msi_10m band_name : "nbart_nir_1" - NBART_NIR_2 : + NIR-2 : <<: *deaustralia_s2a_msi_20m band_name : "nbart_nir_2" - NBART_SWIR_2 : + SWIR-2 : <<: *deaustralia_s2a_msi_20m band_name : "nbart_swir_2" - NBART_SWIR_3 : + SWIR-3 : <<: *deaustralia_s2a_msi_20m band_name : "nbart_swir_3" CLOUD : diff --git a/inst/extdata/tmap/api_tmap_v3.R b/inst/extdata/tmap/api_tmap_v3.R index 01b3181b..b4461b94 100644 --- a/inst/extdata/tmap/api_tmap_v3.R +++ b/inst/extdata/tmap/api_tmap_v3.R @@ -188,7 +188,7 @@ #' @noRd #' @param st Stars object. #' @param labels Class labels -#' @param label_plot Class labels to be plotted +#' @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) @@ -196,7 +196,7 @@ #' @return A plot object .tmap_probs_map <- function(probs_st, labels, - label_plot, + labels_plot, palette, rev, scale, @@ -212,7 +212,7 @@ #' .tmap_probs_map.tmap_v3 <- function(probs_st, labels, - label_plot, + labels_plot, palette, rev, scale, @@ -222,15 +222,16 @@ palette <- paste0("-", palette) } # select stars bands to be plotted - bds <- as.numeric(names(labels[labels %in% label_plot])) + 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% label_plot] + title = labels[labels %in% labels_plot] ) + + tmap::tm_facets(sync = FALSE) + tmap::tm_graticules( labels.size = tmap_params[["graticules_labels_size"]] ) + @@ -258,12 +259,12 @@ #' @param palette A sequential RColorBrewer palette #' @param rev Reverse the color palette? #' @param labels Class labels -#' @param label_plot Class label to be plotted +#' @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, label_plot, + labels, labels_plot, scale, tmap_params){ if (as.numeric_version(utils::packageVersion("tmap")) < "3.9") class(sf_seg) <- "tmap_v3" @@ -273,7 +274,7 @@ } #' @export .tmap_vector_probs.tmap_v3 <- function(sf_seg, palette, rev, - labels, label_plot, + labels, labels_plot, scale, tmap_params){ # revert the palette? if (rev) { @@ -283,11 +284,11 @@ # plot the segments p <- tmap::tm_shape(sf_seg) + tmap::tm_fill( - label_plot, + labels_plot, style = "cont", palette = palette, midpoint = NA, - title = labels[labels %in% label_plot]) + + title = labels[labels %in% labels_plot]) + tmap::tm_graticules( labels.size = tmap_params[["graticules_labels_size"]] ) + diff --git a/man/plot.probs_vector_cube.Rd b/man/plot.probs_vector_cube.Rd index 70129f5e..f30dd48a 100644 --- a/man/plot.probs_vector_cube.Rd +++ b/man/plot.probs_vector_cube.Rd @@ -44,7 +44,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 ) # segment the image diff --git a/tests/testthat/test-plot.R b/tests/testthat/test-plot.R index 51685215..18a7f827 100644 --- a/tests/testthat/test-plot.R +++ b/tests/testthat/test-plot.R @@ -67,7 +67,7 @@ test_that("Plot Time Series and Images", { ) p_probs <- plot(sinop_probs) expect_equal(p_probs$tm_raster$palette, "YlGn") - expect_equal(length(p_probs$tm_raster$title), 1) + expect_equal(length(p_probs$tm_raster$title), 4) expect_equal(p_probs$tm_layout$legend.bg.color, "white") p_probs_f <- plot(sinop_probs, labels = "Forest")