当前位置: 首页>>代码示例>>Python>>正文


Python Brain.add_data方法代码示例

本文整理汇总了Python中surfer.Brain.add_data方法的典型用法代码示例。如果您正苦于以下问题:Python Brain.add_data方法的具体用法?Python Brain.add_data怎么用?Python Brain.add_data使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在surfer.Brain的用法示例。


在下文中一共展示了Brain.add_data方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: plot_surface

# 需要导入模块: from surfer import Brain [as 别名]
# 或者: from surfer.Brain import add_data [as 别名]
def plot_surface(vtx_data, subject_id, subjects_dir, hemi, surface, output_dir, prefix, l, u, cmap, center, thresh):
    # Open up a brain in pysurfer
    brain = Brain(
        subject_id,
        hemi,
        surface,
        subjects_dir=subjects_dir,
        config_opts=dict(background="white", height=665, width=800),
    )

    if center:
        # Make sure the colorbar is centered
        if l ** 2 < u ** 2:
            l = u * -1
        else:
            u = l * -1

    # Create an empty brain if the values are all below threshold
    if np.max(vtx_data) < thresh:
        # Add your data to the brain
        brain.add_data(vtx_data * 0, l, u, thresh=thresh, colormap=cmap, alpha=0.0)

    # Otherwise, add the data appropriately!
    else:
        # Add your data to the brain
        brain.add_data(vtx_data, l, u, thresh=thresh, colormap=cmap, alpha=0.8)

    # Save the images for medial and lateral
    # putting a color bar on all of them
    brain.save_imageset(prefix=os.path.join(output_dir, prefix), views=views_list, colorbar=range(len(views_list)))
开发者ID:KirstieJane,项目名称:DESCRIBING_DATA,代码行数:32,代码来源:pysurfer_plot_VISAN_surface_values.py

示例2: test_meg_inverse

# 需要导入模块: from surfer import Brain [as 别名]
# 或者: from surfer.Brain import add_data [as 别名]
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()
开发者ID:Nasim-photon,项目名称:PySurfer,代码行数:32,代码来源:test_viz.py

示例3: test_movie

# 需要导入模块: from surfer import Brain [as 别名]
# 或者: from surfer.Brain import add_data [as 别名]
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()
开发者ID:nipy,项目名称:PySurfer,代码行数:31,代码来源:test_viz.py

示例4: test_movie

# 需要导入模块: from surfer import Brain [as 别名]
# 或者: from surfer.Brain import add_data [as 别名]
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()
开发者ID:bpinsard,项目名称:PySurfer,代码行数:36,代码来源:test_viz.py

示例5: test_movie

# 需要导入模块: from surfer import Brain [as 别名]
# 或者: from surfer.Brain import add_data [as 别名]
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()
开发者ID:mwaskom,项目名称:PySurfer,代码行数:37,代码来源:test_viz.py

示例6: plot_parcel

# 需要导入模块: from surfer import Brain [as 别名]
# 或者: from surfer.Brain import add_data [as 别名]
def plot_parcel(num_nodes=600,numbers=[1],hemi='lh'):
    from surfer import Brain, io
    for n in numbers:
        brain = Brain("fsaverage", "%s" %(hemi), "pial",config_opts=dict(background="white"))
        image = io.project_volume_data('/home/despo/mb3152/random_nodes/%s/parcel_%s.nii'%(num_nodes,n),hemi, subject_id="fsaverage", projsum = 'max', smooth_fwhm = 0)
        brain.add_data(image,thresh=1,colormap = "spectral")
        brain.save_imageset('/home/despo/mb3152/random_nodes/%s/parcel_%s' %(num_nodes,n),['med','lat'],'jpg',colorbar= None)
        brain.close()
开发者ID:kathryndevaney,项目名称:random_nodes,代码行数:10,代码来源:random_parcellate_avg_multi.py

示例7: test_data_limits

# 需要导入模块: from surfer import Brain [as 别名]
# 或者: from surfer.Brain import add_data [as 别名]
def test_data_limits():
    """Test handling of data limits."""
    _set_backend()
    brain = Brain(*std_args)
    surf_data = np.zeros(163842)
    pytest.raises(ValueError, brain.add_data, surf_data, 0, 0)
    brain.add_data(surf_data, 0, 1)
    brain.close()
开发者ID:nipy,项目名称:PySurfer,代码行数:10,代码来源:test_viz.py

示例8: test_data

# 需要导入模块: from surfer import Brain [as 别名]
# 或者: from surfer.Brain import add_data [as 别名]
def test_data():
    """Test plotting of data
    """
    mlab.options.backend = 'test'
    brain = Brain(*std_args)
    mri_file = pjoin(data_dir, 'resting_corr.nii.gz')
    reg_file = pjoin(data_dir, 'register.dat')
    surf_data = io.project_volume_data(mri_file, "lh", reg_file)
    brain.add_data(surf_data, -.7, .7, colormap="jet", alpha=.7)
开发者ID:joewalter,项目名称:PySurfer,代码行数:11,代码来源:test_viz.py

示例9: img2disc

# 需要导入模块: from surfer import Brain [as 别名]
# 或者: from surfer.Brain import add_data [as 别名]
 def img2disc(data, foci_all=False, foci_dmn=False, labelfile=False, hemi='lh', filename='temp.png'):
     brain = Brain('fsaverage5', hemi, 'inflated', curv=False)
     brain.add_data(data, data.min(), data.max(), colormap="spectral", alpha=0.6)
     if labelfile:
         brain.add_label(labelfile, borders=True, color='grey')
     if foci_all:
         brain.add_foci(foci_all, coords_as_verts=True, scale_factor=.5, color='black')
     if foci_dmn:
         brain.add_foci(foci_dmn, coords_as_verts=True, scale_factor=.7, color='blue')
     brain.save_montage(filename, order=['lat', 'med'], orientation='h', border_size=10)
开发者ID:soligschlager,项目名称:topography,代码行数:12,代码来源:individual_dist_label.py

示例10: test_data

# 需要导入模块: from surfer import Brain [as 别名]
# 或者: from surfer.Brain import add_data [as 别名]
def test_data():
    """Test plotting of data."""
    _set_backend()
    brain = Brain(*std_args)
    mri_file = pjoin(data_dir, 'resting_corr.nii.gz')
    reg_file = pjoin(data_dir, 'register.dat')
    surf_data = io.project_volume_data(mri_file, "lh", reg_file)
    brain.add_data(surf_data, -.7, .7, colormap="jet", alpha=.7)
    brain.set_surf('white')
    brain.add_data([], vertices=np.array([], int))
    brain.close()
开发者ID:mwaskom,项目名称:PySurfer,代码行数:13,代码来源:test_viz.py

示例11: pysurfer_plot_perm_ttest_results

# 需要导入模块: from surfer import Brain [as 别名]
# 或者: from surfer.Brain import add_data [as 别名]
def pysurfer_plot_perm_ttest_results(vertices, vertives_values, max_vals, fol):
    T = max(vertices.keys())
    for t in range(T+1):
        print(t)
        brain = Brain('fsaverage', 'split', 'pial', curv=False, offscreen=False, views=['lat', 'med'], title='{} ms'.format(t))
        for hemi in ['rh', 'lh']:
            if t in vertices:
                brain.add_data(np.array(vertives_values[t][hemi]), hemi=hemi, min=1, max=max_vals, remove_existing=True,
                         colormap="YlOrRd", alpha=1, vertices=np.array(vertices[t][hemi]))
        brain.save_image(os.path.join(fol, '{}.jpg'.format(t)))
        brain.close()
开发者ID:ofek-schechner,项目名称:mmvt,代码行数:13,代码来源:meg_statistics.py

示例12: curvature_normalization

