Not all data formats which NASA EarthData makes available on cloud storage are provided in cloud-optimized or even VSI-compatible formats. A stark example is HDF4. Here we illustrate how to work with these data formats while staying as close to the cloud-native workflow shown in other vignettes.
Aside: note that in many cases, these same data products may be available in cloud-native formats from other providers. Particular to the example here, see the cloud-optimized MODIS catalog on the Planetary Computer STAC.
CA <- spData::us_states |> dplyr::filter(NAME=="California")
bbox <- CA |> st_bbox()
start <- "2022-01-01"
end <- "2022-12-31"
items <- stac("https://cmr.earthdata.nasa.gov/stac/LPCLOUD") |>
stac_search(collections = "MOD13Q1.v061",
bbox = c(bbox),
datetime = paste(start,end, sep = "/")) |>
post_request() |>
items_fetch()
#>
|
|==========================================================================================================================================================================================================================================================| 100%
HDF4 doesn’t support cloud (range-request-based) access / VSI.
Instead, we download all matching assets with
earthdatalogin
authentication:
paths <- items$features |>
purrr::map(list("assets", "data", "href")) |>
unlist() |>
purrr::map_chr(edl_download)
Rather than create an image collection using STAC metadata, we can use the recognized format and the local paths:
paths <- fs::dir_ls(".", glob="*.hdf")
col <- gdalcubes::create_image_collection(paths, format = "MxD13Q1")