ApplyFunctionSpatialFilter#

class myoverse.datasets.filters.spatial.ApplyFunctionSpatialFilter(input_is_chunked, is_output=False, name=None, run_checks=True, *, kernel_size, function, strides=(1, 1), padding='same', grids_to_process='all')[source]#

Apply a function over the EMG grids using a user defined kernel.

This filter applies a function over a user defined grid. The user can define the kernel and the function will be applied over the grid using the kernel.

Parameters:
  • kernel_size (tuple[int, int]) – The kernel size to use for the convolution. Must be a tuple of two integers.

  • strides (tuple[int, int]) – The strides to use for the convolution. Must be a tuple of two integers.

  • padding (str) – The padding to use for the convolution. Must be one of “same” or “valid”.

  • function (callable) –

    The function to apply over the grid. If input_is_chunked is True, the function must take and return a 4D array otherwise it must take and return a 3D array.

    Note

    The input shape will be (chunks, time, y, x) if input_is_chunked is True and (time, y, x) if input_is_chunked is False.

    Warning

    The function should only modify the y and x dimensions of the input array.

  • input_is_chunked (bool) – Whether the input data is organized in chunks (3D array) or not (2D array).

  • grids_to_process (Union[Literal["all"], List[int]]) –

    Specifies which grids to apply the filter to:

    • ”all”: Process all grids (default)

    • List[int]: Process only the grids with these indices

  • is_output (bool, default=False) – Whether the filter is an output filter.

  • name (str, optional) – Custom name for the filter. If None, the class name will be used.

  • run_checks (bool, default=True) – Whether to run validation checks when filtering.

Notes

This filter can work with both chunked and non-chunked EMG data, and can selectively process specific grids when multiple grids are present in the data.

Important

Because the filter can have strides the output will always be row-major. This also reflects in the new grid layout.

Methods

__init__(input_is_chunked[, is_output, ...])

_apply_custom_filter(grid_data, grid_layout)

Apply custom filter to a single grid's data.

_filter(input_array, **kwargs)

Apply the selected differential spatial filter to the input array.

_run_filter_checks(input_array)

Additional validation for input data.