Exemple #1
0
 def test_mne_switch(self):
     """Test function mne_switch."""
     # Download sleep file :
     sleep_file = path_to_visbrain_data('excerpt2.edf')
     if not os.path.isfile(sleep_file):
         download_file('sleep_edf.zip', unzip=True)
     to_exclude = ['VAB', 'NAF2P-A1', 'PCPAP', 'POS', 'FP2-A1', 'O2-A1',
                   'CZ2-A1', 'event_pneumo', 'event_pneumo_aut']
     kwargs = dict(exclude=to_exclude, stim_channel=False)
     mne_switch(path_to_visbrain_data('excerpt2'), '.edf', 100.,
                preload=True, **kwargs)
Exemple #2
0
 def test_mne_switch(self):
     """Test function mne_switch."""
     # Download sleep file :
     sleep_file = path_to_visbrain_data('excerpt2.edf', 'example_data')
     file, ext = os.path.splitext(sleep_file)
     if not os.path.isfile(sleep_file):
         download_file('sleep_edf.zip', unzip=True, astype='example_data')
     to_exclude = ['VAB', 'NAF2P-A1', 'PCPAP', 'POS', 'FP2-A1', 'O2-A1',
                   'CZ2-A1', 'event_pneumo', 'event_pneumo_aut']
     kwargs = dict(exclude=to_exclude, stim_channel=False)
     mne_switch(file, ext, 100., preload=True, **kwargs)
Exemple #3
0
    def test_figure(self):
        """Test function figure."""
        # Get files :
        files = [path_to_visbrain_data(k) for k in _FILES]

        # Titles :
        titles = ['Default', 'Sources inside', 'Connectivity',
                  'Connectivity', 'Repartition', 'Projection']

        # X-labels / Y-labels :
        xlabels = [None, None, 'Nice', 'Looks good', 'Repartition', 'ROI']
        ylabels = ['Dirty', 'Better', None, None, None, 'BA 4 and 6']

        # Background color of each axis :
        ax_bgcolor = ['slateblue', 'olive', 'black', 'darkgray', None, None]

        f = Figure(files, titles=titles, xlabels=xlabels, ylabels=ylabels,
                   figtitle='Brain module', grid=(3, 2), ax_bgcolor=ax_bgcolor,
                   y=1., fig_bgcolor='white', figsize=(12, 12),
                   text_color='black', subspace={'wspace': 0.1, 'left': 0.})
        # Colorbar to the first connectivity plot :
        f.colorbar_to_axis(2, (1, 5), 'viridis', title='Color by count',
                           ticks='minmax', fz_ticks=12)
        # Colorbar to the second connectivity plot :
        f.colorbar_to_axis(3, (0., 35.), 'magma', title='Color by density',
                           ticks='complete', vmax=30, over='darkred',
                           fz_ticks=12, vmin=10., under='gray')
        # Colorbar to the first projection plot :
        f.colorbar_to_axis(4, (1, 6), 'viridis', title='Contributing sources',
                           ticks=1., fz_ticks=10, orientation='horizontal',
                           vmin=2, under='gray', vmax=4, over='#ab4642')
        # Colorbar to the second projection plot :
        f.colorbar_to_axis(5, (.1, .5), 'inferno', title='ROI projection',
                           ticks=[.2, .3], fz_ticks=10,
                           orientation='horizontal')
        # Add a vertical shared colormap :
        f.shared_colorbar((-10, 10), 'inferno', fz_title=30, vmin=-7, vmax=6,
                          under='olive', over='firebrick', position='right',
                          title='Shared vertical colorbar', fz_ticks=20,
                          pltmargin=.1, figmargin=.1)
        # Add a horizontal shared colormap :
        f.shared_colorbar(cmap='magma', clim=(-17, 17), fz_title=25, vmin=-11,
                          vmax=12, under='olive', over='firebrick',
                          position='bottom', title='Shared horizontal',
                          fz_ticks=15, pltmargin=.1)

        # Save the picture :
        f.save(self.to_tmp_dir('figure.png'), dpi=100)
Exemple #4
0
from visbrain.objects.tests._testing_objects import _TestVolumeObject
from visbrain.objects import SourceObj, RoiObj
from visbrain.io import (download_file, path_to_visbrain_data, read_nifti,
                         clean_tmp)

