e-sensing / sits

Satellite image time series in R

Home Page:https://e-sensing.github.io/sitsbook/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

sits_colors_set function does not work as expected

fredtaka opened this issue · comments

Describe the bug
When executing the example of the sits_colors_set function, the result obtained does not correspond to what was expected (that is, the color palette appears in the list of palettes displayed by the sits_colors_show command and the graph displays the palette). In fact, the graphics for the default palettes are not generated after using the sits_colors_set command. This is reversible by the sits_colors_reset command.

To Reproduce

> sits_colors_reset()
> sits_colors_show("UMD") #graph looks OK
> us_nlcd <- tibble::tibble(name = character(), color = character())
> us_nlcd <- us_nlcd |>
+     tibble::add_row(name = "Urban Built Up", color = "#85929E") |>
+     tibble::add_row(name = "Agricultural Land", color = "#F0B27A") |>
+     tibble::add_row(name = "Rangeland", color = "#F1C40F") |>
+     tibble::add_row(name = "Forest Land", color = "#27AE60") |>
+     tibble::add_row(name = "Water", color = "#2980B9") |>
+     tibble::add_row(name = "Wetland", color = "#D4E6F1") |>
+     tibble::add_row(name = "Barren Land", color = "#FDEBD0") |>
+     tibble::add_row(name = "Tundra", color = "#EBDEF0") |>
+     tibble::add_row(name = "Snow and Ice", color = "#F7F9F9")
> 
> sits_colors_set(us_nlcd)
> sits_colors_show("us_nlcd")
[1] "Please select one of the legends: IGBP, UMD, ESA_CCI_LC, WORLDCOVER, PRODES, PRODES_VISUAL, TERRA_CLASS, TERRA_CLASS_PT"
> sits_colors_show("UMD") #graph with NA
> sessionInfo() R version 4.3.0 (2023-04-21) Platform: x86_64-pc-linux-gnu (64-bit) Running under: Ubuntu 22.04.2 LTS

Matrix products: default
BLAS: /usr/lib/x86_64-linux-gnu/blas/libblas.so.3.10.0
LAPACK: /usr/lib/x86_64-linux-gnu/lapack/liblapack.so.3.10.0

locale:
[1] LC_CTYPE=en_US.UTF-8 LC_NUMERIC=C LC_TIME=en_US.UTF-8
[4] LC_COLLATE=en_US.UTF-8 LC_MONETARY=en_US.UTF-8 LC_MESSAGES=en_US.UTF-8
[7] LC_PAPER=en_US.UTF-8 LC_NAME=C LC_ADDRESS=C
[10] LC_TELEPHONE=C LC_MEASUREMENT=en_US.UTF-8 LC_IDENTIFICATION=C

time zone: America/Sao_Paulo
tzcode source: system (glibc)

attached base packages:
[1] stats graphics grDevices utils datasets methods base

other attached packages:
[1] mapview_2.11.0 tictoc_1.2 data.table_1.14.8 sits_1.4.2-1
[5] dplyr_1.1.2 sf_1.0-13

loaded via a namespace (and not attached):
[1] DBI_1.1.3 tmaptools_3.1-1
[3] s2_1.1.4 rlang_1.1.1
[5] magrittr_2.0.3 e1071_1.7-13
[7] compiler_4.3.0 png_0.1-8
[9] callr_3.7.3 vctrs_0.6.4
[11] slider_0.3.0 stringr_1.5.0
[13] sysfonts_0.8.8 pkgconfig_2.0.3
[15] wk_0.7.3 crayon_1.5.2
[17] fastmap_1.1.1 ellipsis_0.3.2
[19] lwgeom_0.2-13 leafem_0.2.0
[21] labeling_0.4.2 utf8_1.2.3
[23] ps_1.7.5 torch_0.11.0
[25] purrr_1.0.2 bit_4.0.5
[27] xfun_0.39 satellite_1.0.4
[29] showtext_0.9-6 randomForest_4.7-1.1
[31] jsonlite_1.8.5 rstac_0.9.2-5
[33] highr_0.10 gdalcubes_0.6.4
[35] reshape_0.8.9 terra_1.7-29
[37] parallel_4.3.0 R6_2.5.1
[39] stringi_1.7.12 RColorBrewer_1.1-3
[41] GGally_2.1.2 lubridate_1.9.2
[43] stars_0.6-1 knitr_1.43
[45] Rcpp_1.0.10 warp_0.2.0
[47] randomForestExplainer_0.10.1 base64enc_0.1-3
[49] leaflet.providers_1.9.0 timechange_0.2.0
[51] tidyselect_1.2.0 rstudioapi_0.14
[53] dichromat_2.0-0.1 abind_1.4-5
[55] yaml_2.3.7 codetools_0.2-19
[57] curl_5.0.0 processx_3.8.1
[59] lattice_0.21-8 tibble_3.2.1
[61] leafsync_0.1.0 plyr_1.8.8
[63] withr_2.5.0 evaluate_0.21
[65] units_0.8-2 proxy_0.4-27
[67] pillar_1.9.0 KernSmooth_2.23-20
[69] DT_0.28 stats4_4.3.0
[71] ncdf4_1.21 generics_0.1.3
[73] sp_1.6-1 ggplot2_3.4.2
[75] munsell_0.5.0 scales_1.2.1
[77] coro_1.0.3 class_7.3-21
[79] glue_1.6.2 tools_4.3.0
[81] webshot_0.5.4 XML_3.99-0.14
[83] grid_4.3.0 tidyr_1.3.0
[85] crosstalk_1.2.0 colorspace_2.1-0
[87] raster_3.6-20 showtextdb_3.0
[89] cli_3.6.1 fansi_1.0.4
[91] tmap_3.3-3 viridisLite_0.4.2
[93] gtable_0.3.3 digest_0.6.31
[95] classInt_0.4-9 ggrepel_0.9.3
[97] htmlwidgets_1.6.2 farver_2.1.1
[99] htmltools_0.5.5 lifecycle_1.0.3
[101] leaflet_2.1.2 httr_1.4.6
[103] bit64_4.0.5

Dear @fredtaka Thanks for pointing out the bug. We have solved it in the "dev" (development) version. You are invited to download the corrections using:

devtools::install_github("e-sensing/sits@dev")

To correct the bug, we had to make some changes to the API. The sits_colors_set() function now takes two parameters: a user-defined color table, and (optionally) a legend to be associated to these colors. Also notice that the colors names should be made of a single string. Composite color names need to be combined with underscores (e.g., "Show_and_Ice" is valid but "Snow and Ice" is not. Please install the dev version and then run the following example:

library(sits)
#. Two examples of user-defined colors 
# Case 1 - Define a color table based on the Anderson Land Classification System 
    us_nlcd <- tibble::tibble(name = character(), color = character())
    us_nlcd <- us_nlcd |>
            tibble::add_row(name = "Urban_Built_Up", color = "#85929E") |>
            tibble::add_row(name = "Agricultural_Land", color = "#F0B27A") |>
            tibble::add_row(name = "Rangeland", color = "#F1C40F") |>
            tibble::add_row(name = "Forest_Land", color = "#27AE60") |> 
            tibble::add_row(name = "Water", color = "#2980B9") |>
            tibble::add_row(name = "Wetland", color = "#D4E6F1") |>
            tibble::add_row(name = "Barren_Land", color = "#FDEBD0") |>
            tibble::add_row(name = "Tundra", color = "#EBDEF0") |>
            tibble::add_row(name = "Snow_and_Ice", color = "#F7F9F9")

 # Load the color table into `sits`
sits_colors_set(colors = us_nlcd, legend = "US_NLCD")

 # Show the new color table used by sits
sits_colors_show("US_NLCD")

# Case 2 - Change colors in the sits global color table
# First show the default colors for the UMD legend
sits_colors_show("UMD")
# Then change some colors associated to the UMD legend
mycolors <- tibble::tibble(name = character(), color = character())
mycolors <- mycolors |>
      tibble::add_row(name = "Savannas", color = "#F8C471") |>
       tibble::add_row(name = "Grasslands", color = "#ABEBC6")

# set the user-defined colors
sits_colors_set(colors = mycolors)
# Notice that the UMD colors change
sits_colors_show("UMD")
# Reset the color table
sits_colors_reset()
# Show the default colors for the UMD legend
sits_colors_show("UMD")