Skip to content

numcodecs

zarr.codecs.numcodecs

__all__ module-attribute

__all__ = [
    "BZ2",
    "CRC32",
    "CRC32C",
    "LZ4",
    "LZMA",
    "ZFPY",
    "Adler32",
    "AsType",
    "BitRound",
    "Blosc",
    "Delta",
    "FixedScaleOffset",
    "Fletcher32",
    "GZip",
    "JenkinsLookup3",
    "PCodec",
    "PackBits",
    "Quantize",
    "Shuffle",
    "Zlib",
    "Zstd",
    "_NumcodecsArrayArrayCodec",
    "_NumcodecsArrayBytesCodec",
    "_NumcodecsBytesBytesCodec",
    "_NumcodecsCodec",
]

Adler32 dataclass

Bases: _NumcodecsChecksumCodec

Source code in zarr/codecs/numcodecs/_codecs.py
class Adler32(_NumcodecsChecksumCodec, codec_name="adler32"):
    pass

codec_config instance-attribute

codec_config: dict[str, JSON]

codec_name instance-attribute

codec_name: str

is_fixed_size instance-attribute

is_fixed_size: bool

__init__

__init__(**codec_config: JSON) -> None
Source code in zarr/codecs/numcodecs/_codecs.py
def __init__(self, **codec_config: JSON) -> None:
    super().__init__(**codec_config)

__init_subclass__

__init_subclass__(
    *, codec_name: str | None = None, **kwargs: Any
) -> None

To be used only when creating the actual public-facing codec class.

Source code in zarr/codecs/numcodecs/_codecs.py
def __init_subclass__(cls, *, codec_name: str | None = None, **kwargs: Any) -> None:
    """To be used only when creating the actual public-facing codec class."""
    super().__init_subclass__(**kwargs)
    if codec_name is not None:
        namespace = codec_name

        cls_name = f"{CODEC_PREFIX}{namespace}.{cls.__name__}"
        cls.codec_name = f"{CODEC_PREFIX}{namespace}"
        cls.__doc__ = f"""
        See [{cls_name}][] for more details and parameters.
        """

__repr__

__repr__() -> str
Source code in zarr/codecs/numcodecs/_codecs.py
def __repr__(self) -> str:
    codec_config = self.codec_config.copy()
    codec_config.pop("id", None)
    return f"{self.__class__.__name__}(codec_name={self.codec_name!r}, codec_config={codec_config!r})"

compute_encoded_size

compute_encoded_size(
    input_byte_length: int, chunk_spec: ArraySpec
) -> int
Source code in zarr/codecs/numcodecs/_codecs.py
def compute_encoded_size(self, input_byte_length: int, chunk_spec: ArraySpec) -> int:
    return input_byte_length + 4  # pragma: no cover

decode async

decode(
    chunks_and_specs: Iterable[tuple[CO | None, ArraySpec]],
) -> Iterable[CI | None]

Decodes a batch of chunks. Chunks can be None in which case they are ignored by the codec.

Parameters:

  • chunks_and_specs (Iterable[tuple[CodecOutput | None, ArraySpec]]) –

    Ordered set of encoded chunks with their accompanying chunk spec.

Returns:

Source code in zarr/abc/codec.py
async def decode(
    self,
    chunks_and_specs: Iterable[tuple[CO | None, ArraySpec]],
) -> Iterable[CI | None]:
    """Decodes a batch of chunks.
    Chunks can be None in which case they are ignored by the codec.

    Parameters
    ----------
    chunks_and_specs : Iterable[tuple[CodecOutput | None, ArraySpec]]
        Ordered set of encoded chunks with their accompanying chunk spec.

    Returns
    -------
    Iterable[CI | None]
    """
    return await _batching_helper(self._decode_single, chunks_and_specs)

encode async

encode(
    chunks_and_specs: Iterable[tuple[CI | None, ArraySpec]],
) -> Iterable[CO | None]

Encodes a batch of chunks. Chunks can be None in which case they are ignored by the codec.

Parameters:

  • chunks_and_specs (Iterable[tuple[CI | None, ArraySpec]]) –

    Ordered set of to-be-encoded chunks with their accompanying chunk spec.

Returns:

Source code in zarr/abc/codec.py
async def encode(
    self,
    chunks_and_specs: Iterable[tuple[CI | None, ArraySpec]],
) -> Iterable[CO | None]:
    """Encodes a batch of chunks.
    Chunks can be None in which case they are ignored by the codec.

    Parameters
    ----------
    chunks_and_specs : Iterable[tuple[CI | None, ArraySpec]]
        Ordered set of to-be-encoded chunks with their accompanying chunk spec.

    Returns
    -------
    Iterable[CodecOutput | None]
    """
    return await _batching_helper(self._encode_single, chunks_and_specs)

evolve_from_array_spec

evolve_from_array_spec(array_spec: ArraySpec) -> Self

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

Parameters:

  • array_spec (ArraySpec) –

Returns:

Source code in zarr/abc/codec.py
def evolve_from_array_spec(self, array_spec: ArraySpec) -> Self:
    """Fills in codec configuration parameters that can be automatically
    inferred from the array metadata.

    Parameters
    ----------
    array_spec : ArraySpec

    Returns
    -------
    Self
    """
    return self

from_dict classmethod

from_dict(data: dict[str, JSON]) -> Self

Create an instance of the model from a dictionary

Source code in zarr/codecs/numcodecs/_codecs.py
@classmethod
def from_dict(cls, data: dict[str, JSON]) -> Self:
    codec_config = _parse_codec_configuration(data)
    return cls(**codec_config)

resolve_metadata

resolve_metadata(chunk_spec: ArraySpec) -> 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_spec (ArraySpec) –

Returns:

  • ArraySpec
Source code in zarr/abc/codec.py
def resolve_metadata(self, chunk_spec: ArraySpec) -> 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_spec : ArraySpec

    Returns
    -------
    ArraySpec
    """
    return chunk_spec

to_dict

to_dict() -> dict[str, JSON]

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.

Source code in zarr/codecs/numcodecs/_codecs.py
def to_dict(self) -> dict[str, JSON]:
    codec_config = self.codec_config.copy()
    codec_config.pop("id", None)
    return {
        "name": self.codec_name,
        "configuration": codec_config,
    }

validate

validate(
    *,
    shape: tuple[int, ...],
    dtype: ZDType[TBaseDType, TBaseScalar],
    chunk_grid: ChunkGridMetadata,
) -> None

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

Parameters:

  • shape (tuple[int, ...]) –

    The array shape

  • dtype (dtype[Any]) –

    The array data type

  • chunk_grid (ChunkGridMetadata) –

    The array chunk grid metadata

Source code in zarr/abc/codec.py
def validate(
    self,
    *,
    shape: tuple[int, ...],
    dtype: ZDType[TBaseDType, TBaseScalar],
    chunk_grid: ChunkGridMetadata,
) -> None:
    """Validates that the codec configuration is compatible with the array metadata.
    Raises errors when the codec configuration is not compatible.

    Parameters
    ----------
    shape : tuple[int, ...]
        The array shape
    dtype : np.dtype[Any]
        The array data type
    chunk_grid : ChunkGridMetadata
        The array chunk grid metadata
    """

AsType dataclass

Bases: _NumcodecsArrayArrayCodec

Source code in zarr/codecs/numcodecs/_codecs.py
class AsType(_NumcodecsArrayArrayCodec, codec_name="astype"):
    def resolve_metadata(self, chunk_spec: ArraySpec) -> ArraySpec:
        dtype = parse_dtype(np.dtype(self.codec_config["encode_dtype"]), zarr_format=3)  # type: ignore[arg-type]
        return replace(chunk_spec, dtype=dtype)

    def evolve_from_array_spec(self, array_spec: ArraySpec) -> AsType:
        if self.codec_config.get("decode_dtype") is None:
            # TODO: remove these coverage exemptions the correct way, i.e. with tests
            dtype = array_spec.dtype.to_native_dtype()  # pragma: no cover
            return AsType(**{**self.codec_config, "decode_dtype": str(dtype)})  # pragma: no cover
        return self

codec_config instance-attribute

codec_config: dict[str, JSON]

codec_name instance-attribute

codec_name: str

is_fixed_size instance-attribute

is_fixed_size: bool

__init__

__init__(**codec_config: JSON) -> None
Source code in zarr/codecs/numcodecs/_codecs.py
def __init__(self, **codec_config: JSON) -> None:
    super().__init__(**codec_config)

__init_subclass__

__init_subclass__(
    *, codec_name: str | None = None, **kwargs: Any
) -> None

To be used only when creating the actual public-facing codec class.

Source code in zarr/codecs/numcodecs/_codecs.py
def __init_subclass__(cls, *, codec_name: str | None = None, **kwargs: Any) -> None:
    """To be used only when creating the actual public-facing codec class."""
    super().__init_subclass__(**kwargs)
    if codec_name is not None:
        namespace = codec_name

        cls_name = f"{CODEC_PREFIX}{namespace}.{cls.__name__}"
        cls.codec_name = f"{CODEC_PREFIX}{namespace}"
        cls.__doc__ = f"""
        See [{cls_name}][] for more details and parameters.
        """

__repr__

__repr__() -> str
Source code in zarr/codecs/numcodecs/_codecs.py
def __repr__(self) -> str:
    codec_config = self.codec_config.copy()
    codec_config.pop("id", None)
    return f"{self.__class__.__name__}(codec_name={self.codec_name!r}, codec_config={codec_config!r})"

compute_encoded_size

compute_encoded_size(
    input_byte_length: int, chunk_spec: ArraySpec
) -> int
Source code in zarr/codecs/numcodecs/_codecs.py
def compute_encoded_size(self, input_byte_length: int, chunk_spec: ArraySpec) -> int:
    raise NotImplementedError  # pragma: no cover

decode async

decode(
    chunks_and_specs: Iterable[tuple[CO | None, ArraySpec]],
) -> Iterable[CI | None]

Decodes a batch of chunks. Chunks can be None in which case they are ignored by the codec.

Parameters:

  • chunks_and_specs (Iterable[tuple[CodecOutput | None, ArraySpec]]) –

    Ordered set of encoded chunks with their accompanying chunk spec.

Returns:

Source code in zarr/abc/codec.py
async def decode(
    self,
    chunks_and_specs: Iterable[tuple[CO | None, ArraySpec]],
) -> Iterable[CI | None]:
    """Decodes a batch of chunks.
    Chunks can be None in which case they are ignored by the codec.

    Parameters
    ----------
    chunks_and_specs : Iterable[tuple[CodecOutput | None, ArraySpec]]
        Ordered set of encoded chunks with their accompanying chunk spec.

    Returns
    -------
    Iterable[CI | None]
    """
    return await _batching_helper(self._decode_single, chunks_and_specs)

encode async

encode(
    chunks_and_specs: Iterable[tuple[CI | None, ArraySpec]],
) -> Iterable[CO | None]

Encodes a batch of chunks. Chunks can be None in which case they are ignored by the codec.

Parameters:

  • chunks_and_specs (Iterable[tuple[CI | None, ArraySpec]]) –

    Ordered set of to-be-encoded chunks with their accompanying chunk spec.

Returns:

Source code in zarr/abc/codec.py
async def encode(
    self,
    chunks_and_specs: Iterable[tuple[CI | None, ArraySpec]],
) -> Iterable[CO | None]:
    """Encodes a batch of chunks.
    Chunks can be None in which case they are ignored by the codec.

    Parameters
    ----------
    chunks_and_specs : Iterable[tuple[CI | None, ArraySpec]]
        Ordered set of to-be-encoded chunks with their accompanying chunk spec.

    Returns
    -------
    Iterable[CodecOutput | None]
    """
    return await _batching_helper(self._encode_single, chunks_and_specs)

evolve_from_array_spec

evolve_from_array_spec(array_spec: ArraySpec) -> AsType

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

Parameters:

  • array_spec (ArraySpec) –

Returns:

Source code in zarr/codecs/numcodecs/_codecs.py
def evolve_from_array_spec(self, array_spec: ArraySpec) -> AsType:
    if self.codec_config.get("decode_dtype") is None:
        # TODO: remove these coverage exemptions the correct way, i.e. with tests
        dtype = array_spec.dtype.to_native_dtype()  # pragma: no cover
        return AsType(**{**self.codec_config, "decode_dtype": str(dtype)})  # pragma: no cover
    return self

from_dict classmethod

from_dict(data: dict[str, JSON]) -> Self

Create an instance of the model from a dictionary

Source code in zarr/codecs/numcodecs/_codecs.py
@classmethod
def from_dict(cls, data: dict[str, JSON]) -> Self:
    codec_config = _parse_codec_configuration(data)
    return cls(**codec_config)

resolve_metadata

resolve_metadata(chunk_spec: ArraySpec) -> 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_spec (ArraySpec) –

Returns:

  • ArraySpec
Source code in zarr/codecs/numcodecs/_codecs.py
def resolve_metadata(self, chunk_spec: ArraySpec) -> ArraySpec:
    dtype = parse_dtype(np.dtype(self.codec_config["encode_dtype"]), zarr_format=3)  # type: ignore[arg-type]
    return replace(chunk_spec, dtype=dtype)

to_dict

to_dict() -> dict[str, JSON]

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.

Source code in zarr/codecs/numcodecs/_codecs.py
def to_dict(self) -> dict[str, JSON]:
    codec_config = self.codec_config.copy()
    codec_config.pop("id", None)
    return {
        "name": self.codec_name,
        "configuration": codec_config,
    }

validate

validate(
    *,
    shape: tuple[int, ...],
    dtype: ZDType[TBaseDType, TBaseScalar],
    chunk_grid: ChunkGridMetadata,
) -> None

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

Parameters:

  • shape (tuple[int, ...]) –

    The array shape

  • dtype (dtype[Any]) –

    The array data type

  • chunk_grid (ChunkGridMetadata) –

    The array chunk grid metadata

Source code in zarr/abc/codec.py
def validate(
    self,
    *,
    shape: tuple[int, ...],
    dtype: ZDType[TBaseDType, TBaseScalar],
    chunk_grid: ChunkGridMetadata,
) -> None:
    """Validates that the codec configuration is compatible with the array metadata.
    Raises errors when the codec configuration is not compatible.

    Parameters
    ----------
    shape : tuple[int, ...]
        The array shape
    dtype : np.dtype[Any]
        The array data type
    chunk_grid : ChunkGridMetadata
        The array chunk grid metadata
    """

BZ2 dataclass

Bases: _NumcodecsBytesBytesCodec

Source code in zarr/codecs/numcodecs/_codecs.py
class BZ2(_NumcodecsBytesBytesCodec, codec_name="bz2"):
    pass

codec_config instance-attribute

codec_config: dict[str, JSON]

codec_name instance-attribute

codec_name: str

is_fixed_size instance-attribute

is_fixed_size: bool

__init__

__init__(**codec_config: JSON) -> None
Source code in zarr/codecs/numcodecs/_codecs.py
def __init__(self, **codec_config: JSON) -> None:
    super().__init__(**codec_config)

__init_subclass__

__init_subclass__(
    *, codec_name: str | None = None, **kwargs: Any
) -> None

To be used only when creating the actual public-facing codec class.

Source code in zarr/codecs/numcodecs/_codecs.py
def __init_subclass__(cls, *, codec_name: str | None = None, **kwargs: Any) -> None:
    """To be used only when creating the actual public-facing codec class."""
    super().__init_subclass__(**kwargs)
    if codec_name is not None:
        namespace = codec_name

        cls_name = f"{CODEC_PREFIX}{namespace}.{cls.__name__}"
        cls.codec_name = f"{CODEC_PREFIX}{namespace}"
        cls.__doc__ = f"""
        See [{cls_name}][] for more details and parameters.
        """

__repr__

__repr__() -> str
Source code in zarr/codecs/numcodecs/_codecs.py
def __repr__(self) -> str:
    codec_config = self.codec_config.copy()
    codec_config.pop("id", None)
    return f"{self.__class__.__name__}(codec_name={self.codec_name!r}, codec_config={codec_config!r})"

compute_encoded_size

compute_encoded_size(
    input_byte_length: int, chunk_spec: ArraySpec
) -> int
Source code in zarr/codecs/numcodecs/_codecs.py
def compute_encoded_size(self, input_byte_length: int, chunk_spec: ArraySpec) -> int:
    raise NotImplementedError  # pragma: no cover

decode async

decode(
    chunks_and_specs: Iterable[tuple[CO | None, ArraySpec]],
) -> Iterable[CI | None]

Decodes a batch of chunks. Chunks can be None in which case they are ignored by the codec.

Parameters:

  • chunks_and_specs (Iterable[tuple[CodecOutput | None, ArraySpec]]) –

    Ordered set of encoded chunks with their accompanying chunk spec.

Returns:

Source code in zarr/abc/codec.py
async def decode(
    self,
    chunks_and_specs: Iterable[tuple[CO | None, ArraySpec]],
) -> Iterable[CI | None]:
    """Decodes a batch of chunks.
    Chunks can be None in which case they are ignored by the codec.

    Parameters
    ----------
    chunks_and_specs : Iterable[tuple[CodecOutput | None, ArraySpec]]
        Ordered set of encoded chunks with their accompanying chunk spec.

    Returns
    -------
    Iterable[CI | None]
    """
    return await _batching_helper(self._decode_single, chunks_and_specs)

encode async

encode(
    chunks_and_specs: Iterable[tuple[CI | None, ArraySpec]],
) -> Iterable[CO | None]

Encodes a batch of chunks. Chunks can be None in which case they are ignored by the codec.

Parameters:

  • chunks_and_specs (Iterable[tuple[CI | None, ArraySpec]]) –

    Ordered set of to-be-encoded chunks with their accompanying chunk spec.

Returns:

Source code in zarr/abc/codec.py
async def encode(
    self,
    chunks_and_specs: Iterable[tuple[CI | None, ArraySpec]],
) -> Iterable[CO | None]:
    """Encodes a batch of chunks.
    Chunks can be None in which case they are ignored by the codec.

    Parameters
    ----------
    chunks_and_specs : Iterable[tuple[CI | None, ArraySpec]]
        Ordered set of to-be-encoded chunks with their accompanying chunk spec.

    Returns
    -------
    Iterable[CodecOutput | None]
    """
    return await _batching_helper(self._encode_single, chunks_and_specs)

evolve_from_array_spec

evolve_from_array_spec(array_spec: ArraySpec) -> Self

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

Parameters:

  • array_spec (ArraySpec) –

Returns:

Source code in zarr/abc/codec.py
def evolve_from_array_spec(self, array_spec: ArraySpec) -> Self:
    """Fills in codec configuration parameters that can be automatically
    inferred from the array metadata.

    Parameters
    ----------
    array_spec : ArraySpec

    Returns
    -------
    Self
    """
    return self

from_dict classmethod

from_dict(data: dict[str, JSON]) -> Self

Create an instance of the model from a dictionary

Source code in zarr/codecs/numcodecs/_codecs.py
@classmethod
def from_dict(cls, data: dict[str, JSON]) -> Self:
    codec_config = _parse_codec_configuration(data)
    return cls(**codec_config)

resolve_metadata

resolve_metadata(chunk_spec: ArraySpec) -> 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_spec (ArraySpec) –

Returns:

  • ArraySpec
Source code in zarr/abc/codec.py
def resolve_metadata(self, chunk_spec: ArraySpec) -> 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_spec : ArraySpec

    Returns
    -------
    ArraySpec
    """
    return chunk_spec

