本文整理汇总了Python中pyhrf.FmriData.from_vol_files方法的典型用法代码示例。如果您正苦于以下问题:Python FmriData.from_vol_files方法的具体用法?Python FmriData.from_vol_files怎么用?Python FmriData.from_vol_files使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pyhrf.FmriData
的用法示例。
在下文中一共展示了FmriData.from_vol_files方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: glm_nipy_from_files
# 需要导入模块: from pyhrf import FmriData [as 别名]
# 或者: from pyhrf.FmriData import from_vol_files [as 别名]
def glm_nipy_from_files(bold_file, tr, paradigm_csv_file, output_dir,
mask_file, session=0, contrasts=None,
con_test_baseline=0.0,
hrf_model='Canonical',
drift_model='Cosine', hfcut=128,
residuals_model='spherical', fit_method='ols',
fir_delays=[0]):
"""
#TODO: handle surface data
hrf_model : Canonical | Canonical with Derivative | FIR
"""
fdata = FmriData.from_vol_files(mask_file, paradigm_csv_file,
[bold_file], tr)
g, dm, cons = glm_nipy(fdata, contrasts=contrasts, hrf_model=hrf_model,
hfcut=hfcut, drift_model=drift_model,
residuals_model=residuals_model,
fit_method=fit_method, fir_delays=fir_delays)
ns, nr = dm.matrix.shape
cdesign_matrix = xndarray(dm.matrix, axes_names=['time','regressor'],
axes_domains={'time':np.arange(ns)*tr,
'regressor':dm.names})
cdesign_matrix.save(op.join(output_dir, 'design_matrix.nii'))
beta_files = []
beta_values = dict.fromkeys(dm.names)
beta_vars = dict.fromkeys(dm.names)
beta_vars_voxels = dict.fromkeys(dm.names)
for ib, bname in enumerate(dm.names):
#beta values
beta_vol = expand_array_in_mask(g.beta[ib], fdata.roiMask>0)
beta_fn = op.join(output_dir, 'beta_%s.nii' %bname)
write_volume(beta_vol, beta_fn, fdata.meta_obj)
beta_files.append(beta_fn)
beta_values[bname] = beta_vol
#normalized variance of betas
beta_vars[bname] = sp.diag(g.nvbeta)[ib] #variance: diag of cov matrix
#sig2 = g.s2 #ResMS
var_cond = sp.diag(g.nvbeta)[ib]*g.s2 #variance for all voxels, condition ib
beta_vars_voxels[bname] = var_cond
#beta_var_fn = op.join(output_dir, 'var_beta_%s.nii' %bname)
#write_volume(beta_var, beta_var_fn, fdata.meta_obj)
#beta_var_files.append(beta_var_fn)
if cons is not None:
con_files = []
pval_files = []
for cname, con in cons.iteritems():
con_vol = expand_array_in_mask(con.effect, fdata.roiMask>0)
con_fn = op.join(output_dir, 'con_effect_%s.nii' %cname)
write_volume(con_vol, con_fn, fdata.meta_obj)
con_files.append(con_fn)
pval_vol = expand_array_in_mask(con.pvalue(con_test_baseline),
fdata.roiMask>0)
pval_fn = op.join(output_dir, 'con_pvalue_%s.nii' %cname)
write_volume(pval_vol, pval_fn, fdata.meta_obj)
pval_files.append(pval_fn)
else:
con_files = None
pval_files = None
dof = g.dof
#if do_ppm:
#for
#TODO: FIR stuffs
return beta_files, beta_values, beta_vars_voxels, dof#, con_files, pval_files