roi_obj = RoiObj('brodmann')
roi_obj.select_roi([4, 6])
rnd = np.random.RandomState(0)
xyz = 100. * rnd.rand(50, 3)
xyz[:, 0] -= 50.
xyz[:, 1] -= 50.
s_obj = SourceObj('S1', xyz)

download_file('MIST_ROI.zip', unzip=True, astype='example_data')
nifti_file = path_to_visbrain_data('MIST_ROI.nii.gz', 'example_data')
csv_file = path_to_visbrain_data('MIST_ROI.csv', 'example_data')
# Read the .csv file :
arr = np.genfromtxt(csv_file, delimiter=';', dtype=str)
# Get column names, labels and index :
column_names = arr[0, :]
arr = np.delete(arr, 0, 0)
n_roi = arr.shape[0]
roi_index = arr[:, 0].astype(int)
roi_labels = arr[:, [1, 2]].astype(object)
# Build the struct array :
label = np.zeros(n_roi, dtype=[('label', object), ('name', object)])
label['label'] = roi_labels[:, 0]
label['name'] = roi_labels[:, 1]
# Get the volume and the hdr transformation :
vol, _, hdr = read_nifti(nifti_file, hdr_as_array=True)
    Every ROI files is downloaded to the ~/visbrain_data/roi folder
"""
import numpy as np

from visbrain.objects import RoiObj, ColorbarObj, SceneObj, SourceObj, BrainObj
from visbrain.io import download_file, path_to_visbrain_data, read_nifti

###############################################################################
# Download data
###############################################################################
# In order to work, this example need to download some data i.e coordinates of
# intracranial sources and a parcellates atlas (MIST) to illustrate how to
# define your own RoiObj

# Get the path to the ~/visbrain_data/example_data folder
vb_path = path_to_visbrain_data(folder='example_data')
# Download (x, y, z) coordinates of intracranial sources
mat = np.load(download_file('xyz_sample.npz', astype='example_data'))
xyz, subjects = mat['xyz'], mat['subjects']
data = np.random.uniform(low=-1., high=1., size=(xyz.shape[0],))
# Download the MIST parcellates
download_file('MIST_ROI.zip', unzip=True, astype='example_data')

###############################################################################
# Scene creation
###############################################################################
# First, we need to create the scene that will host objects

# Scene creation with a dark background and a custom size
sc = SceneObj(size=(1400, 1000))
# In this example, we also illustrate the use of the colorbar object. Hence, we
Exemple #6
0
    Every ROI files is downloaded to the ~/visbrain_data/roi folder
"""
import numpy as np

from visbrain.objects import RoiObj, ColorbarObj, SceneObj, SourceObj, BrainObj
from visbrain.io import download_file, path_to_visbrain_data, read_nifti

###############################################################################
# Download data
###############################################################################
# In order to work, this example need to download some data i.e coordinates of
# intracranial sources and a parcellates atlas (MIST) to illustrate how to
# define your own RoiObj

# Get the path to the ~/visbrain_data/example_data folder
vb_path = path_to_visbrain_data(folder='example_data')
# Download (x, y, z) coordinates of intracranial sources
mat = np.load(download_file('xyz_sample.npz', astype='example_data'))
xyz, subjects = mat['xyz'], mat['subjects']
data = np.random.uniform(low=-1., high=1., size=(xyz.shape[0], ))
# Download the MIST parcellates
download_file('MIST_ROI.zip', unzip=True, astype='example_data')

###############################################################################
# Scene creation
###############################################################################
# First, we need to create the scene that will host objects

# Scene creation with a dark background and a custom size
sc = SceneObj(size=(1400, 1000))
# In this example, we also illustrate the use of the colorbar object. Hence, we
Exemple #7
0
 def to_tmp_dir(self, file=None):
     """Path to a tmp dir in visbrain-data."""
     vb_path = os.path.join(path_to_visbrain_data(), 'tmp')
     if not os.path.exists(vb_path):
         os.makedirs(vb_path)
     return path_to_visbrain_data(file=file, folder='tmp')
https://www.dropbox.com/s/bj1ra95rbksukro/sleep_edf.zip?dl=1

