Error when trying to generate image collection of Landsat 8 items from STAC catalog
Closed this issue · 2 comments
Hi Marius,
thanks for your work on gdalcubes
! We are currently trying to build a workflow around it for our own analysis.
With Sentinel-2 images everything works as expected, but we also tried to build an image collection for Landsat 8 (collection = "landsat-8-l1-c1") from the same catalog. Interestingly executing stac_image_collection
throws an error, see the reprex below. We compared the datetime information to the sentinel collection and it looks like the decimal seconds provided with the Landsat items cause the error. If we correct the timestamp in the itemlist manually the error does not occur any more and we can load the collection.
Can you pls. have a look?
Thanks and best regards,
Hendrik
library(rstac)
library(gdalcubes)
# AOI bbox
bbox = c(
"xmin" = 11.14079
, "ymin" = 49.75891
, "xmax" = 11.14321
, "ymax" = 49.76039
)
# STAC
s = stac("https://earth-search.aws.element84.com/v0")
# example with Landsat collection
items_ls = s |>
stac_search(collections = "landsat-8-l1-c1",
bbox = bbox,
datetime = "2021-01-01/2021-06-30",
limit = 500) |>
post_request()
stac_image_collection(items_ls$features)
#> Error in libgdalcubes_create_stac_collection(bands_df, images_df, gdalrefs_df, : ERROR in datetime::from_string(): cannot derive datetime from string
# example with Sentinel collection
items_sen = s |>
stac_search(collections = "sentinel-s2-l2a-cogs",
bbox = bbox,
datetime = "2021-01-01/2021-06-30",
limit = 500) |>
post_request()
stac_image_collection(items_sen$features)
#> Image collection object, referencing 37 images with 18 bands
#> Images:
#> name left top bottom right
#> 1 S2B_32UPA_20210630_0_L2A 10.3827 50.54373 49.52843 11.95937
#> 2 S2A_32UPA_20210625_0_L2A 10.3827 50.54373 49.52843 11.95937
#> 3 S2B_32UPA_20210620_0_L2A 10.3827 50.54373 49.52843 11.95937
#> 4 S2A_32UPA_20210615_0_L2A 10.3827 50.54373 49.52843 11.95937
#> 5 S2B_32UPA_20210610_0_L2A 10.3827 50.54373 49.52843 11.95937
#> 6 S2A_32UPA_20210605_0_L2A 10.3827 50.54373 49.52843 11.95937
#> datetime srs
#> 1 2021-06-30T10:26:59 EPSG:32632
#> 2 2021-06-25T10:26:59 EPSG:32632
#> 3 2021-06-20T10:26:59 EPSG:32632
#> 4 2021-06-15T10:26:58 EPSG:32632
#> 5 2021-06-10T10:26:59 EPSG:32632
#> 6 2021-06-05T10:26:59 EPSG:32632
#> [ omitted 31 images ]
#>
#> Bands:
#> name offset scale unit nodata image_count
#> 1 B01 0 1 37
#> 2 B02 0 1 37
#> 3 B03 0 1 37
#> 4 B04 0 1 37
#> 5 B05 0 1 37
#> 6 B06 0 1 37
#> 7 B07 0 1 37
#> 8 B08 0 1 37
#> 9 B09 0 1 37
#> 10 B11 0 1 37
#> 11 B12 0 1 37
#> 12 B8A 0 1 37
#> 13 overview:B02 0 1 37
#> 14 overview:B03 0 1 37
#> 15 overview:B04 0 1 37
#> 16 visual:B02 0 1 37
#> 17 visual:B03 0 1 37
#> 18 visual:B04 0 1 37
# compare datetime
items_ls$features[[1]]$properties$datetime
#> [1] "2021-06-29T10:03:38.494534Z"
items_sen$features[[1]]$properties$datetime
#> [1] "2021-06-30T10:26:59Z"
Created on 2021-10-19 by the reprex package (v2.0.1)
Session info
sessioninfo::session_info()
#> ─ Session info ───────────────────────────────────────────────────────────────
#> setting value
#> version R version 4.1.1 (2021-08-10)
#> os Ubuntu 20.04.3 LTS
#> system x86_64, linux-gnu
#> ui X11
#> language en_US:en
#> collate en_US.UTF-8
#> ctype en_US.UTF-8
#> tz Europe/Berlin
#> date 2021-10-19
#>
#> ─ Packages ───────────────────────────────────────────────────────────────────
#> package * version date lib source
#> backports 1.2.1 2020-12-09 [2] CRAN (R 4.1.1)
#> cli 3.0.1 2021-07-17 [2] CRAN (R 4.1.1)
#> crayon 1.4.1 2021-02-08 [2] CRAN (R 4.1.1)
#> curl 4.3.2 2021-06-23 [1] CRAN (R 4.1.1)
#> digest 0.6.28 2021-09-23 [1] CRAN (R 4.1.1)
#> ellipsis 0.3.2 2021-04-29 [2] CRAN (R 4.1.1)
#> evaluate 0.14 2019-05-28 [2] CRAN (R 4.1.1)
#> fansi 0.5.0 2021-05-25 [2] CRAN (R 4.1.1)
#> fastmap 1.1.0 2021-01-25 [2] CRAN (R 4.1.1)
#> fs 1.5.0 2020-07-31 [1] CRAN (R 4.1.1)
#> gdalcubes * 0.4.1 2021-07-29 [1] CRAN (R 4.1.1)
#> glue 1.4.2 2020-08-27 [1] CRAN (R 4.1.1)
#> highr 0.9 2021-04-16 [2] CRAN (R 4.1.1)
#> htmltools 0.5.2 2021-08-25 [2] CRAN (R 4.1.1)
#> httr 1.4.2 2020-07-20 [1] CRAN (R 4.1.1)
#> jsonlite 1.7.2 2020-12-09 [1] CRAN (R 4.1.1)
#> knitr 1.36 2021-09-29 [1] CRAN (R 4.1.1)
#> lifecycle 1.0.1 2021-09-24 [1] CRAN (R 4.1.1)
#> magrittr 2.0.1 2020-11-17 [1] CRAN (R 4.1.1)
#> ncdf4 1.17 2019-10-23 [1] CRAN (R 4.1.1)
#> pillar 1.6.2 2021-07-29 [2] CRAN (R 4.1.1)
#> pkgconfig 2.0.3 2019-09-22 [2] CRAN (R 4.1.1)
#> purrr 0.3.4 2020-04-17 [1] CRAN (R 4.1.1)
#> R.cache 0.15.0 2021-04-30 [1] CRAN (R 4.1.1)
#> R.methodsS3 1.8.1 2020-08-26 [2] CRAN (R 4.1.1)
#> R.oo 1.24.0 2020-08-26 [2] CRAN (R 4.1.1)
#> R.utils 2.11.0 2021-09-26 [1] CRAN (R 4.1.1)
#> R6 2.5.1 2021-08-19 [1] CRAN (R 4.1.1)
#> Rcpp 1.0.7 2021-07-07 [1] CRAN (R 4.1.1)
#> RcppProgress 0.4.2 2020-02-06 [1] CRAN (R 4.1.1)
#> reprex 2.0.1 2021-08-05 [1] CRAN (R 4.1.1)
#> rlang 0.4.11 2021-04-30 [1] CRAN (R 4.1.1)
#> rmarkdown 2.11 2021-09-14 [1] CRAN (R 4.1.1)
#> rstac * 0.9.1-4 2021-07-10 [1] CRAN (R 4.1.1)
#> rstudioapi 0.13 2020-11-12 [2] CRAN (R 4.1.1)
#> sessioninfo 1.1.1 2018-11-05 [2] CRAN (R 4.1.1)
#> stringi 1.7.5 2021-10-04 [1] CRAN (R 4.1.1)
#> stringr 1.4.0 2019-02-10 [1] CRAN (R 4.1.1)
#> styler 1.6.2 2021-09-23 [1] CRAN (R 4.1.1)
#> tibble 3.1.5 2021-09-30 [1] CRAN (R 4.1.1)
#> utf8 1.2.2 2021-07-24 [1] CRAN (R 4.1.1)
#> vctrs 0.3.8 2021-04-29 [2] CRAN (R 4.1.1)
#> withr 2.4.2 2021-04-18 [1] CRAN (R 4.1.1)
#> xfun 0.26 2021-09-14 [2] CRAN (R 4.1.1)
#> yaml 2.2.1 2020-02-01 [1] CRAN (R 4.1.1)
#>
#> [1] /home/hendrik/R/x86_64-pc-linux-gnu-library/4.1
#> [2] /usr/local/lib/R/site-library
#> [3] /usr/lib/R/site-library
#> [4] /usr/lib/R/library
Hi Hendrik, thanks for the report and the reprex. It should work now (commit aef6b7c) for datetime strings with fractional seconds although they are ignored so far when creating the image collection. Let me know if anything does not work for you, I am planning a new CRAN release at the end of October.
Thanks for the quick fix. Works as expected!