Пример #1
0
"""Define a dictionary with interface customization entries
"""
kwargs = {
    'xlabel': 'xlabel',
    'ylabel': 'ylabel',
    'title': 'title',
    'color': 'lightgray',
    'marker_symbol': 'x',
    'title_font_size': 20,
    'hist_nbins': 100,
    'line_lw': 2.5,
    'tf_norm': 3,
    'tf_interp': 'nearest',
    'tf_cmap': 'Spectral_r',
    'tf_baseline': (250, 750),
    'tf_av_window': 100,
    'tf_av_overlap': .5,
    'tf_clim': (-.5, .5),
    'axis_font_size': 18,
    'tick_font_size': 8,
    'axis_color': 'white',
    'bgcolor': (.1, .1, .1),
    'form': 'marker',
    'grid_titles': gtitles,
    'grid_font_size': gfz,
    'grid_titles_color': 'white'
}

sg = Signal(data, sf=sf, axis=-1, **kwargs)
sg.show()
Пример #2
0
                          noise=100)
time += 8.  # force the time vector to start at 8 seconds
time *= 1000.  # millisecond conversion
"""The data have a shape of (125 channels, 4000 time points). In order to work,
the program need to know that the time axis is not the first dimension. Hence,
we use the `axis` parameter to specify that the time axis is the second one
`axis=1`
"""
axis = 1  # localization of the time axis
"""Add a label to the x-axis (xlabel), y-axis (ylabel) and a title
"""
xlabel = 'Time (ms)'
ylabel = 'Amplitude (uV)'
title = 'Plot of a 1-d signal'
"""Build the title to add to each time-series in the grid
"""
gtitles = ['Trial ' + str(k) for k in range(n_trials)]  # grid titles
gfz = 8.  # grid titles font-size
glw = 2.  # grid line width

Signal(data,
       sf=sf,
       axis=axis,
       time=time,
       xlabel=xlabel,
       ylabel=ylabel,
       title=title,
       grid_titles=gtitles,
       grid_font_size=gfz,
       grid_lw=glw).show()
Пример #3
0
from visbrain.gui import Signal

sf = 1000.  # Sampling-frequency
n_pts = 4000  # Number of time points
n_sines = 10  # Number of sines

"""Create artificial sines :
"""
time = np.arange(n_pts) / sf
f_sines = np.linspace(13, 30, n_sines)
data = np.sin(2 * np.pi * f_sines.reshape(-1, 1) * time.reshape(1, -1))
data += np.random.randn(*data.shape)

"""Create the signal instance and pass data to it
"""
sig = Signal(data, axis=1, sf=sf, time=time, form='tf', tf_cmap='Spectral_r',
             psd_nperseg=n_pts)

"""Start by exporting the grid of signals.
"""
sig.screenshot('grid.tiff', canvas='grid', dpi=600, autocrop=True)

"""Loop over all of the signals and export all time-frequency maps.
"""
for k in sig:
    # Set the signal index :
    sig.set_signal_index(k)
    # Set final exported image to be the power spectrum density
    if k == n_sines - 2:
        sig.set_signal_form('psd')
    # Export image :
    sig.screenshot('tf_' + str(k) + '.png', dpi=600, autocrop=True)
from visbrain.gui import Signal
from visbrain.utils import generate_eeg

sf = 512.  # sampling frequency
n_pts = 4000  # number of time points
n_trials = 125  # number of trials in the dataset

"""Generate a random EEG vector of shape (n_trials, n_pts). This time, we
smooth signals and decrease the noise on it.
"""
data, _ = generate_eeg(sf=sf, n_pts=n_pts, n_trials=n_trials, smooth=200,
                       noise=1000)

gtitles = ['Trial ' + str(k) for k in range(n_trials)]  # grid titles
gfz = 8.  # grid titles font-size

"""Define a dictionary with interface customization entries
"""
kwargs = {'xlabel': 'xlabel', 'ylabel': 'ylabel', 'title': 'title',
          'color': 'lightgray', 'marker_symbol': 'x', 'title_font_size': 20,
          'hist_nbins': 100, 'line_lw': 2.5, 'tf_norm': 3,
          'tf_interp': 'nearest', 'tf_cmap': 'Spectral_r',
          'tf_baseline': (250, 750), 'tf_av_window': 100, 'tf_av_overlap': .5,
          'tf_clim': (-.5, .5), 'axis_font_size': 18, 'tick_font_size': 8,
          'axis_color': 'white', 'bgcolor': (.1, .1, .1), 'form': 'marker',
          'grid_titles': gtitles, 'grid_font_size': gfz,
          'grid_titles_color': 'white'}

sg = Signal(data, sf=sf, axis=-1, **kwargs)
sg.show()
Пример #5
0
    'title': 'My title',
    'display_grid': True,
    'color': 'darkgray',
    'symbol': 'x',
    'title_font_size': 20,
    'axis_font_size': 18,
    'tick_font_size': 8,
    'axis_color': 'blue',
    'bgcolor': 'white',
    'enable_grid': True,
    'display_signal': True,
    'form': 'psd'
}

# ---------------- Application  ----------------
sig = Signal(data, sf=sf, axis=-1, time=time)


class TestSignal(_TestVisbrain):
    """Test signal.py."""

    ###########################################################################
    #                                 LABELS
    ###########################################################################
    def test_xlabel(self):
        """Test setting xlabel."""
        # Text :
        sig._sig_xlab.setText('New x label')
        sig._fcn_axis_xlab()
        # Size :
        sig._sig_lab_fz.setValue(24.)
Пример #6
0
Import annotations from a text file and annotate trials.

All annotations are added to the Annotations/ tab. Then, select a row of the
table to jump to it.

Download an example of annotation file :
https://drive.google.com/file/d/0B6vtJiCQZUBvMG95RHNXbDEwaGs/view?usp=sharing

.. image:: ../../_static/examples/ex_annotations.png
"""
from visbrain.gui import Signal
from visbrain.utils import generate_eeg

sf = 512.  # sampling frequency
n_pts = 4000  # number of time points
n_trials = 125  # number of trials in the dataset
"""Generate a random EEG vector of shape (n_trials, n_pts). This time, we
smooth signals and decrease the noise on it.
"""
data, _ = generate_eeg(sf=sf,
                       n_pts=n_pts,
                       n_trials=n_trials,
                       smooth=200,
                       noise=1000)
"""Specify the path to the annotation file :
"""
annotations = 'signal_annotations.txt'

Signal(data, sf=sf, axis=-1, line_lw=2., annotations=annotations).show()
Пример #7
0
Superimposition of all the signals.

.. image:: ../../_static/examples/ex_butterfly.png
"""
import numpy as np
from visbrain.gui import Signal

sf = 1024.  # Sampling frequency
n_pts = 1000  # Number of time points
n_sines = 100  # Number of sines
f_sines = (.4, .6)  # (Min, Max) sines frequencies
"""Generate the time vector
"""
time_2d = np.mgrid[0:n_sines, 0:n_pts][1] / sf
time = time_2d[0, :] * 1000.
"""Generate a random dataset to illustrate the butterfly
"""
phy = np.random.uniform(0., np.pi / 2., n_sines)
f_sines = np.random.uniform(f_sines[0], f_sines[1], (n_sines, )).reshape(-1, 1)
data = np.sin(2 * np.pi * f_sines * time_2d + phy.reshape(-1, 1))
data += np.random.rand(*data.shape) / 100.
data *= np.random.uniform(.7, 1.3, (n_sines, )).reshape(-1, 1)

Signal(data,
       time=time,
       form='butterfly',
       xlabel='Time (ms)',
       ylabel='Amplitude (uV)',
       color='darkgray').show()
Пример #8
0
sf = 1000.  # Sampling-frequency
n_pts = 4000  # Number of time points
n_sines = 10  # Number of sines
"""Create artificial sines :
"""
time = np.arange(n_pts) / sf
f_sines = np.linspace(13, 30, n_sines)
data = np.sin(2 * np.pi * f_sines.reshape(-1, 1) * time.reshape(1, -1))
data += np.random.randn(*data.shape)
"""Create the signal instance and pass data to it
"""
sig = Signal(data,
             axis=1,
             sf=sf,
             time=time,
             form='tf',
             tf_cmap='Spectral_r',
             psd_nperseg=n_pts)
"""Start by exporting the grid of signals.
"""
sig.screenshot('grid.tiff', canvas='grid', dpi=600, autocrop=True)
"""Loop over all of the signals and export all time-frequency maps.
"""
for k in sig:
    # Set the signal index :
    sig.set_signal_index(k)
    # Set final exported image to be the power spectrum density
    if k == n_sines - 2:
        sig.set_signal_form('psd')
    # Export image :
Пример #9
0
Shortcuts
---------

* Mouse wheel : to zoom over the canvas
* Mouse press and hold : to move the center of the camera
* Double click : insert an annotation under the mouse cursor
* <delete> : reset the camera

.. image:: ../../_static/examples/ex_1d_signal.png
"""
from visbrain.gui import Signal
from visbrain.utils import generate_eeg

sf = 512.  # sampling frequency
n_pts = 4000  # number of time points
"""Generate a random EEG vector of shape (n_pts,). Also get the associated
time vector with the same length as the data.
"""
data, time = generate_eeg(sf=sf, n_pts=n_pts)
time += 8.  # force the time vector to start at 8 seconds
time *= 1000.  # millisecond conversion
"""Add a label to the x-axis (xlabel), y-axis (ylabel) and a title
"""
xlabel = 'Time (ms)'
ylabel = 'Amplitude (uV)'
title = 'Plot of a 1-d signal'

Signal(data, sf=sf, time=time, xlabel=xlabel, ylabel=ylabel,
       title=title).show()