yasa.Hypnogram.as_events#
- Hypnogram.as_events()[source]#
Return a pandas DataFrame summarizing epoch-level information.
The
onsetanddurationcolumns (in seconds) follow the BIDS events file specification. Thedescriptioncolumn is compatible with MNE Annotations, making it straightforward to attach the hypnogram to an MNERawobject (see Examples below).- Returns:
- events
pandas.DataFrame A dataframe containing epoch onset, duration, stage, etc.
- events
Examples
>>> from yasa import Hypnogram >>> hyp = Hypnogram(["W", "W", "LIGHT", "LIGHT", "DEEP", "REM", "WAKE"], n_stages=4) >>> hyp.as_events() onset duration value description epoch 0 0.0 30.0 0 WAKE 1 30.0 30.0 0 WAKE 2 60.0 30.0 2 LIGHT 3 90.0 30.0 2 LIGHT 4 120.0 30.0 3 DEEP 5 150.0 30.0 4 REM 6 180.0 30.0 0 WAKE
To attach the hypnogram to an MNE
Rawobject as annotations, pass theonset,duration, anddescriptioncolumns tomne.Annotationsand callset_annotations:import mne events = hyp.as_events() annotations = mne.Annotations( onset=events["onset"], duration=events["duration"], description=events["description"], ) raw.set_annotations(annotations) # raw is an mne.io.Raw object