BaseHypnoPipeο
Tip
See the π¨ Abstract Class - This class is abstract and cannot be used directly. Subclass it and implement the required methods. for usage examples.
- class sleepeegpy.base.BaseHypnoPipe(*, prec_pipe=None, path_to_eeg=NOTHING, output_dir=NOTHING, path_to_hypno=None, hypno_freq=NOTHING, hypno=NOTHING)[source]ο
Bases:
BasePipe
,ABC
A base class for the sleep-stage-analysis pipeline segments.
Methods:
A wrapper for
mne.io.Raw.interpolate_bads()
A wrapper for
mne.io.Raw.plot()
.A wrapper for
mne.viz.plot_sensors()
with a legend.Runs YASA's automatic sleep staging.
A wrapper for
mne.io.Raw.save()
.A wrapper for
mne.io.Raw.set_eeg_reference()
.A wrapper for
yasa.sleep_statistics()
.Attributes:
Calculates percent of data segments annotated as BAD.
A wrapper for
raw.info["sfreq"]
.Path to hypnogram.
Sampling rate of the hypnogram in Hz.
Hypnogram with sampling frequency hypno_freq with int representing sleep stage.
Hypnogram upsampled to the sampling frequency of the raw data.
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
.-
path_to_hypno:
Path
ο Path to hypnogram. Must be text file with every row being int representing sleep stage for the epoch.
-
hypno_freq:
float
ο Sampling rate of the hypnogram in Hz.
E.g., 1/30 means 1 sample per 30 secs epoch, 250 means 1 sample per 1/250 sec epoch.
-
hypno:
ndarray
ο Hypnogram with sampling frequency hypno_freq with int representing sleep stage.
-
hypno_up:
array
ο Hypnogram upsampled to the sampling frequency of the raw data.
- predict_hypno(eeg_name='E183', eog_name='E252', emg_name='E247', ref_name='E26', save=True)[source]ο
Runs YASAβs automatic sleep staging.
- Parameters:
eeg_name (
str
) β Preferentially a central electrode. Defaults to βE183β.eog_name (
str
) β Preferentially, the left LOC channel. Defaults to βE252β.emg_name (
str
) β Preferentially a chin electrode. Defaults to βE247β.ref_name (
str
) β Reference channel, preferentially a mastoid. Defaults to βE26β.save (
bool
) β Whether to save the hypnogram to file. Defaults to True.
- sleep_stats(save=False)[source]ο
A wrapper for
yasa.sleep_statistics()
.- Parameters:
save (
bool
) β Whether to save the stats to csv. 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
[TypeVar
(BasePipeType
, bound= BasePipe)]ο 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:
Raw
ο An instanse of
mne.io.Raw
.
-
path_to_hypno: