######################################## positions = np.array([[60, -30, 5], [50, 27, 5]]) # in mm (here in the MNI space) radii = np.array([8, 6]) domain = grid_domain_from_image(mask) my_roi = mroi.subdomain_from_balls(domain, positions, radii) # to save an image of the ROIs save(my_roi.to_image(), path.join(write_dir, "roi.nii")) ####################################### # Get the FMRI data ####################################### fmri_data = surrogate_4d_dataset(mask=mask, dmtx=X)[0] Y = fmri_data.get_data()[mask_array] # artificially added signal in ROIs to make the example more meaningful activation = 30 * (X.T[1] + .5 * X.T[0]) for (position, radius) in zip(positions, radii): Y[((domain.coord - position)**2).sum(1) < radius**2 + 1] += activation ######################################## # Perform a GLM analysis ######################################## # GLM fit glm = GeneralLinearModel(X) glm.fit(Y.T)
######################################## # Design matrix ######################################## paradigm = dm.EventRelatedParadigm(conditions, onsets) X, names = dm.dmtx_light(frametimes, paradigm, drift_model='Cosine', hfcut=128, hrf_model=hrf_model, add_regs=motion, add_reg_names=add_reg_names) ####################################### # Get the FMRI data ####################################### fmri_data = surrogate_4d_dataset(shape=shape, n_scans=n_scans)[0] # if you want to save it as an image data_file = op.join(swd, 'fmri_data.nii') save(fmri_data, data_file) ######################################## # Perform a GLM analysis ######################################## # GLM fit Y = fmri_data.get_data() model = "ar1" method = "kalman" glm = GLM.glm() glm.fit(Y.T, X, method=method, model=model)
paradigm = np.vstack(([conditions, onsets])).T paradigm = EventRelatedParadigm(conditions, onsets) X, names = dmtx_light(frametimes, paradigm, drift_model='cosine', hfcut=128, hrf_model=hrf_model, add_regs=motion, add_reg_names=add_reg_names) ####################################### # Get the FMRI data ####################################### fmri_data = surrogate_4d_dataset(mask=mask, dmtx=X, seed=1)[0] ######################################## # Perform a GLM analysis ######################################## # GLM fit Y = fmri_data.get_data()[mask_array] glm = GeneralLinearModel(X) glm.fit(Y.T) # specifiy the contrast [1 -1 0 ..] contrast = np.zeros(X.shape[1]) contrast[:2] = np.array([1, -1]) # compute the constrast image related to it
######################################## # Design matrix ######################################## paradigm = np.vstack(([conditions, onsets])).T paradigm = EventRelatedParadigm(conditions, onsets) X, names = dmtx_light(frametimes, paradigm, drift_model='cosine', hfcut=128, hrf_model=hrf_model, add_regs=motion, add_reg_names=add_reg_names) ####################################### # Get the FMRI data ####################################### fmri_data = surrogate_4d_dataset(mask=mask, dmtx=X, seed=1)[0] # if you want to save it as an image # data_file = op.join(write_dir,'fmri_data.nii') # save(fmri_data, data_file) ######################################## # Perform a GLM analysis ######################################## # GLM fit Y = fmri_data.get_data()[mask_array] glm = GeneralLinearModel(X) glm.fit(Y.T) # specifiy the contrast [1 -1 0 ..]
######################################## paradigm = EventRelatedParadigm(conditions, onsets) X, names = dm.dmtx_light(frametimes, paradigm, drift_model='cosine', hfcut=128, hrf_model=hrf_model, add_regs=motion, add_reg_names=add_reg_names) ####################################### # Get the FMRI data ####################################### fmri_data = surrogate_4d_dataset(shape=shape, n_scans=n_scans)[0] # if you want to save it as an image data_file = 'fmri_data.nii' save(fmri_data, data_file) ######################################## # Perform a GLM analysis ######################################## # GLM fit Y = fmri_data.get_data().reshape(np.prod(shape), n_scans) glm = GeneralLinearModel(X) glm.fit(Y.T) # specify the contrast [1 -1 0 ..]
######################################## positions = np.array([[60, -30, 5], [50, 27, 5]]) # in mm (here in the MNI space) radii = np.array([8, 6]) domain = grid_domain_from_image(mask) my_roi = mroi.subdomain_from_balls(domain, positions, radii) # to save an image of the ROIs save(my_roi.to_image(), path.join(write_dir, "roi.nii")) ####################################### # Get the FMRI data ####################################### fmri_data = surrogate_4d_dataset(mask=mask, dmtx=X)[0] Y = fmri_data.get_data()[mask_array] # artificially added signal in ROIs to make the example more meaningful activation = 30 * (X.T[1] + .5 * X.T[0]) for (position, radius) in zip(positions, radii): Y[((domain.coord - position) ** 2).sum(1) < radius ** 2 + 1] += activation ######################################## # Perform a GLM analysis ######################################## # GLM fit glm = GeneralLinearModel(X) glm.fit(Y.T)