Esempio n. 1
0
def test_meg_inverse():
    """Test plotting of MEG inverse solution."""
    _set_backend()
    brain = Brain(*std_args)
    stc_fname = os.path.join(data_dir, 'meg_source_estimate-lh.stc')
    stc = io.read_stc(stc_fname)
    vertices = stc['vertices']
    colormap = 'hot'
    data = stc['data']
    data_full = (brain.geo['lh'].nn[vertices][..., np.newaxis] *
                 data[:, np.newaxis])
    time = np.linspace(stc['tmin'], stc['tmin'] + data.shape[1] * stc['tstep'],
                       data.shape[1], endpoint=False)

    def time_label(t):
        return 'time=%0.2f ms' % (1e3 * t)

    for use_data in (data, data_full):
        brain.add_data(use_data, colormap=colormap, vertices=vertices,
                       smoothing_steps=1, time=time, time_label=time_label)

    brain.scale_data_colormap(fmin=13, fmid=18, fmax=22, transparent=True)
    assert brain.data_dict['lh']['time_idx'] == 0

    brain.set_time(.1)
    assert brain.data_dict['lh']['time_idx'] == 2
    # viewer = TimeViewer(brain)

    # multiple data layers
    pytest.raises(ValueError, brain.add_data, data, vertices=vertices,
                  time=time[:-1])
    brain.add_data(data, colormap=colormap, vertices=vertices,
                   smoothing_steps=1, time=time, time_label=time_label,
                   initial_time=.09)
    assert brain.data_dict['lh']['time_idx'] == 1
    data_dicts = brain._data_dicts['lh']
    assert len(data_dicts) == 3
    assert data_dicts[0]['time_idx'] == 1
    assert data_dicts[1]['time_idx'] == 1

    # shift time in both layers
    brain.set_data_time_index(0)
    assert data_dicts[0]['time_idx'] == 0
    assert data_dicts[1]['time_idx'] == 0
    brain.set_data_smoothing_steps(2)

    # add second data-layer without time axis
    brain.add_data(data[:, 1], colormap=colormap, vertices=vertices,
                   smoothing_steps=2)
    brain.set_data_time_index(2)
    assert len(data_dicts) == 4

    # change surface
    brain.set_surf('white')

    # remove all layers
    brain.remove_data()
    assert brain._data_dicts['lh'] == []

    brain.close()
Esempio n. 2
0
def plot_overlays_Fgroup(condition,modality,hemi,azimuth):

    brain = Brain(subject_id='fsaverage', hemi=hemi,surf='pial',cortex = 'low_contrast', size=(600, 600))
    stc_fname = ('/neurospin/meg/meg_tmp/MTT_MEG_Baptiste/MEG/GROUP/mne_python/Plot_STATS/'
                 +"_vs_".join(condition) +'/fmap'+ modality+ '_'
                 +"_vs_".join(condition)+ '-' + hemi+'.stc')
    stc = read_stc(stc_fname)
    data = stc['data']
    vertices = stc['vertices']

    brain.add_data(data, thresh = 3.259,colormap='hot',alpha=1, vertices=vertices,
                   smoothing_steps=3,hemi=hemi)
    brain.set_data_time_index(0)
    brain.scale_data_colormap(fmin=3.26, fmid=5.84, fmax= 8.42, transparent=False)
    brain.show_view(dict(azimuth=azimuth,elevation=None, distance=None))
    #    mayavi.mlab.view(azimuth=0, elevation=None, distance=None, focalpoint=None,
    #         roll=None, reset_roll=True, figure=None)
    
    PlotDir = []
    PlotDir = ('/neurospin/meg/meg_tmp/MTT_MEG_Baptiste/MEG/GROUP/mne_python/Plot_STATS/'  
               + "_vs_".join(condition)) 
    
    if not os.path.exists(PlotDir):
        os.makedirs(PlotDir)

    brain.save_image(PlotDir + '/Fmap_IcaCorr_' + modality + '_' + 'dSPM' + '_'
                        + '_' + "_vs_".join(condition) + '_'
                        +  hemi + '_'+ str(azimuth)+ '_ico-5-fwd-fsaverage-'+'.png')                      
