msqms.libs.pyprep.prep_pipeline module#

Module for PREP pipeline.

Summary#

Classes:#

PrepPipeline

Early stage preprocessing (PREP) of EEG data.

Reference#

class msqms.libs.pyprep.prep_pipeline.PrepPipeline(raw, prep_params, montage, ransac=True, channel_wise=False, max_chunk_size=None, random_state=None, filter_kwargs=None, matlab_strict=False)[source]#

Bases: object

Early stage preprocessing (PREP) of EEG data.

This class implements the functionality of the PREP (preprocessing pipeline) for EEG data described in [1].

Parameters:
  • raw (mne.io.Raw) – The data. Channel types must be correctly assigned (e.g., ocular channels are assigned the type ‘eog’).

  • prep_params (dict) –

    Parameters of PREP which include at least the following keys:

    • ref_chs{list, ‘eeg’}
      • A list of channel names to be used for rereferencing. These channels will be used to construct the reference signal. Can be a str ‘eeg’ to use all EEG channels.

    • reref_chs{list, ‘eeg’}
      • A list of channel names to define from which channels the reference signal will be subtracted. Can be a str ‘eeg’ to use all EEG channels.

    • line_freqs{np.ndarray, list}
      • list of floats indicating frequencies to be removed. For example, for 60Hz you may specify np.arange(60, sfreq / 2, 60). Specify an empty list to skip the line noise removal step.

    • max_iterationsint, optional
      • The maximum number of iterations of noisy channel removal to perform during robust referencing. Defaults to 4.

  • montage (mne.channels.DigMontage) – Digital montage of EEG data.

  • ransac (bool, optional) – Whether or not to use RANSAC for noisy channel detection in addition to the other methods in NoisyChannels. Defaults to True.

  • channel_wise (bool, optional) – Whether RANSAC should predict signals for chunks of channels over the entire signal length (“channel-wise RANSAC”, see max_chunk_size parameter). If False, RANSAC will instead predict signals for all channels at once but over a number of smaller time windows instead of over the entire signal length (“window-wise RANSAC”). Channel-wise RANSAC generally has higher RAM demands than window-wise RANSAC (especially if max_chunk_size is None), but can be faster on systems with lots of RAM to spare. Has no effect if not using RANSAC. Defaults to False.

  • max_chunk_size ({int, None}, optional) – The maximum number of channels to predict at once during channel-wise RANSAC. If None, RANSAC will use the largest chunk size that will fit into the available RAM, which may slow down other programs on the host system. If using window-wise RANSAC (the default) or not using RANSAC at all, this parameter has no effect. Defaults to None.

  • random_state ({int, None, np.random.RandomState}, optional) – The random seed at which to initialize the class. If random_state is an int, it will be used as a seed for RandomState. If None, the seed will be obtained from the operating system (see RandomState for details). Default is None.

  • filter_kwargs ({dict, None}, optional) – Optional keywords arguments to be passed on to mne.filter.notch_filter. Do not set the “x”, Fs”, and “freqs” arguments via the filter_kwargs parameter, but use the “raw” and “prep_params” parameters instead. If None is passed, the pyprep default settings for filtering are used instead.

  • matlab_strict (bool, optional) – Whether or not PyPREP should strictly follow MATLAB PREP’s internal math, ignoring any improvements made in PyPREP over the original code (see matlab-diffs for more details). Defaults to False.

raw#

The data including eeg and non eeg channels. It is unprocessed if accessed before the fit method, processed if accessed after a successful fit method.

Type:

mne.io.Raw

raw_eeg#

The only-eeg part of the data. It is unprocessed if accessed before the fit method, processed if accessed after a successful fit method.

Type:

mne.io.Raw

raw_non_eeg#

The non-eeg part of the data. It is not processed when calling the fit method. If the input was only EEG it will be None.

Type:

{mne.io.Raw, None}

noisy_channels_original#

Detailed bad channels in each criteria before robust reference.

Type:

dict

noisy_channels_before_interpolation#

Detailed bad channels in each criteria just before interpolation.

Type:

dict

noisy_channels_after_interpolation#

Detailed bad channels in each criteria just after interpolation.

Type:

dict

bad_before_interpolation#

bad channels after robust reference but before interpolation

Type:

list

EEG_before_interpolation#

EEG data in uV before the interpolation

Type:

np.ndarray

reference_before_interpolation#

Reference signal in uV before interpolation.

Type:

np.ndarray

reference_after_interpolation#

Reference signal in uV after interpolation.

Type:

np.ndarray

interpolated_channels#

Names of the interpolated channels.

Type:

list

still_noisy_channels#

Names of the noisy channels after interpolation.

Type:

list

References

property raw#

Return a version of self.raw_eeg that includes the non-eeg channels.

fit()[source]#

Run the whole PREP pipeline.