abczarr.metadata.v2.codecs
Classes
Codec
Codec(id: str | bytes = '', *, extra_items: Iterable[tuple[str | bytes, Any]] | Mapping[str | bytes, Any] = FrozenDict({}))
Bases: Metadata
A Codec names a numcodecs codec through id and carries that
codec's own parameters.
A v2 codec's parameters sit directly alongside id, not nested
under a separate key.
The three metadata versions spell the same codec differently. A v1
codec carries its numcodecs id as a class attribute and its
parameters as fields. A v2 codec carries the id as a field alongside
its parameters, as shown here. A v3 codec names itself through
name and nests its parameters under a separate configuration
object. The gzip codec, with its single level parameter, shows
the three side by side:
>>> from abczarr.metadata import v1, v2, v3
>>> v1.GzipCodecOptions(level=1)
GzipCodecOptions(level=1)
>>> v2.GzipCodec(id="gzip", level=1)
GzipCodec(id='gzip', level=1)
>>> codec = v3.GzipCodec(name="gzip", configuration={"level": 1})
>>> codec.name, codec.configuration
('gzip', GzipConfig(level=1))
Attributes
Methods:
to_version
to_version(version: ZarrVersion) -> Codec
Convert this codec to another Zarr version.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
version
|
ZarrVersion
|
The target Zarr format version: 1, 2 or 3. |
required |
Returns:
| Type | Description |
|---|---|
Codec
|
The equivalent codec for |
Raises:
| Type | Description |
|---|---|
ValueError
|
If |
CodecImpl
Bases: Codec
This class is the base for a v2 codec whose options are all declared, not open-ended.
Methods:
BloscCodec
BloscCodec(id: Literal['blosc'] = 'blosc', cname: Literal['blosclz', 'lz4', 'lz4hc', 'snappy', 'zlib', 'zstd'] = 'lz4', clevel: Literal[0, 1, 2, 3, 4, 5, 6, 7, 8, 9] = 5, shuffle: Literal[0, 1, 2, -1] = 1, blocksize: Integral | integer | bool = 0, typesize: Integral | integer | bool | None = None)
Bases: CodecImpl
Compresses data with Blosc, a meta-compressor that shuffles bytes and then applies an inner compressor.
Blosc groups same-typed bytes together before handing them to
cname (one of blosclz, lz4, lz4hc, snappy, zlib or zstd), and
compresses the result in blocks so multiple threads can be used.
Attributes
CompressionLevel
class-attribute
instance-attribute
CompressionLevel: ClassVar = codecs.BloscCompressionLevel
cname
class-attribute
instance-attribute
cname: CodecName = 'lz4'
The inner compressor Blosc applies.
clevel
class-attribute
instance-attribute
clevel: CompressionLevel = 5
The compression level, from 0 to 9.
shuffle
class-attribute
instance-attribute
shuffle: Shuffle = 1
The byte-shuffle filter applied before compression: 0 for
none, 1 for byte shuffle, 2 for bit shuffle, or -1 to
let Blosc choose automatically.
blocksize
class-attribute
instance-attribute
blocksize: int = 0
The block size Blosc compresses in, in bytes. 0 lets Blosc
choose automatically.
typesize
class-attribute
instance-attribute
typesize: int | None = None
The size, in bytes, of the array's element type. Blosc uses this to group same-position bytes together when shuffling.
Methods:
to_version
to_version(version: ZarrVersion) -> Metadata
Convert this codec to another Zarr version.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
version
|
ZarrVersion
|
The target Zarr format version: 1, 2 or 3. |
required |
Returns:
| Type | Description |
|---|---|
Metadata
|
The equivalent Blosc codec for |
Raises:
| Type | Description |
|---|---|
ValueError
|
If |
GzipCodec
Bases: CodecImpl
Applies DEFLATE compression (gzip) at a configurable compression level.
Attributes
CompressionLevel
class-attribute
instance-attribute
CompressionLevel: ClassVar = codecs.GzipCompressionLevel
level
class-attribute
instance-attribute
level: CompressionLevel = 5
The compression level, from 0 to 9.
Methods:
Bz2Codec
LZMACodec
LZMACodec(id: Literal['lzma'] = 'lzma', format: Literal[0, 1, 2, 3] = 0, check: Literal[0, 1, 4, 10, 15, 16] = 0, preset: Literal[0, 1, 2, 3, 4, 5, 6, 7, 8, 9] = 0, filters: Iterable[Iterable[tuple[str | bytes, Any]] | Mapping[str | bytes, Any]] = ())
Bases: CodecImpl
Compresses each chunk with LZMA, the compression used by
.xz/.7z files, via Python's lzma module.
filters carries the raw lzma filter chain for cases that need
one, such as selecting a custom dictionary size. Most uses only
need format, check and preset.
Attributes
CompressionLevel
class-attribute
instance-attribute
CompressionLevel: ClassVar = codecs.LZMACompressionLevel
filters
instance-attribute
The raw lzma filter chain, when a custom one is needed.
Methods:
LZ4Codec
Bases: CodecImpl
Compresses each chunk with LZ4, which is very fast at the cost of a lower compression ratio.
acceleration trades ratio for speed further. A higher value
compresses faster and produces a lower ratio.
PCodec
PCodec(id: Literal['pcodec'] = 'pcodec', level: Literal[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12] = 0, mode_spec: Literal['auto', 'classic'] = 'auto', delta_spec: Literal['auto', 'none', 'try_consecutive', 'try_lookback'] = 'auto', paging_spec: Literal['equal_pages_up_to'] = 'equal_pages_up_to', delta_encoding_order: Literal[0, 1, 2, 3, 4, 5, 6, 7] = 0, equal_pages_up_to: Integral | integer | bool = 0)
Bases: CodecImpl
Compresses numeric arrays with Pcodec (pco).
Pcodec models each chunk's value distribution directly, optionally after delta encoding, instead of treating the chunk as a byte stream. Pcodec typically outperforms general-purpose compressors on numeric data while remaining lossless.
Attributes
CompressionLevel
class-attribute
instance-attribute
CompressionLevel: ClassVar = codecs.PCodecCompressionLevel
mode_spec
instance-attribute
mode_spec: Mode
How Pcodec chooses its numerical mode: "auto" or
"classic".
delta_spec
instance-attribute
delta_spec: Delta
How Pcodec chooses whether to delta-encode values before modeling them.
paging_spec
instance-attribute
paging_spec: Paging
How Pcodec splits a chunk into pages for encoding.
delta_encoding_order
instance-attribute
delta_encoding_order: DeltaOrder
The order of delta encoding applied, when delta_spec selects
one.
equal_pages_up_to
instance-attribute
equal_pages_up_to: int
The maximum page size, in elements, when paging_spec is
"equal_pages_up_to".
Methods:
ZFPYCodec
ZFPYCodec(id: Literal['zfpy'] = 'zfpy', mode: Literal[0, 1, 2, 3, 4] = 0, tolerance: Real | floating | bool = 0.0, rate: Integral | integer | bool = 0, precision: Integral | integer | bool = 0, compression_kwargs: Iterable[tuple[str | bytes, Any]] | Mapping[str | bytes, Any] = FrozenDict({}))
Bases: CodecImpl
Compresses floating-point arrays with ZFP, via the zfpy
bindings.
mode selects which of tolerance, rate and precision
governs the accuracy/size trade-off. Compression is lossy, except
in the fixed-accuracy mode with a tolerance of zero.
Attributes
tolerance
instance-attribute
tolerance: float
The maximum absolute error allowed, in fixed-accuracy mode.
precision
instance-attribute
precision: int
The number of bits of precision retained, in fixed-precision mode.
compression_kwargs
instance-attribute
Extra keyword arguments forwarded to the underlying zfpy
call.