Esempio n. 3
0
def test_meg_inverse():
    """Test plotting of MEG inverse solution."""
    _set_backend()
    brain = Brain(*std_args)
    stc_fname = os.path.join(data_dir, 'meg_source_estimate-lh.stc')
    stc = io.read_stc(stc_fname)
    vertices = stc['vertices']
    colormap = 'hot'
    data = stc['data']
    data_full = (brain.geo['lh'].nn[vertices][..., np.newaxis] *
                 data[:, np.newaxis])
    time = np.linspace(stc['tmin'], stc['tmin'] + data.shape[1] * stc['tstep'],
                       data.shape[1], endpoint=False)

    def time_label(t):
        return 'time=%0.2f ms' % (1e3 * t)

    for use_data in (data, data_full):
        brain.add_data(use_data, colormap=colormap, vertices=vertices,
                       smoothing_steps=1, time=time, time_label=time_label)

    brain.scale_data_colormap(fmin=13, fmid=18, fmax=22, transparent=True)
    assert_equal(brain.data_dict['lh']['time_idx'], 0)

    brain.set_time(.1)
    assert_equal(brain.data_dict['lh']['time_idx'], 2)
    # viewer = TimeViewer(brain)

    # multiple data layers
    assert_raises(ValueError, brain.add_data, data, vertices=vertices,
                  time=time[:-1])
    brain.add_data(data, colormap=colormap, vertices=vertices,
                   smoothing_steps=1, time=time, time_label=time_label,
                   initial_time=.09)
    assert_equal(brain.data_dict['lh']['time_idx'], 1)
    data_dicts = brain._data_dicts['lh']
    assert_equal(len(data_dicts), 3)
    assert_equal(data_dicts[0]['time_idx'], 1)
    assert_equal(data_dicts[1]['time_idx'], 1)

    # shift time in both layers
    brain.set_data_time_index(0)
    assert_equal(data_dicts[0]['time_idx'], 0)
    assert_equal(data_dicts[1]['time_idx'], 0)
    brain.set_data_smoothing_steps(2)

    # add second data-layer without time axis
    brain.add_data(data[:, 1], colormap=colormap, vertices=vertices,
                   smoothing_steps=2)
    brain.set_data_time_index(2)
    assert_equal(len(data_dicts), 4)

    # change surface
    brain.set_surf('white')

    # remove all layers
    brain.remove_data()
    assert_equal(brain._data_dicts['lh'], [])

    brain.close()
Esempio n. 4
0
def test_meg_inverse():
    """Test plotting of MEG inverse solution."""
    mlab.options.backend = 'test'
    brain = Brain(*std_args)
    stc_fname = os.path.join(data_dir, 'meg_source_estimate-lh.stc')
    stc = io.read_stc(stc_fname)
    data = stc['data']
    vertices = stc['vertices']
    time = np.linspace(stc['tmin'], stc['tmin'] + data.shape[1] * stc['tstep'],
                       data.shape[1], endpoint=False)
    colormap = 'hot'

    def time_label(t):
        return 'time=%0.2f ms' % (1e3 * t)

    brain.add_data(data, colormap=colormap, vertices=vertices,
                   smoothing_steps=10, time=time, time_label=time_label)
    brain.scale_data_colormap(fmin=13, fmid=18, fmax=22, transparent=True)
    assert_equal(brain.data_dict['lh']['time_idx'], 0)

    brain.set_time(.1)
    assert_equal(brain.data_dict['lh']['time_idx'], 2)
    # viewer = TimeViewer(brain)

    # multiple data layers
    assert_raises(ValueError, brain.add_data, data, vertices=vertices,
                  time=time[:-1])
    brain.add_data(data, colormap=colormap, vertices=vertices,
                   smoothing_steps=10, time=time, time_label=time_label,
                   initial_time=.09)
    assert_equal(brain.data_dict['lh']['time_idx'], 1)
    data_dicts = brain._data_dicts['lh']
    assert_equal(len(data_dicts), 2)
    assert_equal(data_dicts[0]['time_idx'], 1)
    assert_equal(data_dicts[1]['time_idx'], 1)

    # shift time in both layers
    brain.set_data_time_index(0)
    assert_equal(data_dicts[0]['time_idx'], 0)
    assert_equal(data_dicts[1]['time_idx'], 0)

    # remove all layers
    brain.remove_data()
    assert_equal(brain._data_dicts['lh'], [])

    brain.close()
