How to plot an image from a `sits` cube

I recently tried to use the sits package to do some classifications based on image time-series in R. Following the instructions in the SITS book (https://e-sensing.github.io/sitsbook/earth-observation-data-cubes.html) I ran the following code, but I am unable to plot an image. I am using the open data collection in AWS to get the data, so there should be no problem to obtain the data. Anyone knows if this is a bug or I am missing something in my code?

library(sits)

# Get data
s2_15QYU_cube <- sits_cube(
  source = "AWS",
  collection = "SENTINEL-S2-L2A-COGS",
  tiles = "15QYU",
  bands = c("B08", "B04", "B03", "CLOUD"),
  start_date = "2019-02-01",
  end_date = "2019-02-28"
)

# see dates in time series
sits_timeline(s2_15QYU_cube)

# See an image
s2_15QYU_cube |>
  # dplyr::filter(tile == "15QYU") |>
  plot(red = "B08", 
       green = "B04", 
       blue = "B03", 
       date = "2019-02-12")

This is the error I am obtaining after running the final line.

Error in CPL_read_gdal(as.character(x), as.character(options), as.character(driver),  : 
  trying to read a band that is not present
In addition: Warning messages:
1: In FUN(X[[i]], ...) :
  st_apply on x/y dimensions applied to downsampled image(s)
2: In CPL_read_gdal(as.character(x), as.character(options), as.character(driver),  :
  GDAL Error 5: /vsicurl/https://sentinel-cogs.s3.us-west-2.amazonaws.com/sentinel-s2-l2a-cogs/15/Q/YU/2019/2/S2B_15QYU_20190212_0_L2A/B04.tif: GDALDataset::GetRasterBand(2) - Illegal band #

The same code seems to work in @aldo_tapia session (thanks for the test) and I am sure I have an active connection to internet, so I am posting my session info to see if the error might be caused by some package version issues.

─ Session info ───────────────────────────────────────────────
 setting  value
 version  R version 4.2.2 (2022-10-31 ucrt)
 os       Windows 10 x64 (build 22621)
 system   x86_64, mingw32
 ui       RStudio
 language (EN)
 collate  Spanish_Mexico.utf8
 ctype    Spanish_Mexico.utf8
 tz       America/Mexico_City
 date     2023-01-20
 rstudio  2022.12.0+353 Elsbeth Geranium (desktop)
 pandoc   NA

─ Packages ───────────────────────────────────────────────────────────
 package      * version   date (UTC) lib source
 abind          1.4-5     2016-07-21 [1] CRAN (R 4.2.0)
 assertthat     0.2.1     2019-03-21 [1] CRAN (R 4.2.2)
 base64enc      0.1-3     2015-07-28 [1] CRAN (R 4.2.0)
 class          7.3-20    2022-01-16 [2] CRAN (R 4.2.2)
 classInt       0.4-8     2022-09-29 [1] CRAN (R 4.2.2)
 cli            3.4.1     2022-09-23 [1] CRAN (R 4.2.2)
 clipr          0.8.0     2022-02-22 [1] CRAN (R 4.2.2)
 codetools      0.2-18    2020-11-04 [2] CRAN (R 4.2.2)
 crayon         1.5.2     2022-09-29 [1] CRAN (R 4.2.2)
 crosstalk      1.2.0     2021-11-04 [1] CRAN (R 4.2.2)
 curl           5.0.0     2023-01-12 [1] CRAN (R 4.2.2)
 data.table     1.14.6    2022-11-16 [1] CRAN (R 4.2.2)
 DBI            1.1.3     2022-06-18 [1] CRAN (R 4.2.2)
 dichromat      2.0-0.1   2022-05-02 [1] CRAN (R 4.2.0)
 digest         0.6.31    2022-12-11 [1] CRAN (R 4.2.2)
 dplyr          1.0.10    2022-09-01 [1] CRAN (R 4.2.2)
 e1071          1.7-12    2022-10-24 [1] CRAN (R 4.2.2)
 fansi          1.0.3     2022-03-24 [1] CRAN (R 4.2.2)
 fastmap        1.1.0     2021-01-25 [1] CRAN (R 4.2.2)
 generics       0.1.3     2022-07-05 [1] CRAN (R 4.2.2)
 glue           1.6.2     2022-02-24 [1] CRAN (R 4.2.2)
 htmltools      0.5.4     2022-12-07 [1] CRAN (R 4.2.2)
 htmlwidgets    1.6.1     2023-01-07 [1] CRAN (R 4.2.2)
 httr           1.4.4     2022-08-17 [1] CRAN (R 4.2.2)
 jsonlite       1.8.4     2022-12-06 [1] CRAN (R 4.2.2)
 KernSmooth     2.23-20   2021-05-03 [2] CRAN (R 4.2.2)
 lattice        0.20-45   2021-09-22 [2] CRAN (R 4.2.2)
 leafem         0.2.0     2022-04-16 [1] CRAN (R 4.2.2)
 leaflet        2.1.1     2022-03-23 [1] CRAN (R 4.2.2)
 leafsync       0.1.0     2019-03-05 [1] CRAN (R 4.2.2)
 lifecycle      1.0.3     2022-10-07 [1] CRAN (R 4.2.2)
 lubridate      1.9.0     2022-11-06 [1] CRAN (R 4.2.2)
 lwgeom         0.2-11    2023-01-14 [1] CRAN (R 4.2.2)
 magrittr       2.0.3     2022-03-30 [1] CRAN (R 4.2.2)
 pillar         1.8.1     2022-08-19 [1] CRAN (R 4.2.2)
 pkgconfig      2.0.3     2019-09-22 [1] CRAN (R 4.2.2)
 png            0.1-8     2022-11-29 [1] CRAN (R 4.2.2)
 proxy          0.4-27    2022-06-09 [1] CRAN (R 4.2.2)
 purrr          1.0.1     2023-01-10 [1] CRAN (R 4.2.2)
 R6             2.5.1     2021-08-19 [1] CRAN (R 4.2.2)
 raster         3.6-14    2023-01-16 [1] CRAN (R 4.2.2)
 RColorBrewer   1.1-3     2022-04-03 [1] CRAN (R 4.2.0)
 Rcpp           1.0.9     2022-07-08 [1] CRAN (R 4.2.1)
 rlang          1.0.6     2022-09-24 [1] CRAN (R 4.2.2)
 rstac          0.9.2     2023-01-20 [1] CRAN (R 4.2.2)
 rstudioapi     0.14      2022-08-22 [1] CRAN (R 4.2.2)
 sessioninfo    1.2.2     2021-12-06 [1] CRAN (R 4.2.2)
 sf             1.0-9     2022-11-08 [1] CRAN (R 4.2.2)
 sits         * 1.2.0     2022-11-16 [1] CRAN (R 4.2.2)
 slider         0.3.0     2022-11-16 [1] CRAN (R 4.2.2)
 sp             1.6-0     2023-01-19 [1] CRAN (R 4.2.2)
 stars          0.6-0     2022-11-21 [1] CRAN (R 4.2.2)
 terra          1.6-53    2023-01-17 [1] CRAN (R 4.2.2)
 tibble         3.1.8     2022-07-22 [1] CRAN (R 4.2.2)
 tidyr          1.2.1     2022-09-08 [1] CRAN (R 4.2.2)
 tidyselect     1.2.0     2022-10-10 [1] CRAN (R 4.2.2)
 timechange     0.2.0     2023-01-11 [1] CRAN (R 4.2.2)
 tmap           3.3-3     2022-03-02 [1] CRAN (R 4.2.2)
 tmaptools      3.1-1     2021-01-19 [1] CRAN (R 4.2.2)
 units          0.8-1     2022-12-10 [1] CRAN (R 4.2.2)
 utf8           1.2.2     2021-07-24 [1] CRAN (R 4.2.2)
 vctrs          0.5.0     2022-10-22 [1] CRAN (R 4.2.2)
 viridisLite    0.4.1     2022-08-22 [1] CRAN (R 4.2.2)
 warp           0.2.0     2020-10-21 [1] CRAN (R 4.2.2)
 withr          2.5.0     2022-03-03 [1] CRAN (R 4.2.2)
 XML            3.99-0.13 2022-12-04 [1] CRAN (R 4.2.2)
 yaml           2.3.6     2022-10-18 [1] CRAN (R 4.2.2)
───────────────────────────────────────────────────────────────────────

Upvotes: 0

Views: 110

Answers (2)

This was indeed a bug. I wrote to the developers and it is now fixed in version v1.2.0-3. To install this version, use: devtools::install_github("e-sensing/sits").

Upvotes: 0

aldo_tapia
aldo_tapia

Reputation: 1228

It should be a connection error. It's working fine:

library(sits)

# Get data
s2_15QYU_cube <- sits_cube(
  source = "AWS",
  collection = "SENTINEL-S2-L2A-COGS",
  tiles = "15QYU",
  bands = c("B08", "B04", "B03", "CLOUD"),
  start_date = "2019-02-01",
  end_date = "2019-02-28"
)

# see dates in time series
sits_timeline(s2_15QYU_cube)

# See an image
s2_15QYU_cube |>
  # dplyr::filter(tile == "15QYU") |>
  plot(red = "B08", 
       green = "B04", 
       blue = "B03", 
       date = "2019-02-12")

enter image description here

Session info:

─ Session info ───────────────────────────────────────────────────────
 setting  value
 version  R version 4.2.0 (2022-04-22)
 os       macOS Monterey 12.5
 system   x86_64, darwin17.0
 ui       RStudio
 language (EN)
 collate  en_US.UTF-8
 ctype    en_US.UTF-8
 tz       America/Santiago
 date     2023-01-20
 rstudio  2022.12.0+353 Elsbeth Geranium (desktop)
 pandoc   2.18 @ /usr/local/bin/pandoc

─ Packages ───────────────────────────────────────────────────────────
 package     * version date (UTC) lib source
 assertthat    0.2.1   2019-03-21 [1] CRAN (R 4.2.0)
 cli           3.6.0   2023-01-09 [1] CRAN (R 4.2.0)
 colorspace    2.0-3   2022-02-21 [1] CRAN (R 4.2.0)
 data.table    1.14.6  2022-11-16 [1] CRAN (R 4.2.0)
 DBI           1.1.3   2022-06-18 [1] CRAN (R 4.2.0)
 dplyr         1.0.9   2022-04-28 [1] CRAN (R 4.2.0)
 fansi         1.0.3   2022-03-24 [1] CRAN (R 4.2.0)
 generics      0.1.3   2022-07-05 [1] CRAN (R 4.2.0)
 glue          1.6.2   2022-02-24 [1] CRAN (R 4.2.0)
 lattice       0.20-45 2021-09-22 [1] CRAN (R 4.2.0)
 lifecycle     1.0.3   2022-10-07 [1] CRAN (R 4.2.0)
 lubridate     1.8.0   2021-10-07 [1] CRAN (R 4.2.0)
 magrittr      2.0.3   2022-03-30 [1] CRAN (R 4.2.0)
 munsell       0.5.0   2018-06-12 [1] CRAN (R 4.2.0)
 pillar        1.8.1   2022-08-19 [1] CRAN (R 4.2.0)
 pkgconfig     2.0.3   2019-09-22 [1] CRAN (R 4.2.0)
 purrr         0.3.4   2020-04-17 [1] CRAN (R 4.2.0)
 R6            2.5.1   2021-08-19 [1] CRAN (R 4.2.0)
 Rcpp          1.0.9   2022-07-08 [1] CRAN (R 4.2.0)
 rlang         1.0.6   2022-09-24 [1] CRAN (R 4.2.0)
 rstudioapi    0.14    2022-08-22 [1] CRAN (R 4.2.0)
 scales        1.2.1   2022-08-20 [1] CRAN (R 4.2.0)
 sessioninfo   1.2.2   2021-12-06 [1] CRAN (R 4.2.0)
 sits        * 1.2.0   2022-11-16 [1] CRAN (R 4.2.0)
 tibble        3.1.8   2022-07-22 [1] CRAN (R 4.2.0)
 tidyselect    1.1.2   2022-02-21 [1] CRAN (R 4.2.0)
 utf8          1.2.2   2021-07-24 [1] CRAN (R 4.2.0)
 vctrs         0.5.1   2022-11-16 [1] CRAN (R 4.2.0)
 writexl       1.4.0   2021-04-20 [1] CRAN (R 4.2.0)
 yaml          2.3.6   2022-10-18 [1] CRAN (R 4.2.0)
 zoo           1.8-11  2022-09-17 [1] CRAN (R 4.2.0)

 [1] /Library/Frameworks/R.framework/Versions/4.2/Resources/library

──────────────────────────────────────────────────────────────────────

Upvotes: 1

Related Questions