to_dict

to_dict() -> dict[str, JSON]

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.

Source code in zarr/codecs/numcodecs/_codecs.py
def to_dict(self) -> dict[str, JSON]:
    codec_config = self.codec_config.copy()
    codec_config.pop("id", None)
    return {
        "name": self.codec_name,
        "configuration": codec_config,
    }

validate

validate(
    *,
    shape: tuple[int, ...],
    dtype: ZDType[TBaseDType, TBaseScalar],
    chunk_grid: ChunkGridMetadata,
) -> None

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

Parameters:

  • shape (tuple[int, ...]) –

    The array shape

  • dtype (dtype[Any]) –

    The array data type

  • chunk_grid (ChunkGridMetadata) –

    The array chunk grid metadata

Source code in zarr/abc/codec.py
def validate(
    self,
    *,
    shape: tuple[int, ...],
    dtype: ZDType[TBaseDType, TBaseScalar],
    chunk_grid: ChunkGridMetadata,
) -> None:
    """Validates that the codec configuration is compatible with the array metadata.
    Raises errors when the codec configuration is not compatible.

    Parameters
    ----------
    shape : tuple[int, ...]
        The array shape
    dtype : np.dtype[Any]
        The array data type
    chunk_grid : ChunkGridMetadata
        The array chunk grid metadata
    """

BitRound dataclass

Bases: _NumcodecsArrayArrayCodec

Source code in zarr/codecs/numcodecs/_codecs.py
class BitRound(_NumcodecsArrayArrayCodec, codec_name="bitround"):
    pass

codec_config instance-attribute

codec_config: dict[str, JSON]

codec_name instance-attribute

codec_name: str

is_fixed_size instance-attribute

is_fixed_size: bool

__init__

__init__(**codec_config: JSON) -> None
Source code in zarr/codecs/numcodecs/_codecs.py
def __init__(self, **codec_config: JSON) -> None:
    super().__init__(**codec_config)

__init_subclass__

__init_subclass__(
    *, codec_name: str | None = None, **kwargs: Any
) -> None

To be used only when creating the actual public-facing codec class.

Source code in zarr/codecs/numcodecs/_codecs.py
def __init_subclass__(cls, *, codec_name: str | None = None, **kwargs: Any) -> None:
    """To be used only when creating the actual public-facing codec class."""
    super().__init_subclass__(**kwargs)
    if codec_name is not None:
        namespace = codec_name

        cls_name = f"{CODEC_PREFIX}{namespace}.{cls.__name__}"
        cls.codec_name = f"{CODEC_PREFIX}{namespace}"
        cls.__doc__ = f"""
        See [{cls_name}][] for more details and parameters.
        """

__repr__

__repr__() -> str
Source code in zarr/codecs/numcodecs/_codecs.py
def __repr__(self) -> str:
    codec_config = self.codec_config.copy()
    codec_config.pop("id", None)
    return f"{self.__class__.__name__}(codec_name={self.codec_name!r}, codec_config={codec_config!r})"

compute_encoded_size

compute_encoded_size(
    input_byte_length: int, chunk_spec: ArraySpec
) -> int
Source code in zarr/codecs/numcodecs/_codecs.py
def compute_encoded_size(self, input_byte_length: int, chunk_spec: ArraySpec) -> int:
    raise NotImplementedError  # pragma: no cover

decode async

decode(
    chunks_and_specs: Iterable[tuple[CO | None, ArraySpec]],
) -> Iterable[CI | None]

Decodes a batch of chunks. Chunks can be None in which case they are ignored by the codec.

Parameters:

  • chunks_and_specs (Iterable[tuple[CodecOutput | None, ArraySpec]]) –

    Ordered set of encoded chunks with their accompanying chunk spec.

Returns:

Source code in zarr/abc/codec.py
async def decode(
    self,
    chunks_and_specs: Iterable[tuple[CO | None, ArraySpec]],
) -> Iterable[CI | None]:
    """Decodes a batch of chunks.
    Chunks can be None in which case they are ignored by the codec.

    Parameters
    ----------
    chunks_and_specs : Iterable[tuple[CodecOutput | None, ArraySpec]]
        Ordered set of encoded chunks with their accompanying chunk spec.

    Returns
    -------
    Iterable[CI | None]
    """
    return await _batching_helper(self._decode_single, chunks_and_specs)

encode async

encode(
    chunks_and_specs: Iterable[tuple[CI | None, ArraySpec]],
) -> Iterable[CO | None]

Encodes a batch of chunks. Chunks can be None in which case they are ignored by the codec.

Parameters:

  • chunks_and_specs (Iterable[tuple[CI | None, ArraySpec]]) –

    Ordered set of to-be-encoded chunks with their accompanying chunk spec.

Returns:

Source code in zarr/abc/codec.py
async def encode(
    self,
    chunks_and_specs: Iterable[tuple[CI | None, ArraySpec]],
) -> Iterable[CO | None]:
    """Encodes a batch of chunks.
    Chunks can be None in which case they are ignored by the codec.

    Parameters
    ----------
    chunks_and_specs : Iterable[tuple[CI | None, ArraySpec]]
        Ordered set of to-be-encoded chunks with their accompanying chunk spec.

    Returns
    -------
    Iterable[CodecOutput | None]
    """
    return await _batching_helper(self._encode_single, chunks_and_specs)

evolve_from_array_spec

evolve_from_array_spec(array_spec: ArraySpec) -> Self

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

Parameters:

  • array_spec (ArraySpec) –

Returns:

Source code in zarr/abc/codec.py
def evolve_from_array_spec(self, array_spec: ArraySpec) -> Self:
    """Fills in codec configuration parameters that can be automatically
    inferred from the array metadata.

    Parameters
    ----------
    array_spec : ArraySpec

    Returns
    -------
    Self
    """
    return self

from_dict classmethod

from_dict(data: dict[str, JSON]) -> Self

Create an instance of the model from a dictionary

Source code in zarr/codecs/numcodecs/_codecs.py
@classmethod
def from_dict(cls, data: dict[str, JSON]) -> Self:
    codec_config = _parse_codec_configuration(data)
    return cls(**codec_config)

resolve_metadata

resolve_metadata(chunk_spec: ArraySpec) -> 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_spec (ArraySpec) –

Returns:

  • ArraySpec
Source code in zarr/abc/codec.py
def resolve_metadata(self, chunk_spec: ArraySpec) -> 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_spec : ArraySpec

    Returns
    -------
    ArraySpec
    """
    return chunk_spec

to_dict

to_dict() -> dict[str, JSON]

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.

Source code in zarr/codecs/numcodecs/_codecs.py
def to_dict(self) -> dict[str, JSON]:
    codec_config = self.codec_config.copy()
    codec_config.pop("id", None)
    return {
        "name": self.codec_name,
        "configuration": codec_config,
    }

validate

validate(
    *,
    shape: tuple[int, ...],
    dtype: ZDType[TBaseDType, TBaseScalar],
    chunk_grid: ChunkGridMetadata,
) -> None

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

Parameters:

  • shape (tuple[int, ...]) –

    The array shape

  • dtype (dtype[Any]) –

    The array data type

  • chunk_grid (ChunkGridMetadata) –

    The array chunk grid metadata

Source code in zarr/abc/codec.py
def validate(
    self,
    *,
    shape: tuple[int, ...],
    dtype: ZDType[TBaseDType, TBaseScalar],
    chunk_grid: ChunkGridMetadata,
) -> None:
    """Validates that the codec configuration is compatible with the array metadata.
    Raises errors when the codec configuration is not compatible.

    Parameters
    ----------
    shape : tuple[int, ...]
        The array shape
    dtype : np.dtype[Any]
        The array data type
    chunk_grid : ChunkGridMetadata
        The array chunk grid metadata
    """

Blosc dataclass

Bases: _NumcodecsBytesBytesCodec

Source code in zarr/codecs/numcodecs/_codecs.py
class Blosc(_NumcodecsBytesBytesCodec, codec_name="blosc"):
    pass

codec_config instance-attribute

codec_config: dict[str, JSON]

codec_name instance-attribute

codec_name: str

is_fixed_size instance-attribute

is_fixed_size: bool

__init__

__init__(**codec_config: JSON) -> None
Source code in zarr/codecs/numcodecs/_codecs.py
def __init__(self, **codec_config: JSON) -> None:
    super().__init__(**codec_config)

__init_subclass__

__init_subclass__(
    *, codec_name: str | None = None, **kwargs: Any
) -> None

To be used only when creating the actual public-facing codec class.

Source code in zarr/codecs/numcodecs/_codecs.py
def __init_subclass__(cls, *, codec_name: str | None = None, **kwargs: Any) -> None:
    """To be used only when creating the actual public-facing codec class."""
    super().__init_subclass__(**kwargs)
    if codec_name is not None:
        namespace = codec_name

        cls_name = f"{CODEC_PREFIX}{namespace}.{cls.__name__}"
        cls.codec_name = f"{CODEC_PREFIX}{namespace}"
        cls.__doc__ = f"""
        See [{cls_name}][] for more details and parameters.
        """

__repr__

__repr__() -> str
Source code in zarr/codecs/numcodecs/_codecs.py
def __repr__(self) -> str:
    codec_config = self.codec_config.copy()
    codec_config.pop("id", None)
    return f"{self.__class__.__name__}(codec_name={self.codec_name!r}, codec_config={codec_config!r})"

compute_encoded_size

compute_encoded_size(
    input_byte_length: int, chunk_spec: ArraySpec
) -> int
Source code in zarr/codecs/numcodecs/_codecs.py
def compute_encoded_size(self, input_byte_length: int, chunk_spec: ArraySpec) -> int:
    raise NotImplementedError  # pragma: no cover

decode async

decode(
    chunks_and_specs: Iterable[tuple[CO | None, ArraySpec]],
) -> Iterable[CI | None]

Decodes a batch of chunks. Chunks can be None in which case they are ignored by the codec.

Parameters:

  • chunks_and_specs (Iterable[tuple[CodecOutput | None, ArraySpec]]) –

    Ordered set of encoded chunks with their accompanying chunk spec.

Returns:

Source code in zarr/abc/codec.py
async def decode(
    self,
    chunks_and_specs: Iterable[tuple[CO | None, ArraySpec]],
) -> Iterable[CI | None]:
    """Decodes a batch of chunks.
    Chunks can be None in which case they are ignored by the codec.

    Parameters
    ----------
    chunks_and_specs : Iterable[tuple[CodecOutput | None, ArraySpec]]
        Ordered set of encoded chunks with their accompanying chunk spec.

    Returns
    -------
    Iterable[CI | None]
    """
    return await _batching_helper(self._decode_single, chunks_and_specs)

encode async

encode(
    chunks_and_specs: Iterable[tuple[CI | None, ArraySpec]],
) -> Iterable[CO | None]

Encodes a batch of chunks. Chunks can be None in which case they are ignored by the codec.

Parameters:

  • chunks_and_specs (Iterable[tuple[CI | None, ArraySpec]]) –

    Ordered set of to-be-encoded chunks with their accompanying chunk spec.

Returns:

Source code in zarr/abc/codec.py
async def encode(
    self,
    chunks_and_specs: Iterable[tuple[CI | None, ArraySpec]],
) -> Iterable[CO | None]:
    """Encodes a batch of chunks.
    Chunks can be None in which case they are ignored by the codec.

    Parameters
    ----------
    chunks_and_specs : Iterable[tuple[CI | None, ArraySpec]]
        Ordered set of to-be-encoded chunks with their accompanying chunk spec.

    Returns
    -------
    Iterable[CodecOutput | None]
    """
    return await _batching_helper(self._encode_single, chunks_and_specs)

evolve_from_array_spec

evolve_from_array_spec(array_spec: ArraySpec) -> Self

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

Parameters:

  • array_spec (ArraySpec) –

Returns:

Source code in zarr/abc/codec.py
def evolve_from_array_spec(self, array_spec: ArraySpec) -> Self:
    """Fills in codec configuration parameters that can be automatically
    inferred from the array metadata.

    Parameters
    ----------
    array_spec : ArraySpec

    Returns
    -------
    Self
    """
    return self

from_dict classmethod

from_dict(data: dict[str, JSON]) -> Self

Create an instance of the model from a dictionary

Source code in zarr/codecs/numcodecs/_codecs.py
@classmethod
def from_dict(cls, data: dict[str, JSON]) -> Self:
    codec_config = _parse_codec_configuration(data)
    return cls(**codec_config)

resolve_metadata

resolve_metadata(chunk_spec: ArraySpec) -> 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_spec (ArraySpec) –

Returns:

  • ArraySpec
Source code in zarr/abc/codec.py
def resolve_metadata(self, chunk_spec: ArraySpec) -> 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_spec : ArraySpec

    Returns
    -------
    ArraySpec
    """
    return chunk_spec

to_dict

to_dict() -> dict[str, JSON]

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.

Source code in zarr/codecs/numcodecs/_codecs.py
def to_dict(self) -> dict[str, JSON]:
    codec_config = self.codec_config.copy()
    codec_config.pop("id", None)
    return {
        "name": self.codec_name,
        "configuration": codec_config,
    }

validate

validate(
    *,
    shape: tuple[int, ...],
    dtype: ZDType[TBaseDType, TBaseScalar],
    chunk_grid: ChunkGridMetadata,
) -> None

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

Parameters:

  • shape (tuple[int, ...]) –

    The array shape

  • dtype (dtype[Any]) –

    The array data type

  • chunk_grid (ChunkGridMetadata) –

    The array chunk grid metadata

Source code in zarr/abc/codec.py
def validate(
    self,
    *,
    shape: tuple[int, ...],
    dtype: ZDType[TBaseDType, TBaseScalar],
    chunk_grid: ChunkGridMetadata,
) -> None:
    """Validates that the codec configuration is compatible with the array metadata.
    Raises errors when the codec configuration is not compatible.

    Parameters
    ----------
    shape : tuple[int, ...]
        The array shape
    dtype : np.dtype[Any]
        The array data type
    chunk_grid : ChunkGridMetadata
        The array chunk grid metadata
    """

CRC32 dataclass

Bases: _NumcodecsChecksumCodec

Source code in zarr/codecs/numcodecs/_codecs.py
class CRC32(_NumcodecsChecksumCodec, codec_name="crc32"):
    pass

codec_config instance-attribute

codec_config: dict[str, JSON]

codec_name instance-attribute

codec_name: str

is_fixed_size instance-attribute

is_fixed_size: bool

__init__

__init__(**codec_config: JSON) -> None
Source code in zarr/codecs/numcodecs/_codecs.py
def __init__(self, **codec_config: JSON) -> None:
    super().__init__(**codec_config)

__init_subclass__

__init_subclass__(
    *, codec_name: str | None = None, **kwargs: Any
) -> None

To be used only when creating the actual public-facing codec class.