.. image:: ../../picture/picsleep/ex_replace_detection_basic.png
"""
###############################################################################
# Load your file and create an instance of Sleep
###############################################################################

import os
import numpy as np

from visbrain import Sleep
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
Exemple #9
0
"""Test Sleep module and related methods."""
import os

import numpy as np
from vispy.app.canvas import MouseEvent, KeyEvent
from vispy.util.keys import Key

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):
Exemple #10
0
"""Test the HypnogramObj."""
import numpy as np

from visbrain.objects.hypno_obj import HypnogramObj
from visbrain.objects.tests._testing_objects import _TestObjects
from visbrain.io import path_to_visbrain_data


data = np.repeat(np.arange(6), 100) - 1.
h_obj = HypnogramObj('hypno', data)
hypno_file = path_to_visbrain_data('Hypnogram_excerpt2.txt', 'example_data')


class TestHypnogramObj(_TestObjects):
    """Test connectivity object."""

    OBJ = h_obj

    def test_definition(self):
        """Test function definition."""
        HypnogramObj('hypno', data)
        HypnogramObj(hypno_file)

    def test_set_stage(self):
        """Test set stage."""
        h_obj.set_stage(-1, 45, 89)
        h_obj.set_stage('wake', 145, 189)

    def test_properties(self):
        """Test hypnogram object properties."""
        self.assert_and_test('line_width', 4.)
"""Test the HypnogramObj."""
import numpy as np

from visbrain.objects.hypno_obj import HypnogramObj
from visbrain.objects.tests._testing_objects import _TestObjects
from visbrain.io import path_to_visbrain_data


data = np.repeat(np.arange(6), 100) - 1.
h_obj = HypnogramObj('hypno', data)
hypno_file = path_to_visbrain_data('Hypnogram_excerpt2.txt')


class TestHypnogramObj(_TestObjects):
    """Test connectivity object."""

    OBJ = h_obj

    def test_definition(self):
        """Test function definition."""
        HypnogramObj('hypno', data)
        HypnogramObj(hypno_file)

    def test_set_stage(self):
        """Test set stage."""
        h_obj.set_stage(-1, 45, 89)
        h_obj.set_stage('wake', 145, 189)

    def test_properties(self):
        """Test hypnogram object properties."""
        self.assert_and_test('line_width', 4.)
Exemple #12
0
See the original example :

https://pysurfer.github.io/auto_examples/plot_meg_inverse_solution.html#sphx-glr-auto-examples-plot-meg-inverse-solution-py

.. image:: ../../picture/picpysurfer/ex_pysurfer_meg_inverse.png
"""
from visbrain import Brain
from visbrain.objects import BrainObj
from visbrain.io import path_to_visbrain_data, download_file, read_stc
"""Download file if needed :
"""
file = 'meg_source_estimate-lh.stc'
download_file(file)

# Read the *.stc file :
file = read_stc(path_to_visbrain_data(file=file))

# Get the data and vertices from the file :
data = file['data'][:, 2]
vertices = file['vertices']

# Define a brain object and add the data to the mesh :
b_obj = BrainObj('inflated', translucent=False, hemisphere='left')
b_obj.add_activation(data=data,
                     vertices=vertices,
                     smoothing_steps=5,
                     clim=(13., 22.),
                     hide_under=13.,
                     cmap='plasma',
                     hemisphere='left')
Exemple #13
0
"""
Load an existing colorbar configuration file
============================================

The configuration is in a config.txt file and is loaded to reproduce the
colorbar configuration.

Configuration files :
https://www.dropbox.com/s/5o1ph08rmpft200/cbar_config.zip?dl=0

.. image:: ../../picture/piccbar/ex_load_existing_config.png
"""
from visbrain import Colorbar
from visbrain.io import download_file, path_to_visbrain_data

download_file('cbar_config.zip', unzip=True, remove_archive=True)
Colorbar(config=path_to_visbrain_data('config_1.txt')).show()
Exemple #14
0
https://pysurfer.github.io/auto_examples/plot_fmri_conjunction.html#sphx-glr-auto-examples-plot-fmri-conjunction-py

.. image:: ../../picture/picpysurfer/ex_pysurfer_conjunction_map.png
"""
from visbrain import Brain
from visbrain.objects import BrainObj
from visbrain.io import path_to_visbrain_data, download_file
"""Download files if needed
"""
file_name_1 = 'lh.sig.nii.gz'
file_name_2 = 'lh.alt_sig.nii.gz'
download_file(file_name_1)
download_file(file_name_2)

file_1 = path_to_visbrain_data(file=file_name_1)
file_2 = path_to_visbrain_data(file=file_name_2)

b_obj = BrainObj('inflated', translucent=False)
b_obj.add_activation(file=file_1,
                     clim=(4., 30.),
                     hide_under=4,
                     cmap='Reds_r',
                     hemisphere='left')
b_obj.add_activation(file=file_2,
                     clim=(4., 30.),
                     hide_under=4,
                     cmap='Blues_r',
                     hemisphere='left')

vb = Brain(brain_obj=b_obj)
Exemple #15
0
"""Test the HypnogramObj."""
import numpy as np

from visbrain.objects.hypno_obj import HypnogramObj
from visbrain.objects.tests._testing_objects import _TestObjects
from visbrain.io import path_to_visbrain_data

data = np.repeat(np.arange(6), 100) - 1.
h_obj = HypnogramObj('hypno', data)
hypno_file = path_to_visbrain_data('Hypnogram_excerpt2.txt', 'example_data')


class TestHypnogramObj(_TestObjects):
    """Test connectivity object."""

    OBJ = h_obj

    def test_definition(self):
        """Test function definition."""
        HypnogramObj('hypno', data)
        HypnogramObj(hypno_file)

    def test_set_stage(self):
        """Test set stage."""
        h_obj.set_stage(-1, 45, 89)
        h_obj.set_stage('wake', 145, 189)

    def test_properties(self):
        """Test hypnogram object properties."""
        self.assert_and_test('line_width', 4.)
        self.assert_and_test('unicolor', True)
Display topographic plots in a grid using several plotting properties.

Download topoplot data (topoplot_data.npz) :
https://www.dropbox.com/s/m76y3p0fyj6lxht/topoplot_data.npz?dl=1

.. image:: ../../picture/pictopo/ex_topoplot_plotting_properties.png
"""
import numpy as np

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

# Load the data :
download_file('topoplot_data.npz')
mat = np.load(path_to_visbrain_data('topoplot_data.npz'))
xyz, data = mat['xyz'], mat['data']
channels = [str(k) for k in range(len(data))]

kwargs = {'title_size': 3., 'cb_txt_size': 2, 'margin': 15 / 100,
          'chan_offset': (0., 1.1, 0.), 'chan_size': 1.5}

# Create a topoplot instance :
t = Topo()

# Topoplot with 10 regulary spaced levels :
t.add_topoplot('Topo_1', data, xyz=xyz, channels=channels,
               title='Regulary spaced levels', cmap='viridis', levels=10,
               level_colors='Spectral_r', cblabel='Beta power',
               title_color='#ab4642', **kwargs)
Exemple #17
0
Further explanations about screenshot and transparency can be foud here :
http://visbrain.org/vbexport.html

Download source's coordinates (xyz_sample.npz) :
https://www.dropbox.com/s/whogfxutyxoir1t/xyz_sample.npz?dl=1

.. image:: ../../_static/examples/ex_brain_screenshot.png
"""
import os
import numpy as np

from visbrain.gui import Brain
from visbrain.objects import BrainObj, SourceObj, RoiObj
from visbrain.io import download_file, path_to_visbrain_data

save_pic_path = path_to_visbrain_data(folder='Example_pic')

# Load the xyz coordinates and corresponding subject name :
s_xyz = np.load(download_file('xyz_sample.npz', astype='example_data'))['xyz']
"""Create a source object with random data between [-50,50]
"""
s_data = np.random.uniform(-50, 50, s_xyz.shape[0])
s_obj = SourceObj('Sobj',
                  s_xyz,
                  data=s_data,
                  color='darkred',
                  alpha=.5,
                  radius_min=2.,
                  radius_max=8.,
                  edge_width=0.)
"""Create a Region of Interest Object (ROI) and display brodmann area 4 and 6
.. image:: ../../_static/examples/ex_replace_detection_basic.png
"""
###############################################################################
# Load your file and create an instance of Sleep
###############################################################################

import os
import numpy as np

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

# Download the file :
download_file('sleep_edf.zip', unzip=True, astype='example_data')
target_path = path_to_visbrain_data(folder='example_data')

# 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
Exemple #19
0
Further explanations about screenshot and transparency can be foud here :
http://visbrain.org/vbexport.html

Download source's coordinates (xyz_sample.npz) :
https://www.dropbox.com/s/whogfxutyxoir1t/xyz_sample.npz?dl=1

.. image:: ../../_static/examples/ex_brain_screenshot.png
"""
import os
import numpy as np

