示例#1
0
def plot_overlays_diff_group_window(condition,method,modality,hemi,window,azimuth,elevation):

    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/GROUP/mne_python/BrainMaps/IcaCorr_Normalized'
                 + modality + '_' + condition[0] + '-' + condition[1] + '_pick_oriNone_' + method 
                 + '_ico-5-fwd-fsaverage.stc-'+ hemi +'.stc')
                 
    stcl_fname = ('/neurospin/meg/meg_tmp/MTT_MEG_Baptiste/MEG/GROUP/mne_python/BrainMaps/IcaCorr_Normalized'
                 + modality + '_' + condition[0] + '-' + condition[1] + '_pick_oriNone_' + method 
                 + '_ico-5-fwd-fsaverage.stc-lh.stc')
    stcr_fname = ('/neurospin/meg/meg_tmp/MTT_MEG_Baptiste/MEG/GROUP/mne_python/BrainMaps/IcaCorr_Normalized'
                 + modality + '_' + condition[0] + '-' + condition[1] + '_pick_oriNone_' + method 
                 + '_ico-5-fwd-fsaverage.stc-rh.stc')    
                 
    stcl  = read_stc(stcl_fname)
    stcr  = read_stc(stcr_fname)
    datal = stcl['data']  
    datar = stcr['data']            
                 
    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])
    winstart = np.where(time < window[0])[0][-1]
    winend   = np.where(time >= window[1])[0][0]
    
    meanval = np.mean(data[:,winstart:winend],1)   
    meanvalr = np.mean(datar[:,winstart:winend],1)   
    meanvall = np.mean(datal[:,winstart:winend],1)  
    maxval = np.max([np.max(meanvalr),np.max(meanvall)])
    minval = np.min([np.min(meanvalr),np.min(meanvall)])
    fmin = -np.max(np.abs([maxval,minval]))*0.8
    fmax = np.max(np.abs([maxval,minval]))*0.8
    
    colormap = mne.viz.mne_analyze_colormap(limits=[fmin, fmin/3, fmin/3.1, fmax/3.1, fmax/3, fmax], format='mayavi')
    #colormap = 'jet'
    
    time_label = lambda t: 'time=%0.2f ms' % (0)
    brain.add_data(meanval, colormap=colormap, vertices=vertices,
                   smoothing_steps=15, time=time, time_label=time_label,
                   hemi=hemi)
    brain.scale_data_colormap(fmin=fmin, fmid=0, fmax=fmax, transparent=False)
    brain.show_view(dict(azimuth=azimuth,elevation=elevation, 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/Plots/IcaCorr_Window_'  
               + condition[0] + '-' + condition[1]  + str(window[0]) + '-' + str(window[1])) 
    
    if not os.path.exists(PlotDir):
        os.makedirs(PlotDir)

    brain.save_image(PlotDir + '/IcaCorr_' + modality + '_' + method + '_'
                        + '_Normalized' + condition[0] + '-' + condition[1] + '_'
                        + str(window[0]) + '-' + str(window[1])
                        +  hemi + '_'+ str(azimuth)+ '_ico-5-fwd-fsaverage-'+'.png')       
示例#2
0
def test_movie():
    """Test saving a movie of an MEG inverse solution."""
    import imageio

    # create and setup the Brain instance
    _set_backend()
    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']
    time = np.arange(data.shape[1]) * stc['tstep'] + stc['tmin']
    brain.add_data(data, colormap='hot', vertices=stc['vertices'],
                   smoothing_steps=10, time=time, time_label='time=%0.2f ms')
    brain.scale_data_colormap(fmin=13, fmid=18, fmax=22, transparent=True)

    # save movies with different options
    tempdir = mkdtemp()
    try:
        dst = os.path.join(tempdir, 'test.mov')
        # test the number of frames in the movie
        brain.save_movie(dst)
        frames = imageio.mimread(dst)
        assert_equal(len(frames), 2)
        brain.save_movie(dst, time_dilation=10)
        frames = imageio.mimread(dst)
        assert_equal(len(frames), 7)
        brain.save_movie(dst, tmin=0.081, tmax=0.102)
        frames = imageio.mimread(dst)
        assert_equal(len(frames), 2)
    finally:
        # clean up
        if not (sys.platform == 'win32' and
                os.getenv('APPVEYOR', 'False') == 'True'):  # cleanup problems
            shutil.rmtree(tempdir)
    brain.close()
示例#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()
示例#4
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')                      
示例#5
0
def test_movie(tmpdir):
    """Test saving a movie of an MEG inverse solution."""
    import imageio
    if sys.version_info < (3, ):
        raise SkipTest('imageio ffmpeg requires Python 3')
    # create and setup the Brain instance
    _set_backend()
    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']
    time = np.arange(data.shape[1]) * stc['tstep'] + stc['tmin']
    brain.add_data(data,
                   colormap='hot',
                   vertices=stc['vertices'],
                   smoothing_steps=10,
                   time=time,
                   time_label='time=%0.2f ms')
    brain.scale_data_colormap(fmin=13, fmid=18, fmax=22, transparent=True)

    # save movies with different options
    dst = str(tmpdir.join('test.mov'))
    # test the number of frames in the movie
    brain.save_movie(dst)
    frames = imageio.mimread(dst)
    assert len(frames) == 2
    brain.save_movie(dst, time_dilation=10)
    frames = imageio.mimread(dst)
    assert len(frames) == 7
    brain.save_movie(dst, tmin=0.081, tmax=0.102)
    frames = imageio.mimread(dst)
    assert len(frames) == 2
    brain.close()
示例#6
0
def test_movie():
    """Test saving a movie of an MEG inverse solution."""
    import imageio

    # create and setup the Brain instance
    _set_backend()
    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']
    time = np.arange(data.shape[1]) * stc['tstep'] + stc['tmin']
    brain.add_data(data, colormap='hot', vertices=stc['vertices'],
                   smoothing_steps=10, time=time, time_label='time=%0.2f ms')
    brain.scale_data_colormap(fmin=13, fmid=18, fmax=22, transparent=True)

    # save movies with different options
    tempdir = mkdtemp()
    try:
        dst = os.path.join(tempdir, 'test.mov')
        # test the number of frames in the movie
        brain.save_movie(dst)
        frames = imageio.mimread(dst)
        assert_equal(len(frames), 2)
        brain.save_movie(dst, time_dilation=10)
        frames = imageio.mimread(dst)
        assert_equal(len(frames), 7)
        brain.save_movie(dst, tmin=0.081, tmax=0.102)
        frames = imageio.mimread(dst)
        assert_equal(len(frames), 2)
    finally:
        # clean up
        if not (sys.platform == 'win32' and
                os.getenv('APPVEYOR', 'False') == 'True'):  # cleanup problems
            shutil.rmtree(tempdir)
    brain.close()
示例#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 = 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)

    brain.add_data(data, colormap=colormap, vertices=vertices,
                   smoothing_steps=10, time=time, time_label=time_label,
                   initial_time=.09, remove_existing=True)
    assert_equal(brain.data_dict['lh']['time_idx'], 1)
    brain.close()
示例#8
0
def test_movie():
    """Test saving a movie of an MEG inverse solution
    """
    # create and setup the Brain instance
    mlab.options.backend = 'auto'
    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']
    time = np.arange(data.shape[1]) * stc['tstep'] + stc['tmin']
    brain.add_data(data, colormap='hot', vertices=stc['vertices'],
                   smoothing_steps=10, time=time, time_label='time=%0.2f ms')
    brain.scale_data_colormap(fmin=13, fmid=18, fmax=22, transparent=True)

    # save movies with different options
    tempdir = mkdtemp()
    try:
        dst = os.path.join(tempdir, 'test.mov')
        brain.save_movie(dst)
        brain.save_movie(dst, tmin=0.081, tmax=0.102)
        # test the number of frames in the movie
        sp = subprocess.Popen(('ffmpeg', '-i', 'test.mov', '-vcodec', 'copy',
                               '-f', 'null', '/dev/null'), cwd=tempdir,
                              stdout=subprocess.PIPE, stderr=subprocess.PIPE)
        stdout, stderr = sp.communicate()
        m = re.search('frame=\s*(\d+)\s', stderr)
        if not m:
            raise RuntimeError(stderr)
        n_frames = int(m.group(1))
        assert_equal(n_frames, 3)
    finally:
        # clean up
        shutil.rmtree(tempdir)
    brain.close()
示例#9
0
文件: test_viz.py 项目: nipy/PySurfer
def test_movie(tmpdir):
    """Test saving a movie of an MEG inverse solution."""
    import imageio
    if sys.version_info < (3,):
        raise SkipTest('imageio ffmpeg requires Python 3')
    # create and setup the Brain instance
    _set_backend()
    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']
    time = np.arange(data.shape[1]) * stc['tstep'] + stc['tmin']
    brain.add_data(data, colormap='hot', vertices=stc['vertices'],
                   smoothing_steps=10, time=time, time_label='time=%0.2f ms')
    brain.scale_data_colormap(fmin=13, fmid=18, fmax=22, transparent=True)

    # save movies with different options
    dst = str(tmpdir.join('test.mov'))
    # test the number of frames in the movie
    brain.save_movie(dst)
    frames = imageio.mimread(dst)
    assert len(frames) == 2
    brain.save_movie(dst, time_dilation=10)
    frames = imageio.mimread(dst)
    assert len(frames) == 7
    brain.save_movie(dst, tmin=0.081, tmax=0.102)
    frames = imageio.mimread(dst)
    assert len(frames) == 2
    brain.close()
示例#10
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()
示例#11
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()
示例#12
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)
示例#13
0
def test_movie():
    """Test saving a movie of an MEG inverse solution
    """
    # create and setup the Brain instance
    mlab.options.backend = 'auto'
    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']
    time = np.arange(data.shape[1]) * stc['tstep'] + stc['tmin']
    brain.add_data(data,
                   colormap='hot',
                   vertices=stc['vertices'],
                   smoothing_steps=10,
                   time=time,
                   time_label='time=%0.2f ms')
    brain.scale_data_colormap(fmin=13, fmid=18, fmax=22, transparent=True)

    # save movies with different options
    tempdir = mkdtemp()
    try:
        dst = os.path.join(tempdir, 'test.mov')
        brain.save_movie(dst)
        brain.save_movie(dst, tmin=0.081, tmax=0.102)
        # test the number of frames in the movie
        sp = subprocess.Popen(('ffmpeg', '-i', 'test.mov', '-vcodec', 'copy',
                               '-f', 'null', '/dev/null'),
                              cwd=tempdir,
                              stdout=subprocess.PIPE,
                              stderr=subprocess.PIPE)
        stdout, stderr = sp.communicate()
        m = re.search('frame=\s*(\d+)\s', stderr)
        if not m:
            raise RuntimeError(stderr)
        n_frames = int(m.group(1))
        assert_equal(n_frames, 3)
    finally:
        # clean up
        shutil.rmtree(tempdir)
    brain.close()
示例#14
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')        
示例#15
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)

    brain.add_data(data,
                   colormap=colormap,
                   vertices=vertices,
                   smoothing_steps=10,
                   time=time,
                   time_label=time_label,
                   initial_time=.09,
                   remove_existing=True)
    assert_equal(brain.data_dict['lh']['time_idx'], 1)
    brain.close()
示例#16
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()
示例#17
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')                      
示例#18
0
        "SUBJECTS_DIR"] = '/Volumes/Server/MORPHLAB/Users/Ellie/Shepard/mri/'
    evoked_fname = meg_dir + subject + '_shepard-evoked-ave.fif'
    inv_fname = meg_dir + subject + '_shepard-inv.fif'
    stc_fname = meg_dir + subject + '_shepard_evoked'

    evoked = Evoked(evoked_fname)
    inverse_operator = read_inverse_operator(inv_fname)
    stc_evoked = apply_inverse(evoked,
                               inverse_operator,
                               lambda2,
                               method='dSPM')
    stc_evoked.save(stc_fname)

    brain = Brain(subject, 'split', 'partially_inflated', size=(800, 400))
    for hemi in ['lh', 'rh']:
        stc = read_stc(stc_fname + '-%s.stc' % hemi)
        data = stc['data']
        times = np.arange(data.shape[1]) * stc['tstep'] + stc['tmin']
        brain.add_data(data,
                       colormap='RdBu',
                       vertices=stc['vertices'],
                       smoothing_steps=10,
                       time=times,
                       time_label=time_label,
                       initial_time=-0.1,
                       hemi=hemi)

    abs_max = (np.abs(data)).max()
    brain.scale_data_colormap(fmin=0,
                              fmid=abs_max / 3,
                              fmax=abs_max,
subject_id, surface = 'mg78', 'pial'
brain = Brain(subject_id, hemi, surface, size=(800, 400))

plot_stc = False
plot_labels = True

if (plot_stc):
    root = '/home/npeled/code/links/meg/MSIT/ep001'
    stc1_fname = op.join(
        root,
        'ep001_msit_nTSSS_interference_neutral_1-15-dSPM-{}.stc'.format(hemi))
    stc2_fname = op.join(
        root,
        'ep001_msit_nTSSS_interference_interference_1-15-dSPM-{}.stc'.format(
            hemi))
    stc1 = read_stc(stc1_fname)
    stc2 = read_stc(stc2_fname)

    data1 = stc1['data'][:, time_point]
    data2 = stc2['data'][:, time_point]
    data = data1 - data2
    print(data.shape)
    vertices = stc1['vertices']

    brain.add_data(data,
                   colormap=colormap,
                   vertices=vertices,
                   smoothing_steps=10,
                   time=time,
                   hemi=hemi)
    mlab.show()
print(__doc__)

# Do some basic things: define subject, surface and hemisphere(s) to plot,
# and create the :class:`surfer.viz.Brain` object.

subject_id, surf = 'fsaverage', 'white'
hemi = 'lh'
brain = Brain(subject_id, hemi, surf, size=(800, 800), interaction='terrain',
              cortex='0.5', alpha=0.5, show_toolbar=True, units='m')

# Read the MNE dSPM inverse solution

hemi = 'lh'
stc_fname = os.path.join('example_data', 'meg_source_estimate-' +
                         hemi + '.stc')
stc = read_stc(stc_fname)

# data and vertices for which the data is defined
data = stc['data']
vertices = stc['vertices']
time = np.linspace(stc['tmin'], stc['tmin'] + data.shape[1] * stc['tstep'],
                   data.shape[1], endpoint=False)

# MNE will soon add the option for a "full" inverse to be computed and stored.
# In the meantime, we can get the equivalent for our data based on the
# surface normals:

data_full = brain.geo['lh'].nn[vertices][..., np.newaxis] * data[:, np.newaxis]

# Now we add the data and set the initial time displayed to 100 ms:
brain.add_data(data_full, colormap='hot', vertices=vertices, alpha=0.5,
示例#21
0
from surfer import Brain, TimeViewer
from surfer.io import read_stc
"""
define subject, surface and hemisphere
"""
subject_id, surface, hemi = 'fsaverage', 'inflated', 'lh'
"""
create Brain object for visualization
"""
brain = Brain(subject_id, hemi, surface)
"""
read MNE dSPM inverse solution
"""
stc_fname = os.path.join('example_data',
                         'meg_source_estimate-' + hemi + '.stc')
stc = read_stc(stc_fname)
"""
data and vertices for which the data is defined
"""
data = stc['data']
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'
"""
示例#22
0
from surfer import Brain
from surfer.io import read_stc

print(__doc__)

"""
create Brain object for visualization
"""
brain = Brain('fsaverage', 'split', 'inflated', size=(800, 400))

"""
read and display MNE dSPM inverse solution
"""
stc_fname = os.path.join('example_data', 'meg_source_estimate-%s.stc')
for hemi in ['lh', 'rh']:
    stc = read_stc(stc_fname % hemi)
    data = stc['data']
    times = np.arange(data.shape[1]) * stc['tstep'] + stc['tmin']
    brain.add_data(data, colormap='hot', vertices=stc['vertices'],
                   smoothing_steps=10, time=times, hemi=hemi,
                   time_label=lambda t: '%s ms' % int(round(t * 1e3)))

"""
scale colormap
"""
brain.scale_data_colormap(fmin=13, fmid=18, fmax=22, transparent=True)

"""
Save a movie. Use a large value for time_dilation because the sample stc only
covers 30 ms.
"""