Array creation¶
zarrista.ArrayBuilder ¶
A chained, immutable builder for creating Zarr arrays.
Every setter returns a new ArrayBuilder and leaves the receiver
unchanged. Start
with the constructor or ArrayBuilder.like,
chain setters to configure it, then make the array with
create or
create_async. To make only the
metadata, use
create_metadata.
Examples:
Create a 1024x1024 int32 array with 256x256 chunks and zstd
compression:
from zarrista import ArrayBuilder, ChunkGrid, DataType, FillValue, codec
from zarrista.store import FilesystemStore
grid = ChunkGrid.regular([1024, 1024], chunk_shape=[256, 256])
dtype = DataType.from_string("int32")
fill_value = FillValue((0).to_bytes(4, "little"))
array = (
ArrayBuilder(grid, dtype, fill_value)
.dimension_names(["y", "x"])
.compressors([codec.zstd(3, checksum=False)])
.create(FilesystemStore("data"), "/temperature")
)
create writes the metadata to the store. Each setter returns a new
builder, so you can keep a partly configured builder and reuse it:
base = ArrayBuilder(grid, dtype, fill_value).dimension_names(["y", "x"])
uncompressed = base.create(store, "/raw")
compressed = base.compressors([codec.zstd(3, checksum=False)]).create(
store, "/compressed"
)
__init__ ¶
attrs ¶
attrs(attrs: Mapping[str, JSONValue]) -> ArrayBuilder
Return a new builder with the given user attributes set.
Parameters:
Returns:
-
ArrayBuilder–A new builder with the user attributes set.
chunk_grid ¶
chunk_grid(chunk_grid: ChunkGrid) -> ArrayBuilder
Return a new builder with the chunk grid set.
This can also change the array shape, because the grid carries one.
Parameters:
-
chunk_grid(ChunkGrid) –The chunk grid of the array.
Returns:
-
ArrayBuilder–A new builder with the chunk grid set.
chunk_key_encoding ¶
chunk_key_encoding(chunk_key_encoding: ChunkKeyEncoding) -> ArrayBuilder
Return a new builder with the chunk key encoding set.
Parameters:
-
chunk_key_encoding(ChunkKeyEncoding) –How the array maps chunk grid indices to store keys.
Returns:
-
ArrayBuilder–A new builder with the chunk key encoding set.
compressors ¶
compressors(compressors: Sequence[BytesToBytesCodec]) -> ArrayBuilder
Return a new builder with the bytes-to-bytes codecs ("compressors") set.
Parameters:
-
compressors(Sequence[BytesToBytesCodec]) –The bytes-to-bytes codecs, in pipeline order.
Returns:
-
ArrayBuilder–A new builder with the compressors set.
create ¶
Build the array in store at path and return it.
This does write to the store. It stores the array's metadata at
path, and it overwrites any metadata already there. Use
ArrayBuilder.create_metadata
to build metadata without a store.
Parameters:
-
store(SyncStore) –The store to write the array metadata to.
-
path(str) –The absolute path of the array in the store.
Returns:
-
Array–The new array.
Raises:
-
ArrayCreateError–If
pathis not a valid absolute node path, if the fill value does not match the data type, or if the number of dimension names does not match the number of dimensions.
create_async
async
¶
create_async(store: AsyncStore, path: str) -> AsyncArray
Build the array in an async store at path and return it.
This does write to the store. It stores the array's metadata at
path, and it overwrites any metadata already there. Use
ArrayBuilder.create_metadata
to build metadata without a store.
Parameters:
-
store(AsyncStore) –The async store to write the array metadata to.
-
path(str) –The absolute path of the array in the store.
Returns:
-
AsyncArray–The new array.
Raises:
-
ArrayCreateError–If
pathis not a valid absolute node path, if the fill value does not match the data type, or if the number of dimension names does not match the number of dimensions.
create_metadata ¶
create_metadata() -> ZarrV3ArrayMetadataJSON
Build the array's Zarr v3 metadata without a store.
This writes nothing. Pass the result to
Array.from_metadata to open an
in-memory array. To build and write in one step, use
ArrayBuilder.create.
Returns:
-
ZarrV3ArrayMetadataJSON–The Zarr v3 metadata of the array.
Raises:
-
ArrayCreateError–If the fill value does not match the data type, or if the number of dimension names does not match the number of dimensions.
data_type ¶
data_type(data_type: DataType) -> ArrayBuilder
Return a new builder with the data type set.
Parameters:
-
data_type(DataType) –The data type of the array. The fill value must match this data type.
Returns:
-
ArrayBuilder–A new builder with the data type set.
dimension_names ¶
dimension_names(dimension_names: Sequence[str | None] | None) -> ArrayBuilder
Return a new builder with the dimension names set (or cleared).
Parameters:
-
dimension_names(Sequence[str | None] | None) –One name per dimension. A name can be
Noneto leave that dimension unnamed. GiveNoneto clear all the names.
Returns:
-
ArrayBuilder–A new builder with the dimension names set.
filters ¶
filters(filters: Sequence[ArrayToArrayCodec]) -> ArrayBuilder
Return a new builder with the array-to-array codecs ("filters") set.
Parameters:
-
filters(Sequence[ArrayToArrayCodec]) –The array-to-array codecs, in pipeline order.
Returns:
-
ArrayBuilder–A new builder with the filters set.
like
staticmethod
¶
like(array: Array | AsyncArray) -> ArrayBuilder
Create a builder that copies the configuration of an existing array.
Parameters:
-
array(Array | AsyncArray) –The array to copy the configuration from.
Returns:
-
ArrayBuilder–A new builder with the same configuration as
array.
serializer ¶
serializer(serializer: ArrayToBytesCodec) -> ArrayBuilder
Return a new builder with the array-to-bytes codec ("serializer") set.
Sharding is itself an array-to-bytes codec. Therefore you pass a sharding serializer here too.
Parameters:
-
serializer(ArrayToBytesCodec) –The array-to-bytes codec of the array.
Returns:
-
ArrayBuilder–A new builder with the serializer set.
shape ¶
shape(shape: Sequence[int]) -> ArrayBuilder
Return a new builder with the array shape set.
This shape replaces the shape that the chunk grid gives.
Parameters:
Returns:
-
ArrayBuilder–A new builder with the array shape set.
subchunk_shape ¶
subchunk_shape(subchunk_shape: Sequence[int] | None) -> ArrayBuilder
Return a new builder with the inner (subchunk) shape, enabling sharding.
Parameters:
-
subchunk_shape(Sequence[int] | None) –The shape of an inner chunk, in elements along each dimension. Give
Noneto disable sharding.
Returns:
-
ArrayBuilder–A new builder with the subchunk shape set.
zarrista.ArrayBytes ¶
Chunk bytes as input to or output from a codec.
The object holds a data buffer. It can also hold the element byte offsets for variable-length data, and a validity mask.
mask
property
¶
mask: Buffer | None
The validity mask (1 byte per element), or None if not optional.
__init__ ¶
__init__(
value: Buffer,
/,
*,
mask: Buffer | None = None,
offsets: list[int] | None = None,
) -> None
Construct from a data buffer, with an optional mask and offsets.
This does not check mask or offsets against value. The codec
pipeline reports an error only when it uses the data.
Parameters:
-
value(Buffer) –The element bytes.
Keyword Arguments: