r-spatial / stars

Spatiotemporal Arrays, Raster and Vector Data Cubes
https://r-spatial.github.io/stars/
Apache License 2.0
550 stars 94 forks source link

cannot read list of .tiff S1_SLC files using time stamps #451

Closed jimoreira closed 2 years ago

jimoreira commented 2 years ago

hi, been trying to read a list of .tiff output files from snap process. They are 3 band files (anisotropy, entropy, alpha), from different dates. what I did

procesado<-list.files(diro,pattern = ".data$", full.names = TRUE)

fecha<-lapply(procesado, function(x){
    fecha1 = unlist(strsplit(x,"_"))[7]
    fecha2 = as.Date(fecha1,"%Y%m%d")
    return(fecha2)
    })
fecha <- do.call("c",fecha)  

#for loop to get the a .tiff file with the 3 bands stack per date

listado_para_collection<-list.files(procesado,pattern = ".tiff$", full.names = TRUE)

veamos_2<-read_stars(listado_para_collection,along = list(time=fecha))

i have tried to use proxy bat it gives the following error: ..: for proxy objects, along argument as list is not implemented

then, the error without proxy: Error in c.stars_proxy(list(S1A_IW_SLC__1SDV_20200107T090637_20200107T090707_030692_0384A4_CA7F.tiff = "D:\\OneDrive\\Agtech_2\\validacion\\ramiroRostan\\testingPolsarPro\\automated\\outputs\\S1A_IW_SLC__1SDV_20200107T090637_20200107T090707_030692_0384A4_CA7F.data\\S1A_IW_SLC__1SDV_20200107T090637_20200107T090707_030692_0384A4_CA7F.tiff"), : don't know how to merge arrays: please specify parameter along

the list of dates looks like this:

list(time=fecha)
$time
 [1] "2020-01-07" "2020-01-19" "2020-01-31" "2020-02-12" "2020-03-07" "2020-03-19"
 [7] "2020-03-31" "2020-04-12" "2020-04-24" "2020-05-06" "2020-05-18" "2020-05-30"
[13] "2020-06-11" "2020-06-23" "2020-07-05" "2020-07-17" "2020-07-29" "2020-08-10"
[19] "2020-08-22" "2020-09-03" "2020-09-15" "2020-09-27" "2020-10-09" "2020-10-21"
[25] "2020-11-02" "2020-01-25" "2020-02-06" "2020-03-25" "2020-04-30" "2020-05-12"
[31] "2020-06-05" "2020-06-29" "2020-07-11" "2020-08-04" "2020-09-09" "2020-09-21"
[37] "2020-10-03" "2020-10-15" "2020-10-27" "2020-11-08" "2020-11-20"

i also have tried along = 3:

veamos_2<-read_stars(listado_para_collection,along = 3, proxy = TRUE))

and the result was this :

st_dimensions(veamos_2)
     from  to   offset        delta refsys point            values x/y
x       1 798 -57.6342  0.000131154 WGS 84 FALSE              NULL [x]
y       1 629 -33.6987 -0.000131154 WGS 84 FALSE              NULL [y]
band    1 123       NA           NA     NA    NA Alpha,...,Entropy    

merge all the bands and times together

Does anybody solve the same problem? thanks a lot!

edzer commented 2 years ago

Mind sharing a (small) reprex?

jimoreira commented 2 years ago
library(stars)
dir<-getwd()
setwd(paste0(dir,"\\testingPolsarPro\\automated\\outputs"))
diro<-getwd()
print(diro)
procesado<-list.files(diro,pattern = ".data$", full.names = TRUE)
print(procesado)

fecha<-lapply(procesado, function(x){
    fecha1 = unlist(strsplit(x,"_"))[7]
    fecha2 = as.Date(fecha1,"%Y%m%d")
    return(fecha2)
    })
fecha <- do.call("c",fecha)  

for (i in procesado){
  lista_img_interna<-list.files(i,pattern = ".img$", full.names = TRUE)
  veamos<-read_stars(lista_img_interna, along ="bands", proxy = TRUE) %>% st_set_dimensions(3, values = c("Alpha","Anisotropy","Entropy")) 
  name<-gsub(pattern = "\\.data$", "", basename(i))
  write_stars(veamos,paste0(i,"/",name,".tiff"))

}
listado_para_collection<-list.files(procesado,pattern = ".tiff$", full.names = TRUE)
veamos_2<-read_stars(listado_para_collection, along = list(time=fecha))

files https://1drv.ms/u/s!AsKUvf59Z2PFsctQUqWULH7eEWXSdw?e=DQtOo9

I reduced the items in the list. Still keep S1A and S1B, because they have different extensions, and I figured that might be one problem. Still, already have tried only with S1A, and the same Error shows.

Thanks!

edzer commented 2 years ago

These images have a different origin, so you can't read them as a single cube. Maybe read one by one, then mosaic them?

edzer commented 2 years ago
l = listado_para_collection
ll = lapply(l, read_stars)
plot(st_mosaic(ll[[1]], ll[[2]], ll[[3]], ll[[4]]))
jimoreira commented 2 years ago

If I use st_crop on a bounding box would work?

edzer commented 2 years ago

Not sure; maybe st_warp?

jimoreira commented 2 years ago

neither of both..thanks..I realized where is the problem..need to go back to SNAP processing to produce coregistered time series.