pyprep.PrepPipeline

class pyprep.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
rawmne.io.Raw

The data. Channel types must be correctly assigned (e.g., ocular channels are assigned the type ‘eog’).

prep_paramsdict

Parameters of PREP which include at least the following keys:

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

  • reref_chs{list, ‘eeg’}
    • A list of channel names to be used for line-noise removed, and referenced. 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.

montagemne.channels.DigMontage

Digital montage of EEG data.

ransacbool, optional

Whether or not to use RANSAC for noisy channel detection in addition to the other methods in NoisyChannels. Defaults to True.

channel_wisebool, 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_strictbool, optional

Whether or not PyPREP should strictly follow MATLAB PREP’s internal math, ignoring any improvements made in PyPREP over the original code (see Deliberate Differences from MATLAB PREP for more details). Defaults to False.

References

1

Bigdely-Shamlo, N., Mullen, T., Kothe, C., Su, K. M., Robbins, K. A. (2015). The PREP pipeline: standardized preprocessing for large-scale EEG analysis. Frontiers in Neuroinformatics, 9, 16.

Attributes

raw

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

raw_eeg

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

raw_non_eeg

({mne.io.Raw, None}) 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.

noisy_channels_original

(dict) Detailed bad channels in each criteria before robust reference.

noisy_channels_before_interpolation

(dict) Detailed bad channels in each criteria just before interpolation.

noisy_channels_after_interpolation

(dict) Detailed bad channels in each criteria just after interpolation.

bad_before_interpolation

(list) bad channels after robust reference but before interpolation

EEG_before_interpolation

(np.ndarray) EEG data in uV before the interpolation

reference_before_interpolation

(np.ndarray) Reference signal in uV before interpolation.

reference_after_interpolation

(np.ndarray) Reference signal in uV after interpolation.

interpolated_channels

(list) Names of the interpolated channels.

still_noisy_channels

(list) Names of the noisy channels after interpolation.

fit()[source]

Run the whole PREP pipeline.

property raw

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

Examples using pyprep.PrepPipeline

Run the full PREP

Run the full PREP

Run the full PREP