visbrain.Sleep

class visbrain.Sleep(data=None, hypno=None, config_file=None, annotations=None, channels=None, sf=None, downsample=100.0, axis=True, href=['art', 'wake', 'rem', 'n1', 'n2', 'n3'], preload=True, use_mne=False, kwargs_mne={}, verbose=None)[source][source]

Visualize and edit sleep data.

Use this module to :

  • Load and visualize polysomnographic data and spectrogram.
  • Load, edit and save hypnogram from the interface
  • Perform automatic events detection
  • Further signal processing tools (de-mean, de-trend and filtering)
  • Topographic data visualization

Sleep has been developped in collaboration with Raphael Vallat.

Parameters:
data : string, array_like | None

Polysomnographic data. Must either be a path to a supported file (see notes) or an array of raw data of shape (n_channels, n_pts). If None, a dialog window to load the file should appear.

hypno : array_like | None

Hypnogram data. Should be a raw vector of shape (n_pts,)

config_file : string | None

Path to the configuration file (.txt)

annotations : string | None

Path to the annotation file (.txt, .csv). Alternatively, you can pass an annotation instance of MNE or simply an (N,) array describing the onset.

channels : list | None

List of channel names. The length of this list must be n_channels.

sf : float | None

The sampling frequency of raw data.

downsample : float | 100.

The downsampling frequency for the data and hypnogram raw data.

axis : bool | False

Specify if each axis have to contains its own axis. Be carefull with this option, the rendering can be much slower.

href : list | [‘art’, ‘wake’, ‘rem’, ‘n1’, ‘n2’, ‘n3’]

List of sleep stages. This list can be used to changed the display order into the GUI.

preload : bool | True

Preload data into memory. For large datasets, turn this parameter to True.

use_mne : bool | False

Force to load the file using mne.io functions.

kwargs_mne : dict | {}

Dictionary to pass to the mne.io loading function.

Notes

Note

  • Supported polysomnographic files : by default, Sleep support .vhdr (BrainVision), .eeg (Elan), .trc (Micromed) and .edf (European Data Format). If mne-python is installed, this default list of supported files is extended to .cnt, .egi, .mff, .edf, .bdf, .gdf, .set, .vhdr.
  • Supported hypnogram files : by default, Sleep support .txt, .csv and .hyp hypnogram files.

Deprecated since version 0.3.4: Input arguments file and hypno_file has been deprecated in 0.3.4 release. Use instead the data and hypno inputs.

replace_detections(dtype, method)[source][source]

Replace the default detection methods.

Parameters:
dtype : string

Name of the method to replace. Should be ‘spindle’, ‘sw’ (slow waves), ‘kc’ (k-complexes), ‘rem’ (rapid eye movements), ‘mt’ (muscle twitches) or ‘peak’.

method : function

Function to replace the detection. The function should take as an input :

  • A vector array of data of shape (n_time_points,)
  • The sampling frequency (float)
  • The time vector of shape (n_time_points,)
  • A vector array for the hypnogram of shape (n_time_points,)

Then, the function should return indices of relevant events. Returned indices should either be :

  • An array of shape (n_events, 2) where n_events describe the number of detected events. The first and second columns of the array respectively describe where detected events start and finished.
  • A boolean vector of shape (n_time_points,) where True values refer to detected events.
  • An array which contains consecutive indices of detected events.

Examples

>>> def method(data, sf, hypno):
>>>     # Do stuff
>>>     indices = ...
>>>     return indices
show()[source]

Display the graphical user interface.