Exemplo n.º 1
0
def cli_sleep(data, hypno, config_file, annotations, downsample, use_mne,
              preload, show):
    """Open the graphical user interface of Sleep."""
    # File conversion :
    if data is not None:
        data = click.format_filename(data)
    if hypno is not None:
        hypno = click.format_filename(hypno)
    if config_file is not None:
        config_file = click.format_filename(config_file)
    if annotations is not None:
        annotations = click.format_filename(annotations)
    s = Sleep(data=data,
              hypno=hypno,
              downsample=downsample,
              use_mne=use_mne,
              preload=preload,
              config_file=config_file,
              annotations=annotations)
    if show:
        s.show()
Exemplo n.º 2
0
"""
Load EDF file
=============

This example demonstrate how to load an EDF file.

Required dataset at :
https://www.dropbox.com/s/bj1ra95rbksukro/sleep_edf.zip?dl=1

.. image:: ../../picture/picsleep/ex_LoadEDF.png
"""
import os
from visbrain import Sleep
from visbrain.io import download_file

current_path = os.getcwd()
target_path = os.path.join(current_path, 'data', 'edf')

download_file('sleep_edf.zip', unzip=True, to_path=target_path)

dfile = os.path.join(target_path, 'excerpt2.edf')
hfile = os.path.join(target_path, 'Hypnogram_excerpt2.txt')
cfile = os.path.join(target_path, 'excerpt2_config.txt')

Sleep(data=dfile, hypno=hfile, config_file=cfile).show()
from visbrain.io import download_file, path_to_visbrain_data

# Get data path and where to save it :
current_path = path_to_visbrain_data()
target_path = os.path.join(current_path, 'sleep_data', 'edf')

# Download the file :
download_file('sleep_edf.zip', unzip=True, to_path=target_path)

# Get data path :
dfile = os.path.join(target_path, 'excerpt2.edf')            # data
hfile = os.path.join(target_path, 'Hypnogram_excerpt2.txt')  # hypnogram
cfile = os.path.join(target_path, 'excerpt2_config.txt')     # GUI config

# Define an instance of Sleep :
sp = Sleep(data=dfile, hypno=hfile, config_file=cfile)

###############################################################################
# Define new methods
###############################################################################

###############################################################################
# Spindle function
# ~~~~~~~~~~~~~~~~

###############################################################################
#
# This function does NOT perform a real spindle detection. It's purpose is to
# show how to replace the default detection behavior by a custom function.
# It just highlights samples between [0, 100], [200, 300] and [400, 500].
Exemplo n.º 4
0
import os
from visbrain import Sleep
from glob import glob
import numpy as np

fs = 250

source_dir = r'C:\Users\Rory\raw_data\CIT_WAY\eeg_numpy\CIT_WAY_1_2018-05-01_15-59-19_PRE'
data = np.load(glob(os.path.join(source_dir, '*.npy'))[0])
path_to_txt = glob(os.path.join(source_dir, '*.txt'))[0]

with open(path_to_txt) as f:
    labs = np.array(f.read().splitlines())

Sleep(data=data, sf=fs, channels=labs).show()
"""
Load a BrainVision file
=======================

This example demonstrate how to load a BrainVision file.

Required dataset at :
https://drive.google.com/drive/folders/0B6vtJiCQZUBvRjc3cFFYcmFIeW8?usp=sharing

.. image:: ../../picture/picsleep/ex_LoadBrainVision.png
"""
from visbrain import Sleep

Sleep(file='sub-02.eeg', hypno_file='sub-02.hyp',
      config_file='sub-02_config.txt').show()
Exemplo n.º 6
0
from visbrain import Sleep
from visbrain.io import download_file, path_to_visbrain_data
from visbrain.tests._tests_visbrain import _TestVisbrain

# File to load :
sleep_file = path_to_visbrain_data('excerpt2.edf')
hypno_file = path_to_visbrain_data('Hypnogram_excerpt2.txt')

# Download sleep file :
if not os.path.isfile(sleep_file):
    download_file('sleep_edf.zip', unzip=True)
onset = np.array([100, 2000, 5000])

# Create Sleep application :
sp = Sleep(data=sleep_file, hypno=hypno_file, axis=True, annotations=onset)


class TestSleep(_TestVisbrain):
    """Test sleep.py."""

    ###########################################################################
    #                                TOOLS
    ###########################################################################
    def test_reference_switch(self):
        """Test function reference_switch."""
        for k in [2]:  # range(3)
            sp._ToolsRefMeth.setCurrentIndex(k)
            sp._fcn_ref_switch()
            sp._fcn_ref_apply()
        sp._fcn_ref_chan_ignore()
Exemplo n.º 7
0
"""
import os
from mne import io
from visbrain import Sleep
from visbrain.io import download_file, path_to_visbrain_data

###############################################################################
#                               LOAD YOUR FILE
###############################################################################
current_path = path_to_visbrain_data()
target_path = os.path.join(current_path, 'sleep_data', 'brainvision')

# Download dataset :
download_file("sleep_brainvision.zip", unzip=True, to_path=target_path)

dfile = os.path.join(target_path, 'sub-02.vhdr')
hfile = os.path.join(target_path, 'sub-02.hyp')

# Read raw data using MNE-python :
raw = io.read_raw_brainvision(vhdr_fname=dfile, preload=True)

# Extract data, sampling frequency and channels names
data, sf, chan = raw._data, raw.info['sfreq'], raw.info['ch_names']

# Now, pass all the arguments to the Sleep module :
Sleep(data=data, sf=sf, channels=chan, hypno=hfile).show()

# Alternatively, these steps can be done automatically by using the 'use_mne'
# input argument of sleep
# Sleep(data=dfile, hypno=hfile, use_mne=True).show()
Exemplo n.º 8
0
.. image:: ../../picture/picsleep/ex_LoadMatlab.png
"""
import os
import numpy as np
from scipy.io import loadmat

from visbrain import Sleep
from visbrain.io import download_file, path_to_visbrain_data

###############################################################################
#                               LOAD YOUR FILE
###############################################################################
current_path = path_to_visbrain_data()
target_path = os.path.join(current_path, 'sleep_data', 'matlab')

# Download matlab file :
download_file("sleep_matlab.zip", unzip=True, to_path=target_path)

# Load the matlab file :
mat = loadmat(os.path.join(target_path, 's2_sleep.mat'))

# Get the data, sampling frequency and channel names :
raw_data = mat['data']
raw_sf = float(mat['sf'])
raw_channels = np.concatenate(mat['channels'].flatten()).tolist()
raw_hypno = mat['hypno'].flatten()

# Open the GUI :
Sleep(data=raw_data, sf=raw_sf, channels=raw_channels, hypno=raw_hypno).show()
Exemplo n.º 9
0
# Create a random dataset :
sf, nelec, npts = 1000., 8, 100000
data = 10. * np.random.rand(nelec, npts)
channels = ['Cz', 'Fz', 'C1', 'C2', 'C3', 'C4', 'F1', 'other']
hypno = np.random.randint(-1, 3, (npts, ))
file, hypno_file = None, None
onset = np.array([100, 2000, 5000])

# Create Sleep application :
app = QtWidgets.QApplication([])
sp = Sleep(file=file,
           hypno_file=hypno_file,
           data=data,
           channels=channels,
           sf=sf,
           downsample=100.,
           hypno=hypno,
           axis=False,
           hedit=True,
           annotation_file=onset)


class TestSleep(object):
    """Test sleep.py."""

    ###########################################################################
    #                                 SETTINGS
    ###########################################################################
    def test_create_tmp_folder(self):
        """Create tmp folder."""
        if not os.path.exists(path_to_tmp):
Exemplo n.º 10
0
"""
Load a file using MNE-python
============================

This example shows how to load data using MNE-Python package.
https://martinos.org/mne/stable/index.html

Install MNE-python : pip install mne

A full list of supported format can be found here:
https://martinos.org/mne/stable/python_reference.html#reading-raw-data

Required dataset at :
https://drive.google.com/drive/folders/0B6vtJiCQZUBvRjc3cFFYcmFIeW8?usp=sharing

.. image:: ../../picture/picsleep/ex_LoadMNE.png
"""
from mne import io
from visbrain import Sleep

