Exemplo n.º 1
0
                  row=1,
                  col=0,
                  rotate='right',
                  use_this_cam=True)

b_obj_proj_right = BrainObj(template_brain,
                            hemisphere='right',
                            translucent=False)
b_obj_proj_right.project_sources(s_obj_all,
                                 clim=(1, 7),
                                 cmap='viridis_spliced')
sc.add_to_subplot(b_obj_proj_right,
                  row=1,
                  col=1,
                  rotate='left',
                  use_this_cam=True)

b_obj_proj_right = BrainObj(template_brain,
                            hemisphere='right',
                            translucent=False)
b_obj_proj_right.project_sources(s_obj_all,
                                 clim=(1, 7),
                                 cmap='viridis_spliced')
sc.add_to_subplot(b_obj_proj_right,
                  row=0,
                  col=1,
                  rotate='right',
                  use_this_cam=True)

sc.screenshot(os.path.join(fig_dir, 'freq_intersection.png'), transparent=True)
Exemplo n.º 2
0
# And add connect, source and brain objects to the scene
# sc.add_to_subplot(s_obj, row=0, col=0, zoom=0.1)
b_obj = BrainObj('B2')
sc.add_to_subplot(b_obj,row=0, col=0, use_this_cam=True)
#, use_this_cam=True
# from visbrain.objects import ColorbarObj
# cb = ColorbarObj(c_default, **CBAR_STATE)
# sc.add_to_subplot(cb, width_max=200, row=0, col=1)

  # clim=(4., 78.2), vmin=10.,
  #                 vmax=72., cblabel='Colorbar title', under='gray',
  #                 over='red', txtcolor='black', cbtxtsz=40, cbtxtsh=2.,
  #                 txtsz=20., width=.04)

sc.screenshot('plain_brain.png', transparent=True)
sc.preview()
#sc.screenshot("test.jpg")

################Different transparency for diff strengths (one color)
# Define the connectivity object
# c_default = ConnectObj('default', nodes, edges, select=select, line_width=0.5,dynamic=(0, 1),
#                        cmap='viridis',custom_colors = {None: "green"})
# # Then, we define the sources
# #node size and color
# s_obj = SourceObj('sources', nodes, color='#000000', radius_min=10.)
# #title
# sc.add_to_subplot(c_default, row=0, col=0, zoom=0.1)

# # And add connect, source and brain objects to the scene
# sc.add_to_subplot(s_obj, row=0, col=0, zoom=0.1)
Exemplo n.º 3
0
    sc.add_to_subplot(b_obj_proj_left,
                      row=0,
                      col=1,
                      rotate='right',
                      use_this_cam=True)

    b_obj_proj_right = BrainObj(template_brain,
                                hemisphere='right',
                                translucent=False)
    b_obj_proj_right.project_sources(s_obj_all, clim=(0, 16), cmap=cmap)
    sc.add_to_subplot(b_obj_proj_right,
                      row=0,
                      col=2,
                      rotate='left',
                      use_this_cam=True)

    b_obj_proj_right = BrainObj(template_brain,
                                hemisphere='right',
                                translucent=False)
    b_obj_proj_right.project_sources(s_obj_all, clim=(0, 16), cmap=cmap)
    sc.add_to_subplot(b_obj_proj_right,
                      row=0,
                      col=3,
                      rotate='right',
                      use_this_cam=True)

    # cb_proj = ColorbarObj(b_obj_proj_right, cblabel='Order', **CBAR_STATE)
    # sc.add_to_subplot(cb_proj, row=0, col=4, width_max=200)

    sc.screenshot(os.path.join(fig_dir, f'{c}_15.png'), transparent=True)
Exemplo n.º 4
0
sc.add_to_subplot(b_obj_proj_left, row=0, col=0, rotate='left', use_this_cam=True)


b_obj_proj_left = BrainObj(template_brain, hemisphere='left', translucent=False)
b_obj_proj_left.project_sources(s_obj_1, clim=(0, 2), cmap='binary')
sc.add_to_subplot(b_obj_proj_left, row=0, col=1, rotate='right', use_this_cam=True)

b_obj_proj_right = BrainObj(template_brain, hemisphere='right', translucent=False)
b_obj_proj_right.project_sources(s_obj_1, clim=(0, 2), cmap='binary')
sc.add_to_subplot(b_obj_proj_right, row=0, col=2, rotate='left', use_this_cam=True)

b_obj_proj_right = BrainObj(template_brain, hemisphere='right', translucent=False)
b_obj_proj_right.project_sources(s_obj_1, clim=(0, 2), cmap='binary')
sc.add_to_subplot(b_obj_proj_right, row=0, col=3, rotate='right', use_this_cam=True)

sc.screenshot(os.path.join(fig_dir, 'intersection.png'), transparent=True)

nii_list = glob.glob(os.path.join(nii_bo_dir, '*_bestloc.nii'))

