brain_pipe.preprocessing.filter.SosFiltFilt

class SosFiltFilt(filter_, data_key='data', emulate_matlab=True, *sosfiltfilt_args, copy_data_dict=False, **sosfiltfilt_kwargs)

Bases: PipelineStep

Filter data with a second-order section filter.

Notes

Wrapper for scipy.signal.sosfiltfilt().

__init__(filter_, data_key='data', emulate_matlab=True, *sosfiltfilt_args, copy_data_dict=False, **sosfiltfilt_kwargs)

Create a SosFiltFilt instance.

Parameters:
  • filter (np.ndarray or Callable) – Array of second-order filter coefficients, must have shape (n_sections, 6). Each row corresponds to a second-order section, with the first three columns providing the numerator coefficients and the last three providing the denominator coefficients. See also the documentation on

  • data_key

  • emulate_matlab

  • sosfiltfilt_args

  • copy_data_dict

  • sosfiltfilt_kwargs

Methods

__init__(filter_[, data_key, ...])

Create a SosFiltFilt instance.

get_matlab_arguments(filter_, ...)

Mimick MATLAB's sosfiltfilt arguments.

parse_dict_keys(key[, name, ...])

Parse a key or a sequence of keys.

get_matlab_arguments(filter_, sosfiltfilt_args, sosfiltfilt_kwargs)

Mimick MATLAB’s sosfiltfilt arguments.

Parameters:
  • filter (np.ndarray) – Array of second-order filter coefficients, must have shape (n_sections, 6).

  • sosfiltfilt_args (Sequence[Any]) – Arguments passed to sosfiltfilt.

  • sosfiltfilt_kwargs (Dict[str, Any]) – Keyword arguments passed to sosfiltfilt.

Returns:

The arguments and keyword arguments to pass to sosfiltfilt to mimick MATLAB’s sosfiltfilt.

Return type:

Tuple[Sequence[Any], Dict[str, Any]]

parse_dict_keys(key: str | Sequence[str] | Mapping[str, str], name='key', require_ordered_dict=False) OrderedDict[str, str]

Parse a key or a sequence of keys.

Parameters:
  • key (Union[str, Sequence[str], Mapping[str,str]]) – A key or a sequence of keys.

  • name (str) – The name of the key. Used for error messages.

  • require_ordered_dict (bool) – If True, the key must be an OrderedDict. If False, the key can also be an ordinary dict.

Returns:

A mapping of input keys to output keys.

Return type:

OrderedDict[str, str]

Raises:

TypeError – If the key is not a string, a sequence of strings or a mapping of strings. If the key is a mapping but require_ordered_dict is True and the mapping is not an OrderedDict.