blosc2.register_filter#
- blosc2.register_filter(id: int, forward: Callable[[np.ndarray[np.uint8], np.ndarray[np.uint8], int, blosc2.SChunk], None] | None = None, backward: Callable[[np.ndarray[np.uint8], np.ndarray[np.uint8], int, blosc2.SChunk], None] | None = None, name: str | None = None) None #
Register a user-defined filter.
- Parameters:
id¶ (int) – Filter id, must be between 160 and 255 (inclusive).
forward¶ (Python function) – Function to apply the filter. Receives an input ndarray of dtype uint8, an output ndarray of dtype uint8, the filter meta and the corresponding SChunk instance. If None, the filter name indicates a dynamic plugin which must be installed.
backward¶ (Python function) – Function to reverse the filter. Receives an input ndarray of dtype uint8, an output ndarray of dtype uint8, the filter meta and the SChunk instance. If None then the filter name indicates a dynamic plugin which must be installed.
name¶ (str) – The filter name. If both forward`and `backward are None, this parameter must be passed to correctly load the dynamic filter.
- Returns:
out
- Return type:
None
Notes
Multi-threading cannot be used with a user-defined filter.
User-defined filters can only be used inside an SChunk instance.
See also
Examples
# Define forward and backward functions def forward(input, output, meta, schunk): nd_input = input.view(dtype) nd_output = output.view(dtype) nd_output[:] = nd_input + 1 def backward(input, output, meta, schunk): nd_input = input.view(dtype) nd_output = output.view(dtype) nd_output[:] = nd_input - 1 # Register filter id = 160 blosc2.register_filter(id, forward, backward)