pycrostates.preprocessing.apply_spatial_filter#

pycrostates.preprocessing.apply_spatial_filter(inst, ch_type='eeg', exclude_bads=True, origin='auto', adjacency='auto', n_jobs=1, verbose=None)[source]#

Apply a spatial filter.

Adapted from Michel and Brunet[1]. Apply an instantaneous filter which interpolates channels with local neighbors while removing outliers. The current implementation proceeds as follows:

  • An interpolation matrix is computed using mne.channels.interpolation._make_interpolation_matrix.

  • An ajdacency matrix is computed using mne.channels.find_ch_adjacency.

  • If exclude_bads is set to True, bad channels are removed from the ajdacency matrix.

  • For each timepoint and each channel, a reduced adjacency matrix is built by removing neighbors with lowest and highest value.

  • For each timepoint and each channel, a reduced interpolation matrix is built by extracting neighbor weights based on the reduced adjacency matrix.

  • The reduced interpolation matrices are normalized.

  • The channel’s timepoints are interpolated using their reduced interpolation matrix.

Parameters:
instRaw | Epochs | ChData

Instance to filter spatially.

ch_typestr

The channel type on which to apply the spatial filter. Currently only supports 'eeg'.

exclude_badsbool

If set to True, bad channels will be removed from the adjacency matrix and therefore not used to interpolate neighbors. In addition, bad channels will not be filtered. If set to False, proceed as if all channels were good.

originarray of shape (3,) | str

Origin of the sphere in the head coordinate frame and in meters. Can be 'auto' (default), which means a head-digitization-based origin fit.

adjacencyarray or csr_matrix of shape (n_channels, n_channels) | str

An adjacency matrix. Can be created using mne.channels.find_ch_adjacency() and edited with mne.viz.plot_ch_adjacency(). If 'auto' (default), the matrix will be automatically created using mne.channels.find_ch_adjacency() and other parameters.

n_jobsint | None

The number of jobs to run in parallel. If -1, it is set to the number of CPU cores. Requires the joblib package. None (default) is a marker for ‘unset’ that will be interpreted as n_jobs=1 (sequential execution) unless the call is performed under a joblib.parallel_config context manager that sets another value for n_jobs.

verboseint | str | bool | None

Sets the verbosity level. The verbosity increases gradually between "CRITICAL", "ERROR", "WARNING", "INFO" and "DEBUG". If None is provided, the verbosity is set to "WARNING". If a bool is provided, the verbosity is set to "WARNING" for False and to "INFO" for True.

Returns:
instRaw | Epochs| ChData

The instance modified in place.

Notes

This function requires a full copy of the data in memory.

References

Examples using pycrostates.preprocessing.apply_spatial_filter#

Spatial Filter

Spatial Filter