Exemplo n.º 1
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:: ../../_static/examples/ex_eegmeg_fmri_activations.png
"""
from visbrain.gui import Brain
from visbrain.objects import BrainObj
from visbrain.io import download_file
"""Download file if needed
"""
file = download_file('lh.sig.nii.gz', astype='example_data')

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()
Exemplo n.º 2
0
"""
Display conjunction map
=======================

Display a conjunction map from a nii.gz file (NiBabel required).

See the original PySurfer example :

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

.. image:: ../../_static/examples/ex_eegmeg_conjunction_map.png
"""
from visbrain.gui import Brain
from visbrain.objects import BrainObj
from visbrain.io import download_file

"""Download files if needed
"""
file_1 = download_file('lh.sig.nii.gz', astype='example_data')
file_2 = download_file('lh.alt_sig.nii.gz', astype='example_data')

b_obj = BrainObj('inflated', translucent=False, sulcus=True)
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)
vb.rotate('left')
vb.show()
Exemplo n.º 3
0
                   xyz,
                   connect,
                   color_by='strength',
                   cmap='Greys',
                   vmin=small_weight_threshold,
                   vmax=large_weight_threshold,
                   under='blue',
                   over='red',
                   antialias=True)
"""Finally, pass source and connectivity objects to Brain :
"""
vb = Brain(source_obj=s_obj, connect_obj=c_obj)
vb.brain_control(alpha=0.1, hemisphere='both')

rotation = 'axial_0'
vb.rotate('axial_0')  # top
#vb.rotate('axial_1') #bottom
#vb.rotate('sagittal_0') # left
#vb.rotate('sagittal_1') # right
#vb.rotate('coronal_0') # front
#vb.rotate('coronal_1') # back

# Save the brain
vb.screenshot('main2.png',
              canvas='main',
              print_size=(10, 20),
              dpi=300,
              autocrop=True)

# What is left to do here is to take different shot of the brain to create a figure of the overal connectivity
# through time
Exemplo n.º 4
0
                   dynamic=(.1, 1.))
vb.screenshot('count.png', autocrop=True)

# ============= Projection =============
vb.connect_control(show=False)
vb.sources_display('all')
vb.cortical_repartition(cmap='viridis',
                        clim=(1., 6.),
                        vmin=2.,
                        under='gray',
                        vmax=4.,
                        over='#ab4642',
                        radius=16.)
vb.brain_control(transparent=False)
vb.sources_opacity(show=False)
vb.rotate(custom=(-125., 0.))
vb.screenshot('repartition.jpg', autocrop=True)

vb.sources_display('all')
vb.roi_control(selection=[4, 6], roi_type='Brodmann', smooth=5)
vb.cortical_projection(project_on='roi',
                       radius=12.,
                       cmap='inferno',
                       clim=(.1, .5),
                       vmin=0.,
                       vmax=6.)
vb.sources_display('none')
vb.brain_control(template='B3')
vb.brain_control(transparent=True)
vb.rotate('coronal')
vb.screenshot('roi.jpg', autocrop=True)
Exemplo n.º 5
0
vb.connect_control(show=True, cmap='magma', colorby='density', clim=(0., 35.),
                   vmin=10., vmax=30., under='gray', over='darkred',
                   dynamic=(.7, 1.))
vb.screenshot('density.png', autocrop=True)
# Color by number of connections per node :
vb.connect_control(show=True, cmap='viridis', colorby='count', clim=(1., 5.),
                   vmin=0., vmax=10., dynamic=(.1, 1.))
vb.screenshot('count.png', autocrop=True)

# ============= Projection =============
vb.connect_control(show=False)
vb.sources_display('all')
vb.cortical_repartition(cmap='viridis', clim=(1., 6.), vmin=2., under='gray',
                        vmax=4., over='#ab4642', radius=16.)
vb.brain_control(transparent=False)
vb.sources_opacity(show=False)
vb.rotate(custom=(-125., 0.))
vb.screenshot('repartition.jpg', autocrop=True)

vb.sources_display('all')
vb.roi_control(selection=[4, 6], roi_type='Brodmann', smooth=5)
vb.cortical_projection(project_on='roi', radius=12., cmap='inferno',
                       clim=(.1, .5), vmin=0., vmax=6.)
vb.sources_display('none')
vb.brain_control(template='B3')
vb.brain_control(transparent=True)
vb.rotate('coronal')
vb.screenshot('roi.jpg', autocrop=True)

vb.show()
Exemplo n.º 6
0
"""Pass the brain, source and ROI object to the GUI
"""
vb = Brain(brain_obj=b_obj, source_obj=s_obj, roi_obj=roi_obj)

"""Render the scene and save the jpg picture with a 300dpi
"""
save_as = os.path.join(save_pic_path, '0_main_brain.jpg')
vb.screenshot(save_as, dpi=300, print_size=(10, 10), autocrop=True)

"""Project source's activity onto the surface
"""
vb.cortical_projection(clim=(0, 50), cmap='Spectral_r', vmin=10.1,
                       under='black', vmax=41.2, over='green')
vb.sources_control('Sobj', visible=False)        # Hide sources
vb.rotate(custom=(-160., 10.))                   # Rotate the brain
vb.brain_control(translucent=False)              # Make the brain opaque

"""Now, we take a screenthot of the scene but this time, we used the
autocrop argument to crop the image as close as possible to the brain.

Then, we used the print_size, dpi and unit inputs to get higher resolution
image.
Taken together, this mean that the image should have a sufficient size to be
(20 centimeters x 20 centimeters) at 300 dpi.
"""
save_as = os.path.join(save_pic_path, '1_proj_brain.tiff')
vb.screenshot(save_as, autocrop=True, print_size=(20, 20),
              unit='centimeter', dpi=300.)

"""Colorbar screenshot
Exemplo n.º 7
0
"""
vb = Brain(brain_obj=b_obj, source_obj=s_obj, roi_obj=roi_obj)
"""Render the scene and save the jpg picture with a 300dpi
"""
save_as = os.path.join(save_pic_path, '0_main_brain.jpg')
vb.screenshot(save_as, dpi=300, print_size=(10, 10), autocrop=True)
"""Project source's activity onto the surface
"""
vb.cortical_projection(clim=(0, 50),
                       cmap='Spectral_r',
                       vmin=10.1,
                       under='black',
                       vmax=41.2,
                       over='green')
vb.sources_control('Sobj', visible=False)  # Hide sources
vb.rotate(custom=(-160., 10.))  # Rotate the brain
vb.brain_control(translucent=False)  # Make the brain opaque
"""Now, we take a screenthot of the scene but this time, we used the
autocrop argument to crop the image as close as possible to the brain.

Then, we used the print_size, dpi and unit inputs to get higher resolution
image.
Taken together, this mean that the image should have a sufficient size to be
(20 centimeters x 20 centimeters) at 300 dpi.
"""
save_as = os.path.join(save_pic_path, '1_proj_brain.tiff')
vb.screenshot(save_as,
              autocrop=True,
              print_size=(20, 20),
              unit='centimeter',
              dpi=300.)