zarr.codecs#

Submodules#

Classes#

BloscCname

Enum for compression library used by blosc.

BloscCodec

Base class for bytes-to-bytes codecs.

BloscShuffle

Enum for shuffle filter used by blosc.

BytesCodec

Base class for array-to-bytes codecs.

Crc32cCodec

Base class for bytes-to-bytes codecs.

Endian

Enum for endian type used by bytes codec.

GzipCodec

Base class for bytes-to-bytes codecs.

ShardingCodec

Base class for array-to-bytes codecs.

ShardingCodecIndexLocation

Enum for index location used by the sharding codec.

TransposeCodec

Base class for array-to-array codecs.

VLenBytesCodec

Base class for array-to-bytes codecs.

VLenUTF8Codec

Base class for array-to-bytes codecs.

ZstdCodec

Base class for bytes-to-bytes codecs.

Package Contents#

class zarr.codecs.BloscCname(*args, **kwds)[source]#

Bases: enum.Enum

Enum for compression library used by blosc.

blosclz = 'blosclz'#
lz4 = 'lz4'#
lz4hc = 'lz4hc'#
snappy = 'snappy'#
zlib = 'zlib'#
zstd = 'zstd'#
class zarr.codecs.BloscCodec(
*,
typesize: int | None = None,
cname: BloscCname | str = BloscCname.zstd,
clevel: int = 5,
shuffle: BloscShuffle | str | None = None,
blocksize: int = 0,
)[source]#

Bases: zarr.abc.codec.BytesBytesCodec

Base class for bytes-to-bytes codecs.

abstract compute_encoded_size(
_input_byte_length: int,
_chunk_spec: zarr.core.array_spec.ArraySpec,
) int[source]#

Given an input byte length, this method returns the output byte length. Raises a NotImplementedError for codecs with variable-sized outputs (e.g. compressors).

Parameters:
input_byte_lengthint
chunk_specArraySpec
Returns:
int
evolve_from_array_spec(array_spec: zarr.core.array_spec.ArraySpec) Self[source]#

Fills in codec configuration parameters that can be automatically inferred from the array metadata.

Parameters:
array_specArraySpec
Returns:
Self
classmethod from_dict(data: dict[str, zarr.core.common.JSON]) Self[source]#

Create an instance of the model from a dictionary

to_dict() dict[str, zarr.core.common.JSON][source]#

Recursively serialize this model to a dictionary. This method inspects the fields of self and calls x.to_dict() for any fields that are instances of Metadata. Sequences of Metadata are similarly recursed into, and the output of that recursion is collected in a list.

blocksize: int = 0#
clevel: int = 5#
cname: BloscCname#
is_fixed_size = False#
shuffle: BloscShuffle | None#
typesize: int | None#
class zarr.codecs.BloscShuffle(*args, **kwds)[source]#

Bases: enum.Enum

Enum for shuffle filter used by blosc.

classmethod from_int(num: int) BloscShuffle[source]#
bitshuffle = 'bitshuffle'#
noshuffle = 'noshuffle'#
shuffle = 'shuffle'#
class zarr.codecs.BytesCodec(*, endian: Endian | str | None = default_system_endian)[source]#

Bases: zarr.abc.codec.ArrayBytesCodec

Base class for array-to-bytes codecs.

compute_encoded_size(
input_byte_length: int,
_chunk_spec: zarr.core.array_spec.ArraySpec,
) int[source]#

Given an input byte length, this method returns the output byte length. Raises a NotImplementedError for codecs with variable-sized outputs (e.g. compressors).

Parameters:
input_byte_lengthint
chunk_specArraySpec
Returns:
int
evolve_from_array_spec(array_spec: zarr.core.array_spec.ArraySpec) Self[source]#

Fills in codec configuration parameters that can be automatically inferred from the array metadata.

Parameters:
array_specArraySpec
Returns:
Self
classmethod from_dict(data: dict[str, zarr.core.common.JSON]) Self[source]#

Create an instance of the model from a dictionary

to_dict() dict[str, zarr.core.common.JSON][source]#

Recursively serialize this model to a dictionary. This method inspects the fields of self and calls x.to_dict() for any fields that are instances of Metadata. Sequences of Metadata are similarly recursed into, and the output of that recursion is collected in a list.

endian: Endian | None#
is_fixed_size = True#
class zarr.codecs.Crc32cCodec[source]#

Bases: zarr.abc.codec.BytesBytesCodec

Base class for bytes-to-bytes codecs.

compute_encoded_size(
input_byte_length: int,
_chunk_spec: zarr.core.array_spec.ArraySpec,
) int[source]#

Given an input byte length, this method returns the output byte length. Raises a NotImplementedError for codecs with variable-sized outputs (e.g. compressors).

Parameters:
input_byte_lengthint
chunk_specArraySpec
Returns:
int
classmethod from_dict(data: dict[str, zarr.core.common.JSON]) Self[source]#

