| Title: | Read 'Zarr' Arrays from Native and Virtual Stores |
|---|---|
| Description: | A low-level reader for 'Zarr' arrays (<https://zarr-specs.readthedocs.io/>), versions 2 and 3 (including version 3 shards), native or virtual, from local disk, HTTP(S), Amazon 'S3' and Google Cloud Storage. Virtual stores read the bytes of existing 'NetCDF', 'HDF5' and 'GeoTIFF' files in place, from 'Kerchunk' 'JSON' and 'Parquet' references, 'VirtualiZarr' manifests and 'byterefs' tables ('SQLite', or the flat 'Parquet' export read by row group). Every read is a plan of byte references (one row per chunk) fetched through one 'curl' connection pool, then decoded in R. Arrays can also be opened as lazy R arrays (via 'altarr') with 'CF' unpacking, and 'Icechunk' repositories read (via 'tabularberg'). 'Arrow' and 'GDAL' (via 'gdalraster') are optional, for 'S3' and Google Cloud Storage listing and credentials and for some codecs. |
| Authors: | Michael Sumner [aut, cre] (ORCID: <https://orcid.org/0000-0002-2471-7511>), Hugo Gruson [ctb] (ORCID: <https://orcid.org/0000-0002-4094-1476>) |
| Maintainer: | Michael Sumner <[email protected]> |
| License: | MIT + file LICENSE |
| Version: | 0.0.1.9048 |
| Built: | 2026-11-22 04:41:03 UTC |
| Source: | https://github.com/hypertidy/zaro |
Connects to a Zarr store at the given path or URI. Dispatches to the appropriate backend based on the URI scheme:
Local paths: base R (no arrow or GDAL needed)
s3://, gs://: listed and read through Arrow when
arrow is installed, else through GDAL's /vsis3/ or
/vsigs/ (gdalraster). When access is known (anonymous, or S3
keys in the environment) chunks are fetched as HTTPS through the curl
pool instead, see zaro_fetch()
http://, https://: curl (no GDAL); chunk reads are
batched through one connection pool, see zaro_fetch(). An HTTP
store can't be listed, so it needs consolidated metadata (or array
names, see zaro_dataset())
/vsi...: any GDAL virtual file system path, through gdalraster
(e.g. /vsicurl/https://... to keep GDAL's HTTP handling)
reference+json://: Kerchunk JSON reference store
reference+parquet://: Kerchunk Parquet references, either
the directory kerchunk and VirtualiZarr write (.zmetadata and
<array>/refs.N.parq; only the files a selection needs are
read) or a single table of key, url, offset and length
virtualizarr://: the same directory layout, by its older
name here
byterefs:// (or the older mdimrefs://): a byterefs
SQLite byte-reference table (https://github.com/byterefs/spec),
byterefs/0.1 or the legacy mdim-refs/0.2. Source paths
are remapped for the store's meta.default_target; pass
target = "public" for another target, or target = "" for
the verbatim sources
flatrefs://: a byterefs flat refs store, the Parquet export
(a directory, local or remote, with arrays.json and one
refs_<array>.parquet per array, as raad.virtualize publishes).
Chunk references are read by row group, only those whose dim
statistics can hold the selection, so a table of tens of millions of
rows is never read whole. target as for byterefs://
icechunk://: an Icechunk repository through tabularberg,
e.g. icechunk:///path/to/repo?tag=v1; the query picks
branch, tag or snapshot. An
icechunk_repo, icechunk_session or
icechunk_storage object works too. See zaro_icechunk()
zaro(source, verbose = zaro_verbose(), ..., validate = FALSE)zaro(source, verbose = zaro_verbose(), ..., validate = FALSE)
source |
character. Path, URI, or reference store locator; or an
Icechunk repository, session or storage from tabularberg (see
|
verbose |
logical. Emit progress and diagnostic messages. Default
|
... |
store options: for |
validate |
logical. Read the root metadata at open, warning if that
fails. Default |
For S3 stores, if Arrow returns a 301 redirect (wrong region), zaro will
fall through to gdalraster's /vsis3/ which handles region detection
automatically.
Known public buckets (e.g. cmip6, aodn-cloud-optimised) are accessed
anonymously by default. For other public stores, pass
anonymous = TRUE.
Opening reads nothing from the store by default (source is only checked
to be a non-empty character string); set validate = TRUE to read the
root metadata at open.
A store object (internal class) for use with other zaro functions.
## a small Zarr V3 store shipped with the package f <- system.file("extdata", "example.zarr", package = "zaro") store <- zaro(f) store zaro_list(store) zaro_read(store, "temp", start = c(0, 0, 0), count = c(1, 4, 8)) ## other sources (see the "Connecting to stores" article): ## zaro("s3://bucket/store.zarr", anonymous = TRUE) ## zaro("gs://bucket/store.zarr") ## zaro("virtualizarr://https://host/dataset.parq") ## zaro("byterefs:///path/to/store.sqlite") ## zaro("flatrefs://https://host/store", target = "public") ## a public store over HTTPS (network access; blosc-compressed chunks) aodn <- zaro(paste0("https://aodn-cloud-optimised.s3.ap-southeast-2.amazonaws.com/", "model_sea_level_anomaly_gridded_realtime.zarr")) zaro_meta(aodn, "GSLA") zaro_read(aodn, "GSLA", start = c(0, 100, 100), count = c(1, 2, 3))## a small Zarr V3 store shipped with the package f <- system.file("extdata", "example.zarr", package = "zaro") store <- zaro(f) store zaro_list(store) zaro_read(store, "temp", start = c(0, 0, 0), count = c(1, 4, 8)) ## other sources (see the "Connecting to stores" article): ## zaro("s3://bucket/store.zarr", anonymous = TRUE) ## zaro("gs://bucket/store.zarr") ## zaro("virtualizarr://https://host/dataset.parq") ## zaro("byterefs:///path/to/store.sqlite") ## zaro("flatrefs://https://host/store", target = "public") ## a public store over HTTPS (network access; blosc-compressed chunks) aodn <- zaro(paste0("https://aodn-cloud-optimised.s3.ap-southeast-2.amazonaws.com/", "model_sea_level_anomaly_gridded_realtime.zarr")) zaro_meta(aodn, "GSLA") zaro_read(aodn, "GSLA", start = c(0, 100, 100), count = c(1, 2, 3))
Returns an ordinary R array (a double, integer or logical vector with a
dim attribute and no class) whose values are read from the store chunk
by chunk, only when R asks for them. It is an ALTREP object built by
altarr::altarr(), with zaro's chunk fetch and codec pipeline behind it.
Nothing is read when the array is created beyond the metadata.
zaro_array( store, path = "", meta = NULL, parallel = FALSE, verbose = zaro_verbose(), cf = FALSE )zaro_array( store, path = "", meta = NULL, parallel = FALSE, verbose = zaro_verbose(), cf = FALSE )
store |
a store object from |
path |
character. Path to the array within the store. |
meta |
optional pre-fetched ZaroMeta, or the root group meta with
consolidated entries, as for |
parallel |
logical. If |
verbose |
logical. Emit diagnostic messages when reading metadata.
Default |
cf |
logical. Apply CF decoding (masking and unpacking, see below).
Default |
The altarr package is not on CRAN; install it from R-universe with
install.packages("altarr", repos = "https://hypertidy.r-universe.dev").
Subsetting with x[i], x[cbind(i, j, k)] and
altarr::altarr_extract(x, i, j, k) plans the chunks it needs and fetches
them in one batch; sum(), mean(), min() and max() stream the chunk
grid. See ?altarr::altarr_contract for what base R does with a lazy
array, and altarr::altarr_stats() to count fetches.
A lazy array, see altarr::altarr().
A C-order Zarr array of shape (s1, ..., sn) (all Zarr V3 arrays, and V2
arrays with "order": "C") is returned with R dim c(sn, ..., s1), and
the dimension names reversed to match. This is the order the bytes are
stored in, so a chunk is used as decoded. For a typical
(time, lat, lon) array, x[lon, lat, time] is the R subscript. V2
arrays with "order": "F" keep their shape. This is the transpose of
what zaro_read() returns.
Chunks absent from the store read as the array's fill_value. Integer
types up to 32 bits give an integer array (uint32 and 64-bit integers
give double, as in zaro_read()), floats give double, bool gives
logical. No CF packing (scale_factor, add_offset, _FillValue) is
applied unless cf = TRUE. String arrays are refused (a lazy array is
numeric or logical); read them with zaro_read().
With cf = TRUE, values equal to the array's fill_value or to the
_FillValue or missing_value attributes (and NaN) read as NA, then
scale_factor and add_offset are applied. Missing chunks read as NA.
A packed array reads as double; an unpacked one keeps its type. This is
what xarray's default decoding and GDAL's nodata plus unscaling give.
saveRDS() on the result writes the recipe (shape, chunk shape and the
fetch function), not the values. Stores backed by Arrow or GDAL hold
external pointers, so a saved array does not read in a new R session;
re-open it with zaro_array().
f <- system.file("extdata", "example.zarr", package = "zaro") store <- zaro(f) x <- zaro_array(store, "temp") dim(x) # lon, lat, time: the Zarr shape reversed x[1:4, 1:2, 1] # reads one chunk altarr::altarr_stats(x)[c("fetch_calls", "chunks_fetched")] ## a public store over HTTPS (network access; blosc-compressed chunks) if (requireNamespace("blosc", quietly = TRUE)) { aodn <- zaro(paste0("https://aodn-cloud-optimised.s3.ap-southeast-2.amazonaws.com/", "model_sea_level_anomaly_gridded_realtime.zarr")) x <- zaro_array(aodn, "GSLA", cf = TRUE) dim(x) # LONGITUDE, LATITUDE, TIME x[cbind(101, 101, 1:5)] # one pixel, five time steps, one fetch altarr::altarr_stats(x)[c("fetch_calls", "chunks_fetched")] }f <- system.file("extdata", "example.zarr", package = "zaro") store <- zaro(f) x <- zaro_array(store, "temp") dim(x) # lon, lat, time: the Zarr shape reversed x[1:4, 1:2, 1] # reads one chunk altarr::altarr_stats(x)[c("fetch_calls", "chunks_fetched")] ## a public store over HTTPS (network access; blosc-compressed chunks) if (requireNamespace("blosc", quietly = TRUE)) { aodn <- zaro(paste0("https://aodn-cloud-optimised.s3.ap-southeast-2.amazonaws.com/", "model_sea_level_anomaly_gridded_realtime.zarr")) x <- zaro_array(aodn, "GSLA", cf = TRUE) dim(x) # LONGITUDE, LATITUDE, TIME x[cbind(101, 101, 1:5)] # one pixel, five time steps, one fetch altarr::altarr_stats(x)[c("fetch_calls", "chunks_fetched")] }
Fetches and decodes one chunk, identified by its position in the chunk grid. Returns the decoded values with metadata about where the chunk sits in the array.
zaro_chunk( store, path, chunk_idx, meta = NULL, shaped = TRUE, verbose = zaro_verbose() )zaro_chunk( store, path, chunk_idx, meta = NULL, shaped = TRUE, verbose = zaro_verbose() )
store |
a store object from |
path |
character. Path to the array. |
chunk_idx |
integer vector. 0-based chunk grid index
(e.g. |
meta |
optional pre-fetched ZaroMeta (or root group meta). |
shaped |
logical. If TRUE (default), reshape the values to the chunk's actual dimensions (handling C-order and edge chunks). If FALSE, return a flat vector. |
verbose |
logical. Emit diagnostic messages. Default
|
A list with components:
integer vector - the chunk grid index
array or vector - decoded chunk data
integer vector - 0-based array coordinates of chunk origin
integer vector - actual shape of this chunk (may be smaller than chunk_shape for edge chunks)
Returns NULL if the chunk doesn't exist (missing/sparse).
f <- system.file("extdata", "example.zarr", package = "zaro") store <- zaro(f) ch <- zaro_chunk(store, "temp", c(0, 1, 1)) ch$start # where the chunk sits in the array (0-based) dim(ch$values)f <- system.file("extdata", "example.zarr", package = "zaro") store <- zaro(f) ch <- zaro_chunk(store, "temp", c(0, 1, 1)) ch$start # where the chunk sits in the array (0-based) dim(ch$values)
Iterates over chunks and applies a function to each, accumulating results. Chunks are fetched and decoded one at a time (or in parallel) so memory usage is proportional to one chunk, not the full array.
zaro_chunk_apply( store, path, fun, ranges = NULL, meta = NULL, shaped = TRUE, parallel = FALSE, verbose = zaro_verbose() )zaro_chunk_apply( store, path, fun, ranges = NULL, meta = NULL, shaped = TRUE, parallel = FALSE, verbose = zaro_verbose() )
store |
a store object from |
path |
character. Path to the array. |
fun |
function. Called with a single chunk result list (as from
|
ranges |
optional range specification (as in |
meta |
optional pre-fetched ZaroMeta (or root group meta). |
shaped |
logical. If TRUE, reshape each chunk's values. |
parallel |
logical. Use future.apply for parallel execution. |
verbose |
logical. Emit diagnostic messages. Default
|
A list of results from fun, one per non-NULL chunk.
f <- system.file("extdata", "example.zarr", package = "zaro") store <- zaro(f) ## per-chunk mean, one chunk in memory at a time means <- zaro_chunk_apply(store, "temp", function(chunk) { mean(chunk$values, na.rm = TRUE) }) unlist(means) ## first time step only, all spatial chunks zaro_chunk_apply(store, "temp", function(chunk) { c(mean = mean(chunk$values, na.rm = TRUE), n_valid = sum(is.finite(chunk$values))) }, ranges = list(0, NULL, NULL))f <- system.file("extdata", "example.zarr", package = "zaro") store <- zaro(f) ## per-chunk mean, one chunk in memory at a time means <- zaro_chunk_apply(store, "temp", function(chunk) { mean(chunk$values, na.rm = TRUE) }) unlist(means) ## first time step only, all spatial chunks zaro_chunk_apply(store, "temp", function(chunk) { c(mean = mean(chunk$values, na.rm = TRUE), n_valid = sum(is.finite(chunk$values))) }, ranges = list(0, NULL, NULL))
Returns the chunk grid dimensions and related metadata needed for chunk-indexed operations.
zaro_chunk_info(store, path, meta = NULL, verbose = zaro_verbose())zaro_chunk_info(store, path, meta = NULL, verbose = zaro_verbose())
store |
a store object from |
path |
character. Path to the array. |
meta |
optional pre-fetched ZaroMeta (or root group meta). |
verbose |
logical. Emit diagnostic messages. Default
|
A list with components:
integer vector - number of chunks along each dimension
integer vector - shape of a full (non-edge) chunk
integer vector - shape of the full array
integer - total number of chunks
character vector or NULL
ZaroMeta for the array
f <- system.file("extdata", "example.zarr", package = "zaro") store <- zaro(f) info <- zaro_chunk_info(store, "temp") info$grid # chunks along time, lat, lon info$chunk_shapef <- system.file("extdata", "example.zarr", package = "zaro") store <- zaro(f) info <- zaro_chunk_info(store, "temp") info$grid # chunks along time, lat, lon info$chunk_shape
Fetches and decodes a set of chunks identified by ranges along each
dimension of the chunk grid, one at a time or in parallel. For
batched, pooled reads use zaro_plan() and zaro_fetch(), or
zaro_read().
zaro_chunks( store, path, ranges = NULL, meta = NULL, shaped = TRUE, parallel = FALSE, verbose = zaro_verbose() )zaro_chunks( store, path, ranges = NULL, meta = NULL, shaped = TRUE, parallel = FALSE, verbose = zaro_verbose() )
store |
a store object from |
path |
character. Path to the array. |
ranges |
a list of integer vectors, one per dimension, giving the
0-based chunk indices to read. Use |
meta |
optional pre-fetched ZaroMeta (or root group meta). |
shaped |
logical. If TRUE, reshape each chunk's values. |
parallel |
logical. Use future.apply for parallel fetch+decode. |
verbose |
logical. Emit diagnostic messages. Default
|
A list of chunk results (as from zaro_chunk()). NULL
entries indicate missing chunks.
f <- system.file("extdata", "example.zarr", package = "zaro") store <- zaro(f) ## every chunk of the first time step chs <- zaro_chunks(store, "temp", ranges = list(0, NULL, NULL)) length(chs) t(sapply(chs, `[[`, "start"))f <- system.file("extdata", "example.zarr", package = "zaro") store <- zaro(f) ## every chunk of the first time step chs <- zaro_chunks(store, "temp", ranges = list(0, NULL, NULL)) length(chs) t(sapply(chs, `[[`, "start"))
Collects 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).
zaro_dataset(source, group = "", arrays = NULL, verbose = zaro_verbose(), ...)zaro_dataset(source, group = "", arrays = NULL, verbose = zaro_verbose(), ...)
source |
a store from |
group |
path of the group to open, e.g.
|
arrays |
optional character vector of array names (within |
verbose |
logical. Emit diagnostic messages. Default
|
... |
passed to |
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).
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.
f <- system.file("extdata", "example.zarr", package = "zaro") ds <- zaro_dataset(f) ds ds$dims$temp zaro_read(ds, "temp", start = c(0, 0, 0), count = c(1, 2, 3)) zaro_dataset(f, group = "detail") ## 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") r10mf <- system.file("extdata", "example.zarr", package = "zaro") ds <- zaro_dataset(f) ds ds$dims$temp zaro_read(ds, "temp", start = c(0, 0, 0), count = c(1, 2, 3)) zaro_dataset(f, group = "detail") ## 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
Executes a zaro_plan(): returns the raw (still encoded) bytes of every
chunk, in plan order, NULL for chunks that are absent (they read as
fill_value). HTTP references are fetched concurrently through one curl
connection pool with a per-host cap, adjacent byte ranges are merged into
single requests, and failures are retried. S3 and GCS objects join the
same pool as HTTPS when their access is known: anonymous (zaro(..., anonymous = TRUE), a known public bucket, AWS_NO_SIGN_REQUEST=YES or
options(zaro.cloud_anonymous = TRUE)), or S3 signed with
AWS_ACCESS_KEY_ID / AWS_SECRET_ACCESS_KEY (and AWS_SESSION_TOKEN)
from the environment. Other credentials (profiles, instance roles,
signed GCS) are read through Arrow or GDAL one object at a time. zaro_read() and
zaro_array() read through this, so they get the same batching.
zaro_fetch( store, plan, max_con = getOption("zaro.max_con", 8L), merge_gap = getOption("zaro.merge_gap", 0), retries = 2L, verbose = zaro_verbose() )zaro_fetch( store, plan, max_con = getOption("zaro.max_con", 8L), merge_gap = getOption("zaro.merge_gap", 0), retries = 2L, verbose = zaro_verbose() )
store |
the store the plan was made from. |
plan |
a |
max_con |
integer. Maximum simultaneous HTTP connections, per host
and in total. Default |
merge_gap |
numeric. Merge byte ranges on the same URL separated by
at most this many bytes (the gap is fetched and discarded). Default
|
retries |
integer. Retries for failed HTTP requests. |
verbose |
logical. Emit diagnostic messages. Default
|
Connections are kept open between calls, so a loop that reads a
chunk at a time reuses them rather than opening one per chunk. Set
options(zaro.http_keepalive = FALSE) for a fresh pool on every call.
A list of raw vectors (or NULL), one per plan row, with
attribute "stats": HTTP requests, bytes received, new
connections opened and seconds.
f <- system.file("extdata", "example.zarr", package = "zaro") store <- zaro(f) p <- zaro_plan(store, "temp", start = c(0, 0, 0), count = c(1, NA, NA)) raw <- zaro_fetch(store, p) lengths(raw) # encoded (gzip) bytes per chunk attr(raw, "stats")f <- system.file("extdata", "example.zarr", package = "zaro") store <- zaro(f) p <- zaro_plan(store, "temp", start = c(0, 0, 0), count = c(1, NA, NA)) raw <- zaro_fetch(store, p) lengths(raw) # encoded (gzip) bytes per chunk attr(raw, "stats")
Lists every group of a Zarr store, the root included, with the number of
arrays directly in each, so a nested product can be opened one group at
a time with zaro_dataset(group = ). Uses consolidated metadata when the
root has it (one request); otherwise lists the store, which needs a store
that can be listed (not plain HTTP).
zaro_groups(source, verbose = zaro_verbose(), ...)zaro_groups(source, verbose = zaro_verbose(), ...)
source |
a store from |
verbose |
logical. Emit diagnostic messages. Default
|
... |
passed to |
A data frame with columns group (path, "" for the root) and
arrays (number of arrays directly in the group), sorted by path.
f <- system.file("extdata", "example.zarr", package = "zaro") zaro_groups(f) ## a nested store (network access) 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") zaro_groups(eopf_url)f <- system.file("extdata", "example.zarr", package = "zaro") zaro_groups(f) ## a nested store (network access) 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") zaro_groups(eopf_url)
Reads one snapshot of an Icechunk repository
through the tabularberg package. Everything zaro does with a store works on
the result: zaro_meta(), zaro_read(), zaro_array(),
zaro_dataset(), zaro_plan().
zaro_icechunk( source, branch = NULL, tag = NULL, snapshot = NULL, authorize = NULL, direct = FALSE, verbose = zaro_verbose() )zaro_icechunk( source, branch = NULL, tag = NULL, snapshot = NULL, authorize = NULL, direct = FALSE, verbose = zaro_verbose() )
source |
an |
branch, tag, snapshot
|
the version to read (one of them; default
branch |
authorize |
virtual chunk containers to authorize, passed to
|
direct |
logical. Fetch virtual chunks with zaro's own fetcher instead of through Icechunk (see Details). |
verbose |
logical. Emit diagnostic messages. |
The tabularberg package is not on CRAN; install it from R-universe with
install.packages("tabularberg", repos = "https://hypertidy.r-universe.dev").
The session is read-only and pinned to one snapshot (its id is in
store@snapshot), so lazy arrays made from it keep reading the same
version after the branch moves on. Pick the version with branch, tag
or snapshot (default branch "main").
Chunks are read through Icechunk by default, which applies the
repository's container authorization and checksums. With direct = TRUE
zaro fetches virtual chunks itself, concurrently and with adjacent byte
ranges merged, but only from containers the repository object has
authorized (see tabularberg::ic_repo_containers()), and without
Icechunk's etag / last-modified checks. Native and inline chunks always
come from Icechunk.
An IcechunkStore.
## a small local repository that tabularberg writes to tempdir() ex <- tabularberg::ic_example_repo() store <- zaro_icechunk(ex$path, tag = "v1", authorize = ex$authorize) zaro_dataset(store) zaro_read(store, "from_bin", start = c(0, 0), count = c(3, 4)) if (requireNamespace("altarr", quietly = TRUE)) { x <- zaro_array(store, "from_bin") x[1:4, 1:4] }## a small local repository that tabularberg writes to tempdir() ex <- tabularberg::ic_example_repo() store <- zaro_icechunk(ex$path, tag = "v1", authorize = ex$authorize) zaro_dataset(store) zaro_read(store, "from_bin", start = c(0, 0), count = c(3, 4)) if (requireNamespace("altarr", quietly = TRUE)) { x <- zaro_array(store, "from_bin") x[1:4, 1:4] }
List contents of a Zarr store
zaro_list(store, path = "", ...)zaro_list(store, path = "", ...)
store |
a store object from |
path |
character. Path prefix within the store (default root). |
... |
arguments for methods (specifically 'recursive = FALSE' is default for local and Arrow stores) |
character vector of keys (relative paths).
f <- system.file("extdata", "example.zarr", package = "zaro") store <- zaro(f) zaro_list(store) zaro_list(store, "temp")f <- system.file("extdata", "example.zarr", package = "zaro") store <- zaro(f) zaro_list(store) zaro_list(store, "temp")
Reads and parses the metadata for an array or group at the given path.
Automatically detects Zarr V2 (.zarray/.zattrs/.zmetadata)
vs V3 (zarr.json) format. For cloud stores, consolidated metadata
(.zmetadata for V2, consolidated zarr.json for V3) is preferred
to minimize the number of requests.
zaro_meta(store, path = "", consolidated = TRUE, verbose = zaro_verbose())zaro_meta(store, path = "", consolidated = TRUE, verbose = zaro_verbose())
store |
a store object from |
path |
character. Path to the array or group within the store.
Use |
consolidated |
logical. If |
verbose |
logical. Emit diagnostic messages. Default
|
A ZaroMeta object. For root group requests with consolidated
metadata, the individual array metadata are attached as
attr(, "consolidated").
f <- system.file("extdata", "example.zarr", package = "zaro") store <- zaro(f) zaro_meta(store) # the root group zaro_meta(store, "temp") # an array zaro_meta(store, "detail/elev") # a sharded array in a nested groupf <- system.file("extdata", "example.zarr", package = "zaro") store <- zaro(f) zaro_meta(store) # the root group zaro_meta(store, "temp") # an array zaro_meta(store, "detail/elev") # a sharded array in a nested group
Works out which chunks of an array a hyperslab touches and where each
chunk's bytes are: a whole object in a native store, a byte range inside
a NetCDF/HDF5/TIFF file for a virtual store (kerchunk, VirtualiZarr,
byterefs), a byte range inside a shard object for a sharded array, inline
bytes, or absent (reads as fill_value). No chunk data
is read. For a native unsharded store no request is made at all; a
sharded array reads the index of each shard it touches, and a virtual
store may fetch the manifest or row groups it needs (cached in the
store).
zaro_plan( store, path = "", start = NULL, count = NULL, meta = NULL, chunks = NULL, verbose = zaro_verbose() )zaro_plan( store, path = "", start = NULL, count = NULL, meta = NULL, chunks = NULL, verbose = zaro_verbose() )
store |
a store from |
path |
character. Path to the array within the store. |
start, count
|
the selection, as for |
meta |
optional array metadata, as for |
chunks |
optional integer matrix of 0-based chunk grid indices (one
row per chunk, Zarr dimension order), instead of |
verbose |
logical. Emit diagnostic messages. Default
|
The result is a data frame you can inspect, filter, save or hand to another tool. Printing it summarises the cost: requests, known bytes and hosts.
A zaro_plan data frame, one row per chunk, in the shape of a
byterefs view (https://github.com/byterefs/spec):
dim_0, ..., dim_{n-1} (the chunk's 0-based grid index, Zarr
dimension order), present (FALSE for an absent chunk, read as
fill_value), path (where the bytes are), offset, size (NA for
a whole object of unknown size), data (list of raw, for inline
chunks), then zaro's own columns: key (the Zarr key) and transport
("store", "http", "s3", "gs", "vsi", "local", "inline" or
"absent": how the bytes are fetched). Attributes array (the array's
path in the store) and meta record what was planned.
f <- system.file("extdata", "example.zarr", package = "zaro") store <- zaro(f) p <- zaro_plan(store, "temp", start = c(0, 0, 0), count = c(1, NA, NA)) p # one row per chunk, whole local files ## a sharded array: byte ranges within each shard zaro_plan(store, "detail/elev", start = c(0, 0), count = c(4, 8)) ## a virtual store: byte ranges in NetCDF files on a THREDDS server ## (network access) vstore <- zaro(paste0("virtualizarr://https://raw.githubusercontent.com/", "mdsumner/virtualized/refs/heads/main/remote/ocean_temp_2023.parq")) p <- zaro_plan(vstore, "temp", start = c(0, 0, 0, 0), count = c(1, 1, NA, NA)) p # 60 byte ranges on one host, ~4 MB table(p$transport)f <- system.file("extdata", "example.zarr", package = "zaro") store <- zaro(f) p <- zaro_plan(store, "temp", start = c(0, 0, 0), count = c(1, NA, NA)) p # one row per chunk, whole local files ## a sharded array: byte ranges within each shard zaro_plan(store, "detail/elev", start = c(0, 0), count = c(4, 8)) ## a virtual store: byte ranges in NetCDF files on a THREDDS server ## (network access) vstore <- zaro(paste0("virtualizarr://https://raw.githubusercontent.com/", "mdsumner/virtualized/refs/heads/main/remote/ocean_temp_2023.parq")) p <- zaro_plan(vstore, "temp", start = c(0, 0, 0, 0), count = c(1, 1, NA, NA)) p # 60 byte ranges on one host, ~4 MB table(p$transport)
Reads a hyperslab from a Zarr array, fetching and decoding the necessary
chunks and assembling them into an R array. Supports Zarr V2 and V3,
including sharded V3 arrays, and every store zaro() opens. The chunks
are planned with zaro_plan() and fetched together with zaro_fetch().
zaro_read( store, path = "", start = NULL, count = NULL, meta = NULL, parallel = FALSE, verbose = zaro_verbose(), assemble = TRUE )zaro_read( store, path = "", start = NULL, count = NULL, meta = NULL, parallel = FALSE, verbose = zaro_verbose(), assemble = TRUE )
store |
a store object from |
path |
character. Path to the array within the store. |
start |
integer vector. 0-based start indices for each dimension. Defaults to the origin. |
count |
integer vector. Number of elements to read along each
dimension. Use |
meta |
optional pre-fetched ZaroMeta object. If NULL (default),
metadata is read from the store. Can also be the root group metadata
from |
parallel |
logical. If |
verbose |
logical. Emit diagnostic messages. Default
|
assemble |
logical. If |
An R array with dimensions matching count, in Zarr
dimension order and named by the array's dimension names (the
transpose of zaro_array() for C-order arrays). String arrays read as
character.
f <- system.file("extdata", "example.zarr", package = "zaro") store <- zaro(f) ## the first time step, every lat and lon (start is 0-based) x <- zaro_read(store, "temp", start = c(0, 0, 0), count = c(1, NA, NA)) dim(x) ## a window of a sharded array zaro_read(store, "detail/elev", start = c(2, 2), count = c(3, 4))f <- system.file("extdata", "example.zarr", package = "zaro") store <- zaro(f) ## the first time step, every lat and lon (start is 0-based) x <- zaro_read(store, "temp", start = c(0, 0, 0), count = c(1, NA, NA)) dim(x) ## a window of a sharded array zaro_read(store, "detail/elev", start = c(2, 2), count = c(3, 4))
Plans every array, fetches all the plans with one zaro_fetch() (so
HTTP chunks of all the arrays share one connection pool and go out
concurrently, and touching byte ranges merge), then decodes each array.
Each result is what zaro_read(store, path) returns. Useful for reading
a dataset's coordinate arrays at open, where each array is small and the
cost is the round trips.
zaro_read_arrays(store, paths, metas = NULL, verbose = zaro_verbose())zaro_read_arrays(store, paths, metas = NULL, verbose = zaro_verbose())
store |
a store from |
paths |
character vector of array paths (or dataset names). |
metas |
optional list of array metadata, one per path (taken from
the dataset when |
verbose |
logical. Emit diagnostic messages. Default
|
A named list of arrays, one per path, each with dim in Zarr
order as from zaro_read(). Fetch statistics are in
attr(, "stats").
f <- system.file("extdata", "example.zarr", package = "zaro") ds <- zaro_dataset(f) xy <- zaro_read_arrays(ds, c("lon", "lat", "time")) lengths(xy) attr(xy, "stats")$requests # 0 for a local store, one pool for HTTPf <- system.file("extdata", "example.zarr", package = "zaro") ds <- zaro_dataset(f) xy <- zaro_read_arrays(ds, c("lon", "lat", "time")) lengths(xy) attr(xy, "stats")$requests # 0 for a local store, one pool for HTTP