A deliberately small reader, to show that a real chunked, compressed
store fits behind the fetch contract in a few lines. Handles Zarr v2
arrays with dtype <f8, <f4, <i4, <i2, |i1, <u2, |u1 or
|b1, compressor null or zlib, order C or F, and missing chunk
files (read as fill_value). Zarr's padded edge chunks are clipped.
Value
a lazy array, see altarr()
Details
The store is listed once, when the array is made, and that listing is
the array's chunk index (present in altarr()): a chunk with no file
is never read, its cells are fill_value (decoded as below), and
sum(), min() and max() count them from the index. See
altarr_present().
This is a demonstration, not a Zarr implementation: no Zarr v3, no
remote stores, no other codecs. For real stores, use a full Zarr reader
and hand its chunk reads to altarr() as the fetch function.
The array's type follows the dtype: floats give a double array, integers
an integer array, |b1 a logical array. With unpack = TRUE, CF
packing attributes found in .zattrs are applied inside the fetch:
values equal to _FillValue or missing_value become NA, and if
scale_factor or add_offset is present the array is double, holding
the unpacked values. The Zarr fill_value itself is not treated as
missing.
A C-order Zarr array of shape (s1, ..., sn) is returned with R dim
c(sn, ..., s1): C-order bytes are already column-major for the
reversed shape, so no transposition is ever done. The array records
that order (store_axes in altarr()), so altarr_plan() names each
chunk by its Zarr chunk key, dim_0 ...
Examples
path <- altarr_example_zarr()
x <- altarr_zarr_v2(path)
dim(x) # the Zarr shape, reversed
#> [1] 70 50 30
x[cbind(70, 50, 30)]
#> [1] 104999
str(x)
#> num [1:70, 1:50, 1:30] 0 1 2 3 4 5 6 7 8 9 ...