Create an instance of the model from a dictionary

to_dict() dict[str, zarr.core.common.JSON][source]#

Recursively serialize this model to a dictionary. This method inspects the fields of self and calls x.to_dict() for any fields that are instances of Metadata. Sequences of Metadata are similarly recursed into, and the output of that recursion is collected in a list.

is_fixed_size = True#
class zarr.codecs.Endian(*args, **kwds)[source]#

Bases: enum.Enum

Enum for endian type used by bytes codec.

big = 'big'#
little = 'little'#
class zarr.codecs.GzipCodec(*, level: int = 5)[source]#

Bases: zarr.abc.codec.BytesBytesCodec

Base class for bytes-to-bytes codecs.

abstract compute_encoded_size(
_input_byte_length: int,
_chunk_spec: zarr.core.array_spec.ArraySpec,
) int[source]#

Given an input byte length, this method returns the output byte length. Raises a NotImplementedError for codecs with variable-sized outputs (e.g. compressors).

Parameters:
input_byte_lengthint
chunk_specArraySpec
Returns:
int
classmethod from_dict(data: dict[str, zarr.core.common.JSON]) Self[source]#

Create an instance of the model from a dictionary

to_dict() dict[str, zarr.core.common.JSON][source]#

Recursively serialize this model to a dictionary. This method inspects the fields of self and calls x.to_dict() for any fields that are instances of Metadata. Sequences of Metadata are similarly recursed into, and the output of that recursion is collected in a list.

is_fixed_size = False#
level: int = 5#
class zarr.codecs.ShardingCodec(
*,
chunk_shape: zarr.core.common.ChunkCoordsLike,
codecs: collections.abc.Iterable[zarr.abc.codec.Codec | dict[str, zarr.core.common.JSON]] = (BytesCodec(),),
index_codecs: collections.abc.Iterable[zarr.abc.codec.Codec | dict[str, zarr.core.common.JSON]] = (BytesCodec(), Crc32cCodec()),
index_location: ShardingCodecIndexLocation | str = ShardingCodecIndexLocation.end,
)[source]#

Bases: zarr.abc.codec.ArrayBytesCodec, zarr.abc.codec.ArrayBytesCodecPartialDecodeMixin, zarr.abc.codec.ArrayBytesCodecPartialEncodeMixin

Base class for array-to-bytes codecs.

compute_encoded_size(
input_byte_length: int,
shard_spec: zarr.core.array_spec.ArraySpec,
) int[source]#

Given an input byte length, this method returns the output byte length. Raises a NotImplementedError for codecs with variable-sized outputs (e.g. compressors).

Parameters:
input_byte_lengthint
chunk_specArraySpec
Returns:
int
evolve_from_array_spec(array_spec: zarr.core.array_spec.ArraySpec) Self[source]#

Fills in codec configuration parameters that can be automatically inferred from the array metadata.

Parameters:
array_specArraySpec
Returns:
Self
classmethod from_dict(data: dict[str, zarr.core.common.JSON]) Self[source]#

Create an instance of the model from a dictionary

to_dict() dict[str, zarr.core.common.JSON][source]#

Recursively serialize this model to a dictionary. This method inspects the fields of self and calls x.to_dict() for any fields that are instances of Metadata. Sequences of Metadata are similarly recursed into, and the output of that recursion is collected in a list.

validate(
*,
shape: zarr.core.common.ChunkCoords,
dtype: numpy.dtype[Any],
chunk_grid: zarr.core.chunk_grids.ChunkGrid,
) None[source]#

Validates that the codec configuration is compatible with the array metadata. Raises errors when the codec configuration is not compatible.

Parameters:
shapeChunkCoords

The array shape

dtypenp.dtype[Any]

The array data type

chunk_gridChunkGrid

The array chunk grid

chunk_shape: zarr.core.common.ChunkCoords#
property codec_pipeline: zarr.abc.codec.CodecPipeline#
codecs: tuple[zarr.abc.codec.Codec, Ellipsis]#
index_codecs: tuple[zarr.abc.codec.Codec, Ellipsis]#
index_location: ShardingCodecIndexLocation#
class zarr.codecs.ShardingCodecIndexLocation(*args, **kwds)[source]#

Bases: enum.Enum

Enum for index location used by the sharding codec.

end = 'end'#
start = 'start'#
class zarr.codecs.TransposeCodec(*, order: zarr.core.common.ChunkCoordsLike)[source]#

Bases: zarr.abc.codec.ArrayArrayCodec

Base class for array-to-array codecs.

compute_encoded_size(
input_byte_length: int,
_chunk_spec: zarr.core.array_spec.ArraySpec,
) int[source]#

Given an input byte length, this method returns the output byte length. Raises a NotImplementedError for codecs with variable-sized outputs (e.g. compressors).

Parameters:
input_byte_lengthint
chunk_specArraySpec
Returns:
int
evolve_from_array_spec(array_spec: zarr.core.array_spec.ArraySpec) Self[source]#