Esempio n. 5
0
def test_meg_inverse():
    """Test plotting of MEG inverse solution
    """
    mlab.options.backend = 'test'
    brain = Brain(*std_args)
    stc_fname = os.path.join(data_dir, 'meg_source_estimate-lh.stc')
    stc = io.read_stc(stc_fname)
    data = stc['data']
    vertices = stc['vertices']
    time = 1e3 * np.linspace(stc['tmin'],
                             stc['tmin'] + data.shape[1] * stc['tstep'],
                             data.shape[1])
    colormap = 'hot'
    time_label = 'time=%0.2f ms'
    brain.add_data(data, colormap=colormap, vertices=vertices,
                   smoothing_steps=10, time=time, time_label=time_label)
    brain.set_data_time_index(2)
    brain.scale_data_colormap(fmin=13, fmid=18, fmax=22, transparent=True)
Esempio n. 6
0
def plot_overlays_diff_singlesubj(subject,condition,method,modality,hemi,indextime, azimuth):

    subject_id, surface = 'fsaverage', 'inflated'
    hemi = hemi
    brain = Brain(subject_id, hemi, surface, size=(600, 600))
    stc_fname = ('/neurospin/meg/meg_tmp/MTT_MEG_Baptiste/MEG/' + subject + '/mne_python/STCS_diff/IcaCorr_' 
               + condition[0] + '-' + condition[1] 
               + '/' + modality + '_' + method + '_' + subject 
                        + '_' + condition[0] + '-' + condition[1] 
                        + '_' + '_ico-5-fwd-fsaverage-.stc-'+hemi+'.stc')
    stc = read_stc(stc_fname)
    data = stc['data']
    vertices = stc['vertices']
    time = np.linspace(stc['tmin'], stc['tmin'] + data.shape[1] * stc['tstep'],
                       data.shape[1])
    
    colormap = 'hot'
    time_label = lambda t: 'time=%0.2f ms' % (t * 1e3)
    brain.add_data(data, colormap=colormap, vertices=vertices,
                   smoothing_steps=4, time=time, time_label=time_label,
                   hemi=hemi)
    brain.set_data_time_index(indextime)
    brain.scale_data_colormap(fmin=0, fmid=2.5, fmax=5, transparent=True)
    brain.show_view(dict(azimuth=azimuth,elevation=None, distance=None))
    #    mayavi.mlab.view(azimuth=0, elevation=None, distance=None, focalpoint=None,
    #         roll=None, reset_roll=True, figure=None)

    realtime = stc['tmin'] + stc['tstep']*indextime  
    
    PlotDir = []
    PlotDir = ('/neurospin/meg/meg_tmp/MTT_MEG_Baptiste/MEG/' + subject + '/mne_python/BrainMaps/IcaCorr_' +  
               + condition[0] + '-' + condition[1]) 
    
    if not os.path.exists(PlotDir):
        os.makedirs(PlotDir)

    brain.save_image(PlotDir + '/IcaCorr_' + modality + '_' + method + '_' + subject 
                        + '_' + condition[0] + '-' + condition[1] + '_' + str(realtime) +  hemi 
                        + '_'+ str(azimuth)+ '_ico-5-fwd-fsaverage-'
                        +'.png')        
Esempio n. 7
0
def test_meg_inverse():
    """Test plotting of MEG inverse solution
    """
    mlab.options.backend = 'test'
    brain = Brain(*std_args)
    stc_fname = os.path.join(data_dir, 'meg_source_estimate-lh.stc')
    stc = io.read_stc(stc_fname)
    data = stc['data']
    vertices = stc['vertices']
    time = 1e3 * np.linspace(
        stc['tmin'], stc['tmin'] + data.shape[1] * stc['tstep'], data.shape[1])
    colormap = 'hot'
    time_label = 'time=%0.2f ms'
    brain.add_data(data,
                   colormap=colormap,
                   vertices=vertices,
                   smoothing_steps=10,
                   time=time,
                   time_label=time_label)
    brain.set_data_time_index(2)
    brain.scale_data_colormap(fmin=13, fmid=18, fmax=22, transparent=True)
    # viewer = TimeViewer(brain)
    brain.close()
