numcodecs_mask

numcodecs_mask

Masking codecs for the numcodecs buffer compression API.

Classes:

  • MaskMetaCodec

    Meta-codec that masks a value during encoding and restores it during decoding.

MaskMetaCodec

MaskMetaCodec(
    *,
    mask: int | float,
    codec: dict | Codec,
    bitmap_codec: dict | Codec,
)

Bases: Codec, CodecCombinatorMixin

Meta-codec that masks a value during encoding and restores it during decoding.

The data is encoded with the codec, the boolean mask of where values need to be restored is encoded with the bitmap_codec.

Multiple MaskMetaCodecs can be nested to mask several values. The masked value can be replaced with a fill value before further encoding by including a numcodecs_replace.ReplaceFilterCodec in the codec, e.g. by stacking using the numcodecs-combinators package.

Parameters:
  • mask (int | float) –

    The value to be masked.

  • codec (dict | Codec) –

    The configuration or instantiated codec that encodes the data.

  • bitmap_codec (dict | Codec) –

    The configuration or instantiated codec that encodes the boolean mask of where values need to be restored.

    For instance, the numcodecs.PackBits codec can be used to pack the mask into a byte array.

Methods:

  • encode

    Encode the data in buf.

  • decode

    Decode the data in buf.

  • get_config

    Returns the configuration of this mask meta-codec.

  • map

    Apply the mapper to this mask meta-codec.

codec_id class-attribute instance-attribute

codec_id: str = 'mask.meta'

encode

encode(buf: Buffer) -> Buffer

Encode the data in buf.

Parameters:
  • buf (Buffer) –

    Data to be encoded. May be any object supporting the new-style buffer protocol.

Returns:
  • enc( Buffer ) –

    Encoded data. May be any object supporting the new-style buffer protocol.

decode

decode(buf: Buffer, out: None | Buffer = None) -> Buffer

Decode the data in buf.

Parameters:
  • buf (Buffer) –

    Encoded data. May be any object supporting the new-style buffer protocol.

  • out (Buffer, default: None ) –

    Writeable buffer to store decoded data. N.B. if provided, this buffer must be exactly the right size to store the decoded data.

Returns:
  • dec( Buffer ) –

    Decoded data. May be any object supporting the new-style buffer protocol.

get_config

get_config() -> dict

Returns the configuration of this mask meta-codec.

numcodecs.registry.get_codec(config) can be used to reconstruct this codec from the returned config.

Returns:
  • config( dict ) –

    Configuration of this mask meta-codec.

map

map(mapper: Callable[[Codec], Codec]) -> MaskMetaCodec

Apply the mapper to this mask meta-codec.

In the returned MaskMetaCodec, the codec and bitmap_codec are replaced by their mapped codecs.

The mapper should recursively apply itself to any inner codecs that also implement the CodecCombinatorMixin mixin.

To automatically handle the recursive application as a caller, you can use

numcodecs_combinators.map_codec(codec, mapper)
instead.

Parameters:
  • mapper (Callable[[Codec], Codec]) –

    The callable that should be applied to the wrapped codec and bitmap_codec to map over this mask meta-codec.

Returns: