SChunk.prefilter#

SChunk.prefilter(input_dtype, output_dtype=None)#

Decorator to set a function as a prefilter.

This function will be executed each time before compressing the data. It will receive three parameters: the actual data as a ndarray from which to read, the ndarray to fill and the offset inside the SChunk instance where the corresponding block begins (see example below).

Parameters:
  • input_dtype (np.dtype) – Data type of the input that will receive the prefilter function.

  • output_dtype (np.dtype) – Data type of the output that will receive and fill the prefilter function. If None (default) it will be input_dtype.

Returns:

out

Return type:

None

Notes

Examples

# Set the compression and decompression parameters
input_dtype = np.dtype(np.int32)
output_dtype = np.dtype(np.float32)
cparams = {"typesize": output_dtype.itemsize, "nthreads": 1}
# Create schunk
schunk = blosc2.SChunk(chunksize=200 * 1000 * input_dtype.itemsize, cparams=cparams)

# Set prefilter with decorator
@schunk.prefilter(input_dtype, output_dtype)
def prefilter(input, output, offset):
    output[:] = input - np.pi