SChunk.prefilter#
- SChunk.prefilter(input_dtype: dtype, output_dtype: dtype = None) 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 be filled,
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 be processed the prefilter function.
output_dtype¶ (np.dtype, optional) – Data type of the output that will be filled by the prefilter function. If None (default), it will be the same as
input_dtype
.
- Returns:
out
- Return type:
None
Notes
nthreads must be 1 when compressing.
The
input_dtype
itemsize must be the same as theoutput_dtype
itemsize.
See also
Examples
# Set the compression and decompression parameters input_dtype = np.dtype(np.int32) output_dtype = np.dtype(np.float32) cparams = blosc2.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