for n in nii_list:

    sc = SceneObj(bgcolor='white', size=(1000, 500))

    nii = nib.load(n)

    fname = os.path.splitext(os.path.basename(n))[0]

    b_obj_proj_ll = BrainObj(template_brain, hemisphere='left', translucent=False)
    b_obj_proj_lr = BrainObj(template_brain, hemisphere='left', translucent=False)
    b_obj_proj_rr = BrainObj(template_brain, hemisphere='right', translucent=False)
    b_obj_proj_rl = BrainObj(template_brain, hemisphere='right', translucent=False)
Exemplo n.º 5
0
def create_graph_picture(filename, xyz, hemisphere, rotation):
    ''' 
    data is a .mat file containing the location and the 3D tensor containing 
    N number of M*M matrices. Output path is where we will be saving the stuff

    hemisphere is 'left' 'right' or 'both'
    rotation is 'left', 'right', 'top', 'bottom'
    '''

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

    # Get the connection matrix
    connect = 1 * np.random.rand(num_electrodes, num_electrodes)
    data = np.mean(connect, axis=1)

    # need a upper triangular matrix (fine for wPLI since we have symmetry)
    connect[np.tril_indices_from(connect)] = 0  # Set to zero inferior triangle

    small_weight_threshold = 0.001
    large_weight_threshold = 0.999

    # 2 - Using masking (True: hide, 1: display):
    connect = np.ma.masked_array(connect, mask=True)
    # This will show (set to hide = False) only the large and small connection
    connect.mask[np.where((connect >= large_weight_threshold)
                          | (connect <= small_weight_threshold))] = False

    s_obj = SourceObj('SourceObj1',
                      xyz,
                      data,
                      color='whitesmoke',
                      alpha=.5,
                      edge_width=2.,
                      radius_min=2.,
                      radius_max=30.)

    c_obj = ConnectObj('ConnectObj1',
                       xyz,
                       connect,
                       color_by='strength',
                       cmap='Greys',
                       vmin=small_weight_threshold,
                       vmax=large_weight_threshold,
                       under='blue',
                       over='red',
                       antialias=True)

    CAM_STATE = dict(
        azimuth=0,
        elevation=90,
    )
    CBAR_STATE = dict(cbtxtsz=12,
                      txtsz=10.,
                      width=.1,
                      cbtxtsh=3.,
                      rect=(-.3, -2., 1., 4.))
    sc = SceneObj(camera_state=CAM_STATE, size=(1400, 1000))
    sc.add_to_subplot(BrainObj('B1', hemisphere=hemisphere),
                      row=0,
                      col=0,
                      rotate=rotation)
    sc.add_to_subplot(c_obj, row=0, col=0, rotate=rotation)
    sc.add_to_subplot(s_obj, row=0, col=0, rotate=rotation)
    sc.screenshot(filename, print_size=(10, 20), dpi=100)
                  txtsz=10.,
                  width=.1,
                  cbtxtsh=3.,
                  rect=(-.3, -2., 1., 4.))
KW = dict(title_size=14., zoom=1)

sc_blank = SceneObj(bgcolor='white', size=(500, 500))
b_obj_proj_blank = BrainObj(template_brain,
                            hemisphere='left',
                            translucent=False)
sc_blank.add_to_subplot(b_obj_proj_blank,
                        row=0,
                        col=0,
                        rotate='left',
                        use_this_cam=True)
sc_blank.screenshot(os.path.join(fig_dir, 'blank.png'), transparent=True)

s_obj_1 = SourceObj('iEEG', xyz1, data=data1, cmap=cmap)
s_obj_1.color_sources(data=data1)
s_obj_2 = SourceObj('iEEG', xyz2, data=data2, cmap=cmap)
s_obj_2.color_sources(data=data2)
s_obj_3 = SourceObj('iEEG', xyz3, data=data3, cmap=cmap)
s_obj_3.color_sources(data=data3)
s_obj_4 = SourceObj('iEEG', xyz4, data=data4, cmap=cmap)
s_obj_4.color_sources(data=data4)

s_obj_all = s_obj_1 + s_obj_2 + s_obj_3 + s_obj_4

b_obj_proj_left = BrainObj(template_brain,
                           hemisphere='both',
                           translucent=False)
Exemplo n.º 7
0
                               translucent=False)
    b_obj_proj_left.project_sources(s_obj_all, clim=(0, 4), cmap=cmap)
    sc.add_to_subplot(b_obj_proj_left,
                      row=0,
                      col=1,
                      rotate='right',
                      use_this_cam=True)

    b_obj_proj_right = BrainObj(template_brain,
                                hemisphere='right',
                                translucent=False)
    b_obj_proj_right.project_sources(s_obj_all, clim=(0, 4), cmap=cmap)
    sc.add_to_subplot(b_obj_proj_right,
                      row=0,
                      col=2,
                      rotate='left',
                      use_this_cam=True)

    b_obj_proj_right = BrainObj(template_brain,
                                hemisphere='right',
                                translucent=False)
    b_obj_proj_right.project_sources(s_obj_all, clim=(0, 4), cmap=cmap)
    sc.add_to_subplot(b_obj_proj_right,
                      row=0,
                      col=3,
                      rotate='right',
                      use_this_cam=True)

    sc.screenshot(os.path.join(fig_dir, f'{c}_largest_abs.png'),
                  transparent=True)
