CleaningPipe¶
- 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
.