zarr.codecs#
Classes#
Enum for compression library used by blosc. |
|
Base class for bytes-to-bytes codecs. |
|
Enum for shuffle filter used by blosc. |
|
Base class for array-to-bytes codecs. |
|
Base class for bytes-to-bytes codecs. |
|
Enum for endian type used by bytes codec. |
|
Base class for bytes-to-bytes codecs. |
|
Base class for array-to-bytes codecs. |
|
Enum for index location used by the sharding codec. |
|
Base class for array-to-array codecs. |
|
Base class for array-to-bytes codecs. |
|
Base class for array-to-bytes codecs. |
|
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,
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,
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
- async decode(
- chunks_and_specs: collections.abc.Iterable[tuple[CodecOutput | None, zarr.core.array_spec.ArraySpec]],
Decodes a batch of chunks. Chunks can be None in which case they are ignored by the codec.
- Parameters:
- chunks_and_specsIterable[tuple[CodecOutput | None, ArraySpec]]
Ordered set of encoded chunks with their accompanying chunk spec.
- Returns:
- Iterable[CodecInput | None]
- async encode(
- chunks_and_specs: collections.abc.Iterable[tuple[CodecInput | None, zarr.core.array_spec.ArraySpec]],
Encodes a batch of chunks. Chunks can be None in which case they are ignored by the codec.
- Parameters:
- chunks_and_specsIterable[tuple[CodecInput | None, ArraySpec]]
Ordered set of to-be-encoded chunks with their accompanying chunk spec.
- Returns:
- Iterable[CodecOutput | None]
- 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,
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: zarr.core.common.ChunkCoords,
- dtype: zarr.core.dtype.wrapper.ZDType[zarr.core.dtype.wrapper.TBaseDType, zarr.core.dtype.wrapper.TBaseScalar],
- chunk_grid: zarr.core.chunk_grids.ChunkGrid,
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
- cname: BloscCname#
- is_fixed_size = False#
- shuffle: BloscShuffle | 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,
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
- async decode(
- chunks_and_specs: collections.abc.Iterable[tuple[CodecOutput | None, zarr.core.array_spec.ArraySpec]],
Decodes a batch of chunks. Chunks can be None in which case they are ignored by the codec.
- Parameters:
- chunks_and_specsIterable[tuple[CodecOutput | None, ArraySpec]]
Ordered set of encoded chunks with their accompanying chunk spec.
- Returns:
- Iterable[CodecInput | None]
- async encode(
- chunks_and_specs: collections.abc.Iterable[tuple[CodecInput | None, zarr.core.array_spec.ArraySpec]],
Encodes a batch of chunks. Chunks can be None in which case they are ignored by the codec.
- Parameters:
- chunks_and_specsIterable[tuple[CodecInput | None, ArraySpec]]
Ordered set of to-be-encoded chunks with their accompanying chunk spec.
- Returns:
- Iterable[CodecOutput | None]
- 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,
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: zarr.core.common.ChunkCoords,
- dtype: zarr.core.dtype.wrapper.ZDType[zarr.core.dtype.wrapper.TBaseDType, zarr.core.dtype.wrapper.TBaseScalar],
- chunk_grid: zarr.core.chunk_grids.ChunkGrid,
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#
- 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,
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
- async decode(
- chunks_and_specs: collections.abc.Iterable[tuple[CodecOutput | None, zarr.core.array_spec.ArraySpec]],
Decodes a batch of chunks. Chunks can be None in which case they are ignored by the codec.
- Parameters:
- chunks_and_specsIterable[tuple[CodecOutput | None, ArraySpec]]
Ordered set of encoded chunks with their accompanying chunk spec.
- Returns:
- Iterable[CodecInput | None]
- async encode(
- chunks_and_specs: collections.abc.Iterable[tuple[CodecInput | None, zarr.core.array_spec.ArraySpec]],
Encodes a batch of chunks. Chunks can be None in which case they are ignored by the codec.
- Parameters:
- chunks_and_specsIterable[tuple[CodecInput | None, ArraySpec]]
Ordered set of to-be-encoded chunks with their accompanying chunk spec.
- Returns:
- Iterable[CodecOutput | None]
- evolve_from_array_spec(array_spec: zarr.core.array_spec.ArraySpec) Self #
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,
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: zarr.core.common.ChunkCoords,
- dtype: zarr.core.dtype.wrapper.ZDType[zarr.core.dtype.wrapper.TBaseDType, zarr.core.dtype.wrapper.TBaseScalar],
- chunk_grid: zarr.core.chunk_grids.ChunkGrid,
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#
- 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,
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
- async decode(
- chunks_and_specs: collections.abc.Iterable[tuple[CodecOutput | None, zarr.core.array_spec.ArraySpec]],
Decodes a batch of chunks. Chunks can be None in which case they are ignored by the codec.
- Parameters:
- chunks_and_specsIterable[tuple[CodecOutput | None, ArraySpec]]
Ordered set of encoded chunks with their accompanying chunk spec.
- Returns:
- Iterable[CodecInput | None]
- async encode(
- chunks_and_specs: collections.abc.Iterable[tuple[CodecInput | None, zarr.core.array_spec.ArraySpec]],
Encodes a batch of chunks. Chunks can be None in which case they are ignored by the codec.
- Parameters:
- chunks_and_specsIterable[tuple[CodecInput | None, ArraySpec]]
Ordered set of to-be-encoded chunks with their accompanying chunk spec.
- Returns:
- Iterable[CodecOutput | None]
- evolve_from_array_spec(array_spec: zarr.core.array_spec.ArraySpec) Self #
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,
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: zarr.core.common.ChunkCoords,
- dtype: zarr.core.dtype.wrapper.ZDType[zarr.core.dtype.wrapper.TBaseDType, zarr.core.dtype.wrapper.TBaseScalar],
- chunk_grid: zarr.core.chunk_grids.ChunkGrid,
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 = False#
- 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,
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,
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
- async decode(
- chunks_and_specs: collections.abc.Iterable[tuple[CodecOutput | None, zarr.core.array_spec.ArraySpec]],
Decodes a batch of chunks. Chunks can be None in which case they are ignored by the codec.
- Parameters:
- chunks_and_specsIterable[tuple[CodecOutput | None, ArraySpec]]
Ordered set of encoded chunks with their accompanying chunk spec.
- Returns:
- Iterable[CodecInput | None]
- async decode_partial(
- batch_info: collections.abc.Iterable[tuple[zarr.abc.store.ByteGetter, zarr.core.indexing.SelectorTuple, zarr.core.array_spec.ArraySpec]],
Partially decodes a batch of chunks. This method determines parts of a chunk from the slice selection, fetches these parts from the store (via ByteGetter) and decodes them.
- Parameters:
- batch_infoIterable[tuple[ByteGetter, SelectorTuple, ArraySpec]]
Ordered set of information about slices of encoded chunks. The slice selection determines which parts of the chunk will be fetched. The ByteGetter is used to fetch the necessary bytes. The chunk spec contains information about the construction of an array from the bytes.
- Returns:
- Iterable[NDBuffer | None]
- async encode(
- chunks_and_specs: collections.abc.Iterable[tuple[CodecInput | None, zarr.core.array_spec.ArraySpec]],
Encodes a batch of chunks. Chunks can be None in which case they are ignored by the codec.
- Parameters:
- chunks_and_specsIterable[tuple[CodecInput | None, ArraySpec]]
Ordered set of to-be-encoded chunks with their accompanying chunk spec.
- Returns:
- Iterable[CodecOutput | None]
- async encode_partial(
- batch_info: collections.abc.Iterable[tuple[zarr.abc.store.ByteSetter, zarr.core.buffer.NDBuffer, zarr.core.indexing.SelectorTuple, zarr.core.array_spec.ArraySpec]],
Partially encodes a batch of chunks. This method determines parts of a chunk from the slice selection, encodes them and writes these parts to the store (via ByteSetter). If merging with existing chunk data in the store is necessary, this method will read from the store first and perform the merge.
- Parameters:
- batch_infoIterable[tuple[ByteSetter, NDBuffer, SelectorTuple, ArraySpec]]
Ordered set of information about slices of to-be-encoded chunks. The slice selection determines which parts of the chunk will be encoded. The ByteSetter is used to write the necessary bytes and fetch bytes for existing chunk data. The chunk spec contains information about the chunk.
- 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,
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: zarr.core.common.ChunkCoords,
- dtype: zarr.core.dtype.wrapper.ZDType[zarr.core.dtype.wrapper.TBaseDType, zarr.core.dtype.wrapper.TBaseScalar],
- chunk_grid: zarr.core.chunk_grids.ChunkGrid,
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#
- 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,
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
- async decode(
- chunks_and_specs: collections.abc.Iterable[tuple[CodecOutput | None, zarr.core.array_spec.ArraySpec]],
Decodes a batch of chunks. Chunks can be None in which case they are ignored by the codec.
- Parameters:
- chunks_and_specsIterable[tuple[CodecOutput | None, ArraySpec]]
Ordered set of encoded chunks with their accompanying chunk spec.
- Returns:
- Iterable[CodecInput | None]
- async encode(
- chunks_and_specs: collections.abc.Iterable[tuple[CodecInput | None, zarr.core.array_spec.ArraySpec]],
Encodes a batch of chunks. Chunks can be None in which case they are ignored by the codec.
- Parameters:
- chunks_and_specsIterable[tuple[CodecInput | None, ArraySpec]]
Ordered set of to-be-encoded chunks with their accompanying chunk spec.
- Returns:
- Iterable[CodecOutput | None]
- 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,
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: zarr.core.dtype.wrapper.ZDType[zarr.core.dtype.wrapper.TBaseDType, zarr.core.dtype.wrapper.TBaseScalar],
- chunk_grid: zarr.core.chunk_grids.ChunkGrid,
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#
- 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,
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
- async decode(
- chunks_and_specs: collections.abc.Iterable[tuple[CodecOutput | None, zarr.core.array_spec.ArraySpec]],
Decodes a batch of chunks. Chunks can be None in which case they are ignored by the codec.
- Parameters:
- chunks_and_specsIterable[tuple[CodecOutput | None, ArraySpec]]
Ordered set of encoded chunks with their accompanying chunk spec.
- Returns:
- Iterable[CodecInput | None]
- async encode(
- chunks_and_specs: collections.abc.Iterable[tuple[CodecInput | None, zarr.core.array_spec.ArraySpec]],
Encodes a batch of chunks. Chunks can be None in which case they are ignored by the codec.
- Parameters:
- chunks_and_specsIterable[tuple[CodecInput | None, ArraySpec]]
Ordered set of to-be-encoded chunks with their accompanying chunk spec.
- Returns:
- Iterable[CodecOutput | None]
- 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,
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: zarr.core.common.ChunkCoords,
- dtype: zarr.core.dtype.wrapper.ZDType[zarr.core.dtype.wrapper.TBaseDType, zarr.core.dtype.wrapper.TBaseScalar],
- chunk_grid: zarr.core.chunk_grids.ChunkGrid,
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
- 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,
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
- async decode(
- chunks_and_specs: collections.abc.Iterable[tuple[CodecOutput | None, zarr.core.array_spec.ArraySpec]],
Decodes a batch of chunks. Chunks can be None in which case they are ignored by the codec.
- Parameters:
- chunks_and_specsIterable[tuple[CodecOutput | None, ArraySpec]]
Ordered set of encoded chunks with their accompanying chunk spec.
- Returns:
- Iterable[CodecInput | None]
- async encode(
- chunks_and_specs: collections.abc.Iterable[tuple[CodecInput | None, zarr.core.array_spec.ArraySpec]],
Encodes a batch of chunks. Chunks can be None in which case they are ignored by the codec.
- Parameters:
- chunks_and_specsIterable[tuple[CodecInput | None, ArraySpec]]
Ordered set of to-be-encoded chunks with their accompanying chunk spec.
- Returns:
- Iterable[CodecOutput | None]
- 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,
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: zarr.core.common.ChunkCoords,
- dtype: zarr.core.dtype.wrapper.ZDType[zarr.core.dtype.wrapper.TBaseDType, zarr.core.dtype.wrapper.TBaseScalar],
- chunk_grid: zarr.core.chunk_grids.ChunkGrid,
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
- 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,
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
- async decode(
- chunks_and_specs: collections.abc.Iterable[tuple[CodecOutput | None, zarr.core.array_spec.ArraySpec]],
Decodes a batch of chunks. Chunks can be None in which case they are ignored by the codec.
- Parameters:
- chunks_and_specsIterable[tuple[CodecOutput | None, ArraySpec]]
Ordered set of encoded chunks with their accompanying chunk spec.
- Returns:
- Iterable[CodecInput | None]
- async encode(
- chunks_and_specs: collections.abc.Iterable[tuple[CodecInput | None, zarr.core.array_spec.ArraySpec]],
Encodes a batch of chunks. Chunks can be None in which case they are ignored by the codec.
- Parameters:
- chunks_and_specsIterable[tuple[CodecInput | None, ArraySpec]]
Ordered set of to-be-encoded chunks with their accompanying chunk spec.
- Returns:
- Iterable[CodecOutput | None]
- evolve_from_array_spec(array_spec: zarr.core.array_spec.ArraySpec) Self #
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,
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: zarr.core.common.ChunkCoords,
- dtype: zarr.core.dtype.wrapper.ZDType[zarr.core.dtype.wrapper.TBaseDType, zarr.core.dtype.wrapper.TBaseScalar],
- chunk_grid: zarr.core.chunk_grids.ChunkGrid,
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#