Delta#
- class numcodecs.delta.Delta(dtype, astype=None)[source]#
Codec to encode data as the difference between adjacent values.
- Parameters:
- dtypedtype
Data type to use for decoded data.
- astypedtype, optional
Data type to use for encoded data.
Notes
If astype is an integer data type, please ensure that it is sufficiently large to store encoded values. No checks are made and data may become corrupted due to integer overflow if astype is too small. Note also that the encoded data for each chunk includes the absolute value of the first element in the chunk, and so the encoded data type in general needs to be large enough to store absolute values from the array.
Examples
>>> import numcodecs >>> import numpy as np >>> x = np.arange(100, 120, 2, dtype='i2') >>> codec = numcodecs.Delta(dtype='i2', astype='i1') >>> y = codec.encode(x) >>> y array([100, 2, 2, 2, 2, 2, 2, 2, 2, 2], dtype=int8) >>> z = codec.decode(y) >>> z array([100, 102, 104, 106, 108, 110, 112, 114, 116, 118], dtype=int16)
- codec_id: str | None = 'delta'#
Codec identifier.
- encode(buf)[source]#
Encode data in buf.
- Parameters:
- bufbuffer-like
Data to be encoded. May be any object supporting the new-style buffer protocol.
- Returns:
- encbuffer-like
Encoded data. May be any object supporting the new-style buffer protocol.
- decode(buf, out=None)[source]#
Decode data in buf.
- Parameters:
- bufbuffer-like
Encoded data. May be any object supporting the new-style buffer protocol.
- outbuffer-like, optional
Writeable buffer to store decoded data. N.B. if provided, this buffer must be exactly the right size to store the decoded data.
- Returns:
- decbuffer-like
Decoded data. May be any object supporting the new-style buffer protocol.
- get_config()[source]#
Return a dictionary holding configuration parameters for this codec. Must include an ‘id’ field with the codec identifier. All values must be compatible with JSON encoding.
- classmethod from_config(config)#
Instantiate codec from a configuration object.