FAQ

#nodeepshit

Frequently asked questions


General

If you’re not a Python user or if you’ve never used Python, this section is for you. To install Python, you should try Anaconda which can be used to manage Python packages and requirement. Then, open a command line window (or terminal) and run :

conda install pip

Once pip is installed, you should be able to install Visbrain. In the terminal, run the following command :

pip install visbrain

And you should be ready to write your first python script. In your file explorer, create a new file, for example py_script.py. Open your file in a notepad like application (or an editor like Atom or Sublime Text). Then, paste the following python code :

# Import only the Brain module from visbrain
from visbrain import Brain
# Open Brain :
Brain().show()

Finally, inside your terminal navigate to your folder where the py_script.py is located and run it using the following command :

python py_script.py

Checkout the Community tab, we provide several Gitter chat rooms where you asked your questions.

Yes, we provide a set of functions to help you with the compatibility with MNE-Python. Checkout visbrain.mne:

import visbrain                                   # import the full package
from visbrain import Brain, Sleep                 # import modules
from visbrain.objects import BrainObj, SourceObj  # import objects

Well, to be honest, the following trick doesn’t work on every system and you could be forced to use Visbrain inside Python script (.py) or ipython instead of notebooks (.ipynb). Try to start your notebook with the following cell :

import matplotlib
matplotlib.use("Qt5Agg")

Objects

In Visbrain, objects are elementary visualization bricks. One object = one visualization type. Objects can be imported from visbrain.objects. For example :

Checkout the visbrain.objects part of the API. Then, each object has a .preview() method to be displayed.

from visbrain.objects import BrainObj

# Create a brain object and display it :
b_obj = BrainObj('B1', translucent=False)

# Display the brain object :
b_obj.preview()
_images/tuto_1.png

Objects can be combined in a scene (see visbrain.objects.SceneObj) to create a figure with several panels.

How to combine objects in separate panels?

import numpy as np
from visbrain.objects import SceneObj, BrainObj, ImageObj, ColorbarObj

# Create a brain object :
b_obj = BrainObj('B1', translucent=False)

# Create a 200x200 image :
im = np.random.rand(200, 200)
im_obj = ImageObj('MyImage', data=im, cmap='inferno')

# Create a colorbar from the image object :
cb_obj = ColorbarObj(im_obj)

# Now, create the scene object and add every objects to it :
sc = SceneObj()
sc.add_to_subplot(b_obj, row=0, col=0, title='Brain object')
sc.add_to_subplot(im_obj, row=0, col=1, title='Image object')
sc.add_to_subplot(cb_obj, row=0, col=2, title='Colorbar object')

# Finally, display the scene :
sc.preview()
_images/tuto_2-1.png

How to stack several objects inside the same panel?

import numpy as np
from visbrain.objects import SceneObj, BrainObj, SourceObj

# Create a brain object :
b_obj = BrainObj('B1', translucent=True)

# Create a first source object with red square symbols :
s1 = np.random.uniform(-50, 0, (20, 3))
s1_obj = SourceObj('S1', xyz=s1, symbol='square', color='red',
                   radius_min=30)

# Create a second source object with green disc symbols :
s2 = np.random.uniform(0, 50, (20, 3))
s2_obj = SourceObj('S2', xyz=s2, symbol='disc', color='green',
                   radius_min=30)

# Now, create the scene object and add every objects to it :
sc = SceneObj()
sc.add_to_subplot(b_obj, title='Brain object + two source object')
sc.add_to_subplot(s1_obj)
sc.add_to_subplot(s2_obj)

# Finally, display the scene :
sc.preview()
_images/tuto_2-2.png

Brain

The visbrain.objects.BrainObj comes with several brain templates (i.e B1, B2, B3 etc.). This is relevant for intracranial data but not always for EEG/MEG data. In that case, you can specify your own vertices and faces and define a new brain template.

from visbrain import Brain
from visbrain.objects import BrainObj

vertices = ...  # the array of vertices
faces = ...  # the array of faces

# Sometimes you can also have the normals to faces but visbrain usually have
# a better visual output when computing normals itself.
# Now, define a brain object :
b_obj = BrainObj('Custom', vertices=vert, faces=faces)

# Then, pass your brain object as an input and use it inside the GUI :
Brain(brain_obj=b_obj).show()

# Note : you can also save your template if you want to reload it later
# checkout the visbrain.objects.BrainObj.save method :
b_obj.save()

# After being saved, your template can be reloaded using :
b_obj = BrainObj('Custom')

For further details, checkout this example : Define a brain template using vertices and faces

Sleep

Two strategies :

  • You already have a function to load your data as a NumPy array. In that case :
from visbrain import Sleep

data = ...        # NumPy array of shape (n_channels, n_time_points)
channels = [...]  # List of channel names. Could be None
hypno = ...       # NumPy array of shape (n_time_points,). Could be None

Sleep(data=data, hypno=hypno, channels=channels).show()

Sleep does not yet provide a function to automatically detect and score the sleep stages. However, Sleep can make the tedious process of manually scoring the sleep stages easier for you, by automatically detecting microstructural events such as spindles, slow waves or rapid eye movements. In addition, the multiple customizable parameters of the spectrogram can be very useful to visually detect period of deep sleep, wakefulness, movements…

Yes! Sleep offers the possibility to implement your own detection algorithm. Please see the Sleep documentation for further details.