本文整理汇总了Python中surfer.Brain.save_imageset方法的典型用法代码示例。如果您正苦于以下问题:Python Brain.save_imageset方法的具体用法?Python Brain.save_imageset怎么用?Python Brain.save_imageset使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类surfer.Brain
的用法示例。
在下文中一共展示了Brain.save_imageset方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: vizify
# 需要导入模块: from surfer import Brain [as 别名]
# 或者: from surfer.Brain import save_imageset [as 别名]
def vizify(self):
for hemi in self.hemis:
print "visualize %s" % hemi
# Bring up the beauty (the underlay)
brain = Brain(self.subject_id, hemi, self.surf, \
config_opts=self.config_opts, \
subjects_dir=self.subjects_dir)
surf_data = io.read_scalar_data(self.overlay_surf[hemi])
if (sum(abs(surf_data)) > 0):
# Overlay another hopeful beauty (functional overlay)
brain.add_overlay(self.overlay_surf[hemi], name=self.overlay_name,
min=self.min, max=self.max, sign=self.sign)
# Update colorbar
#brain.overlays[self.overlay_name].pos_bar.lut_mode = self.colorbar
tmp = brain.overlays[self.overlay_name]
lut = tmp.pos_bar.lut.table.to_array()
lut[:,0:3] = self.colorbar
tmp.pos_bar.lut.table = lut
# Refresh
brain.show_view("lat")
brain.hide_colorbar()
# Save the beauts
brain.save_imageset("%s_%s" % (self.outprefix, hemi), self.views,
'jpg', colorbar=None)
# End a great journey, till another life
brain.close()
return
示例2: plot_surface
# 需要导入模块: from surfer import Brain [as 别名]
# 或者: from surfer.Brain import save_imageset [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)))
示例3: plot_parcel
# 需要导入模块: from surfer import Brain [as 别名]
# 或者: from surfer.Brain import save_imageset [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()
示例4: test_image
# 需要导入模块: from surfer import Brain [as 别名]
# 或者: from surfer.Brain import save_imageset [as 别名]
def test_image():
"""Test image saving
"""
mlab.options.backend = 'auto'
brain = Brain(*std_args, config_opts=small_brain)
tmp_name = mktemp() + '.png'
brain.save_image(tmp_name)
brain.save_imageset(tmp_name, ['med', 'lat'], 'jpg')
brain.save_montage(tmp_name, ['l', 'v', 'm'], orientation='v')
brain.screenshot()
示例5: save_groups_labels_figures
# 需要导入模块: from surfer import Brain [as 别名]
# 或者: from surfer.Brain import save_imageset [as 别名]
def save_groups_labels_figures():
labels, groups = get_groups()
for group in groups:
print(group)
if len(get_group_labels(group)) < 4:
group_label = [l for l in labels if group in l]
colors = get_spaced_colors(len(group_label))
brain = Brain(subject, hemi, surf, offscreen=False)
for label_id, label in enumerate(group_label):
print(label)
brain.add_label(label, color=colors[label_id])
fol = os.path.join(subjects_dir, subject, 'label', '{}_figures'.format(aparc_name))
if not os.path.isdir(fol):
os.mkdir(fol)
brain.save_imageset(os.path.join(fol, group), get_views(), 'jpg')
brain.remove_labels()
brain.close()
示例6: corr_image
# 需要导入模块: from surfer import Brain [as 别名]
# 或者: from surfer.Brain import save_imageset [as 别名]
def corr_image(resting_image,fwhm):
"""This function makes correlation image on brain surface"""
import numpy as np
import nibabel as nb
import matplotlib.pyplot as plt
from surfer import Brain, Surface
import os
img = nb.load(resting_image)
corrmat = np.corrcoef(np.squeeze(img.get_data()))
corrmat[np.isnan(corrmat)] = 0
corrmat_npz = os.path.abspath('corrmat.npz')
np.savez(corrmat_npz,corrmat=corrmat)
br = Brain('fsaverage5', 'lh', 'smoothwm')
#br.add_overlay(corrmat[0,:], min=0.2, name=0, visible=True)
lh_aparc_annot_file = os.path.join(os.environ["FREESURFER_HOME"],'/subjects/label/lh.aparc.annot')
values = nb.freesurfer.read_annot(lh_aparc_annot_file)
#br.add_overlay(np.mean(corrmat[values[0]==5,:], axis=0), min=0.8, name='mean', visible=True)
data = img.get_data()
data = np.squeeze(img.get_data())
#
precuneus_signal = np.mean(data[values[0]==np.nonzero(np.array(values[2])=='precuneus')[0][0],:], axis=0)
precuneus = np.corrcoef(precuneus_signal, data)
#precuneus.shape
#br.add_overlay(precuneus[0,1:], min=0.3, sign='pos', name='mean', visible=True)
br.add_overlay(precuneus[0,1:], min=0.2, name='mean')#, visible=True)
#br.add_overlay(precuneus[0,1:], min=0.2, name='mean')#, visible=True)
plt.hist(precuneus[0,1:], 128)
plt.savefig(os.path.abspath("histogram.png"))
plt.close()
corr_image = os.path.abspath("corr_image%s.png"%fwhm)
br.save_montage(corr_image)
ims = br.save_imageset(prefix=os.path.abspath('fwhm_%s'%str(fwhm)),views=['medial','lateral','caudal','rostral','dorsal','ventral'])
br.close()
print ims
#precuneus[np.isnan(precuneus)] = 0
#plt.hist(precuneus[0,1:])
roitable = [['Region','Mean Correlation']]
for i, roi in enumerate(np.unique(values[2])):
roitable.append([roi,np.mean(precuneus[values[0]==np.nonzero(np.array(values[2])==roi)[0][0]])])
#images = [corr_fimage]+ims+[os.path.abspath("histogram.png"), roitable]
roitable=[roitable]
histogram = os.path.abspath("histogram.png")
return corr_image, ims, roitable, histogram, corrmat_npz
示例7: test_image
# 需要导入模块: from surfer import Brain [as 别名]
# 或者: from surfer.Brain import save_imageset [as 别名]
def test_image():
"""Test image saving
"""
tmp_name = mktemp() + '.png'
mlab.options.backend = 'auto'
subject_id, _, surf = std_args
brain = Brain(subject_id, 'both', surf=surf, size=100)
brain.add_overlay(overlay_fname, hemi='lh', min=5, max=20, sign="pos")
brain.save_imageset(tmp_name, ['med', 'lat'], 'jpg')
brain = Brain(*std_args, size=100)
brain.save_image(tmp_name)
brain.save_montage(tmp_name, ['l', 'v', 'm'], orientation='v')
brain.save_montage(tmp_name, ['l', 'v', 'm'], orientation='h')
brain.save_montage(tmp_name, [['l', 'v'], ['m', 'f']])
brain.screenshot()
brain.close()
示例8: plot_group
# 需要导入模块: from surfer import Brain [as 别名]
# 或者: from surfer.Brain import save_imageset [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/final_group_%s.nii'%(num_nodes,hub),hemi, subject_id="fsaverage", projsum = 'max', smooth_fwhm = 20)
brain.add_data(image,thresh = np.nanmin(image[image>0]),colormap = "jet", colorbar= True)
brain.save_imageset('/home/despo/mb3152/random_nodes/%s/final_%s' %(num_nodes,hub),['med','lat'],'jpg',colorbar= None)
else:
pc_image = io.project_volume_data('/home/despo/mb3152/random_nodes/%s/final_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/final_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 = max(wmd_image), colormap = 'Blues',alpha= .65,hemi=hemi,smoothing_steps = 0)
# brain.add_data(connector_hub_image,thresh=pc_thresh,max=np.nanmax(pc_image), colormap = 'Purples',alpha= .65,hemi=hemi,smoothing_steps = 0)
# brain.add_data(satellite_image,thresh= pc_thresh,max=np.nanmax(pc_image),colormap = 'Reds',alpha= .65,hemi=hemi,smoothing_steps = 0)
# brain.add_data(provincial_hub_image,thresh=wmd_thresh,max=np.nanmax(wmd_image),colormap = 'Blues',alpha= .65,hemi=hemi,smoothing_steps = 0)
brain.add_data(node_image,thresh= 0, max = max(wmd_image), colormap = 'Blues',hemi=hemi,smoothing_steps = 0)
brain.add_data(connector_hub_image,thresh=pc_thresh,max=np.nanmax(pc_image), colormap = 'Purples',hemi=hemi,smoothing_steps = 0)
brain.add_data(satellite_image,thresh= pc_thresh,max=np.nanmax(pc_image),colormap = 'Reds',hemi=hemi,smoothing_steps = 0)
brain.add_data(provincial_hub_image,thresh=wmd_thresh,max=np.nanmax(wmd_image),colormap = 'Blues',hemi=hemi,smoothing_steps = 0)
brain.save_imageset('/home/despo/mb3152/random_nodes/%s/final_combined' %(num_nodes),['med','lat'],'jpg',colorbar= None)
示例9: test_image
# 需要导入模块: from surfer import Brain [as 别名]
# 或者: from surfer.Brain import save_imageset [as 别名]
def test_image(tmpdir):
"""Test image saving."""
tmp_name = tmpdir.join('temp.png')
tmp_name = str(tmp_name) # coerce to str to avoid PIL error
_set_backend()
subject_id, _, surf = std_args
brain = Brain(subject_id, 'both', surf=surf, size=100)
brain.add_overlay(overlay_fname, hemi='lh', min=5, max=20, sign="pos")
brain.save_imageset(tmp_name, ['med', 'lat'], 'jpg')
brain.close()
brain = Brain(*std_args, size=100)
brain.save_image(tmp_name)
brain.save_image(tmp_name, 'rgba', True)
brain.screenshot()
if os.getenv('TRAVIS', '') != 'true':
# for some reason these fail on Travis sometimes
brain.save_montage(tmp_name, ['l', 'v', 'm'], orientation='v')
brain.save_montage(tmp_name, ['l', 'v', 'm'], orientation='h')
brain.save_montage(tmp_name, [['l', 'v'], ['m', 'f']])
brain.close()
示例10: overlay
# 需要导入模块: from surfer import Brain [as 别名]
# 或者: from surfer.Brain import save_imageset [as 别名]
config_opts=dict(background="white"),
subjects_dir="/home2/data/PublicProgram/freesurfer")
"""Get the volume => surface file"""
cwas_file = path.join(mdmr_dir, "surf_lh_fdr_logp_%s.nii.gz" % factor)
"""
You can pass this array to the add_overlay method for
a typical activation overlay (with thresholding, etc.)
"""
brain.add_overlay(cwas_file, min=2, max=max_zvals[i], name="%s_lh" % factor)
## get overlay and color bar
tmp1 = brain.overlays["%s_lh" % factor]
lut = tmp1.pos_bar.lut.table.to_array()
## update color scheme
lut[:,0:3] = cols
tmp1.pos_bar.lut.table = lut
## refresh view
brain.show_view("lat")
brain.hide_colorbar()
"""Save Pictures"""
brain.save_imageset(path.join(odir, "zpics_%s_%s_surface_lh" % (sample, factor)),
['med', 'lat', 'ros', 'caud'], 'jpg')
brain.close()
示例11: Brain
# 需要导入模块: from surfer import Brain [as 别名]
# 或者: from surfer.Brain import save_imageset [as 别名]
## update color scheme
single = [251, 154, 143]
overlap = [227, 26, 28]
lut[0:85,0:3] = single
lut[85:170,0:3] = single
lut[170:256,0:3] = overlap
tmp1.pos_bar.lut.table = lut
## refresh view
brain.show_view("lat")
brain.hide_colorbar()
"""Save Pictures"""
odir = "/home/data/Projects/CWAS/age+gender/03_robustness/viz_cwas/pysurfer"
brain.save_imageset(path.join(odir, "zpics_overlap_age_surface_rh"),
['med', 'lat', 'ros', 'caud'], 'jpg')
brain.close()
## SEX
"""Bring up the visualization"""
brain = Brain("fsaverage_copy", "rh", "iter8_inflated",
config_opts=dict(background="white"),
subjects_dir="/home2/data/PublicProgram/freesurfer")
"""Project the volume file and return as an array"""
cwas_file = path.join(overlap_dir, "surf_rh_fdr_logp_sex_thr2.nii.gz")
"""
示例12:
# 需要导入模块: from surfer import Brain [as 别名]
# 或者: from surfer.Brain import save_imageset [as 别名]
projmeth=projmeth,
projsum=projsum,
projarg=projarg,
smooth_fwhm = smooth_fwhm,
subject_id='fsaverage')
# nothing to do, if all points in the projection are nul
if surf_data.max()!=0:
name_overlay = '{name_roi}_{hemi}'.format(name_roi=name_roi, hemi=hemi)
brain.add_overlay(surf_data, name=name_overlay, hemi=hemi)
overlay_roi = brain.overlays[name_overlay]
lut = overlay_roi.pos_bar.lut.table.to_array()
lut[0:255, 0:3] = color_list[cpt_color]
overlay_roi.pos_bar.lut.table = lut
# Save in png
#brain.save_imageset(save_png, ['lat'], 'png', colorbar=None)
# Color cpt
cpt_color += 1
# If you just want one roi by one
# Remove for the next roi
# for overlay in brain.overlays_dict[name_overlay]:
# overlay.remove()
# Save in png
save_png = os.path.join(datadir, "all_rois")
brain.save_imageset(save_png, ['lat'], 'png', colorbar=None)
brain.close()
示例13: Brain
# 需要导入模块: from surfer import Brain [as 别名]
# 或者: from surfer.Brain import save_imageset [as 别名]
tmp1 = brain.overlays["%s_rh" % factor]
lut = tmp1.pos_bar.lut.table.to_array()
## update color scheme
lut[:,0:3] = cols
tmp1.pos_bar.lut.table = lut
## refresh view
brain.show_view("lat")
brain.hide_colorbar()
"""
Save some images
"""
odir = "/home/data/Projects/CWAS/development+motion/viz"
brain.save_imageset(path.join(odir, "zpics_surface_%s_rh" % "only_age"),
['med', 'lat', 'ros', 'caud'], 'jpg')
brain.close()
## Age with motion as covariate
print "age with motion"
mdmr_dir = "/home2/data/Projects/CWAS/development+motion/cwas/rois_random_k3200/age+motion_sex+tr.mdmr"
factor = "age"
"""Bring up the visualization"""
brain = Brain("fsaverage_copy", "rh", "iter8_inflated",
config_opts=dict(background="white"),
subjects_dir="/home2/data/PublicProgram/freesurfer")
示例14: Brain
# 需要导入模块: from surfer import Brain [as 别名]
# 或者: from surfer.Brain import save_imageset [as 别名]
l = u*-1
else:
cmap = "jet"
"""
Make a vector containing the data point at each vertex.
"""
vtx_data = roi_data[labels]
"""
Display these values on the brain.
"""
### MEAN
brain = Brain(subject_id, hemi, surface,
subjects_dir = subjects_dir,
config_opts=dict(background="white"))
brain.add_data(vtx_data,
l,
u,
thresh = -98,
colormap=cmap,
alpha=.8)
views_list = [ 'medial', 'lateral' ]
prefix = '_'.join([data_file.strip('.csv'), surface, hemi])
brain.save_imageset(prefix = os.path.join(fs_rois_dir, prefix),
views = views_list,
colorbar = range(len(views_list)) )
示例15: overlay
# 需要导入模块: from surfer import Brain [as 别名]
# 或者: from surfer.Brain import save_imageset [as 别名]
data_min = 0
else:
data_min = data[data.nonzero()].min()
"""
You can pass this array to the add_overlay method for
a typical activation overlay (with thresholding, etc.)
"""
brain.add_overlay(cwas_file, min=data_min, max=data_max, name="%s_rh" % factor)
## get overlay and color bar
tmp1 = brain.overlays["%s_rh" % factor]
lut = tmp1.pos_bar.lut.table.to_array()
## update color scheme
lut[:,0:3] = cols
tmp1.pos_bar.lut.table = lut
## refresh view
brain.show_view("lat")
brain.hide_colorbar()
"""
Save some images
"""
odir = "/home/data/Projects/CWAS/%s/viz" % study
brain.save_imageset(path.join(odir, "zpics_surface_%s_rh" % onames[i][j]),
['med', 'lat', 'ros', 'caud'], 'jpg')
brain.close()