# 需要导入模块: from surfer import Brain [as 别名]
# 或者: from surfer.Brain import add_data [as 别名]
def curvature_normalization(data_dir, subj):
    """Normalize the curvature map and plot contour over fsaverage."""
    surf_dir = op.join(data_dir, subj, "surf")
    snap_dir = op.join(data_dir, subj, "snapshots")
    panels = []
    for hemi in ["lh", "rh"]:

        # Load the curv values and apply registration to fsaverage
        curv_fname = op.join(surf_dir, "{}.curv".format(hemi))
        curv_vals = nib.freesurfer.read_morph_data(curv_fname)
        subj_curv_vals = apply_surface_warp(data_dir, subj,
                                            hemi, curv_vals)
        subj_curv_binary = (subj_curv_vals > 0)

        # Load the template curvature
        norm_fname = op.join(data_dir, "fsaverage", "surf",
                             "{}.curv".format(hemi))
        norm_curv_vals = nib.freesurfer.read_morph_data(norm_fname)
        norm_curv_binary = (norm_curv_vals > 0)

        # Compute the curvature overlap image
        curv_overlap = np.zeros_like(norm_curv_binary, np.int)
        curv_overlap[norm_curv_binary & subj_curv_binary] = 1
        curv_overlap[norm_curv_binary ^ subj_curv_binary] = 2

        # Mask out the medial wall
        cortex_fname = op.join(data_dir, "fsaverage", "label",
                               "{}.cortex.label".format(hemi))
        cortex = nib.freesurfer.read_label(cortex_fname)
        medial_wall = ~np.in1d(np.arange(curv_overlap.size), cortex)
        curv_overlap[medial_wall] = 1

        # Plot the curvature overlap image
        try:
            b = Brain("fsaverage", hemi, "inflated", background="white")
        except TypeError:
            # PySurfer <= 0.5
            b = Brain("fsaverage", hemi, "inflated",
                      config_opts=dict(background="white"))

        b.add_data(curv_overlap, min=0, max=2,
                   colormap=[".9", ".45", "indianred"], colorbar=False)

        for view in ["lat", "med", "ven"]:
            b.show_view(view, distance="auto")
            panels.append(crop(b.screenshot()))
        b.close()

    # Make and save a figure
    f = multi_panel_brain_figure(panels)
    fname = op.join(snap_dir, "surface_registration.png")
    f.savefig(fname, bbox_inches="tight")
    plt.close(f)
开发者ID:kellyhennigan,项目名称:lyman,代码行数:55,代码来源:anatomy_snapshots.py

示例13: plot_group

# 需要导入模块: from surfer import Brain [as 别名]
# 或者: from surfer.Brain import add_data [as 别名]
def plot_group(hub,num_nodes,hemi='lh'):
    from surfer import Brain, io
    brain = Brain("fsaverage", "%s" %(hemi), "pial",config_opts=dict(background="white"))
    if hub == 'pc' or hub =='wmd':
        image = io.project_volume_data('/home/despo/mb3152/random_nodes/%s/group_%s.nii'%(num_nodes,hub),hemi, subject_id="fsaverage", projsum = 'max', smooth_fwhm = 20)
        brain.add_data(image,colormap = "Reds", colorbar= True)
    else:
        pc_image = io.project_volume_data('/home/despo/mb3152/random_nodes/%s/group_pc.nii'%(num_nodes),hemi, subject_id="fsaverage", projsum = 'max', smooth_fwhm = 20)
        wmd_image = io.project_volume_data('/home/despo/mb3152/random_nodes/%s/group_wmd.nii'%(num_nodes),hemi, subject_id="fsaverage", projsum = 'max', smooth_fwhm = 20) 
        wmd_thresh = np.nanmean(wmd_image[wmd_image>0])
        pc_thresh = np.nanmean(pc_image[pc_image >0])
        #find connetor hub activity
        connector_hub_image = pc_image.copy()
        connector_hub_image[pc_image < pc_thresh] = 0.
        connector_hub_image[wmd_image < wmd_thresh] = 0.
        #find sattelite connector activty
        satellite_image = pc_image.copy()
        satellite_image[pc_image < pc_thresh] = 0.
        satellite_image[wmd_image > wmd_thresh] = 0.
        # find provincial hub activity
        provincial_hub_image = wmd_image.copy()
        provincial_hub_image[pc_image > pc_thresh] = 0.
        provincial_hub_image[wmd_image < wmd_thresh] = 0.

        node_image = pc_image.copy()
        node_image[provincial_hub_image > 0] = 0
        node_image[connector_hub_image > 0] = 0
        node_image[satellite_image > 0] = 0
        node_image[node_image > 0] = 1

        # brain.add_data(node_image,thresh= 0, max = 2, colormap = 'gray',hemi=hemi,smoothing_steps = 0)
        brain.add_data(connector_hub_image,thresh= np.nanmin(pc_image),max=pc_thresh + np.std(pc_image), colormap = 'Reds',hemi=hemi,smoothing_steps = 0)
        brain.add_data(satellite_image,thresh= np.nanmin(pc_image),max=pc_thresh + np.std(pc_image),colormap = 'autumn',hemi=hemi,smoothing_steps = 0)
        brain.add_data(provincial_hub_image,thresh=np.nanmin(wmd_image),max=wmd_thresh +np.std(wmd_image),colormap = 'Blues',hemi=hemi,smoothing_steps = 0)
开发者ID:jrcohen02,项目名称:random_nodes,代码行数:36,代码来源:random_parcellate_avg_multi.py

示例14: plot_data_surf_bh

# 需要导入模块: from surfer import Brain [as 别名]
# 或者: from surfer.Brain import add_data [as 别名]
def plot_data_surf_bh(in_file, colormap='jet', thr_list=[(None, None, None)],roi_coords=(), fwhm=0):
    '''
    allows more flexible visualization than plot_rs_surf_bh
    thr_list = [(min, max, thresh)]
    colormap: matplotlib colormap (http://matplotlib.org/examples/color/colormaps_reference.html)
    '''

    # in_file .nii to be projected on surface


    import os
    from surfer import Brain, io

    out_file_list = []
    in_file_name = os.path.basename(in_file)

    reg_file = os.path.join(os.environ["FREESURFER_HOME"],"average/mni152.register.dat")
    for thr in thr_list:
        min_thr = thr[0]
        max_thr = thr[1]
        thr_thr = thr[2]


        brain = Brain("fsaverage", "split", "inflated", views=['lat', 'med'], config_opts=dict(background="white"))

        surf_data_lh = io.project_volume_data(in_file, "lh", reg_file, smooth_fwhm=fwhm)
        surf_data_rh = io.project_volume_data(in_file, "rh", reg_file, smooth_fwhm=fwhm)

        brain.add_data(surf_data_lh, min=min_thr, max=max_thr, thresh=thr_thr, colormap=colormap, hemi='lh')
        brain.add_data(surf_data_rh, min=min_thr, max=max_thr, thresh=thr_thr, colormap=colormap, hemi='rh')

        roi_str = ''
        if not(roi_coords == ()):
            if roi_coords[0] <0: #lh
                hemi_str = 'lh'
            else:
                hemi_str = 'rh'
            roi_str = '_roi_%s.%s.%s' % roi_coords

            brain.add_foci(roi_coords, map_surface="white", hemi=hemi_str, color='red', scale_factor=2)


        out_filename = os.path.join(os.getcwd(), in_file_name + roi_str + '_thr_%s' % min_thr + '.png')
        out_file_list += [out_filename]
        brain.save_image(out_filename)
        brain.close()
    return out_file_list
开发者ID:NeuroanatomyAndConnectivity,项目名称:LeiCA,代码行数:49,代码来源:plot_resting_correlations.py

示例15: test_meg_inverse

# 需要导入模块: from surfer import Brain [as 别名]
# 或者: from surfer.Brain import add_data [as 别名]
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)
开发者ID:joewalter,项目名称:PySurfer,代码行数:20,代码来源:test_viz.py


注:本文中的surfer.Brain.add_data方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。