raw = io.read_raw_brainvision(vhdr_fname='sub-02.vhdr', preload=True)

# Extract data, sampling frequency and channels names
data, sf, chan = raw._data, raw.info['sfreq'], raw.info['ch_names']

# Now, pass all the arguments to the Sleep module :
Sleep(data=data, sf=sf, channels=chan, hypno_file='sub-02.hyp').show()
Exemplo n.º 11
0
"""
Load ELAN files
===============

This example demonstrate how to load an ELAN file.

Required dataset at :
https://www.dropbox.com/s/95xvdqivpgk90hg/sleep_elan.zip?dl=1

.. image:: ../../picture/picsleep/ex_LoadElan.png
"""
import os
from visbrain import Sleep
from visbrain.io import download_file

current_path = os.getcwd()
target_path = os.path.join(current_path, 'data', 'elan')

# Download dataset :
download_file("sleep_elan.zip", unzip=True, to_path=target_path)

dfile = os.path.join(target_path, 'sub-02.eeg')
hfile = os.path.join(target_path, 'sub-02.hyp')

Sleep(data=dfile, hypno=hfile).show()
Exemplo n.º 12
0
==============

This example demonstrate how to load a .rec file.

Required dataset at :
https://www.dropbox.com/s/hc18bgn2hlnmiph/sleep_edf.zip?dl=1

.. image:: ../../picture/picsleep/ex_load_rec.png
"""
import os

from visbrain import Sleep
from visbrain.io import download_file, path_to_visbrain_data

###############################################################################
#                               LOAD YOUR FILE
###############################################################################
current_path = path_to_visbrain_data()
target_path = os.path.join(current_path, 'sleep_data', 'rec')

# Download the rec file :
download_file('sleep_rec.zip',
              unzip=True,
              to_path=target_path,
              remove_archive=True)

dfile = os.path.join(target_path, '1.rec')

# Open the GUI :
Sleep(data=dfile).show()
Exemplo n.º 13
0
"""
Load a Matlab file
==================

This example demonstrate how to load an ELAN file.

Required dataset at :
https://drive.google.com/drive/folders/0B6vtJiCQZUBvRjc3cFFYcmFIeW8?usp=sharing

.. image:: ../../picture/picsleep/ex_LoadMatlab.png
"""
from visbrain import Sleep
import numpy as np
from scipy.io import loadmat

mat = loadmat('s2_sleep.mat')

# Get the data, sampling frequency and channel names :
raw_data = mat['data']
raw_sf = float(mat['sf'])
raw_channels = np.concatenate(mat['channels'].flatten()).tolist()
raw_hypno = mat['hypno'].flatten()

Sleep(data=raw_data, sf=raw_sf, channels=raw_channels, hypno=raw_hypno,
      config_file='s2_config.txt').show()
Exemplo n.º 14
0
"""
Load ELAN files
===============

This example demonstrate how to load an ELAN file.

Required dataset at :
https://drive.google.com/drive/folders/0B6vtJiCQZUBvRjc3cFFYcmFIeW8?usp=sharing

.. image:: ../../picture/picsleep/ex_LoadElan.png
"""
from visbrain import Sleep
Sleep(file='s101_sleep.eeg',
      hypno_file='s101_hypno.hyp',
      config_file='s101_config.txt').show()
Exemplo n.º 15
0
"""
Load EDF file
=============

This example demonstrate how to load an EDF file.

Required dataset at :
https://drive.google.com/drive/folders/0B6vtJiCQZUBvRjc3cFFYcmFIeW8?usp=sharing

.. image:: ../../picture/picsleep/ex_LoadEDF.png
"""
from visbrain import Sleep

Sleep(file='excerpt2.edf', hypno_file='Hypnogram_excerpt2.txt',
      config_file='excerpt2_config.txt').show()