Source code in zarr/codecs/numcodecs/_codecs.py
def __init_subclass__(cls, *, codec_name: str | None = None, **kwargs: Any) -> None:
    """To be used only when creating the actual public-facing codec class."""
    super().__init_subclass__(**kwargs)
    if codec_name is not None:
        namespace = codec_name

        cls_name = f"{CODEC_PREFIX}{namespace}.{cls.__name__}"
        cls.codec_name = f"{CODEC_PREFIX}{namespace}"
        cls.__doc__ = f"""
        See [{cls_name}][] for more details and parameters.
        """

__repr__

__repr__() -> str
Source code in zarr/codecs/numcodecs/_codecs.py
def __repr__(self) -> str:
    codec_config = self.codec_config.copy()
    codec_config.pop("id", None)
    return f"{self.__class__.__name__}(codec_name={self.codec_name!r}, codec_config={codec_config!r})"

compute_encoded_size

compute_encoded_size(
    input_byte_length: int, chunk_spec: ArraySpec
) -> int
Source code in zarr/codecs/numcodecs/_codecs.py
def compute_encoded_size(self, input_byte_length: int, chunk_spec: ArraySpec) -> int:
    return input_byte_length + 4  # pragma: no cover

decode async

decode(
    chunks_and_specs: Iterable[tuple[CO | None, ArraySpec]],
) -> Iterable[CI | None]

Decodes a batch of chunks. Chunks can be None in which case they are ignored by the codec.

Parameters:

  • chunks_and_specs (Iterable[tuple[CodecOutput | None, ArraySpec]]) –

    Ordered set of encoded chunks with their accompanying chunk spec.

Returns:

Source code in zarr/abc/codec.py
async def decode(
    self,
    chunks_and_specs: Iterable[tuple[CO | None, ArraySpec]],
) -> Iterable[CI | None]:
    """Decodes a batch of chunks.
    Chunks can be None in which case they are ignored by the codec.

    Parameters
    ----------
    chunks_and_specs : Iterable[tuple[CodecOutput | None, ArraySpec]]
        Ordered set of encoded chunks with their accompanying chunk spec.

    Returns
    -------
    Iterable[CI | None]
    """
    return await _batching_helper(self._decode_single, chunks_and_specs)

encode async

encode(
    chunks_and_specs: Iterable[tuple[CI | None, ArraySpec]],
) -> Iterable[CO | None]

Encodes a batch of chunks. Chunks can be None in which case they are ignored by the codec.

Parameters:

  • chunks_and_specs (Iterable[tuple[CI | None, ArraySpec]]) –

    Ordered set of to-be-encoded chunks with their accompanying chunk spec.

Returns:

Source code in zarr/abc/codec.py
async def encode(
    self,
    chunks_and_specs: Iterable[tuple[CI | None, ArraySpec]],
) -> Iterable[CO | None]:
    """Encodes a batch of chunks.
    Chunks can be None in which case they are ignored by the codec.

    Parameters
    ----------
    chunks_and_specs : Iterable[tuple[CI | None, ArraySpec]]
        Ordered set of to-be-encoded chunks with their accompanying chunk spec.

    Returns
    -------
    Iterable[CodecOutput | None]
    """
    return await _batching_helper(self._encode_single, chunks_and_specs)

evolve_from_array_spec

evolve_from_array_spec(array_spec: ArraySpec) -> Self

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

Parameters:

  • array_spec (ArraySpec) –

Returns:

Source code in zarr/abc/codec.py
def evolve_from_array_spec(self, array_spec: ArraySpec) -> Self:
    """Fills in codec configuration parameters that can be automatically
    inferred from the array metadata.

    Parameters
    ----------
    array_spec : ArraySpec

    Returns
    -------
    Self
    """
    return self

from_dict classmethod

from_dict(data: dict[str, JSON]) -> Self

Create an instance of the model from a dictionary

Source code in zarr/codecs/numcodecs/_codecs.py
@classmethod
def from_dict(cls, data: dict[str, JSON]) -> Self:
    codec_config = _parse_codec_configuration(data)
    return cls(**codec_config)

resolve_metadata

resolve_metadata(chunk_spec: ArraySpec) -> 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_spec (ArraySpec) –

Returns:

  • ArraySpec
Source code in zarr/abc/codec.py
def resolve_metadata(self, chunk_spec: ArraySpec) -> 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_spec : ArraySpec

    Returns
    -------
    ArraySpec
    """
    return chunk_spec

to_dict

to_dict() -> dict[str, JSON]

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.

Source code in zarr/codecs/numcodecs/_codecs.py
def to_dict(self) -> dict[str, JSON]:
    codec_config = self.codec_config.copy()
    codec_config.pop("id", None)
    return {
        "name": self.codec_name,
        "configuration": codec_config,
    }

validate

validate(
    *,
    shape: tuple[int, ...],
    dtype: ZDType[TBaseDType, TBaseScalar],
    chunk_grid: ChunkGridMetadata,
) -> None

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

Parameters:

  • shape (tuple[int, ...]) –

    The array shape

  • dtype (dtype[Any]) –

    The array data type

  • chunk_grid (ChunkGridMetadata) –

    The array chunk grid metadata

Source code in zarr/abc/codec.py
def validate(
    self,
    *,
    shape: tuple[int, ...],
    dtype: ZDType[TBaseDType, TBaseScalar],
    chunk_grid: ChunkGridMetadata,
) -> None:
    """Validates that the codec configuration is compatible with the array metadata.
    Raises errors when the codec configuration is not compatible.

    Parameters
    ----------
    shape : tuple[int, ...]
        The array shape
    dtype : np.dtype[Any]
        The array data type
    chunk_grid : ChunkGridMetadata
        The array chunk grid metadata
    """

CRC32C dataclass

Bases: _NumcodecsChecksumCodec

Source code in zarr/codecs/numcodecs/_codecs.py
class CRC32C(_NumcodecsChecksumCodec, codec_name="crc32c"):
    pass

codec_config instance-attribute

codec_config: dict[str, JSON]

codec_name instance-attribute

codec_name: str

is_fixed_size instance-attribute

is_fixed_size: bool

__init__

__init__(**codec_config: JSON) -> None
Source code in zarr/codecs/numcodecs/_codecs.py
def __init__(self, **codec_config: JSON) -> None:
    super().__init__(**codec_config)

__init_subclass__

__init_subclass__(
    *, codec_name: str | None = None, **kwargs: Any
) -> None

To be used only when creating the actual public-facing codec class.

Source code in zarr/codecs/numcodecs/_codecs.py
def __init_subclass__(cls, *, codec_name: str | None = None, **kwargs: Any) -> None:
    """To be used only when creating the actual public-facing codec class."""
    super().__init_subclass__(**kwargs)
    if codec_name is not None:
        namespace = codec_name

        cls_name = f"{CODEC_PREFIX}{namespace}.{cls.__name__}"
        cls.codec_name = f"{CODEC_PREFIX}{namespace}"
        cls.__doc__ = f"""
        See [{cls_name}][] for more details and parameters.
        """

__repr__

__repr__() -> str
Source code in zarr/codecs/numcodecs/_codecs.py
def __repr__(self) -> str:
    codec_config = self.codec_config.copy()
    codec_config.pop("id", None)
    return f"{self.__class__.__name__}(codec_name={self.codec_name!r}, codec_config={codec_config!r})"

compute_encoded_size

compute_encoded_size(
    input_byte_length: int, chunk_spec: ArraySpec
) -> int
Source code in zarr/codecs/numcodecs/_codecs.py
def compute_encoded_size(self, input_byte_length: int, chunk_spec: ArraySpec) -> int:
    return input_byte_length + 4  # pragma: no cover

decode async

decode(
    chunks_and_specs: Iterable[tuple[CO | None, ArraySpec]],
) -> Iterable[CI | None]

Decodes a batch of chunks. Chunks can be None in which case they are ignored by the codec.

Parameters:

  • chunks_and_specs (Iterable[tuple[CodecOutput | None, ArraySpec]]) –

    Ordered set of encoded chunks with their accompanying chunk spec.

Returns:

Source code in zarr/abc/codec.py
async def decode(
    self,
    chunks_and_specs: Iterable[tuple[CO | None, ArraySpec]],
) -> Iterable[CI | None]:
    """Decodes a batch of chunks.
    Chunks can be None in which case they are ignored by the codec.

    Parameters
    ----------
    chunks_and_specs : Iterable[tuple[CodecOutput | None, ArraySpec]]
        Ordered set of encoded chunks with their accompanying chunk spec.

    Returns
    -------
    Iterable[CI | None]
    """
    return await _batching_helper(self._decode_single, chunks_and_specs)

encode async

encode(
    chunks_and_specs: Iterable[tuple[CI | None, ArraySpec]],
) -> Iterable[CO | None]

Encodes a batch of chunks. Chunks can be None in which case they are ignored by the codec.

Parameters:

  • chunks_and_specs (Iterable[tuple[CI | None, ArraySpec]]) –

    Ordered set of to-be-encoded chunks with their accompanying chunk spec.

Returns:

Source code in zarr/abc/codec.py
async def encode(
    self,
    chunks_and_specs: Iterable[tuple[CI | None, ArraySpec]],
) -> Iterable[CO | None]:
    """Encodes a batch of chunks.
    Chunks can be None in which case they are ignored by the codec.

    Parameters
    ----------
    chunks_and_specs : Iterable[tuple[CI | None, ArraySpec]]
        Ordered set of to-be-encoded chunks with their accompanying chunk spec.

    Returns
    -------
    Iterable[CodecOutput | None]
    """
    return await _batching_helper(self._encode_single, chunks_and_specs)

evolve_from_array_spec

evolve_from_array_spec(array_spec: ArraySpec) -> Self

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

Parameters:

  • array_spec (ArraySpec) –

Returns:

Source code in zarr/abc/codec.py
def evolve_from_array_spec(self, array_spec: ArraySpec) -> Self:
    """Fills in codec configuration parameters that can be automatically
    inferred from the array metadata.

    Parameters
    ----------
    array_spec : ArraySpec

    Returns
    -------
    Self
    """
    return self

from_dict classmethod

from_dict(data: dict[str, JSON]) -> Self

Create an instance of the model from a dictionary

Source code in zarr/codecs/numcodecs/_codecs.py
@classmethod
def from_dict(cls, data: dict[str, JSON]) -> Self:
    codec_config = _parse_codec_configuration(data)
    return cls(**codec_config)

resolve_metadata

resolve_metadata(chunk_spec: ArraySpec) -> 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_spec (ArraySpec) –

Returns:

  • ArraySpec
Source code in zarr/abc/codec.py
def resolve_metadata(self, chunk_spec: ArraySpec) -> 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_spec : ArraySpec

    Returns
    -------
    ArraySpec
    """
    return chunk_spec

to_dict

to_dict() -> dict[str, JSON]

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.

Source code in zarr/codecs/numcodecs/_codecs.py
def to_dict(self) -> dict[str, JSON]:
    codec_config = self.codec_config.copy()
    codec_config.pop("id", None)
    return {
        "name": self.codec_name,
        "configuration": codec_config,
    }

validate

validate(
    *,
    shape: tuple[int, ...],
    dtype: ZDType[TBaseDType, TBaseScalar],
    chunk_grid: ChunkGridMetadata,
) -> None

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

Parameters:

  • shape (tuple[int, ...]) –

    The array shape

  • dtype (dtype[Any]) –

    The array data type

  • chunk_grid (ChunkGridMetadata) –

    The array chunk grid metadata

Source code in zarr/abc/codec.py
def validate(
    self,
    *,
    shape: tuple[int, ...],
    dtype: ZDType[TBaseDType, TBaseScalar],
    chunk_grid: ChunkGridMetadata,
) -> None:
    """Validates that the codec configuration is compatible with the array metadata.
    Raises errors when the codec configuration is not compatible.

    Parameters
    ----------
    shape : tuple[int, ...]
        The array shape
    dtype : np.dtype[Any]
        The array data type
    chunk_grid : ChunkGridMetadata
        The array chunk grid metadata
    """

Delta dataclass

Bases: _NumcodecsArrayArrayCodec

Source code in zarr/codecs/numcodecs/_codecs.py
class Delta(_NumcodecsArrayArrayCodec, codec_name="delta"):
    def resolve_metadata(self, chunk_spec: ArraySpec) -> ArraySpec:
        if astype := self.codec_config.get("astype"):
            dtype = parse_dtype(np.dtype(astype), zarr_format=3)  # type: ignore[call-overload]
            return replace(chunk_spec, dtype=dtype)
        return chunk_spec

codec_config instance-attribute

codec_config: dict[str, JSON]

codec_name instance-attribute

codec_name: str

is_fixed_size instance-attribute

is_fixed_size: bool

__init__

__init__(**codec_config: JSON) -> None
Source code in zarr/codecs/numcodecs/_codecs.py
def __init__(self, **codec_config: JSON) -> None:
    super().__init__(**codec_config)

__init_subclass__

__init_subclass__(
    *, codec_name: str | None = None, **kwargs: Any
) -> None

To be used only when creating the actual public-facing codec class.

Source code in zarr/codecs/numcodecs/_codecs.py
def __init_subclass__(cls, *, codec_name: str | None = None, **kwargs: Any) -> None:
    """To be used only when creating the actual public-facing codec class."""
    super().__init_subclass__(**kwargs)
    if codec_name is not None:
        namespace = codec_name

        cls_name = f"{CODEC_PREFIX}{namespace}.{cls.__name__}"
        cls.codec_name = f"{CODEC_PREFIX}{namespace}"
        cls.__doc__ = f"""
        See [{cls_name}][] for more details and parameters.
        """

__repr__

__repr__() -> str
Source code in zarr/codecs/numcodecs/_codecs.py
def __repr__(self) -> str:
    codec_config = self.codec_config.copy()
    codec_config.pop("id", None)
    return f"{self.__class__.__name__}(codec_name={self.codec_name!r}, codec_config={codec_config!r})"

compute_encoded_size

compute_encoded_size(
    input_byte_length: int, chunk_spec: ArraySpec
) -> int
Source code in zarr/codecs/numcodecs/_codecs.py
def compute_encoded_size(self, input_byte_length: int, chunk_spec: ArraySpec) -> int:
    raise NotImplementedError  # pragma: no cover

decode async

decode(
    chunks_and_specs: Iterable[tuple[CO | None, ArraySpec]],
) -> Iterable[CI | None]

Decodes a batch of chunks. Chunks can be None in which case they are ignored by the codec.

Parameters:

  • chunks_and_specs (Iterable[tuple[CodecOutput | None, ArraySpec]]) –

    Ordered set of encoded chunks with their accompanying chunk spec.

Returns:

Source code in zarr/abc/codec.py
async def decode(
    self,
    chunks_and_specs: Iterable[tuple[CO | None, ArraySpec]],
) -> Iterable[CI | None]:
    """Decodes a batch of chunks.
    Chunks can be None in which case they are ignored by the codec.

    Parameters
    ----------
    chunks_and_specs : Iterable[tuple[CodecOutput | None, ArraySpec]]
        Ordered set of encoded chunks with their accompanying chunk spec.

    Returns
    -------
    Iterable[CI | None]
    """
    return await _batching_helper(self._decode_single, chunks_and_specs)

encode async

encode(
    chunks_and_specs: Iterable[tuple[CI | None, ArraySpec]],
) -> Iterable[CO | None]

Encodes a batch of chunks. Chunks can be None in which case they are ignored by the codec.

Parameters:

  • chunks_and_specs (Iterable[tuple[CI | None, ArraySpec]]) –

    Ordered set of to-be-encoded chunks with their accompanying chunk spec.

Returns:

Source code in zarr/abc/codec.py
async def encode(
    self,
    chunks_and_specs: Iterable[tuple[CI | None, ArraySpec]],
) -> Iterable[CO | None]:
    """Encodes a batch of chunks.
    Chunks can be None in which case they are ignored by the codec.

    Parameters
    ----------
    chunks_and_specs : Iterable[tuple[CI | None, ArraySpec]]
        Ordered set of to-be-encoded chunks with their accompanying chunk spec.

    Returns
    -------
    Iterable[CodecOutput | None]
    """
    return await _batching_helper(self._encode_single, chunks_and_specs)

evolve_from_array_spec

evolve_from_array_spec(array_spec: ArraySpec) -> Self

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

Parameters:

  • array_spec (ArraySpec) –

Returns:

Source code in zarr/abc/codec.py
def evolve_from_array_spec(self, array_spec: ArraySpec) -> Self:
    """Fills in codec configuration parameters that can be automatically
    inferred from the array metadata.

    Parameters
    ----------
    array_spec : ArraySpec

    Returns
    -------
    Self
    """
    return self

from_dict classmethod

from_dict(data: dict[str, JSON]) -> Self

Create an instance of the model from a dictionary

Source code in zarr/codecs/numcodecs/_codecs.py
@classmethod
def from_dict(cls, data: dict[str, JSON]) -> Self:
    codec_config = _parse_codec_configuration(data)
    return cls(**codec_config)

resolve_metadata

resolve_metadata(chunk_spec: ArraySpec) -> 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_spec (ArraySpec) –

Returns:

  • ArraySpec
Source code in zarr/codecs/numcodecs/_codecs.py
def resolve_metadata(self, chunk_spec: ArraySpec) -> ArraySpec:
    if astype := self.codec_config.get("astype"):
        dtype = parse_dtype(np.dtype(astype), zarr_format=3)  # type: ignore[call-overload]
        return replace(chunk_spec, dtype=dtype)
    return chunk_spec