from visbrain.gui import Brain
from visbrain.objects import BrainObj, SourceObj, RoiObj
from visbrain.io import download_file, path_to_visbrain_data

save_pic_path = path_to_visbrain_data(folder='Example_pic')

# Load the xyz coordinates and corresponding subject name :
s_xyz = np.load(download_file('xyz_sample.npz', astype='example_data'))['xyz']

"""Create a source object with random data between [-50,50]
"""
s_data = np.random.uniform(-50, 50, s_xyz.shape[0])
s_obj = SourceObj('Sobj', s_xyz, data=s_data, color='darkred', alpha=.5,
                  radius_min=2., radius_max=8., edge_width=0.)

"""Create a Region of Interest Object (ROI) and display brodmann area 4 and 6
"""
roi_obj = RoiObj('brodmann')
idx_4_6 = roi_obj.where_is(['BA4', 'BA6'], exact=True)
roi_color = {idx_4_6[0]: 'red',    # BA4 in red and BA6 in green
 def to_tmp_dir(self, file=None):
     """Path to a tmp dir in visbrain-data."""
     vb_path = os.path.join(path_to_visbrain_data(), 'tmp')
     if not os.path.exists(vb_path):
         os.makedirs(vb_path)
     return path_to_visbrain_data(file=file, folder='tmp')
Exemple #21
0
"""
from __future__ import print_function
import numpy as np

from visbrain import Brain
from visbrain.objects import SourceObj, ConnectObj
from visbrain.io import download_file, path_to_visbrain_data

# Create an empty kwargs dictionnary :
kwargs = {}

# ____________________________ DATA ____________________________

# Load the xyz coordinates and corresponding subject name :
download_file('xyz_sample.npz')
mat = np.load(path_to_visbrain_data('xyz_sample.npz'))
xyz, subjects = mat['xyz'], mat['subjects']

N = xyz.shape[0]  # Number of electrodes

# Now, create some random data between [-50,50]
data = np.random.uniform(-50, 50, len(subjects))

"""Create the source object :
"""
s_obj = SourceObj('SourceObj1', xyz, data, color='crimson', alpha=.5,
                  edge_width=2., radius_min=2., radius_max=10.)

"""
To connect sources between them, we create a (N, N) array.
This array should be either upper or lower triangular to avoid
Exemple #22
0
from visbrain.objects.tests._testing_objects import _TestVolumeObject
from visbrain.objects import SourceObj, RoiObj
from visbrain.io import (download_file, path_to_visbrain_data, read_nifti,
                         clean_tmp)


roi_obj = RoiObj('brodmann')
roi_obj.select_roi([4, 6])
rnd = np.random.RandomState(0)
xyz = 100. * rnd.rand(50, 3)
xyz[:, 0] -= 50.
xyz[:, 1] -= 50.
s_obj = SourceObj('S1', xyz)

download_file('MIST_ROI.zip', unzip=True, astype='example_data')
nifti_file = path_to_visbrain_data('MIST_ROI.nii.gz', 'example_data')
csv_file = path_to_visbrain_data('MIST_ROI.csv', 'example_data')
# Read the .csv file :
arr = np.genfromtxt(csv_file, delimiter=';', dtype=str)
# Get column names, labels and index :
column_names = arr[0, :]
arr = np.delete(arr, 0, 0)
n_roi = arr.shape[0]
roi_index = arr[:, 0].astype(int)
roi_labels = arr[:, [1, 2]].astype(object)
# Build the struct array :
label = np.zeros(n_roi, dtype=[('label', object), ('name', object)])
label['label'] = roi_labels[:, 0]
label['name'] = roi_labels[:, 1]
# Get the volume and the hdr transformation :
vol, _, hdr = read_nifti(nifti_file, hdr_as_array=True)
Exemple #23
0
"""
Display fMRI activation
=======================

Display fMRI activations from a nii.gz file (NiBabel required).

See the original example :

https://pysurfer.github.io/auto_examples/plot_fmri_activation.html#sphx-glr-auto-examples-plot-fmri-activation-py

.. image:: ../../picture/picpysurfer/ex_pysurfer_fmri_activations.png
"""
from visbrain import Brain
from visbrain.objects import BrainObj
from visbrain.io import path_to_visbrain_data, download_file

"""Download file if needed
"""
file_name = 'lh.sig.nii.gz'
download_file(file_name)
file = path_to_visbrain_data(file=file_name)


b_obj = BrainObj('inflated', translucent=False, sulcus=True)
b_obj.add_activation(file=file, clim=(5., 20.), hide_under=5, cmap='viridis',
                     hemisphere='left')

vb = Brain(brain_obj=b_obj)
vb.rotate('left')
vb.show()
Exemple #24
0
from visbrain.objects.tests._testing_objects import _TestVolumeObject
from visbrain.objects import SourceObj, RoiObj
from visbrain.io import (download_file, path_to_visbrain_data, read_nifti,
                         clean_tmp)

roi_obj = RoiObj('brodmann')
roi_obj.select_roi([4, 6])
rnd = np.random.RandomState(0)
xyz = 100. * rnd.rand(50, 3)
xyz[:, 0] -= 50.
xyz[:, 1] -= 50.
s_obj = SourceObj('S1', xyz)

download_file('MIST_ROI.zip', unzip=True)
nifti_file = path_to_visbrain_data('MIST_ROI.nii.gz')
csv_file = path_to_visbrain_data('MIST_ROI.csv')
# Read the .csv file :
arr = np.genfromtxt(csv_file, delimiter=';', dtype=str)
# Get column names, labels and index :
column_names = arr[0, :]
arr = np.delete(arr, 0, 0)
n_roi = arr.shape[0]
roi_index = arr[:, 0].astype(int)
roi_labels = arr[:, [1, 2]].astype(object)
# Build the struct array :
label = np.zeros(n_roi, dtype=[('label', object), ('name', object)])
label['label'] = roi_labels[:, 0]
label['name'] = roi_labels[:, 1]
# Get the volume and the hdr transformation :
vol, _, hdr = read_nifti(nifti_file, hdr_as_array=True)
Exemple #25
0
###############################################################################
# Load your file and create an instance of Sleep
###############################################################################

import os
import numpy as np

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

from wonambi.detect.spindle import DetectSpindle, detect_Moelle2011
from wonambi.detect.slowwave import DetectSlowWave, detect_Massimini2004

# Download the file :
download_file('sleep_edf.zip', unzip=True, astype='example_data')
target_path = path_to_visbrain_data(folder='example_data')

# 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
Exemple #26
0
"""Test command lines."""
import os

from visbrain import Figure
from visbrain.io import download_file, path_to_visbrain_data
from visbrain.tests._tests_visbrain import _TestVisbrain

# List of image files to test with :
_FILES = ['default.png', 'inside.png', 'count.png', 'density.png',
          'repartition.jpg', 'roi.jpg']
all_downloaded = [os.path.isfile(path_to_visbrain_data(k)) for k in _FILES]
if not all(all_downloaded):
    download_file('figure.zip', unzip=True)

# Create a tmp/ directory :
dir_path = os.path.dirname(os.path.realpath(__file__))
path_to_tmp = os.path.join(*(dir_path, 'tmp'))


class TestFigure(_TestVisbrain):
    """Test figure.py."""

    ###########################################################################
    #                                 FIGURE
    ###########################################################################
    def test_figure(self):
        """Test function figure."""
        # Get files :
        files = [path_to_visbrain_data(k) for k in _FILES]

        # Titles :
Exemple #27
0
Arange pictures in a grid. 

Download the archive :
https://www.dropbox.com/s/jsjct54ynvdjzfq/figure.zip?dl=1
"""
from visbrain import Figure
from visbrain.io import download_file, path_to_visbrain_data

download_file("figure.zip", unzip=True)

# Files to load :
files = [
    'default.png', 'inside.png', 'count.png', 'density.png', 'repartition.jpg',
    'roi.jpg'
]
files = [path_to_visbrain_data(k) for k in files]

# Titles :
titles = [
    'Default view', 'Select sources inside', 'Connectivity', 'Connectivity',
    'Cortical repartition', 'Cortical projection'
]

# X-labels / Y-labels :
xlabels = [None, None, 'Looks nice', 'Looks good', 'Repartition', 'ROI']
ylabels = ['Dirty', 'Better', None, None, None, 'Brodmann area 4 and 6']

# Background color of each axis :
ax_bgcolor = ['slateblue', 'olive', 'black', 'darkgray', None, None]

f = Figure(files,