Esempio n. 8
0
def plot_overlays_diff_group(condition,method,modality,hemi,indextime,azimuth):

    hemi = hemi
    brain = Brain(subject_id='fsaverage', hemi=hemi, surface='pial', size=(600, 600))
    stc_fname = ('/neurospin/meg/meg_tmp/MTT_MEG_Baptiste/MEG/GROUP/mne_python/BrainMaps/IcaCorr_' 
                 + modality + '_' + condition[0] + '-' + condition[1] + '_pick_oriNone_' + method 
                 + '_ico-5-fwd-fsaverage.stc-'+ hemi +'.stc')
    stc = read_stc(stc_fname)
    data = stc['data']
    vertices = stc['vertices']
    time = np.linspace(stc['tmin'], stc['tmin'] + data.shape[1] * stc['tstep'],
                       data.shape[1])
    
    # colormap = 'seismic'
    colormap = mne.viz.mne_analyze_colormap(limits=[-3,-1.81,-1.80, 1.80,1.81, 3], format='mayavi')
    time_label = lambda t: 'time=%0.2f ms' % (t * 1e3)
    brain.add_data(data, colormap=colormap, vertices=vertices,
                   smoothing_steps=20, time=time, time_label=time_label,
                   hemi=hemi)
    brain.set_data_time_index(indextime)
    brain.scale_data_colormap(fmin=-1.82, fmid=0, fmax= 1.82, transparent=False)
    brain.show_view(dict(azimuth=azimuth,elevation=None, distance=None))
    #    mayavi.mlab.view(azimuth=0, elevation=None, distance=None, focalpoint=None,
    #         roll=None, reset_roll=True, figure=None)

    realtime = stc['tmin'] + stc['tstep']*indextime  
    
    PlotDir = []
    PlotDir = ('/neurospin/meg/meg_tmp/MTT_MEG_Baptiste/MEG/GROUP/mne_python/Plots/IcaCorr_'  
               + condition[0] + '-' + condition[1] ) 
    
    if not os.path.exists(PlotDir):
        os.makedirs(PlotDir)

    brain.save_image(PlotDir + '/IcaCorr_' + modality + '_' + method + '_'
                        + '_' + condition[0] + '-' + condition[1] + '_' + str(realtime)
                        +  hemi + '_'+ str(azimuth)+ '_ico-5-fwd-fsaverage-'+'.png')                      
Esempio n. 9
0
vertices = stc['vertices']
"""
time points in milliseconds
"""
time = 1e3 * np.linspace(
    stc['tmin'], stc['tmin'] + data.shape[1] * stc['tstep'], data.shape[1])
"""
colormap to use
"""
colormap = 'hot'
"""
label for time annotation
"""
time_label = 'time=%0.2f ms'

brain.add_data(data,
               colormap=colormap,
               vertices=vertices,
               smoothing_steps=10,
               time=time,
               time_label=time_label)
"""
scale colormap and set time (index) to display
"""
brain.set_data_time_index(2)
brain.scale_data_colormap(fmin=13, fmid=18, fmax=22, transparent=True)
"""
uncomment this line to use the interactive TimeViewer GUI
"""
#viewer = TimeViewer(brain)
    time points in milliseconds
    """
    time = 1e3 * np.linspace(stc['tmin'],
                             stc['tmin'] + data.shape[1] * stc['tstep'],
                             data.shape[1])
    """
    colormap to use
    """
    colormap = 'hot'

    """
    label for time annotation
    """
    time_label = 'time=%0.2f ms'

    brain.add_data(data, colormap=colormap, vertices=vertices,
                   smoothing_steps=10, time=time, time_label=time_label,
                   hemi=hemi)

"""
scale colormap and set time (index) to display
"""
brain.set_data_time_index(2)
brain.scale_data_colormap(fmin=13, fmid=18, fmax=22, transparent=True)

"""
uncomment these lines to use the interactive TimeViewer GUI
"""
#from surfer import TimeViewer
#viewer = TimeViewer(brain)
Esempio n. 11
0




 brain = Brain(subject_id=mri_partic,subjects_dir=shared_dir,surf='orig',hemi='both', background='white', size=(800, 600))
    brain.add_annotation(parc)
 






brain = stc.plot(surface='inflated', hemi='lh', subjects_dir=shared_dir)
brain.set_data_time_index(300)  # 221 for S2
brain.scale_data_colormap(fmin=-1e-12, fmid=1e-12, fmax=50e-12, transparent=True)
brain.show_view('lateral')








vertno_max, time_max = stc.get_peak(hemi='rh')

surfer_kwargs = dict(
    subjects_dir=shared_dir,
    clim=dict(kind='value', lims=[8, 12, 15]), views='lateral',