Fills in codec configuration parameters that can be automatically inferred from the array metadata.

Parameters:
array_specArraySpec
Returns:
Self
classmethod from_dict(data: dict[str, zarr.core.common.JSON]) Self[source]#

Create an instance of the model from a dictionary

resolve_metadata(
chunk_spec: zarr.core.array_spec.ArraySpec,
) zarr.core.array_spec.ArraySpec[source]#

Computed the spec of the chunk after it has been encoded by the codec. This is important for codecs that change the shape, data type or fill value of a chunk. The spec will then be used for subsequent codecs in the pipeline.

Parameters:
chunk_specArraySpec
Returns:
ArraySpec
to_dict() dict[str, zarr.core.common.JSON][source]#

Recursively serialize this model to a dictionary. This method inspects the fields of self and calls x.to_dict() for any fields that are instances of Metadata. Sequences of Metadata are similarly recursed into, and the output of that recursion is collected in a list.

validate(
shape: tuple[int, Ellipsis],
dtype: numpy.dtype[Any],
chunk_grid: zarr.core.chunk_grids.ChunkGrid,
) None[source]#

Validates that the codec configuration is compatible with the array metadata. Raises errors when the codec configuration is not compatible.

Parameters:
shapeChunkCoords

The array shape

dtypenp.dtype[Any]

The array data type

chunk_gridChunkGrid

The array chunk grid

is_fixed_size = True#
order: tuple[int, Ellipsis]#
class zarr.codecs.VLenBytesCodec[source]#

Bases: zarr.abc.codec.ArrayBytesCodec

Base class for array-to-bytes codecs.

abstract compute_encoded_size(
input_byte_length: int,
_chunk_spec: zarr.core.array_spec.ArraySpec,
) int[source]#

Given an input byte length, this method returns the output byte length. Raises a NotImplementedError for codecs with variable-sized outputs (e.g. compressors).

Parameters:
input_byte_lengthint
chunk_specArraySpec
Returns:
int
evolve_from_array_spec(array_spec: zarr.core.array_spec.ArraySpec) Self[source]#

Fills in codec configuration parameters that can be automatically inferred from the array metadata.

Parameters:
array_specArraySpec
Returns:
Self
classmethod from_dict(data: dict[str, zarr.core.common.JSON]) Self[source]#

Create an instance of the model from a dictionary

to_dict() dict[str, zarr.core.common.JSON][source]#

Recursively serialize this model to a dictionary. This method inspects the fields of self and calls x.to_dict() for any fields that are instances of Metadata. Sequences of Metadata are similarly recursed into, and the output of that recursion is collected in a list.

class zarr.codecs.VLenUTF8Codec[source]#

Bases: zarr.abc.codec.ArrayBytesCodec

Base class for array-to-bytes codecs.

abstract compute_encoded_size(
input_byte_length: int,
_chunk_spec: zarr.core.array_spec.ArraySpec,
) int[source]#

Given an input byte length, this method returns the output byte length. Raises a NotImplementedError for codecs with variable-sized outputs (e.g. compressors).

Parameters:
input_byte_lengthint
chunk_specArraySpec
Returns:
int
evolve_from_array_spec(array_spec: zarr.core.array_spec.ArraySpec) Self[source]#

Fills in codec configuration parameters that can be automatically inferred from the array metadata.

Parameters:
array_specArraySpec
Returns:
Self
classmethod from_dict(data: dict[str, zarr.core.common.JSON]) Self[source]#

Create an instance of the model from a dictionary

to_dict() dict[str, zarr.core.common.JSON][source]#

Recursively serialize this model to a dictionary. This method inspects the fields of self and calls x.to_dict() for any fields that are instances of Metadata. Sequences of Metadata are similarly recursed into, and the output of that recursion is collected in a list.

class zarr.codecs.ZstdCodec(*, level: int = 0, checksum: bool = False)[source]#

Bases: zarr.abc.codec.BytesBytesCodec

Base class for bytes-to-bytes codecs.

abstract compute_encoded_size(
_input_byte_length: int,
_chunk_spec: zarr.core.array_spec.ArraySpec,
) int[source]#

Given an input byte length, this method returns the output byte length. Raises a NotImplementedError for codecs with variable-sized outputs (e.g. compressors).

Parameters:
input_byte_lengthint
chunk_specArraySpec
Returns:
int
classmethod from_dict(data: dict[str, zarr.core.common.JSON]) Self[source]#

Create an instance of the model from a dictionary

to_dict() dict[str, zarr.core.common.JSON][source]#

Recursively serialize this model to a dictionary. This method inspects the fields of self and calls x.to_dict() for any fields that are instances of Metadata. Sequences of Metadata are similarly recursed into, and the output of that recursion is collected in a list.

checksum: bool = False#
is_fixed_size = True#
level: int = 0#