CleaningPipeο
Tip
π‘ Usage Examples - See the notebook for usage examples and code snippets: Cleaning
- class sleepeegpy.pipeline.CleaningPipe(*, prec_pipe=None, path_to_eeg=NOTHING, output_dir=NOTHING)[source]ο
Bases:
BasePipe
The cleaning pipeline element.
Contains resampling function, band and notch filters, mne browser for manual selection of bad channels and bad data spans.
Methods:
Writes bad channels file automatically based on pyprep lib
Sets annotations automatically based on MNE preprocessing library.
A wrapper for
mne.io.Raw.filter()
.A wrapper for
mne.io.Raw.interpolate_bads()
A wrapper for
mne.io.Raw.notch_filter()
.A wrapper for
mne.io.Raw.plot()
.A wrapper for
mne.viz.plot_sensors()
with a legend.Imports annotations from file to mne raw object
Imports bad channels from file to mne raw object.
A wrapper for
mne.io.Raw.resample()
with an additional option to save the resampled data to file.Writes annotations to "annotations.txt" file.
Adds bad channels from info["bads"] to the "bad_channels.txt" file.
A wrapper for
mne.io.Raw.save()
.A wrapper for
mne.io.Raw.set_eeg_reference()
.Attributes:
Calculates percent of data segments annotated as BAD.
A wrapper for
raw.info["sfreq"]
.Preceding pipe that hands over mne_raw object and output_dir.
Can be any eeg file type supported by
mne.io.read_raw()
.Path to the directory where the output will be saved.
An instanse of
mne.io.Raw
.- resample(sfreq=250, **resample_kwargs)[source]ο
A wrapper for
mne.io.Raw.resample()
with an additional option to save the resampled data to file.- Parameters:
sfreq (
float
) β Desired new frequency. Defaults to 250.save β Whether to save a resampled data to a fif file. Defaults to False.
**resample_kwargs β Arguments passed to
mne.io.Raw.resample()
.
- filter(l_freq=0.3, h_freq=None, **filter_kwargs)[source]ο
A wrapper for
mne.io.Raw.filter()
.- Parameters:
l_freq (
float
|None
) β Lower pass-band edge in Hz. Defaults to 0.3.h_freq (
float
|None
) β Upper pass-band edge in Hz. Defaults to None.**filter_kwargs β Arguments passed to
mne.io.Raw.filter()
.
- notch(freqs='50s', **notch_kwargs)[source]ο
A wrapper for
mne.io.Raw.notch_filter()
.- Parameters:
freqs (
str
|Iterable
[float
]) β Frequencies to notch filter in Hz. Can be either array of floats, or β50sβ or β60sβ to filter harmonics of 50 and 60 Hz, respectively. Defaults to β50sβ.**notch_kwargs β Arguments passed to
mne.io.Raw.notch_filter()
.
- auto_set_annotations(amplitude_peak=0.0001, amplitude_min_duration=0.005)[source]ο
Sets annotations automatically based on MNE preprocessing library.
- Parameters:
amplitude_peak (float) β Maximum accepted peak-to-peak (PTP) amplitude.
amplitude_min_duration (float) β Minimum required duration for the annotation.c
For more information about these parameters, check: https://mne.tools/dev/generated/mne.preprocessing.annotate_amplitude.html
- auto_detect_bad_channels(path=None, methods=dict_keys(['ransac', 'SNR', 'hf_noise', 'correlation', 'deviation', 'dropout', 'flat']))[source]ο
Writes bad channels file automatically based on pyprep lib
- Parameters:
path β Path to the output bad channels file. if None will be saved in default path.
- Returns:
The path of the generated bad channels file.
- Return type:
str
- read_bad_channels(path=None)[source]ο
Imports bad channels from file to mne raw object.
- Parameters:
path (
str
|None
) β Path to the txt file with bad channel name per row. Defaults to None.
- read_annotations(path=None)[source]ο
Imports annotations from file to mne raw object
- Parameters:
path (
str
|None
) β Path to txt file with mne-style annotations. Defaults to None.
- save_bad_channels(overwrite=False)[source]ο
Adds bad channels from info[βbadsβ] to the βbad_channels.txtβ file.
- Parameters:
overwrite β Whether to overwrite the file if exists. If False will add unique new channels to the file. Defaults to False.
- save_annotations(overwrite=False)[source]ο
Writes annotations to βannotations.txtβ file.
- Parameters:
overwrite β Whether to overwrite the file if exists. If False and the file exists will throw an exception. Defaults to False.
- property bad_data_percent[source]ο
Calculates percent of data segments annotated as BAD.
- Returns:
percent of bad data spans in raw data
- Return type:
float
- interpolate_bads(**interp_kwargs)[source]ο
A wrapper for
mne.io.Raw.interpolate_bads()
- Parameters:
**interp_kwargs β Arguments passed to
mne.io.Raw.interpolate_bads()
.
- plot(save_annotations=False, save_bad_channels=False, overwrite=False, **kwargs)[source]ο
A wrapper for
mne.io.Raw.plot()
.- Parameters:
save_annotations (
bool
) β Whether to save annotations as txt. Defaults to False.save_bad_channels (
bool
) β Whether to save bad channels as txt. Defaults to False.overwrite (
bool
) β Whether to overwrite annotations and bad_channels files if exist. Defaults to False.**kwargs β Arguments passed to
mne.io.Raw.plot()
.
- plot_sensors(legend=None, legend_args=None, **kwargs)[source]ο
A wrapper for
mne.viz.plot_sensors()
with a legend.- Parameters:
legend (
Iterable
[str
]) β ch_groups names to connect to colors. Defaults to None.legend_args (
dict
) β Arguments passed tomatplotlib.axes.Axes.legend()
. Defaults to None.**kwargs β Arguments passed to
mne.viz.plot_sensors()
.
- save_raw(fname, **kwargs)[source]ο
A wrapper for
mne.io.Raw.save()
.- Parameters:
fname (
str
) β Filename for the fif file being saved.**kwargs β Arguments passed to
mne.io.Raw.save()
.
- set_eeg_reference(ref_channels='average', projection=False, **kwargs)[source]ο
A wrapper for
mne.io.Raw.set_eeg_reference()
.- Parameters:
ref_channels β
ref_channels
. Defaults to βaverageβ.projection β
projection
. Defaults to False.**kwargs β Additional arguments passed to
mne.io.Raw.set_eeg_reference()
.
- property sf[source]ο
A wrapper for
raw.info["sfreq"]
.- Returns:
sampling frequency
- Return type:
float
- prec_pipe: Type[BasePipeType]ο
Preceding pipe that hands over mne_raw object and output_dir.
- path_to_eeg: Pathο
Can be any eeg file type supported by
mne.io.read_raw()
.
- output_dir: Pathο
Path to the directory where the output will be saved.
- mne_raw: mne.io.Rawο
An instanse of
mne.io.Raw
.