e-sensing / sits

Satellite image time series in R
https://e-sensing.github.io/sitsbook/
GNU General Public License v2.0
481 stars 78 forks source link

Error with `sits_get_data` #1223

Closed paulacopelli closed 1 week ago

paulacopelli commented 1 month ago

Hello!
I encountered an issue where, despite having a valid data cube for sits and a set of points from which I want to extract information, I received an error.

Code:

samples_itata <- sits_get_data(
  cube = cube_itata_mosaic,                # data cube to extract information from
  samples = Puntos_totales,                # sample points
  bands = sits_bands(cube_itata_mosaic),   # bands to extract the time series from
  label_attr = "label",                    # attribute column for class label of each sample
  pol_id = "Nivel3",                       # polygon ID
  crs = "EPSG:32718",                      # coordinate reference system
  multicores = 1,                          # number of cores to process the time series
  progress = TRUE                          # show progress bar
)

I don't have the exact error message, but it was related to "invalid input," without specifying whether it referred to the data cube or the sample points.

paulacopelli commented 1 month ago

The exact message error is:

Error: sits_get_data: unable to retrieve data - check input parameters
> sessionInfo()
R version 4.3.1 (2023-06-16 ucrt)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows 11 x64 (build 22621)

Matrix products: default

locale:
[1] LC_COLLATE=Spanish_Chile.utf8  LC_CTYPE=Spanish_Chile.utf8    LC_MONETARY=Spanish_Chile.utf8
[4] LC_NUMERIC=C                   LC_TIME=Spanish_Chile.utf8    

time zone: America/Santiago
tzcode source: internal

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

other attached packages:
 [1] leaflet.extras_2.0.1 leaflet_2.2.2        lubridate_1.9.3      forcats_1.0.0        stringr_1.5.1       
 [6] dplyr_1.1.4          purrr_1.0.2          readr_2.1.5          tidyr_1.3.0          tibble_3.2.1        
[11] ggplot2_3.4.4        tidyverse_2.0.0      sf_1.0-16            sits_1.5.1          

loaded via a namespace (and not attached):
 [1] gtable_0.3.4       htmlwidgets_1.6.4  tzdb_0.4.0         vctrs_0.6.5        tools_4.3.1        crosstalk_1.2.1   
 [7] generics_0.1.3     parallel_4.3.1     proxy_0.4-27       fansi_1.0.5        pacman_0.5.1       pkgconfig_2.0.3   
[13] KernSmooth_2.23-21 RColorBrewer_1.1-3 lifecycle_1.0.4    compiler_4.3.1     munsell_0.5.0      leafsync_0.1.0    
[19] stars_0.6-6        htmltools_0.5.8.1  class_7.3-22       yaml_2.3.8         pillar_1.9.0       classInt_0.4-10   
[25] abind_1.4-5        tidyselect_1.2.1   digest_0.6.33      stringi_1.8.2      fastmap_1.2.0      grid_4.3.1        
[31] colorspace_2.1-0   cli_3.6.1          magrittr_2.0.3     dichromat_2.0-0.1  XML_3.99-0.17      utf8_1.2.4        
[37] e1071_1.7-14       withr_2.5.2        scales_1.3.0       warp_0.2.1         timechange_0.3.0   slider_0.3.1      
[43] hms_1.1.3          rlang_1.1.2        Rcpp_1.0.11        glue_1.6.2         DBI_1.2.3          rstudioapi_0.16.0 
[49] R6_2.5.1           units_0.8-5    
gilbertocamara commented 1 month ago

Dear @paulacopelli, this error could be caused by a mismatch between the format of your input data ("puntos totales"). the function sits_get_data() accepts samples in different formats. The most common would be CVS files or SHP files. In these cases, the function requires you to provide a valid path (e.g. "/path_to_my_files/puntos_totales.shp" or "/path_to_my_files/puntos_totales.csv".

An alternative our be to read the SHP files as an sf object, for example

puntos_totales <- sf::st_read("/path_to_my_files/puntos_totales.shp") 

This sf object can be used as a samples parameter to the sits_get_data() function.

Could you share with us your sample file?

paulacopelli commented 1 month ago

Dear Gilberto. Thank you very much for your response. Indeed, the file I am using to extract data is a .shp file. I tried the suggestion you provided but it doesn't solve the problem. I just realized that the problem is not the samples or the cube in general, but rather the index files, this is because when I delete the indexes from my data cube, the extraction works fine, so must be something wrong with sits_apply(), wich I described earlier

gilbertocamara commented 3 weeks ago

Dear @paulacopelli we are working on a more long-lasting solution to your problem. Please see issue #1231

gilbertocamara commented 1 week ago

Dear @paulacopelli we has solved your problem. The correction is currently in the development version of sits and we will load the corrections to CRAN on November 20th. To get the latest version of sits, please run the command

% devtools::install_github("e-sensing/sits@dev")
gilbertocamara commented 1 week ago

Dear @paulacopelli we has solved your problem. The correction is currently in the development version of sits and we will load the corrections to CRAN on November 20th. To get the latest version of sits, please run the command

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