Exemplo n.º 8
0
                  row=1,
                  col=1,
                  rotate='left',
                  use_this_cam=True)

b_obj_proj_right = BrainObj(template_brain,
                            hemisphere='right',
                            translucent=False)
b_obj_proj_right.project_sources(s_obj_1, clim=(1, 7), cmap=cmap)
sc.add_to_subplot(b_obj_proj_right,
                  row=0,
                  col=1,
                  rotate='right',
                  use_this_cam=True)

sc.screenshot(os.path.join(fig_dir, '7_networks.png'), transparent=True)

for f in freqs:

    sc = SceneObj(bgcolor='white', size=(1000, 1000))

    b_yeo = se.load(os.path.join(nii_bo_dir, f + '_network.bo'))

    data1 = b_yeo.get_data().values.ravel()
    xyz1 = b_yeo.locs.values

    s_obj_1 = SourceObj('iEEG', xyz1, data=data1, cmap=cmap)
    s_obj_1.color_sources(data=data1)

    b_obj_proj_left = BrainObj(template_brain,
                               hemisphere='left',
Exemplo n.º 9
0
"""
import numpy as np

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

# Create the scene
CAM_STATE = dict(
    azimuth=0,  # azimuth angle
    elevation=90,  # elevation angle
    scale_factor=180  # distance to the camera
)
sc = SceneObj(bgcolor='white', size=(1600, 1000))
b_obj = BrainObj('B3', translucent=False)
sc.add_to_subplot(b_obj)
sc.screenshot('plain_brain.png')

sc.preview()
###############################################################################
# .. warning::
#     To be clear with the vocabulary used, the SourceObj has a different
#     meaning depending on the recording type. For scalp or intracranial EEG,
#     sources reflect electrode, in MEG it could be sensors or source
#     reconstruction.

###############################################################################
# Download data
###############################################################################
# To illustrate the functionalities of the source object, here, we download an
# intracranial dataset consisting of 583 deep recording sites.
Exemplo n.º 10
0
def generate_img(l_file,
                 r_file,
                 activated_areas,
                 brain_name,
                 out_file,
                 views,
                 add_hemispheres,
                 is_estimate=False,
                 cmap='copper',
                 vmin=0.,
                 vmax=0.01,
                 save_gif=False):
    """Generate .png and .gif animation of rotating brains
    """
    sc = SceneObj(size=(1000 * (len(views) // 2 +
                                (1 if add_hemispheres else 0)),
                        1000 * (len(views) > 1)),
                  bgcolor='black')
    KW = dict(title_size=14., zoom=2.)  # zoom not working
    CBAR_STATE = dict(cbtxtsz=12,
                      txtsz=10.,
                      width=.1,
                      cbtxtsh=3.,
                      rect=(-.3, -2., 1., 4.))
    # PLOT OBJECTS
    for i, rot in enumerate(views):
        # cannot use the same object
        b_obj = create_brain_obj(l_file,
                                 r_file,
                                 activated_areas,
                                 brain_name,
                                 cmap=cmap,
                                 vmin=vmin,
                                 vmax=vmax)
        sc.add_to_subplot(b_obj,
                          row=i // 2,
                          col=i % 2,
                          rotate=rot,
                          title=rot,
                          **KW)
        # Get the colorbar of the brain object and add it to the scene
        # Identical brain ==> same colorbar
    if add_hemispheres:
        # add left brain
        b_obj = create_brain_obj(l_file,
                                 r_file,
                                 activated_areas,
                                 brain_name,
                                 hemisphere='right',
                                 cmap=cmap,
                                 vmin=vmin,
                                 vmax=vmax)
        sc.add_to_subplot(b_obj,
                          row=i // 2 + 1,
                          col=0,
                          rotate='left',
                          title='right half',
                          **KW)
        b_obj = create_brain_obj(l_file,
                                 r_file,
                                 activated_areas,
                                 brain_name,
                                 hemisphere='left',
                                 cmap=cmap,
                                 vmin=vmin,
                                 vmax=vmax)
        sc.add_to_subplot(b_obj,
                          row=i // 2 + 1,
                          col=1,
                          rotate='right',
                          title='left half',
                          **KW)
    if is_estimate:
        # cmap needs to be set for all objects
        cb_parr = ColorbarObj(b_obj,
                              cblabel='Data to parcellates',
                              **CBAR_STATE)
        # not working properly and can't find a way to rotate that bar
        # sc.add_to_subplot(cb_parr, row=0, col=2, row_span=i//2+1, width_max=200)
    # gif and png
    # sc.preview()
    if save_gif:
        sc.record_animation(out_file + ('_est' if is_estimate else '') +
                            "_areas.gif")
    sc.screenshot(saveas=out_file + ('_est' if is_estimate else '') +
                  "_areas.png")
    return sc.render()