def glm_fit(fMRI_path, DesignMatrix=None, output_glm=None, glm_info=None, fit="Kalman_AR1", mask_url=None): """ Call the GLM Fit function with apropriate arguments Parameters ---------- fMRI_path, string or list of strings, path of the fMRI data file(s) design_matrix, DesignMatrix instance, optional design matrix of the model output_glm, string, optional path of the output glm .npz dump glm_info, string,optional path of the output configobj that gives dome infor on the glm fit= 'Kalman_AR1', string to be chosen among "Kalman_AR1", "Ordinary Least Squares", "Kalman" that represents both the model and the fit method mask_url=None string, path of the mask file if None, no mask is applied Returns ------- glm, a nipy.neurospin.glm.glm instance representing the GLM Note ---- either DesignMatrix or design_matrix_path have to be defined fixme: mask should be optional """ import nipy.neurospin.glm if fit == "Kalman_AR1": model = "ar1" method = "kalman" elif fit == "Ordinary Least Squares": method = "ols" model="spherical" elif fit == "Kalman": method = "kalman" model = "spherical" # get the design matrix if isinstance(DesignMatrix, basestring): import nipy.neurospin.utils.design_matrix as dm X = dm.dmtx_from_csv( DesignMatrix).matrix #DM = dm.DesignMatrix() #DM.read_from_csv(DesignMatrix) #X = DM.matrix else: X = DesignMatrix.matrix Y = load_image(fMRI_path, mask_url) glm = nipy.neurospin.glm.glm() glm.fit(Y.T, X, method=method, model=model) if output_glm is not None: glm.save(output_glm) if glm_info is not None: cobj = ConfigObj(glm_info) cobj["DesignMatrix"] = X cobj["mask_url"] = mask_url cobj["GlmDumpFile"] = output_glm cobj.write() return glm
def glm_fit(fMRI_path, DesignMatrix=None, output_glm=None, outputCon=None, fit="Kalman_AR1", design_matrix_path=None, data_scaling=True): """ Call the GLM Fit function with apropriate arguments Parameters ---------- fMRI_path, string or list of strings, path of the fMRI data file(s) design_matrix, DesignMatrix instance, optional design matrix of the model output_glm, string, optional path of the output glm .npz dump outputCon, string,optional path of the output configobj contrast object fit= 'Kalman_AR1', string to be chosen among "Kalman_AR1", "Ordinary Least Squares", "Kalman" that represents both the model and the fit method design_marix_path: string, path of the design matrix .csv file data_scaling: bool, Optional scaling of the data to mean value Returns ------- glm, a nipy.neurospin.glm.glm instance representing the GLM Note ---- either DesignMatrix or design_matrix_path have to be defined """ import nipy.neurospin.glm if fit == "Kalman_AR1": model = "ar1" method = "kalman" elif fit == "Ordinary Least Squares": method = "ols" model="spherical" elif fit == "Kalman": method = "kalman" model = "spherical" # get the design matrix if isinstance(DesignMatrix, basestring): import nipy.neurospin.utils.design_matrix as dm X = dm.dmtx_from_csv( DesignMatrix).matrix #X = dm.DesignMatrix().read_from_csv(DesignMatrix).matrix else: X = DesignMatrix.matrix Y = load_texture(fMRI_path) # data_scaling to percent of mean, and mean removal if data_scaling: # divide each voxel time course by its mean value, subtract 1, # mulitply by 100 to deal with percent of average BOLD fluctuations mY = np.repeat(np.expand_dims(Y.mean(-1), -1), Y.shape[-1], Y.ndim-1) Y = 100* (Y/mY - 1) # acveat:untested glm = nipy.neurospin.glm.glm() glm.fit(Y, X, method=method, model=model) if output_glm is not None: glm.save(output_glm) if outputCon is not None: cobj = ConfigObj(outputCon) cobj["DesignMatrix"] = X cobj["GlmDumpFile"] = output_glm cobj.write() return glm
def glm_fit(fMRI_path, DesignMatrix=None, output_glm=None, outputCon=None, fit="Kalman_AR1", design_matrix_path=None): """ Call the GLM Fit function with apropriate arguments Parameters ---------- fMRI_path, string or list of strings, path of the fMRI data file(s) design_matrix, DesignMatrix instance, optional design matrix of the model output_glm, string, optional path of the output glm .npz dump outputCon, string,optional path of the output configobj contrast object fit= 'Kalman_AR1', string to be chosen among "Kalman_AR1", "Ordinary Least Squares", "Kalman" that represents both the model and the fit method design_marix_path: string, path of the design matrix .csv file Returns ------- glm, a nipy.neurospin.glm.glm instance representing the GLM Note ---- either DesignMatrix or design_matrix_path have to be defined """ import nipy.neurospin.glm if fit == "Kalman_AR1": model = "ar1" method = "kalman" elif fit == "Ordinary Least Squares": method = "ols" model="spherical" elif fit == "Kalman": method = "kalman" model = "spherical" # get the design matrix if isinstance(DesignMatrix, basestring): import nipy.neurospin.utils.design_matrix as dm X = dm.DesignMatrix().read_from_csv(DesignMatrix).matrix else: X = DesignMatrix.matrix Y = load_texture(fMRI_path) glm = nipy.neurospin.glm.glm() glm.fit(Y, X, method=method, model=model) if output_glm is not None: glm.save(output_glm) if outputCon is not None: cobj = ConfigObj(outputCon) cobj["DesignMatrix"] = X cobj["GlmDumpFile"] = output_glm cobj.write() return glm
def glm_fit( fMRI_path, DesignMatrix, output_glm=None, glm_info=None, fit="Kalman_AR1", mask_url=None, data_scaling=True ): """ Call the GLM Fit function with apropriate arguments Parameters ---------- fMRI_path: string or list of strings, path of the fMRI data file(s) design_matrix: DesignMatrix instance, design matrix of the model output_glm: string, optional path of the output glm .npz dump glm_info: string,optional path of the output configobj that gives dome infor on the glm fit: string, Optional, to be chosen among 'Kalman_AR1', 'Ordinary Least Squares', 'Kalman' that represents both the model and the fit method mask_url: string, Optional, path of the mask file if None, no mask is applied data_scaling: bool, Optional scaling of the data to mean value Returns ------- glm, a nipy.neurospin.glm.glm instance representing the GLM Note ---- either DesignMatrix or design_matrix_path have to be defined fixme: mask should be optional """ import nipy.neurospin.glm # get the model/fit methods if fit == "Kalman_AR1": model = "ar1" method = "kalman" elif fit == "Ordinary Least Squares": method = "ols" model = "spherical" elif fit == "Kalman": method = "kalman" model = "spherical" # get the design matrix if isinstance(DesignMatrix, basestring): import nipy.neurospin.utils.design_matrix as dm X = dm.dmtx_from_csv(DesignMatrix).matrix else: X = DesignMatrix.matrix # load the fMRI data Y = load_image(fMRI_path, mask_url) # data_scaling to percent of mean, and mean removal if data_scaling: # divide each voxel time course by its mean value, subtract 1, # mulitply by 100 to deal with percent of average BOLD fluctuations mY = np.repeat(np.expand_dims(Y.mean(-1), -1), Y.shape[-1], Y.ndim - 1) Y = 100 * (Y / mY - 1) # apply the GLM glm = nipy.neurospin.glm.glm() glm.fit(Y.T, X, method=method, model=model) # Write outputs if output_glm is not None: glm.save(output_glm) if glm_info is not None: cobj = ConfigObj(glm_info) cobj["DesignMatrix"] = X cobj["mask_url"] = mask_url cobj["GlmDumpFile"] = output_glm cobj.write() return glm