to_dict

to_dict() -> dict[str, JSON]

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.

Source code in zarr/codecs/numcodecs/_codecs.py
def to_dict(self) -> dict[str, JSON]:
    codec_config = self.codec_config.copy()
    codec_config.pop("id", None)
    return {
        "name": self.codec_name,
        "configuration": codec_config,
    }

validate

validate(
    *,
    shape: tuple[int, ...],
    dtype: ZDType[TBaseDType, TBaseScalar],
    chunk_grid: ChunkGridMetadata,
) -> None

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

Parameters:

  • shape (tuple[int, ...]) –

    The array shape

  • dtype (dtype[Any]) –

    The array data type

  • chunk_grid (ChunkGridMetadata) –

    The array chunk grid metadata

Source code in zarr/abc/codec.py
def validate(
    self,
    *,
    shape: tuple[int, ...],
    dtype: ZDType[TBaseDType, TBaseScalar],
    chunk_grid: ChunkGridMetadata,
) -> None:
    """Validates that the codec configuration is compatible with the array metadata.
    Raises errors when the codec configuration is not compatible.

    Parameters
    ----------
    shape : tuple[int, ...]
        The array shape
    dtype : np.dtype[Any]
        The array data type
    chunk_grid : ChunkGridMetadata
        The array chunk grid metadata
    """

FixedScaleOffset dataclass

Bases: _NumcodecsArrayArrayCodec

Source code in zarr/codecs/numcodecs/_codecs.py
class FixedScaleOffset(_NumcodecsArrayArrayCodec, codec_name="fixedscaleoffset"):
    def resolve_metadata(self, chunk_spec: ArraySpec) -> ArraySpec:
        if astype := self.codec_config.get("astype"):
            dtype = parse_dtype(np.dtype(astype), zarr_format=3)  # type: ignore[call-overload]
            return replace(chunk_spec, dtype=dtype)
        return chunk_spec

    def evolve_from_array_spec(self, array_spec: ArraySpec) -> FixedScaleOffset:
        if self.codec_config.get("dtype") is None:
            dtype = array_spec.dtype.to_native_dtype()
            return FixedScaleOffset(**{**self.codec_config, "dtype": str(dtype)})
        return self

codec_config instance-attribute

codec_config: dict[str, JSON]

codec_name instance-attribute

codec_name: str

is_fixed_size instance-attribute

is_fixed_size: bool

__init__

__init__(**codec_config: JSON) -> None
Source code in zarr/codecs/numcodecs/_codecs.py
def __init__(self, **codec_config: JSON) -> None:
    super().__init__(**codec_config)

__init_subclass__

__init_subclass__(
    *, codec_name: str | None = None, **kwargs: Any
) -> None

To be used only when creating the actual public-facing codec class.

Source code in zarr/codecs/numcodecs/_codecs.py
def __init_subclass__(cls, *, codec_name: str | None = None, **kwargs: Any) -> None:
    """To be used only when creating the actual public-facing codec class."""
    super().__init_subclass__(**kwargs)
    if codec_name is not None:
        namespace = codec_name

        cls_name = f"{CODEC_PREFIX}{namespace}.{cls.__name__}"
        cls.codec_name = f"{CODEC_PREFIX}{namespace}"
        cls.__doc__ = f"""
        See [{cls_name}][] for more details and parameters.
        """

__repr__

__repr__() -> str
Source code in zarr/codecs/numcodecs/_codecs.py
def __repr__(self) -> str:
    codec_config = self.codec_config.copy()
    codec_config.pop("id", None)
    return f"{self.__class__.__name__}(codec_name={self.codec_name!r}, codec_config={codec_config!r})"

compute_encoded_size

compute_encoded_size(
    input_byte_length: int, chunk_spec: ArraySpec
) -> int
Source code in zarr/codecs/numcodecs/_codecs.py
def compute_encoded_size(self, input_byte_length: int, chunk_spec: ArraySpec) -> int:
    raise NotImplementedError  # pragma: no cover

decode async

decode(
    chunks_and_specs: Iterable[tuple[CO | None, ArraySpec]],
) -> Iterable[CI | None]

Decodes a batch of chunks. Chunks can be None in which case they are ignored by the codec.

Parameters:

  • chunks_and_specs (Iterable[tuple[CodecOutput | None, ArraySpec]]) –

    Ordered set of encoded chunks with their accompanying chunk spec.

Returns:

Source code in zarr/abc/codec.py
async def decode(
    self,
    chunks_and_specs: Iterable[tuple[CO | None, ArraySpec]],
) -> Iterable[CI | None]:
    """Decodes a batch of chunks.
    Chunks can be None in which case they are ignored by the codec.

    Parameters
    ----------
    chunks_and_specs : Iterable[tuple[CodecOutput | None, ArraySpec]]
        Ordered set of encoded chunks with their accompanying chunk spec.

    Returns
    -------
    Iterable[CI | None]
    """
    return await _batching_helper(self._decode_single, chunks_and_specs)

encode async

encode(
    chunks_and_specs: Iterable[tuple[CI | None, ArraySpec]],
) -> Iterable[CO | None]

Encodes a batch of chunks. Chunks can be None in which case they are ignored by the codec.

Parameters:

  • chunks_and_specs (Iterable[tuple[CI | None, ArraySpec]]) –

    Ordered set of to-be-encoded chunks with their accompanying chunk spec.

Returns:

Source code in zarr/abc/codec.py
async def encode(
    self,
    chunks_and_specs: Iterable[tuple[CI | None, ArraySpec]],
) -> Iterable[CO | None]:
    """Encodes a batch of chunks.
    Chunks can be None in which case they are ignored by the codec.

    Parameters
    ----------
    chunks_and_specs : Iterable[tuple[CI | None, ArraySpec]]
        Ordered set of to-be-encoded chunks with their accompanying chunk spec.

    Returns
    -------
    Iterable[CodecOutput | None]
    """
    return await _batching_helper(self._encode_single, chunks_and_specs)

evolve_from_array_spec

evolve_from_array_spec(
    array_spec: ArraySpec,
) -> FixedScaleOffset

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

Parameters:

  • array_spec (ArraySpec) –

Returns:

Source code in zarr/codecs/numcodecs/_codecs.py
def evolve_from_array_spec(self, array_spec: ArraySpec) -> FixedScaleOffset:
    if self.codec_config.get("dtype") is None:
        dtype = array_spec.dtype.to_native_dtype()
        return FixedScaleOffset(**{**self.codec_config, "dtype": str(dtype)})
    return self

from_dict classmethod

from_dict(data: dict[str, JSON]) -> Self

Create an instance of the model from a dictionary

Source code in zarr/codecs/numcodecs/_codecs.py
@classmethod
def from_dict(cls, data: dict[str, JSON]) -> Self:
    codec_config = _parse_codec_configuration(data)
    return cls(**codec_config)

resolve_metadata

resolve_metadata(chunk_spec: ArraySpec) -> 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_spec (ArraySpec) –

Returns:

  • ArraySpec
Source code in zarr/codecs/numcodecs/_codecs.py
def resolve_metadata(self, chunk_spec: ArraySpec) -> ArraySpec:
    if astype := self.codec_config.get("astype"):
        dtype = parse_dtype(np.dtype(astype), zarr_format=3)  # type: ignore[call-overload]
        return replace(chunk_spec, dtype=dtype)
    return chunk_spec

to_dict

to_dict() -> dict[str, JSON]

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.

Source code in zarr/codecs/numcodecs/_codecs.py
def to_dict(self) -> dict[str, JSON]:
    codec_config = self.codec_config.copy()
    codec_config.pop("id", None)
    return {
        "name": self.codec_name,
        "configuration": codec_config,
    }

validate

validate(
    *,
    shape: tuple[int, ...],
    dtype: ZDType[TBaseDType, TBaseScalar],
    chunk_grid: ChunkGridMetadata,
) -> None

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

Parameters:

  • shape (tuple[int, ...]) –

    The array shape

  • dtype (dtype[Any]) –

    The array data type

  • chunk_grid (ChunkGridMetadata) –

    The array chunk grid metadata

Source code in zarr/abc/codec.py
def validate(
    self,
    *,
    shape: tuple[int, ...],
    dtype: ZDType[TBaseDType, TBaseScalar],
    chunk_grid: ChunkGridMetadata,
) -> None:
    """Validates that the codec configuration is compatible with the array metadata.
    Raises errors when the codec configuration is not compatible.

    Parameters
    ----------
    shape : tuple[int, ...]
        The array shape
    dtype : np.dtype[Any]
        The array data type
    chunk_grid : ChunkGridMetadata
        The array chunk grid metadata
    """

Fletcher32 dataclass

Bases: _NumcodecsChecksumCodec

Source code in zarr/codecs/numcodecs/_codecs.py
class Fletcher32(_NumcodecsChecksumCodec, codec_name="fletcher32"):
    pass

codec_config instance-attribute

codec_config: dict[str, JSON]

codec_name instance-attribute

codec_name: str

is_fixed_size instance-attribute

is_fixed_size: bool

__init__

__init__(**codec_config: JSON) -> None
Source code in zarr/codecs/numcodecs/_codecs.py
def __init__(self, **codec_config: JSON) -> None:
    super().__init__(**codec_config)

__init_subclass__

__init_subclass__(
    *, codec_name: str | None = None, **kwargs: Any
) -> None

To be used only when creating the actual public-facing codec class.

Source code in zarr/codecs/numcodecs/_codecs.py
def __init_subclass__(cls, *, codec_name: str | None = None, **kwargs: Any) -> None:
    """To be used only when creating the actual public-facing codec class."""
    super().__init_subclass__(**kwargs)
    if codec_name is not None:
        namespace = codec_name

        cls_name = f"{CODEC_PREFIX}{namespace}.{cls.__name__}"
        cls.codec_name = f"{CODEC_PREFIX}{namespace}"
        cls.__doc__ = f"""
        See [{cls_name}][] for more details and parameters.
        """

__repr__

__repr__() -> str
Source code in zarr/codecs/numcodecs/_codecs.py
def __repr__(self) -> str:
    codec_config = self.codec_config.copy()
    codec_config.pop("id", None)
    return f"{self.__class__.__name__}(codec_name={self.codec_name!r}, codec_config={codec_config!r})"

compute_encoded_size

compute_encoded_size(
    input_byte_length: int, chunk_spec: ArraySpec
) -> int
Source code in zarr/codecs/numcodecs/_codecs.py
def compute_encoded_size(self, input_byte_length: int, chunk_spec: ArraySpec) -> int:
    return input_byte_length + 4  # pragma: no cover

decode async

decode(
    chunks_and_specs: Iterable[tuple[CO | None, ArraySpec]],
) -> Iterable[CI | None]

Decodes a batch of chunks. Chunks can be None in which case they are ignored by the codec.

Parameters:

  • chunks_and_specs (Iterable[tuple[CodecOutput | None, ArraySpec]]) –

    Ordered set of encoded chunks with their accompanying chunk spec.

Returns:

Source code in zarr/abc/codec.py
async def decode(
    self,
    chunks_and_specs: Iterable[tuple[CO | None, ArraySpec]],
) -> Iterable[CI | None]:
    """Decodes a batch of chunks.
    Chunks can be None in which case they are ignored by the codec.

    Parameters
    ----------
    chunks_and_specs : Iterable[tuple[CodecOutput | None, ArraySpec]]
        Ordered set of encoded chunks with their accompanying chunk spec.

    Returns
    -------
    Iterable[CI | None]
    """
    return await _batching_helper(self._decode_single, chunks_and_specs)

encode async

encode(
    chunks_and_specs: Iterable[tuple[CI | None, ArraySpec]],
) -> Iterable[CO | None]

Encodes a batch of chunks. Chunks can be None in which case they are ignored by the codec.

Parameters:

  • chunks_and_specs (Iterable[tuple[CI | None, ArraySpec]]) –

    Ordered set of to-be-encoded chunks with their accompanying chunk spec.

Returns:

Source code in zarr/abc/codec.py
async def encode(
    self,
    chunks_and_specs: Iterable[tuple[CI | None, ArraySpec]],
) -> Iterable[CO | None]:
    """Encodes a batch of chunks.
    Chunks can be None in which case they are ignored by the codec.

    Parameters
    ----------
    chunks_and_specs : Iterable[tuple[CI | None, ArraySpec]]
        Ordered set of to-be-encoded chunks with their accompanying chunk spec.

    Returns
    -------
    Iterable[CodecOutput | None]
    """
    return await _batching_helper(self._encode_single, chunks_and_specs)

evolve_from_array_spec

evolve_from_array_spec(array_spec: ArraySpec) -> Self

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

Parameters:

  • array_spec (ArraySpec) –

Returns:

Source code in zarr/abc/codec.py
def evolve_from_array_spec(self, array_spec: ArraySpec) -> Self:
    """Fills in codec configuration parameters that can be automatically
    inferred from the array metadata.

    Parameters
    ----------
    array_spec : ArraySpec

    Returns
    -------
    Self
    """
    return self

from_dict classmethod

from_dict(data: dict[str, JSON]) -> Self

Create an instance of the model from a dictionary

Source code in zarr/codecs/numcodecs/_codecs.py
@classmethod
def from_dict(cls, data: dict[str, JSON]) -> Self:
    codec_config = _parse_codec_configuration(data)
    return cls(**codec_config)

resolve_metadata

resolve_metadata(chunk_spec: ArraySpec) -> 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_spec (ArraySpec) –

Returns:

  • ArraySpec
Source code in zarr/abc/codec.py
def resolve_metadata(self, chunk_spec: ArraySpec) -> 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_spec : ArraySpec

    Returns
    -------
    ArraySpec
    """
    return chunk_spec

to_dict

to_dict() -> dict[str, JSON]

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.

Source code in zarr/codecs/numcodecs/_codecs.py
def to_dict(self) -> dict[str, JSON]:
    codec_config = self.codec_config.copy()
    codec_config.pop("id", None)
    return {
        "name": self.codec_name,
        "configuration": codec_config,
    }

validate

validate(
    *,
    shape: tuple[int, ...],
    dtype: ZDType[TBaseDType, TBaseScalar],
    chunk_grid: ChunkGridMetadata,
) -> None

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

Parameters:

  • shape (tuple[int, ...]) –

    The array shape

  • dtype (dtype[Any]) –

    The array data type

  • chunk_grid (ChunkGridMetadata) –

    The array chunk grid metadata

Source code in zarr/abc/codec.py
def validate(
    self,
    *,
    shape: tuple[int, ...],
    dtype: ZDType[TBaseDType, TBaseScalar],
    chunk_grid: ChunkGridMetadata,
) -> None:
    """Validates that the codec configuration is compatible with the array metadata.
    Raises errors when the codec configuration is not compatible.

    Parameters
    ----------
    shape : tuple[int, ...]
        The array shape
    dtype : np.dtype[Any]
        The array data type
    chunk_grid : ChunkGridMetadata
        The array chunk grid metadata
    """

GZip dataclass

Bases: _NumcodecsBytesBytesCodec

Source code in zarr/codecs/numcodecs/_codecs.py
class GZip(_NumcodecsBytesBytesCodec, codec_name="gzip"):
    pass

codec_config instance-attribute

codec_config: dict[str, JSON]

codec_name instance-attribute

codec_name: str

is_fixed_size instance-attribute

is_fixed_size: bool

__init__

__init__(**codec_config: JSON) -> None
Source code in zarr/codecs/numcodecs/_codecs.py
def __init__(self, **codec_config: JSON) -> None:
    super().__init__(**codec_config)

__init_subclass__

__init_subclass__(
    *, codec_name: str | None = None, **kwargs: Any
) -> None

To be used only when creating the actual public-facing codec class.

Source code in zarr/codecs/numcodecs/_codecs.py
def __init_subclass__(cls, *, codec_name: str | None = None, **kwargs: Any) -> None:
    """To be used only when creating the actual public-facing codec class."""
    super().__init_subclass__(**kwargs)
    if codec_name is not None:
        namespace = codec_name

        cls_name = f"{CODEC_PREFIX}{namespace}.{cls.__name__}"
        cls.codec_name = f"{CODEC_PREFIX}{namespace}"
        cls.__doc__ = f"""
        See [{cls_name}][] for more details and parameters.
        """

__repr__

__repr__() -> str
Source code in zarr/codecs/numcodecs/_codecs.py
def __repr__(self) -> str:
    codec_config = self.codec_config.copy()
    codec_config.pop("id", None)
    return f"{self.__class__.__name__}(codec_name={self.codec_name!r}, codec_config={codec_config!r})"

compute_encoded_size

compute_encoded_size(
    input_byte_length: int, chunk_spec: ArraySpec
) -> int
Source code in zarr/codecs/numcodecs/_codecs.py
def compute_encoded_size(self, input_byte_length: int, chunk_spec: ArraySpec) -> int:
    raise NotImplementedError  # pragma: no cover

decode async

decode(
    chunks_and_specs: Iterable[tuple[CO | None, ArraySpec]],
) -> Iterable[CI | None]

Decodes a batch of chunks. Chunks can be None in which case they are ignored by the codec.

Parameters:

  • chunks_and_specs (Iterable[tuple[CodecOutput | None, ArraySpec]]) –

    Ordered set of encoded chunks with their accompanying chunk spec.

Returns:

Source code in zarr/abc/codec.py
async def decode(
    self,
    chunks_and_specs: Iterable[tuple[CO | None, ArraySpec]],
) -> Iterable[CI | None]:
    """Decodes a batch of chunks.
    Chunks can be None in which case they are ignored by the codec.

    Parameters
    ----------
    chunks_and_specs : Iterable[tuple[CodecOutput | None, ArraySpec]]
        Ordered set of encoded chunks with their accompanying chunk spec.

    Returns
    -------
    Iterable[CI | None]
    """
    return await _batching_helper(self._decode_single, chunks_and_specs)

encode async

encode(
    chunks_and_specs: Iterable[tuple[CI | None, ArraySpec]],
) -> Iterable[CO | None]

Encodes a batch of chunks. Chunks can be None in which case they are ignored by the codec.

Parameters:

  • chunks_and_specs (Iterable[tuple[CI | None, ArraySpec]]) –

    Ordered set of to-be-encoded chunks with their accompanying chunk spec.

Returns:

Source code in zarr/abc/codec.py
async def encode(
    self,
    chunks_and_specs: Iterable[tuple[CI | None, ArraySpec]],
) -> Iterable[CO | None]:
    """Encodes a batch of chunks.
    Chunks can be None in which case they are ignored by the codec.

    Parameters
    ----------
    chunks_and_specs : Iterable[tuple[CI | None, ArraySpec]]
        Ordered set of to-be-encoded chunks with their accompanying chunk spec.

    Returns
    -------
    Iterable[CodecOutput | None]
    """
    return await _batching_helper(self._encode_single, chunks_and_specs)

evolve_from_array_spec

evolve_from_array_spec(array_spec: ArraySpec) -> Self

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

Parameters:

  • array_spec (ArraySpec) –

Returns:

Source code in zarr/abc/codec.py
def evolve_from_array_spec(self, array_spec: ArraySpec) -> Self:
    """Fills in codec configuration parameters that can be automatically
    inferred from the array metadata.

    Parameters
    ----------
    array_spec : ArraySpec

    Returns
    -------
    Self
    """
    return self

from_dict classmethod

from_dict(data: dict[str, JSON]) -> Self

Create an instance of the model from a dictionary

Source code in zarr/codecs/numcodecs/_codecs.py
@classmethod
def from_dict(cls, data: dict[str, JSON]) -> Self:
    codec_config = _parse_codec_configuration(data)
    return cls(**codec_config)

resolve_metadata

resolve_metadata(chunk_spec: ArraySpec) -> 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_spec (ArraySpec) –

Returns:

  • ArraySpec
Source code in zarr/abc/codec.py
def resolve_metadata(self, chunk_spec: ArraySpec) -> 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_spec : ArraySpec

    Returns
    -------
    ArraySpec
    """
    return chunk_spec

to_dict

to_dict() -> dict[str, JSON]

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.

Source code in zarr/codecs/numcodecs/_codecs.py
def to_dict(self) -> dict[str, JSON]:
    codec_config = self.codec_config.copy()
    codec_config.pop("id", None)
    return {
        "name": self.codec_name,
        "configuration": codec_config,
    }

validate

validate(
    *,
    shape: tuple[int, ...],
    dtype: ZDType[TBaseDType, TBaseScalar],
    chunk_grid: ChunkGridMetadata,
) -> None

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

Parameters:

  • shape (tuple[int, ...]) –

    The array shape

  • dtype (dtype[Any]) –

    The array data type

  • chunk_grid (ChunkGridMetadata) –

    The array chunk grid metadata

Source code in zarr/abc/codec.py
def validate(
    self,
    *,
    shape: tuple[int, ...],
    dtype: ZDType[TBaseDType, TBaseScalar],
    chunk_grid: ChunkGridMetadata,
) -> None:
    """Validates that the codec configuration is compatible with the array metadata.
    Raises errors when the codec configuration is not compatible.

    Parameters
    ----------
    shape : tuple[int, ...]
        The array shape
    dtype : np.dtype[Any]
        The array data type
    chunk_grid : ChunkGridMetadata
        The array chunk grid metadata
    """

JenkinsLookup3 dataclass

Bases: _NumcodecsChecksumCodec

Source code in zarr/codecs/numcodecs/_codecs.py
class JenkinsLookup3(_NumcodecsChecksumCodec, codec_name="jenkins_lookup3"):
    pass

codec_config instance-attribute

codec_config: dict[str, JSON]

codec_name instance-attribute

codec_name: str

is_fixed_size instance-attribute

is_fixed_size: bool

__init__

__init__(**codec_config: JSON) -> None
Source code in zarr/codecs/numcodecs/_codecs.py
def __init__(self, **codec_config: JSON) -> None:
    super().__init__(**codec_config)

__init_subclass__

__init_subclass__(
    *, codec_name: str | None = None, **kwargs: Any
) -> None

To be used only when creating the actual public-facing codec class.

Source code in zarr/codecs/numcodecs/_codecs.py
def __init_subclass__(cls, *, codec_name: str | None = None, **kwargs: Any) -> None:
    """To be used only when creating the actual public-facing codec class."""
    super().__init_subclass__(**kwargs)
    if codec_name is not None:
        namespace = codec_name

        cls_name = f"{CODEC_PREFIX}{namespace}.{cls.__name__}"
        cls.codec_name = f"{CODEC_PREFIX}{namespace}"
        cls.__doc__ = f"""
        See [{cls_name}][] for more details and parameters.
        """

__repr__

__repr__() -> str
Source code in zarr/codecs/numcodecs/_codecs.py
def __repr__(self) -> str:
    codec_config = self.codec_config.copy()
    codec_config.pop("id", None)
    return f"{self.__class__.__name__}(codec_name={self.codec_name!r}, codec_config={codec_config!r})"

compute_encoded_size

compute_encoded_size(
    input_byte_length: int, chunk_spec: ArraySpec
) -> int
Source code in zarr/codecs/numcodecs/_codecs.py
def compute_encoded_size(self, input_byte_length: int, chunk_spec: ArraySpec) -> int:
    return input_byte_length + 4  # pragma: no cover

decode async

decode(
    chunks_and_specs: Iterable[tuple[CO | None, ArraySpec]],
) -> Iterable[CI | None]

Decodes a batch of chunks. Chunks can be None in which case they are ignored by the codec.

Parameters:

  • chunks_and_specs (Iterable[tuple[CodecOutput | None, ArraySpec]]) –

    Ordered set of encoded chunks with their accompanying chunk spec.

Returns:

Source code in zarr/abc/codec.py
async def decode(
    self,
    chunks_and_specs: Iterable[tuple[CO | None, ArraySpec]],
) -> Iterable[CI | None]:
    """Decodes a batch of chunks.
    Chunks can be None in which case they are ignored by the codec.

    Parameters
    ----------
    chunks_and_specs : Iterable[tuple[CodecOutput | None, ArraySpec]]
        Ordered set of encoded chunks with their accompanying chunk spec.

    Returns
    -------
    Iterable[CI | None]
    """
    return await _batching_helper(self._decode_single, chunks_and_specs)

encode async

encode(
    chunks_and_specs: Iterable[tuple[CI | None, ArraySpec]],
) -> Iterable[CO | None]

Encodes a batch of chunks. Chunks can be None in which case they are ignored by the codec.

Parameters:

  • chunks_and_specs (Iterable[tuple[CI | None, ArraySpec]]) –

    Ordered set of to-be-encoded chunks with their accompanying chunk spec.

Returns:

Source code in zarr/abc/codec.py
async def encode(
    self,
    chunks_and_specs: Iterable[tuple[CI | None, ArraySpec]],
) -> Iterable[CO | None]:
    """Encodes a batch of chunks.
    Chunks can be None in which case they are ignored by the codec.

    Parameters
    ----------
    chunks_and_specs : Iterable[tuple[CI | None, ArraySpec]]
        Ordered set of to-be-encoded chunks with their accompanying chunk spec.

    Returns
    -------
    Iterable[CodecOutput | None]
    """
    return await _batching_helper(self._encode_single, chunks_and_specs)

evolve_from_array_spec

evolve_from_array_spec(array_spec: ArraySpec) -> Self

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

Parameters:

  • array_spec (ArraySpec) –

Returns:

Source code in zarr/abc/codec.py
def evolve_from_array_spec(self, array_spec: ArraySpec) -> Self:
    """Fills in codec configuration parameters that can be automatically
    inferred from the array metadata.

    Parameters
    ----------
    array_spec : ArraySpec

    Returns
    -------
    Self
    """
    return self

from_dict classmethod

from_dict(data: dict[str, JSON]) -> Self

Create an instance of the model from a dictionary

Source code in zarr/codecs/numcodecs/_codecs.py
@classmethod
def from_dict(cls, data: dict[str, JSON]) -> Self:
    codec_config = _parse_codec_configuration(data)
    return cls(**codec_config)

resolve_metadata

resolve_metadata(chunk_spec: ArraySpec) -> 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_spec (ArraySpec) –

Returns:

  • ArraySpec
Source code in zarr/abc/codec.py
def resolve_metadata(self, chunk_spec: ArraySpec) -> 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_spec : ArraySpec

    Returns
    -------
    ArraySpec
    """
    return chunk_spec

to_dict

to_dict() -> dict[str, JSON]

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.

Source code in zarr/codecs/numcodecs/_codecs.py
def to_dict(self) -> dict[str, JSON]:
    codec_config = self.codec_config.copy()
    codec_config.pop("id", None)
    return {
        "name": self.codec_name,
        "configuration": codec_config,
    }

validate

validate(
    *,
    shape: tuple[int, ...],
    dtype: ZDType[TBaseDType, TBaseScalar],
    chunk_grid: ChunkGridMetadata,
) -> None

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

Parameters:

  • shape (tuple[int, ...]) –

    The array shape

  • dtype (dtype[Any]) –

    The array data type

  • chunk_grid (ChunkGridMetadata) –

    The array chunk grid metadata

Source code in zarr/abc/codec.py
def validate(
    self,
    *,
    shape: tuple[int, ...],
    dtype: ZDType[TBaseDType, TBaseScalar],
    chunk_grid: ChunkGridMetadata,
) -> None:
    """Validates that the codec configuration is compatible with the array metadata.
    Raises errors when the codec configuration is not compatible.

    Parameters
    ----------
    shape : tuple[int, ...]
        The array shape
    dtype : np.dtype[Any]
        The array data type
    chunk_grid : ChunkGridMetadata
        The array chunk grid metadata
    """

LZ4 dataclass

Bases: _NumcodecsBytesBytesCodec

Source code in zarr/codecs/numcodecs/_codecs.py
class LZ4(_NumcodecsBytesBytesCodec, codec_name="lz4"):
    pass

codec_config instance-attribute

codec_config: dict[str, JSON]

codec_name instance-attribute

codec_name: str

is_fixed_size instance-attribute

is_fixed_size: bool

__init__

__init__(**codec_config: JSON) -> None
Source code in zarr/codecs/numcodecs/_codecs.py
def __init__(self, **codec_config: JSON) -> None:
    super().__init__(**codec_config)

__init_subclass__

__init_subclass__(
    *, codec_name: str | None = None, **kwargs: Any
) -> None

To be used only when creating the actual public-facing codec class.

Source code in zarr/codecs/numcodecs/_codecs.py
def __init_subclass__(cls, *, codec_name: str | None = None, **kwargs: Any) -> None:
    """To be used only when creating the actual public-facing codec class."""
    super().__init_subclass__(**kwargs)
    if codec_name is not None:
        namespace = codec_name

        cls_name = f"{CODEC_PREFIX}{namespace}.{cls.__name__}"
        cls.codec_name = f"{CODEC_PREFIX}{namespace}"
        cls.__doc__ = f"""
        See [{cls_name}][] for more details and parameters.
        """

__repr__

__repr__() -> str
Source code in zarr/codecs/numcodecs/_codecs.py
def __repr__(self) -> str:
    codec_config = self.codec_config.copy()
    codec_config.pop("id", None)
    return f"{self.__class__.__name__}(codec_name={self.codec_name!r}, codec_config={codec_config!r})"

compute_encoded_size

compute_encoded_size(
    input_byte_length: int, chunk_spec: ArraySpec
) -> int
Source code in zarr/codecs/numcodecs/_codecs.py
def compute_encoded_size(self, input_byte_length: int, chunk_spec: ArraySpec) -> int:
    raise NotImplementedError  # pragma: no cover

decode async

decode(
    chunks_and_specs: Iterable[tuple[CO | None, ArraySpec]],
) -> Iterable[CI | None]

Decodes a batch of chunks. Chunks can be None in which case they are ignored by the codec.

Parameters:

  • chunks_and_specs (Iterable[tuple[CodecOutput | None, ArraySpec]]) –

    Ordered set of encoded chunks with their accompanying chunk spec.

Returns:

Source code in zarr/abc/codec.py
async def decode(
    self,
    chunks_and_specs: Iterable[tuple[CO | None, ArraySpec]],
) -> Iterable[CI | None]:
    """Decodes a batch of chunks.
    Chunks can be None in which case they are ignored by the codec.

    Parameters
    ----------
    chunks_and_specs : Iterable[tuple[CodecOutput | None, ArraySpec]]
        Ordered set of encoded chunks with their accompanying chunk spec.

    Returns
    -------
    Iterable[CI | None]
    """
    return await _batching_helper(self._decode_single, chunks_and_specs)

encode async

encode(
    chunks_and_specs: Iterable[tuple[CI | None, ArraySpec]],
) -> Iterable[CO | None]

Encodes a batch of chunks. Chunks can be None in which case they are ignored by the codec.

Parameters:

  • chunks_and_specs (Iterable[tuple[CI | None, ArraySpec]]) –

    Ordered set of to-be-encoded chunks with their accompanying chunk spec.

Returns:

Source code in zarr/abc/codec.py
async def encode(
    self,
    chunks_and_specs: Iterable[tuple[CI | None, ArraySpec]],
) -> Iterable[CO | None]:
    """Encodes a batch of chunks.
    Chunks can be None in which case they are ignored by the codec.

    Parameters
    ----------
    chunks_and_specs : Iterable[tuple[CI | None, ArraySpec]]
        Ordered set of to-be-encoded chunks with their accompanying chunk spec.

    Returns
    -------
    Iterable[CodecOutput | None]
    """
    return await _batching_helper(self._encode_single, chunks_and_specs)

evolve_from_array_spec

evolve_from_array_spec(array_spec: ArraySpec) -> Self

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

Parameters:

  • array_spec (ArraySpec) –

Returns:

Source code in zarr/abc/codec.py
def evolve_from_array_spec(self, array_spec: ArraySpec) -> Self:
    """Fills in codec configuration parameters that can be automatically
    inferred from the array metadata.

    Parameters
    ----------
    array_spec : ArraySpec

    Returns
    -------
    Self
    """
    return self

from_dict classmethod

from_dict(data: dict[str, JSON]) -> Self

Create an instance of the model from a dictionary

Source code in zarr/codecs/numcodecs/_codecs.py
@classmethod
def from_dict(cls, data: dict[str, JSON]) -> Self:
    codec_config = _parse_codec_configuration(data)
    return cls(**codec_config)

resolve_metadata

resolve_metadata(chunk_spec: ArraySpec) -> 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_spec (ArraySpec) –

Returns:

  • ArraySpec
Source code in zarr/abc/codec.py
def resolve_metadata(self, chunk_spec: ArraySpec) -> 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_spec : ArraySpec

    Returns
    -------
    ArraySpec
    """
    return chunk_spec

to_dict

to_dict() -> dict[str, JSON]

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.

Source code in zarr/codecs/numcodecs/_codecs.py
def to_dict(self) -> dict[str, JSON]:
    codec_config = self.codec_config.copy()
    codec_config.pop("id", None)
    return {
        "name": self.codec_name,
        "configuration": codec_config,
    }

validate

validate(
    *,
    shape: tuple[int, ...],
    dtype: ZDType[TBaseDType, TBaseScalar],
    chunk_grid: ChunkGridMetadata,
) -> None

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

Parameters:

  • shape (tuple[int, ...]) –

    The array shape

  • dtype (dtype[Any]) –

    The array data type

  • chunk_grid (ChunkGridMetadata) –

    The array chunk grid metadata

Source code in zarr/abc/codec.py
def validate(
    self,
    *,
    shape: tuple[int, ...],
    dtype: ZDType[TBaseDType, TBaseScalar],
    chunk_grid: ChunkGridMetadata,
) -> None:
    """Validates that the codec configuration is compatible with the array metadata.
    Raises errors when the codec configuration is not compatible.

    Parameters
    ----------
    shape : tuple[int, ...]
        The array shape
    dtype : np.dtype[Any]
        The array data type
    chunk_grid : ChunkGridMetadata
        The array chunk grid metadata
    """

LZMA dataclass

Bases: _NumcodecsBytesBytesCodec

Source code in zarr/codecs/numcodecs/_codecs.py
class LZMA(_NumcodecsBytesBytesCodec, codec_name="lzma"):
    pass

codec_config instance-attribute

codec_config: dict[str, JSON]

codec_name instance-attribute

codec_name: str

is_fixed_size instance-attribute

is_fixed_size: bool

