Open a store as a dataset: every array, its dimensions, no data read
Source:R/dataset.R
zaro_dataset.RdCollects the metadata of every array in one group of a Zarr store (the
root by default) and
reports each array's dimension names and sizes in R order (the order
zaro_array() returns). Consolidated metadata (.zmetadata or a
consolidated zarr.json) is used when present, which is one request for
the whole store. Otherwise the store is listed and each child is probed
for array metadata; pass arrays to skip the listing (useful over plain
HTTP, which can't list).
Arguments
- source
a store from
zaro(), or a character source passed tozaro()along with....- group
path of the group to open, e.g.
"measurements/reflectance/r10m". Default"", the root.- arrays
optional character vector of array names (within
group) to include. With consolidated metadata it filters; without, it replaces the listing.- verbose
logical. Emit diagnostic messages. Default
getOption("zaro.verbose", TRUE).- ...
passed to
zaro()whensourceis character.
Value
A zaro_dataset: a list with store, group (the group's
path), attributes (the group's attributes), arrays (named list of
array metadata), paths (named character vector: each array's path in
the store), dims (named list of R-order dimension names per array) and
shape (named list of R-order sizes per array). Arrays are named
within the group; zaro_array(), zaro_read() and zaro_plan() take
the dataset with those names.
Details
No array data is read. Use zaro_array() on the result to get a lazy
array, or zaro_read() with meta = ds$arrays[[name]].
Arrays with no dimension names (Zarr V2 without xarray's
_ARRAY_DIMENSIONS) get names "<array>_dim<k>", with k the 0-based
Zarr axis, so they never collide with another array's dimensions.
Only arrays directly in group are included; use zaro_groups() to see
a nested store's groups (e.g. EOPF and GeoZarr products, which keep their
arrays several groups down).
Examples
f <- system.file("extdata", "example.zarr", package = "zaro")
ds <- zaro_dataset(f)
#> [zaro] opening local store: /usr/local/lib/R/site-library/zaro/extdata/example.zarr
#> [zaro] found zarr.json at root (Zarr V3)
#> [zaro] reading consolidated metadata (6 entries)
ds
#> <zaro_dataset> 4 array(s) [zaro::LocalStore]
#> lat float64 (lat: 8)
#> lon float64 (lon: 16)
#> temp float32 (lon: 16, lat: 8, time: 3)
#> time int32 (time: 3)
#> attributes: 1
ds$dims$temp
#> [1] "lon" "lat" "time"
zaro_read(ds, "temp", start = c(0, 0, 0), count = c(1, 2, 3))
#> [zaro] reading 1 chunk(s) for path 'temp' (V3)
#> , , 1
#>
#> [,1] [,2]
#> [1,] NaN 14.875
#>
#> , , 2
#>
#> [,1] [,2]
#> [1,] NaN 14.975
#>
#> , , 3
#>
#> [,1] [,2]
#> [1,] NaN 15.075
#>
zaro_dataset(f, group = "detail")
#> [zaro] opening local store: /usr/local/lib/R/site-library/zaro/extdata/example.zarr
#> [zaro] found zarr.json at root (Zarr V3)
#> [zaro] reading consolidated metadata (6 entries)
#> <zaro_dataset> 1 array(s) group 'detail' [zaro::LocalStore]
#> elev int16 (x: 16, y: 16)
#> attributes: 1
if (FALSE) { # interactive() && requireNamespace("blosc", quietly = TRUE)
## public cloud stores (network access; blosc-compressed chunks)
ds <- zaro_dataset("s3://aodn-cloud-optimised/model_sea_level_anomaly_gridded_realtime.zarr",
anonymous = TRUE, region = "ap-southeast-2")
ds
ds$dims$GSLA # "LONGITUDE" "LATITUDE" "TIME"
if (requireNamespace("altarr", quietly = TRUE)) {
gsla <- zaro_array(ds, "GSLA", cf = TRUE) # lazy, CF-unpacked
}
## a nested store: list the groups, open one
eopf_url <- paste0(
"https://s3.explorer.eopf.copernicus.eu/esa-zarr-sentinel-explorer-fra/",
"tests-output/sentinel-2-l2a/",
"S2C_MSIL2A_20260120T084301_N0511_R064_T36UXA_20260120T122910.zarr")
eopf <- zaro(eopf_url)
zaro_groups(eopf)
r10m <- zaro_dataset(eopf, group = "measurements/reflectance/r10m")
r10m
}