DifferentialSpatialFilter#

class myoverse.datasets.filters.spatial.DifferentialSpatialFilter(input_is_chunked, is_output=False, name=None, run_checks=True, *, filter_name, grids_to_process='all')[source]#

Differential spatial filter for EMG data.

This filter applies various differential spatial filters to EMG data, which help improve signal quality by enhancing differences between adjacent electrodes. The filters are defined according to https://doi.org/10.1088/1741-2552/ad3498.

Parameters:
  • filter_name (Literal["LSD", "TSD", "LDD", "TDD", "NDD", "IB2", "IR", "identity"]) –

    Name of the filter to be applied. Options include:

    • ”LSD”: Longitudinal Single Differential - computes difference between adjacent electrodes along columns

    • ”TSD”: Transverse Single Differential - computes difference between adjacent electrodes along rows

    • ”LDD”: Longitudinal Double Differential - computes double difference along columns

    • ”TDD”: Transverse Double Differential - computes double difference along rows

    • ”NDD”: Normal Double Differential - combines information from electrodes in cross pattern

    • ”IB2”: Inverse Binomial filter of the 2nd order

    • ”IR”: Inverse Rectangle filter

    • ”identity”: No filtering, returns the original signal

  • 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.

The convolution operation reduces the spatial dimensions based on the filter size, which means the output will have fewer electrodes than the input.

Examples

>>> import numpy as np
>>> from myoverse.datatypes import EMGData
>>> from myoverse.datasets.filters.spatial import DifferentialSpatialFilter
>>>
>>> # Create sample EMG data (64 channels, 1000 samples)
>>> emg_data = np.random.randn(64, 1000)
>>> emg = EMGData(emg_data, 2000)
>>>
>>> # Apply Laplacian filter to all grids
>>> ndd_filter = DifferentialSpatialFilter(
>>>     filter_name="NDD",
>>>     input_is_chunked=False
>>> )
>>> filtered_data = emg.apply_filter(ndd_filter)
>>>
>>> # Apply Laplacian filter to only the first grid
>>> ndd_first_grid = DifferentialSpatialFilter(
>>>     filter_name="NDD",
>>>     input_is_chunked=False,
>>>     grids_to_process=0
>>> )
>>> filtered_first = emg.apply_filter(ndd_first_grid)

Methods

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

_apply_differential_filter(grid_data, ...)

Apply differential 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.