__init__

__init__(**codec_config: JSON) -> None
Source code in zarr/codecs/numcodecs/_codecs.py
def __init__(self, **codec_config: JSON) -> None:
    super().__init__(**codec_config)

__init_subclass__

__init_subclass__(
    *, codec_name: str | None = None, **kwargs: Any
) -> None

To be used only when creating the actual public-facing codec class.

Source code in zarr/codecs/numcodecs/_codecs.py
def __init_subclass__(cls, *, codec_name: str | None = None, **kwargs: Any) -> None:
    """To be used only when creating the actual public-facing codec class."""
    super().__init_subclass__(**kwargs)
    if codec_name is not None:
        namespace = codec_name

        cls_name = f"{CODEC_PREFIX}{namespace}.{cls.__name__}"
        cls.codec_name = f"{CODEC_PREFIX}{namespace}"
        cls.__doc__ = f"""
        See [{cls_name}][] for more details and parameters.
        """

__repr__

__repr__() -> str
Source code in zarr/codecs/numcodecs/_codecs.py
def __repr__(self) -> str:
    codec_config = self.codec_config.copy()
    codec_config.pop("id", None)
    return f"{self.__class__.__name__}(codec_name={self.codec_name!r}, codec_config={codec_config!r})"

compute_encoded_size

compute_encoded_size(
    input_byte_length: int, chunk_spec: ArraySpec
) -> int
Source code in zarr/codecs/numcodecs/_codecs.py
def compute_encoded_size(self, input_byte_length: int, chunk_spec: ArraySpec) -> int:
    raise NotImplementedError  # pragma: no cover

decode async

decode(
    chunks_and_specs: Iterable[tuple[CO | None, ArraySpec]],
) -> Iterable[CI | None]

Decodes a batch of chunks. Chunks can be None in which case they are ignored by the codec.

Parameters:

  • chunks_and_specs (Iterable[tuple[CodecOutput | None, ArraySpec]]) –

    Ordered set of encoded chunks with their accompanying chunk spec.

Returns:

Source code in zarr/abc/codec.py
async def decode(
    self,
    chunks_and_specs: Iterable[tuple[CO | None, ArraySpec]],
) -> Iterable[CI | None]:
    """Decodes a batch of chunks.
    Chunks can be None in which case they are ignored by the codec.

    Parameters
    ----------
    chunks_and_specs : Iterable[tuple[CodecOutput | None, ArraySpec]]
        Ordered set of encoded chunks with their accompanying chunk spec.

    Returns
    -------
    Iterable[CI | None]
    """
    return await _batching_helper(self._decode_single, chunks_and_specs)

encode async

encode(
    chunks_and_specs: Iterable[tuple[CI | None, ArraySpec]],
) -> Iterable[CO | None]

Encodes a batch of chunks. Chunks can be None in which case they are ignored by the codec.

Parameters:

  • chunks_and_specs (Iterable[tuple[CI | None, ArraySpec]]) –

    Ordered set of to-be-encoded chunks with their accompanying chunk spec.

Returns:

Source code in zarr/abc/codec.py
async def encode(
    self,
    chunks_and_specs: Iterable[tuple[CI | None, ArraySpec]],
) -> Iterable[CO | None]:
    """Encodes a batch of chunks.
    Chunks can be None in which case they are ignored by the codec.

    Parameters
    ----------
    chunks_and_specs : Iterable[tuple[CI | None, ArraySpec]]
        Ordered set of to-be-encoded chunks with their accompanying chunk spec.

    Returns
    -------
    Iterable[CodecOutput | None]
    """
    return await _batching_helper(self._encode_single, chunks_and_specs)

evolve_from_array_spec

evolve_from_array_spec(array_spec: ArraySpec) -> Self

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

Parameters:

  • array_spec (ArraySpec) –

Returns:

Source code in zarr/abc/codec.py
def evolve_from_array_spec(self, array_spec: ArraySpec) -> Self:
    """Fills in codec configuration parameters that can be automatically
    inferred from the array metadata.

    Parameters
    ----------
    array_spec : ArraySpec

    Returns
    -------
    Self
    """
    return self

from_dict classmethod

from_dict(data: dict[str, JSON]) -> Self

Create an instance of the model from a dictionary

Source code in zarr/codecs/numcodecs/_codecs.py
@classmethod
def from_dict(cls, data: dict[str, JSON]) -> Self:
    codec_config = _parse_codec_configuration(data)
    return cls(**codec_config)

resolve_metadata

resolve_metadata(chunk_spec: ArraySpec) -> 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_spec (ArraySpec) –

Returns:

  • ArraySpec
Source code in zarr/abc/codec.py
def resolve_metadata(self, chunk_spec: ArraySpec) -> 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_spec : ArraySpec

    Returns
    -------
    ArraySpec
    """
    return chunk_spec

to_dict

to_dict() -> dict[str, JSON]

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.

Source code in zarr/codecs/numcodecs/_codecs.py
def to_dict(self) -> dict[str, JSON]:
    codec_config = self.codec_config.copy()
    codec_config.pop("id", None)
    return {
        "name": self.codec_name,
        "configuration": codec_config,
    }

validate

validate(
    *,
    shape: tuple[int, ...],
    dtype: ZDType[TBaseDType, TBaseScalar],
    chunk_grid: ChunkGridMetadata,
) -> None

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

Parameters:

  • shape (tuple[int, ...]) –

    The array shape

  • dtype (dtype[Any]) –

    The array data type

  • chunk_grid (ChunkGridMetadata) –

    The array chunk grid metadata

Source code in zarr/abc/codec.py
def validate(
    self,
    *,
    shape: tuple[int, ...],
    dtype: ZDType[TBaseDType, TBaseScalar],
    chunk_grid: ChunkGridMetadata,
) -> None:
    """Validates that the codec configuration is compatible with the array metadata.
    Raises errors when the codec configuration is not compatible.

    Parameters
    ----------
    shape : tuple[int, ...]
        The array shape
    dtype : np.dtype[Any]
        The array data type
    chunk_grid : ChunkGridMetadata
        The array chunk grid metadata
    """

PCodec dataclass

Bases: _NumcodecsArrayBytesCodec

Source code in zarr/codecs/numcodecs/_codecs.py
class PCodec(_NumcodecsArrayBytesCodec, codec_name="pcodec"):
    pass

codec_config instance-attribute

codec_config: dict[str, JSON]

codec_name instance-attribute

codec_name: str

is_fixed_size instance-attribute

is_fixed_size: bool

__init__

__init__(**codec_config: JSON) -> None
Source code in zarr/codecs/numcodecs/_codecs.py
def __init__(self, **codec_config: JSON) -> None:
    super().__init__(**codec_config)

__init_subclass__

__init_subclass__(
    *, codec_name: str | None = None, **kwargs: Any
) -> None

To be used only when creating the actual public-facing codec class.

Source code in zarr/codecs/numcodecs/_codecs.py
def __init_subclass__(cls, *, codec_name: str | None = None, **kwargs: Any) -> None:
    """To be used only when creating the actual public-facing codec class."""
    super().__init_subclass__(**kwargs)
    if codec_name is not None:
        namespace = codec_name

        cls_name = f"{CODEC_PREFIX}{namespace}.{cls.__name__}"
        cls.codec_name = f"{CODEC_PREFIX}{namespace}"
        cls.__doc__ = f"""
        See [{cls_name}][] for more details and parameters.
        """

__repr__

__repr__() -> str
Source code in zarr/codecs/numcodecs/_codecs.py
def __repr__(self) -> str:
    codec_config = self.codec_config.copy()
    codec_config.pop("id", None)
    return f"{self.__class__.__name__}(codec_name={self.codec_name!r}, codec_config={codec_config!r})"

compute_encoded_size

compute_encoded_size(
    input_byte_length: int, chunk_spec: ArraySpec
) -> int
Source code in zarr/codecs/numcodecs/_codecs.py
def compute_encoded_size(self, input_byte_length: int, chunk_spec: ArraySpec) -> int:
    raise NotImplementedError  # pragma: no cover

decode async

decode(
    chunks_and_specs: Iterable[tuple[CO | None, ArraySpec]],
) -> Iterable[CI | None]

Decodes a batch of chunks. Chunks can be None in which case they are ignored by the codec.

Parameters:

  • chunks_and_specs (Iterable[tuple[CodecOutput | None, ArraySpec]]) –

    Ordered set of encoded chunks with their accompanying chunk spec.

Returns:

Source code in zarr/abc/codec.py
async def decode(
    self,
    chunks_and_specs: Iterable[tuple[CO | None, ArraySpec]],
) -> Iterable[CI | None]:
    """Decodes a batch of chunks.
    Chunks can be None in which case they are ignored by the codec.

    Parameters
    ----------
    chunks_and_specs : Iterable[tuple[CodecOutput | None, ArraySpec]]
        Ordered set of encoded chunks with their accompanying chunk spec.

    Returns
    -------
    Iterable[CI | None]
    """
    return await _batching_helper(self._decode_single, chunks_and_specs)

encode async

encode(
    chunks_and_specs: Iterable[tuple[CI | None, ArraySpec]],
) -> Iterable[CO | None]

Encodes a batch of chunks. Chunks can be None in which case they are ignored by the codec.

Parameters:

  • chunks_and_specs (Iterable[tuple[CI | None, ArraySpec]]) –

    Ordered set of to-be-encoded chunks with their accompanying chunk spec.

Returns:

Source code in zarr/abc/codec.py
async def encode(
    self,
    chunks_and_specs: Iterable[tuple[CI | None, ArraySpec]],
) -> Iterable[CO | None]:
    """Encodes a batch of chunks.
    Chunks can be None in which case they are ignored by the codec.

    Parameters
    ----------
    chunks_and_specs : Iterable[tuple[CI | None, ArraySpec]]
        Ordered set of to-be-encoded chunks with their accompanying chunk spec.

    Returns
    -------
    Iterable[CodecOutput | None]
    """
    return await _batching_helper(self._encode_single, chunks_and_specs)

evolve_from_array_spec

evolve_from_array_spec(array_spec: ArraySpec) -> Self

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

Parameters:

  • array_spec (ArraySpec) –

Returns:

Source code in zarr/abc/codec.py
def evolve_from_array_spec(self, array_spec: ArraySpec) -> Self:
    """Fills in codec configuration parameters that can be automatically
    inferred from the array metadata.

    Parameters
    ----------
    array_spec : ArraySpec

    Returns
    -------
    Self
    """
    return self

from_dict classmethod

from_dict(data: dict[str, JSON]) -> Self

Create an instance of the model from a dictionary

Source code in zarr/codecs/numcodecs/_codecs.py
@classmethod
def from_dict(cls, data: dict[str, JSON]) -> Self:
    codec_config = _parse_codec_configuration(data)
    return cls(**codec_config)

resolve_metadata

resolve_metadata(chunk_spec: ArraySpec) -> 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_spec (ArraySpec) –

Returns:

  • ArraySpec
Source code in zarr/abc/codec.py
def resolve_metadata(self, chunk_spec: ArraySpec) -> 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_spec : ArraySpec

    Returns
    -------
    ArraySpec
    """
    return chunk_spec

to_dict

to_dict() -> dict[str, JSON]

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.

Source code in zarr/codecs/numcodecs/_codecs.py
def to_dict(self) -> dict[str, JSON]:
    codec_config = self.codec_config.copy()
    codec_config.pop("id", None)
    return {
        "name": self.codec_name,
        "configuration": codec_config,
    }

validate

validate(
    *,
    shape: tuple[int, ...],
    dtype: ZDType[TBaseDType, TBaseScalar],
    chunk_grid: ChunkGridMetadata,
) -> None

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

Parameters:

  • shape (tuple[int, ...]) –

    The array shape

  • dtype (dtype[Any]) –

    The array data type

  • chunk_grid (ChunkGridMetadata) –

    The array chunk grid metadata

Source code in zarr/abc/codec.py
def validate(
    self,
    *,
    shape: tuple[int, ...],
    dtype: ZDType[TBaseDType, TBaseScalar],
    chunk_grid: ChunkGridMetadata,
) -> None:
    """Validates that the codec configuration is compatible with the array metadata.
    Raises errors when the codec configuration is not compatible.

    Parameters
    ----------
    shape : tuple[int, ...]
        The array shape
    dtype : np.dtype[Any]
        The array data type
    chunk_grid : ChunkGridMetadata
        The array chunk grid metadata
    """

PackBits dataclass

Bases: _NumcodecsArrayArrayCodec

Source code in zarr/codecs/numcodecs/_codecs.py
class PackBits(_NumcodecsArrayArrayCodec, codec_name="packbits"):
    def resolve_metadata(self, chunk_spec: ArraySpec) -> ArraySpec:
        return replace(
            chunk_spec,
            shape=(1 + math.ceil(product(chunk_spec.shape) / 8),),
            dtype=UInt8(),
        )

    # todo: remove this type: ignore when this class can be defined w.r.t.
    # a single zarr dtype API
    def validate(self, *, dtype: ZDType[Any, Any], **_kwargs: Any) -> None:
        # this is bugged and will fail
        _dtype = dtype.to_native_dtype()
        if _dtype != np.dtype("bool"):
            raise ValueError(f"Packbits filter requires bool dtype. Got {dtype}.")

codec_config instance-attribute

codec_config: dict[str, JSON]

codec_name instance-attribute

codec_name: str

is_fixed_size instance-attribute

is_fixed_size: bool

__init__

__init__(**codec_config: JSON) -> None
Source code in zarr/codecs/numcodecs/_codecs.py
def __init__(self, **codec_config: JSON) -> None:
    super().__init__(**codec_config)

__init_subclass__

__init_subclass__(
    *, codec_name: str | None = None, **kwargs: Any
) -> None

To be used only when creating the actual public-facing codec class.

Source code in zarr/codecs/numcodecs/_codecs.py
def __init_subclass__(cls, *, codec_name: str | None = None, **kwargs: Any) -> None:
    """To be used only when creating the actual public-facing codec class."""
    super().__init_subclass__(**kwargs)
    if codec_name is not None:
        namespace = codec_name

        cls_name = f"{CODEC_PREFIX}{namespace}.{cls.__name__}"
        cls.codec_name = f"{CODEC_PREFIX}{namespace}"
        cls.__doc__ = f"""
        See [{cls_name}][] for more details and parameters.
        """

__repr__

__repr__() -> str
Source code in zarr/codecs/numcodecs/_codecs.py
def __repr__(self) -> str:
    codec_config = self.codec_config.copy()
    codec_config.pop("id", None)
    return f"{self.__class__.__name__}(codec_name={self.codec_name!r}, codec_config={codec_config!r})"

compute_encoded_size

compute_encoded_size(
    input_byte_length: int, chunk_spec: ArraySpec
) -> int
Source code in zarr/codecs/numcodecs/_codecs.py
def compute_encoded_size(self, input_byte_length: int, chunk_spec: ArraySpec) -> int:
    raise NotImplementedError  # pragma: no cover

decode async

decode(
    chunks_and_specs: Iterable[tuple[CO | None, ArraySpec]],
) -> Iterable[CI | None]

Decodes a batch of chunks. Chunks can be None in which case they are ignored by the codec.

Parameters:

  • chunks_and_specs (Iterable[tuple[CodecOutput | None, ArraySpec]]) –

    Ordered set of encoded chunks with their accompanying chunk spec.

Returns:

Source code in zarr/abc/codec.py
async def decode(
    self,
    chunks_and_specs: Iterable[tuple[CO | None, ArraySpec]],
) -> Iterable[CI | None]:
    """Decodes a batch of chunks.
    Chunks can be None in which case they are ignored by the codec.

    Parameters
    ----------
    chunks_and_specs : Iterable[tuple[CodecOutput | None, ArraySpec]]
        Ordered set of encoded chunks with their accompanying chunk spec.

    Returns
    -------
    Iterable[CI | None]
    """
    return await _batching_helper(self._decode_single, chunks_and_specs)

encode async

encode(
    chunks_and_specs: Iterable[tuple[CI | None, ArraySpec]],
) -> Iterable[CO | None]

Encodes a batch of chunks. Chunks can be None in which case they are ignored by the codec.

Parameters:

  • chunks_and_specs (Iterable[tuple[CI | None, ArraySpec]]) –

    Ordered set of to-be-encoded chunks with their accompanying chunk spec.

Returns:

Source code in zarr/abc/codec.py
async def encode(
    self,
    chunks_and_specs: Iterable[tuple[CI | None, ArraySpec]],
) -> Iterable[CO | None]:
    """Encodes a batch of chunks.
    Chunks can be None in which case they are ignored by the codec.

    Parameters
    ----------
    chunks_and_specs : Iterable[tuple[CI | None, ArraySpec]]
        Ordered set of to-be-encoded chunks with their accompanying chunk spec.

    Returns
    -------
    Iterable[CodecOutput | None]
    """
    return await _batching_helper(self._encode_single, chunks_and_specs)

evolve_from_array_spec

evolve_from_array_spec(array_spec: ArraySpec) -> Self

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

Parameters:

  • array_spec (ArraySpec) –

Returns:

Source code in zarr/abc/codec.py
def evolve_from_array_spec(self, array_spec: ArraySpec) -> Self:
    """Fills in codec configuration parameters that can be automatically
    inferred from the array metadata.

    Parameters
    ----------
    array_spec : ArraySpec

    Returns
    -------
    Self
    """
    return self

