ApplyFunctionFilter#
- class myoverse.datasets.filters.generic.ApplyFunctionFilter(input_is_chunked, is_output=False, name=None, run_checks=True, *, function=None, **function_kwargs)[source]#
Filter that applies a function to the input array.
This filter provides a flexible way to apply any function to the input data array. The function can be a simple lambda, a NumPy function, or any custom function that operates on numpy arrays.
- Parameters:
input_is_chunked (bool) – Whether the input is chunked or not.
is_output (bool, optional) – Whether this is an output filter, by default False.
name (str, optional) – Name of the filter, by default None.
run_checks (bool) –
Whether to run the checks when filtering. By default, True. If False can potentially speed up performance.
Warning
If False, the user is responsible for ensuring that the input array is valid.
function (callable, optional) – The function to apply to the input array, by default None
**function_kwargs – Additional keyword arguments to pass to the function.
Examples
>>> import numpy as np >>> from myoverse.datasets.filters.generic import ApplyFunctionFilter >>> # Create data >>> data = np.random.rand(10, 500) >>> # Apply absolute value function >>> abs_filter = ApplyFunctionFilter(function=np.abs, input_is_chunked=False) >>> abs_data = abs_filter(data) >>> # Apply mean function with axis parameter >>> mean_filter = ApplyFunctionFilter(function=np.mean, axis=-1, input_is_chunked=False) >>> mean_data = mean_filter(data) >>> # Apply custom function >>> custom_filter = ApplyFunctionFilter(function=lambda x: x**2 - x, input_is_chunked=False) >>> custom_data = custom_filter(data)
Notes
The function is applied directly to the input array without any pre-processing. The output shape depends on the function being applied. For example, np.mean with axis=-1 will reduce the last dimension, changing the output shape.
See also
IdentityFilter
A filter that returns the input unchanged
Methods
__init__
(input_is_chunked[, is_output, ...])_filter
(input_array, **kwargs)Apply the function to the input array.
_run_filter_checks
(input_array)Run checks on the input array.