from_dict classmethod

from_dict(data: dict[str, JSON]) -> Self

Create an instance of the model from a dictionary

Source code in zarr/codecs/numcodecs/_codecs.py
@classmethod
def from_dict(cls, data: dict[str, JSON]) -> Self:
    codec_config = _parse_codec_configuration(data)
    return cls(**codec_config)

resolve_metadata

resolve_metadata(chunk_spec: ArraySpec) -> 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_spec (ArraySpec) –

Returns:

  • ArraySpec
Source code in zarr/codecs/numcodecs/_codecs.py
def resolve_metadata(self, chunk_spec: ArraySpec) -> ArraySpec:
    return replace(
        chunk_spec,
        shape=(1 + math.ceil(product(chunk_spec.shape) / 8),),
        dtype=UInt8(),
    )

to_dict

to_dict() -> dict[str, JSON]

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.

Source code in zarr/codecs/numcodecs/_codecs.py
def to_dict(self) -> dict[str, JSON]:
    codec_config = self.codec_config.copy()
    codec_config.pop("id", None)
    return {
        "name": self.codec_name,
        "configuration": codec_config,
    }

validate

validate(
    *, dtype: ZDType[Any, Any], **_kwargs: Any
) -> None

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

Parameters:

  • shape (tuple[int, ...]) –

    The array shape

  • dtype (dtype[Any]) –

    The array data type

  • chunk_grid (ChunkGridMetadata) –

    The array chunk grid metadata

Source code in zarr/codecs/numcodecs/_codecs.py
def validate(self, *, dtype: ZDType[Any, Any], **_kwargs: Any) -> None:
    # this is bugged and will fail
    _dtype = dtype.to_native_dtype()
    if _dtype != np.dtype("bool"):
        raise ValueError(f"Packbits filter requires bool dtype. Got {dtype}.")

Quantize

Bases: _NumcodecsArrayArrayCodec

Source code in zarr/codecs/numcodecs/_codecs.py
class Quantize(_NumcodecsArrayArrayCodec, codec_name="quantize"):
    def __init__(self, **codec_config: JSON) -> None:
        super().__init__(**codec_config)

    def evolve_from_array_spec(self, array_spec: ArraySpec) -> Quantize:
        if self.codec_config.get("dtype") is None:
            dtype = array_spec.dtype.to_native_dtype()
            return Quantize(**{**self.codec_config, "dtype": str(dtype)})
        return self

codec_config instance-attribute

codec_config: dict[str, JSON]

codec_name instance-attribute

codec_name: str

is_fixed_size instance-attribute

is_fixed_size: bool

__init__

__init__(**codec_config: JSON) -> None
Source code in zarr/codecs/numcodecs/_codecs.py
def __init__(self, **codec_config: JSON) -> None:
    super().__init__(**codec_config)

__init_subclass__

__init_subclass__(
    *, codec_name: str | None = None, **kwargs: Any
) -> None

To be used only when creating the actual public-facing codec class.

Source code in zarr/codecs/numcodecs/_codecs.py
def __init_subclass__(cls, *, codec_name: str | None = None, **kwargs: Any) -> None:
    """To be used only when creating the actual public-facing codec class."""
    super().__init_subclass__(**kwargs)
    if codec_name is not None:
        namespace = codec_name

        cls_name = f"{CODEC_PREFIX}{namespace}.{cls.__name__}"
        cls.codec_name = f"{CODEC_PREFIX}{namespace}"
        cls.__doc__ = f"""
        See [{cls_name}][] for more details and parameters.
        """

__repr__

__repr__() -> str
Source code in zarr/codecs/numcodecs/_codecs.py
def __repr__(self) -> str:
    codec_config = self.codec_config.copy()
    codec_config.pop("id", None)
    return f"{self.__class__.__name__}(codec_name={self.codec_name!r}, codec_config={codec_config!r})"

compute_encoded_size

compute_encoded_size(
    input_byte_length: int, chunk_spec: ArraySpec
) -> int
Source code in zarr/codecs/numcodecs/_codecs.py
def compute_encoded_size(self, input_byte_length: int, chunk_spec: ArraySpec) -> int:
    raise NotImplementedError  # pragma: no cover

decode async

decode(
    chunks_and_specs: Iterable[tuple[CO | None, ArraySpec]],
) -> Iterable[CI | None]

Decodes a batch of chunks. Chunks can be None in which case they are ignored by the codec.

Parameters:

  • chunks_and_specs (Iterable[tuple[CodecOutput | None, ArraySpec]]) –

    Ordered set of encoded chunks with their accompanying chunk spec.

Returns:

Source code in zarr/abc/codec.py
async def decode(
    self,
    chunks_and_specs: Iterable[tuple[CO | None, ArraySpec]],
) -> Iterable[CI | None]:
    """Decodes a batch of chunks.
    Chunks can be None in which case they are ignored by the codec.

    Parameters
    ----------
    chunks_and_specs : Iterable[tuple[CodecOutput | None, ArraySpec]]
        Ordered set of encoded chunks with their accompanying chunk spec.

    Returns
    -------
    Iterable[CI | None]
    """
    return await _batching_helper(self._decode_single, chunks_and_specs)

encode async

encode(
    chunks_and_specs: Iterable[tuple[CI | None, ArraySpec]],
) -> Iterable[CO | None]

Encodes a batch of chunks. Chunks can be None in which case they are ignored by the codec.

Parameters:

  • chunks_and_specs (Iterable[tuple[CI | None, ArraySpec]]) –

    Ordered set of to-be-encoded chunks with their accompanying chunk spec.

Returns:

Source code in zarr/abc/codec.py
async def encode(
    self,
    chunks_and_specs: Iterable[tuple[CI | None, ArraySpec]],
) -> Iterable[CO | None]:
    """Encodes a batch of chunks.
    Chunks can be None in which case they are ignored by the codec.

    Parameters
    ----------
    chunks_and_specs : Iterable[tuple[CI | None, ArraySpec]]
        Ordered set of to-be-encoded chunks with their accompanying chunk spec.

    Returns
    -------
    Iterable[CodecOutput | None]
    """
    return await _batching_helper(self._encode_single, chunks_and_specs)

evolve_from_array_spec

evolve_from_array_spec(array_spec: ArraySpec) -> Quantize

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

Parameters:

  • array_spec (ArraySpec) –

Returns:

Source code in zarr/codecs/numcodecs/_codecs.py
def evolve_from_array_spec(self, array_spec: ArraySpec) -> Quantize:
    if self.codec_config.get("dtype") is None:
        dtype = array_spec.dtype.to_native_dtype()
        return Quantize(**{**self.codec_config, "dtype": str(dtype)})
    return self

from_dict classmethod

from_dict(data: dict[str, JSON]) -> Self

Create an instance of the model from a dictionary

Source code in zarr/codecs/numcodecs/_codecs.py
@classmethod
def from_dict(cls, data: dict[str, JSON]) -> Self:
    codec_config = _parse_codec_configuration(data)
    return cls(**codec_config)

resolve_metadata

resolve_metadata(chunk_spec: ArraySpec) -> 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_spec (ArraySpec) –

Returns:

  • ArraySpec
Source code in zarr/abc/codec.py
def resolve_metadata(self, chunk_spec: ArraySpec) -> 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_spec : ArraySpec

    Returns
    -------
    ArraySpec
    """
    return chunk_spec

to_dict

to_dict() -> dict[str, JSON]

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.

Source code in zarr/codecs/numcodecs/_codecs.py
def to_dict(self) -> dict[str, JSON]:
    codec_config = self.codec_config.copy()
    codec_config.pop("id", None)
    return {
        "name": self.codec_name,
        "configuration": codec_config,
    }

validate

validate(
    *,
    shape: tuple[int, ...],
    dtype: ZDType[TBaseDType, TBaseScalar],
    chunk_grid: ChunkGridMetadata,
) -> None

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

Parameters:

  • shape (tuple[int, ...]) –

    The array shape

  • dtype (dtype[Any]) –

    The array data type

  • chunk_grid (ChunkGridMetadata) –

    The array chunk grid metadata

Source code in zarr/abc/codec.py
def validate(
    self,
    *,
    shape: tuple[int, ...],
    dtype: ZDType[TBaseDType, TBaseScalar],
    chunk_grid: ChunkGridMetadata,
) -> None:
    """Validates that the codec configuration is compatible with the array metadata.
    Raises errors when the codec configuration is not compatible.

    Parameters
    ----------
    shape : tuple[int, ...]
        The array shape
    dtype : np.dtype[Any]
        The array data type
    chunk_grid : ChunkGridMetadata
        The array chunk grid metadata
    """

Shuffle dataclass

Bases: _NumcodecsBytesBytesCodec

Source code in zarr/codecs/numcodecs/_codecs.py
class Shuffle(_NumcodecsBytesBytesCodec, codec_name="shuffle"):
    def evolve_from_array_spec(self, array_spec: ArraySpec) -> Shuffle:
        if self.codec_config.get("elementsize") is None:
            dtype = array_spec.dtype.to_native_dtype()
            return Shuffle(**{**self.codec_config, "elementsize": dtype.itemsize})
        return self  # pragma: no cover

codec_config instance-attribute

codec_config: dict[str, JSON]

codec_name instance-attribute

codec_name: str

is_fixed_size instance-attribute

is_fixed_size: bool

__init__

__init__(**codec_config: JSON) -> None
Source code in zarr/codecs/numcodecs/_codecs.py
def __init__(self, **codec_config: JSON) -> None:
    super().__init__(**codec_config)

__init_subclass__

__init_subclass__(
    *, codec_name: str | None = None, **kwargs: Any
) -> None

To be used only when creating the actual public-facing codec class.

Source code in zarr/codecs/numcodecs/_codecs.py
def __init_subclass__(cls, *, codec_name: str | None = None, **kwargs: Any) -> None:
    """To be used only when creating the actual public-facing codec class."""
    super().__init_subclass__(**kwargs)
    if codec_name is not None:
        namespace = codec_name

        cls_name = f"{CODEC_PREFIX}{namespace}.{cls.__name__}"
        cls.codec_name = f"{CODEC_PREFIX}{namespace}"
        cls.__doc__ = f"""
        See [{cls_name}][] for more details and parameters.
        """

__repr__

__repr__() -> str
Source code in zarr/codecs/numcodecs/_codecs.py
def __repr__(self) -> str:
    codec_config = self.codec_config.copy()
    codec_config.pop("id", None)
    return f"{self.__class__.__name__}(codec_name={self.codec_name!r}, codec_config={codec_config!r})"

compute_encoded_size

compute_encoded_size(
    input_byte_length: int, chunk_spec: ArraySpec
) -> int
Source code in zarr/codecs/numcodecs/_codecs.py
def compute_encoded_size(self, input_byte_length: int, chunk_spec: ArraySpec) -> int:
    raise NotImplementedError  # pragma: no cover

decode async

decode(
    chunks_and_specs: Iterable[tuple[CO | None, ArraySpec]],
) -> Iterable[CI | None]

Decodes a batch of chunks. Chunks can be None in which case they are ignored by the codec.

Parameters:

  • chunks_and_specs (Iterable[tuple[CodecOutput | None, ArraySpec]]) –

    Ordered set of encoded chunks with their accompanying chunk spec.

Returns:

Source code in zarr/abc/codec.py
async def decode(
    self,
    chunks_and_specs: Iterable[tuple[CO | None, ArraySpec]],
) -> Iterable[CI | None]:
    """Decodes a batch of chunks.
    Chunks can be None in which case they are ignored by the codec.

    Parameters
    ----------
    chunks_and_specs : Iterable[tuple[CodecOutput | None, ArraySpec]]
        Ordered set of encoded chunks with their accompanying chunk spec.

    Returns
    -------
    Iterable[CI | None]
    """
    return await _batching_helper(self._decode_single, chunks_and_specs)

encode async

encode(
    chunks_and_specs: Iterable[tuple[CI | None, ArraySpec]],
) -> Iterable[CO | None]

Encodes a batch of chunks. Chunks can be None in which case they are ignored by the codec.

Parameters:

  • chunks_and_specs (Iterable[tuple[CI | None, ArraySpec]]) –

    Ordered set of to-be-encoded chunks with their accompanying chunk spec.

Returns:

Source code in zarr/abc/codec.py
async def encode(
    self,
    chunks_and_specs: Iterable[tuple[CI | None, ArraySpec]],
) -> Iterable[CO | None]:
    """Encodes a batch of chunks.
    Chunks can be None in which case they are ignored by the codec.

    Parameters
    ----------
    chunks_and_specs : Iterable[tuple[CI | None, ArraySpec]]
        Ordered set of to-be-encoded chunks with their accompanying chunk spec.

    Returns
    -------
    Iterable[CodecOutput | None]
    """
    return await _batching_helper(self._encode_single, chunks_and_specs)

evolve_from_array_spec

evolve_from_array_spec(array_spec: ArraySpec) -> Shuffle

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

Parameters:

  • array_spec (ArraySpec) –

Returns:

Source code in zarr/codecs/numcodecs/_codecs.py
def evolve_from_array_spec(self, array_spec: ArraySpec) -> Shuffle:
    if self.codec_config.get("elementsize") is None:
        dtype = array_spec.dtype.to_native_dtype()
        return Shuffle(**{**self.codec_config, "elementsize": dtype.itemsize})
    return self  # pragma: no cover

from_dict classmethod

from_dict(data: dict[str, JSON]) -> Self

Create an instance of the model from a dictionary

Source code in zarr/codecs/numcodecs/_codecs.py
@classmethod
def from_dict(cls, data: dict[str, JSON]) -> Self:
    codec_config = _parse_codec_configuration(data)
    return cls(**codec_config)

resolve_metadata

resolve_metadata(chunk_spec: ArraySpec) -> 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_spec (ArraySpec) –

Returns:

  • ArraySpec
Source code in zarr/abc/codec.py
def resolve_metadata(self, chunk_spec: ArraySpec) -> 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_spec : ArraySpec

    Returns
    -------
    ArraySpec
    """
    return chunk_spec

to_dict

to_dict() -> dict[str, JSON]

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.

Source code in zarr/codecs/numcodecs/_codecs.py
def to_dict(self) -> dict[str, JSON]:
    codec_config = self.codec_config.copy()
    codec_config.pop("id", None)
    return {
        "name": self.codec_name,
        "configuration": codec_config,
    }

validate

validate(
    *,
    shape: tuple[int, ...],
    dtype: ZDType[TBaseDType, TBaseScalar],
    chunk_grid: ChunkGridMetadata,
) -> None

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

Parameters:

  • shape (tuple[int, ...]) –

    The array shape

  • dtype (dtype[Any]) –

    The array data type

  • chunk_grid (ChunkGridMetadata) –

    The array chunk grid metadata

Source code in zarr/abc/codec.py
def validate(
    self,
    *,
    shape: tuple[int, ...],
    dtype: ZDType[TBaseDType, TBaseScalar],
    chunk_grid: ChunkGridMetadata,
) -> None:
    """Validates that the codec configuration is compatible with the array metadata.
    Raises errors when the codec configuration is not compatible.

    Parameters
    ----------
    shape : tuple[int, ...]
        The array shape
    dtype : np.dtype[Any]
        The array data type
    chunk_grid : ChunkGridMetadata
        The array chunk grid metadata
    """

ZFPY dataclass

Bases: _NumcodecsArrayBytesCodec

Source code in zarr/codecs/numcodecs/_codecs.py
class ZFPY(_NumcodecsArrayBytesCodec, codec_name="zfpy"):
    pass

codec_config instance-attribute

codec_config: dict[str, JSON]

codec_name instance-attribute

codec_name: str

is_fixed_size instance-attribute

is_fixed_size: bool

__init__

__init__(**codec_config: JSON) -> None
Source code in zarr/codecs/numcodecs/_codecs.py
def __init__(self, **codec_config: JSON) -> None:
    super().__init__(**codec_config)

__init_subclass__

__init_subclass__(
    *, codec_name: str | None = None, **kwargs: Any
) -> None

To be used only when creating the actual public-facing codec class.

Source code in zarr/codecs/numcodecs/_codecs.py
def __init_subclass__(cls, *, codec_name: str | None = None, **kwargs: Any) -> None:
    """To be used only when creating the actual public-facing codec class."""
    super().__init_subclass__(**kwargs)
    if codec_name is not None:
        namespace = codec_name

        cls_name = f"{CODEC_PREFIX}{namespace}.{cls.__name__}"
        cls.codec_name = f"{CODEC_PREFIX}{namespace}"
        cls.__doc__ = f"""
        See [{cls_name}][] for more details and parameters.
        """

__repr__

__repr__() -> str
Source code in zarr/codecs/numcodecs/_codecs.py
def __repr__(self) -> str:
    codec_config = self.codec_config.copy()
    codec_config.pop("id", None)
    return f"{self.__class__.__name__}(codec_name={self.codec_name!r}, codec_config={codec_config!r})"

compute_encoded_size

compute_encoded_size(
    input_byte_length: int, chunk_spec: ArraySpec
) -> int
Source code in zarr/codecs/numcodecs/_codecs.py
def compute_encoded_size(self, input_byte_length: int, chunk_spec: ArraySpec) -> int:
    raise NotImplementedError  # pragma: no cover

decode async

decode(
    chunks_and_specs: Iterable[tuple[CO | None, ArraySpec]],
) -> Iterable[CI | None]

Decodes a batch of chunks. Chunks can be None in which case they are ignored by the codec.

Parameters:

  • chunks_and_specs (Iterable[tuple[CodecOutput | None, ArraySpec]]) –

    Ordered set of encoded chunks with their accompanying chunk spec.

Returns:

Source code in zarr/abc/codec.py
async def decode(
    self,
    chunks_and_specs: Iterable[tuple[CO | None, ArraySpec]],
) -> Iterable[CI | None]:
    """Decodes a batch of chunks.
    Chunks can be None in which case they are ignored by the codec.

    Parameters
    ----------
    chunks_and_specs : Iterable[tuple[CodecOutput | None, ArraySpec]]
        Ordered set of encoded chunks with their accompanying chunk spec.

    Returns
    -------
    Iterable[CI | None]
    """
    return await _batching_helper(self._decode_single, chunks_and_specs)

encode async

encode(
    chunks_and_specs: Iterable[tuple[CI | None, ArraySpec]],
) -> Iterable[CO | None]

Encodes a batch of chunks. Chunks can be None in which case they are ignored by the codec.

Parameters:

  • chunks_and_specs (Iterable[tuple[CI | None, ArraySpec]]) –

    Ordered set of to-be-encoded chunks with their accompanying chunk spec.

Returns:

Source code in zarr/abc/codec.py
async def encode(
    self,
    chunks_and_specs: Iterable[tuple[CI | None, ArraySpec]],
) -> Iterable[CO | None]:
    """Encodes a batch of chunks.
    Chunks can be None in which case they are ignored by the codec.

    Parameters
    ----------
    chunks_and_specs : Iterable[tuple[CI | None, ArraySpec]]
        Ordered set of to-be-encoded chunks with their accompanying chunk spec.

    Returns
    -------
    Iterable[CodecOutput | None]
    """
    return await _batching_helper(self._encode_single, chunks_and_specs)

evolve_from_array_spec

evolve_from_array_spec(array_spec: ArraySpec) -> Self

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

Parameters:

  • array_spec (ArraySpec) –

Returns:

Source code in zarr/abc/codec.py
def evolve_from_array_spec(self, array_spec: ArraySpec) -> Self:
    """Fills in codec configuration parameters that can be automatically
    inferred from the array metadata.

    Parameters
    ----------
    array_spec : ArraySpec

    Returns
    -------
    Self
    """
    return self

from_dict classmethod

from_dict(data: dict[str, JSON]) -> Self

Create an instance of the model from a dictionary

Source code in zarr/codecs/numcodecs/_codecs.py
@classmethod
def from_dict(cls, data: dict[str, JSON]) -> Self:
    codec_config = _parse_codec_configuration(data)
    return cls(**codec_config)

resolve_metadata

resolve_metadata(chunk_spec: ArraySpec) -> 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_spec (ArraySpec) –

Returns:

  • ArraySpec
Source code in zarr/abc/codec.py
def resolve_metadata(self, chunk_spec: ArraySpec) -> 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_spec : ArraySpec

    Returns
    -------
    ArraySpec
    """
    return chunk_spec

to_dict

to_dict() -> dict[str, JSON]

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.

Source code in zarr/codecs/numcodecs/_codecs.py
def to_dict(self) -> dict[str, JSON]:
    codec_config = self.codec_config.copy()
    codec_config.pop("id", None)
    return {
        "name": self.codec_name,
        "configuration": codec_config,
    }

validate

validate(
    *,
    shape: tuple[int, ...],
    dtype: ZDType[TBaseDType, TBaseScalar],
    chunk_grid: ChunkGridMetadata,
) -> None

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

Parameters:

  • shape (tuple[int, ...]) –

    The array shape

  • dtype (dtype[Any]) –

    The array data type

  • chunk_grid (ChunkGridMetadata) –

    The array chunk grid metadata

Source code in zarr/abc/codec.py
def validate(
    self,
    *,
    shape: tuple[int, ...],
    dtype: ZDType[TBaseDType, TBaseScalar],
    chunk_grid: ChunkGridMetadata,
) -> None:
    """Validates that the codec configuration is compatible with the array metadata.
    Raises errors when the codec configuration is not compatible.

    Parameters
    ----------
    shape : tuple[int, ...]
        The array shape
    dtype : np.dtype[Any]
        The array data type
    chunk_grid : ChunkGridMetadata
        The array chunk grid metadata
    """

Zlib dataclass

Bases: _NumcodecsBytesBytesCodec

Source code in zarr/codecs/numcodecs/_codecs.py
class Zlib(_NumcodecsBytesBytesCodec, codec_name="zlib"):
    pass

codec_config instance-attribute

codec_config: dict[str, JSON]

codec_name instance-attribute

codec_name: str

is_fixed_size instance-attribute

is_fixed_size: bool

__init__

__init__(**codec_config: JSON) -> None
Source code in zarr/codecs/numcodecs/_codecs.py
def __init__(self, **codec_config: JSON) -> None:
    super().__init__(**codec_config)

__init_subclass__

__init_subclass__(
    *, codec_name: str | None = None, **kwargs: Any
) -> None

To be used only when creating the actual public-facing codec class.

Source code in zarr/codecs/numcodecs/_codecs.py
def __init_subclass__(cls, *, codec_name: str | None = None, **kwargs: Any) -> None:
    """To be used only when creating the actual public-facing codec class."""
    super().__init_subclass__(**kwargs)
    if codec_name is not None:
        namespace = codec_name

        cls_name = f"{CODEC_PREFIX}{namespace}.{cls.__name__}"
        cls.codec_name = f"{CODEC_PREFIX}{namespace}"
        cls.__doc__ = f"""
        See [{cls_name}][] for more details and parameters.
        """

__repr__

__repr__() -> str
Source code in zarr/codecs/numcodecs/_codecs.py
def __repr__(self) -> str:
    codec_config = self.codec_config.copy()
    codec_config.pop("id", None)
    return f"{self.__class__.__name__}(codec_name={self.codec_name!r}, codec_config={codec_config!r})"

compute_encoded_size

compute_encoded_size(
    input_byte_length: int, chunk_spec: ArraySpec
) -> int
Source code in zarr/codecs/numcodecs/_codecs.py
def compute_encoded_size(self, input_byte_length: int, chunk_spec: ArraySpec) -> int:
    raise NotImplementedError  # pragma: no cover

decode async

decode(
    chunks_and_specs: Iterable[tuple[CO | None, ArraySpec]],
) -> Iterable[CI | None]

Decodes a batch of chunks. Chunks can be None in which case they are ignored by the codec.

Parameters:

  • chunks_and_specs (Iterable[tuple[CodecOutput | None, ArraySpec]]) –

    Ordered set of encoded chunks with their accompanying chunk spec.

Returns:

Source code in zarr/abc/codec.py
async def decode(
    self,
    chunks_and_specs: Iterable[tuple[CO | None, ArraySpec]],
) -> Iterable[CI | None]:
    """Decodes a batch of chunks.
    Chunks can be None in which case they are ignored by the codec.

    Parameters
    ----------
    chunks_and_specs : Iterable[tuple[CodecOutput | None, ArraySpec]]
        Ordered set of encoded chunks with their accompanying chunk spec.

    Returns
    -------
    Iterable[CI | None]
    """
    return await _batching_helper(self._decode_single, chunks_and_specs)

encode async

encode(
    chunks_and_specs: Iterable[tuple[CI | None, ArraySpec]],
) -> Iterable[CO | None]

Encodes a batch of chunks. Chunks can be None in which case they are ignored by the codec.

Parameters:

  • chunks_and_specs (Iterable[tuple[CI | None, ArraySpec]]) –

    Ordered set of to-be-encoded chunks with their accompanying chunk spec.

Returns:

Source code in zarr/abc/codec.py
async def encode(
    self,
    chunks_and_specs: Iterable[tuple[CI | None, ArraySpec]],
) -> Iterable[CO | None]:
    """Encodes a batch of chunks.
    Chunks can be None in which case they are ignored by the codec.

    Parameters
    ----------
    chunks_and_specs : Iterable[tuple[CI | None, ArraySpec]]
        Ordered set of to-be-encoded chunks with their accompanying chunk spec.

    Returns
    -------
    Iterable[CodecOutput | None]
    """
    return await _batching_helper(self._encode_single, chunks_and_specs)

evolve_from_array_spec

evolve_from_array_spec(array_spec: ArraySpec) -> Self

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

Parameters:

  • array_spec (ArraySpec) –

Returns:

Source code in zarr/abc/codec.py
def evolve_from_array_spec(self, array_spec: ArraySpec) -> Self:
    """Fills in codec configuration parameters that can be automatically
    inferred from the array metadata.

    Parameters
    ----------
    array_spec : ArraySpec

    Returns
    -------
    Self
    """
    return self

from_dict classmethod

from_dict(data: dict[str, JSON]) -> Self

Create an instance of the model from a dictionary

Source code in zarr/codecs/numcodecs/_codecs.py
@classmethod
def from_dict(cls, data: dict[str, JSON]) -> Self:
    codec_config = _parse_codec_configuration(data)
    return cls(**codec_config)

resolve_metadata

resolve_metadata(chunk_spec: ArraySpec) -> 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_spec (ArraySpec) –

Returns:

  • ArraySpec
Source code in zarr/abc/codec.py
def resolve_metadata(self, chunk_spec: ArraySpec) -> 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_spec : ArraySpec

    Returns
    -------
    ArraySpec
    """
    return chunk_spec

to_dict

to_dict() -> dict[str, JSON]

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.

Source code in zarr/codecs/numcodecs/_codecs.py
def to_dict(self) -> dict[str, JSON]:
    codec_config = self.codec_config.copy()
    codec_config.pop("id", None)
    return {
        "name": self.codec_name,
        "configuration": codec_config,
    }

validate

validate(
    *,
    shape: tuple[int, ...],
    dtype: ZDType[TBaseDType, TBaseScalar],
    chunk_grid: ChunkGridMetadata,
) -> None

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

Parameters:

  • shape (tuple[int, ...]) –

    The array shape

  • dtype (dtype[Any]) –

    The array data type

  • chunk_grid (ChunkGridMetadata) –

    The array chunk grid metadata

Source code in zarr/abc/codec.py
def validate(
    self,
    *,
    shape: tuple[int, ...],
    dtype: ZDType[TBaseDType, TBaseScalar],
    chunk_grid: ChunkGridMetadata,
) -> None:
    """Validates that the codec configuration is compatible with the array metadata.
    Raises errors when the codec configuration is not compatible.

    Parameters
    ----------
    shape : tuple[int, ...]
        The array shape
    dtype : np.dtype[Any]
        The array data type
    chunk_grid : ChunkGridMetadata
        The array chunk grid metadata
    """

Zstd dataclass

Bases: _NumcodecsBytesBytesCodec

Source code in zarr/codecs/numcodecs/_codecs.py
class Zstd(_NumcodecsBytesBytesCodec, codec_name="zstd"):
    pass

codec_config instance-attribute

codec_config: dict[str, JSON]

codec_name instance-attribute

codec_name: str

is_fixed_size instance-attribute

is_fixed_size: bool

__init__

__init__(**codec_config: JSON) -> None
Source code in zarr/codecs/numcodecs/_codecs.py
def __init__(self, **codec_config: JSON) -> None:
    super().__init__(**codec_config)

__init_subclass__

__init_subclass__(
    *, codec_name: str | None = None, **kwargs: Any
) -> None

To be used only when creating the actual public-facing codec class.

Source code in zarr/codecs/numcodecs/_codecs.py
def __init_subclass__(cls, *, codec_name: str | None = None, **kwargs: Any) -> None:
    """To be used only when creating the actual public-facing codec class."""
    super().__init_subclass__(**kwargs)
    if codec_name is not None:
        namespace = codec_name

        cls_name = f"{CODEC_PREFIX}{namespace}.{cls.__name__}"
        cls.codec_name = f"{CODEC_PREFIX}{namespace}"
        cls.__doc__ = f"""
        See [{cls_name}][] for more details and parameters.
        """

__repr__

__repr__() -> str
Source code in zarr/codecs/numcodecs/_codecs.py
def __repr__(self) -> str:
    codec_config = self.codec_config.copy()
    codec_config.pop("id", None)
    return f"{self.__class__.__name__}(codec_name={self.codec_name!r}, codec_config={codec_config!r})"

compute_encoded_size

compute_encoded_size(
    input_byte_length: int, chunk_spec: ArraySpec
) -> int
Source code in zarr/codecs/numcodecs/_codecs.py
def compute_encoded_size(self, input_byte_length: int, chunk_spec: ArraySpec) -> int:
    raise NotImplementedError  # pragma: no cover

decode async

decode(
    chunks_and_specs: Iterable[tuple[CO | None, ArraySpec]],
) -> Iterable[CI | None]

Decodes a batch of chunks. Chunks can be None in which case they are ignored by the codec.

Parameters:

  • chunks_and_specs (Iterable[tuple[CodecOutput | None, ArraySpec]]) –

    Ordered set of encoded chunks with their accompanying chunk spec.

Returns:

Source code in zarr/abc/codec.py
async def decode(
    self,
    chunks_and_specs: Iterable[tuple[CO | None, ArraySpec]],
) -> Iterable[CI | None]:
    """Decodes a batch of chunks.
    Chunks can be None in which case they are ignored by the codec.

    Parameters
    ----------
    chunks_and_specs : Iterable[tuple[CodecOutput | None, ArraySpec]]
        Ordered set of encoded chunks with their accompanying chunk spec.

    Returns
    -------
    Iterable[CI | None]
    """
    return await _batching_helper(self._decode_single, chunks_and_specs)

encode async

encode(
    chunks_and_specs: Iterable[tuple[CI | None, ArraySpec]],
) -> Iterable[CO | None]

Encodes a batch of chunks. Chunks can be None in which case they are ignored by the codec.

Parameters:

  • chunks_and_specs (Iterable[tuple[CI | None, ArraySpec]]) –

    Ordered set of to-be-encoded chunks with their accompanying chunk spec.

Returns:

Source code in zarr/abc/codec.py
async def encode(
    self,
    chunks_and_specs: Iterable[tuple[CI | None, ArraySpec]],
) -> Iterable[CO | None]:
    """Encodes a batch of chunks.
    Chunks can be None in which case they are ignored by the codec.

    Parameters
    ----------
    chunks_and_specs : Iterable[tuple[CI | None, ArraySpec]]
        Ordered set of to-be-encoded chunks with their accompanying chunk spec.

    Returns
    -------
    Iterable[CodecOutput | None]
    """
    return await _batching_helper(self._encode_single, chunks_and_specs)

evolve_from_array_spec

evolve_from_array_spec(array_spec: ArraySpec) -> Self

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

Parameters:

  • array_spec (ArraySpec) –

Returns:

Source code in zarr/abc/codec.py
def evolve_from_array_spec(self, array_spec: ArraySpec) -> Self:
    """Fills in codec configuration parameters that can be automatically
    inferred from the array metadata.

    Parameters
    ----------
    array_spec : ArraySpec

    Returns
    -------
    Self
    """
    return self

from_dict classmethod

from_dict(data: dict[str, JSON]) -> Self

Create an instance of the model from a dictionary

Source code in zarr/codecs/numcodecs/_codecs.py
@classmethod
def from_dict(cls, data: dict[str, JSON]) -> Self:
    codec_config = _parse_codec_configuration(data)
    return cls(**codec_config)

resolve_metadata

resolve_metadata(chunk_spec: ArraySpec) -> 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_spec (ArraySpec) –

Returns:

  • ArraySpec
Source code in zarr/abc/codec.py
def resolve_metadata(self, chunk_spec: ArraySpec) -> 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_spec : ArraySpec

    Returns
    -------
    ArraySpec
    """
    return chunk_spec

to_dict

to_dict() -> dict[str, JSON]

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.

Source code in zarr/codecs/numcodecs/_codecs.py
def to_dict(self) -> dict[str, JSON]:
    codec_config = self.codec_config.copy()
    codec_config.pop("id", None)
    return {
        "name": self.codec_name,
        "configuration": codec_config,
    }

validate

validate(
    *,
    shape: tuple[int, ...],
    dtype: ZDType[TBaseDType, TBaseScalar],
    chunk_grid: ChunkGridMetadata,
) -> None

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

Parameters:

  • shape (tuple[int, ...]) –

    The array shape

  • dtype (dtype[Any]) –

    The array data type

  • chunk_grid (ChunkGridMetadata) –

    The array chunk grid metadata

Source code in zarr/abc/codec.py
def validate(
    self,
    *,
    shape: tuple[int, ...],
    dtype: ZDType[TBaseDType, TBaseScalar],
    chunk_grid: ChunkGridMetadata,
) -> None:
    """Validates that the codec configuration is compatible with the array metadata.
    Raises errors when the codec configuration is not compatible.

    Parameters
    ----------
    shape : tuple[int, ...]
        The array shape
    dtype : np.dtype[Any]
        The array data type
    chunk_grid : ChunkGridMetadata
        The array chunk grid metadata
    """