def test_fetch_localizer(): dataset = datasets.fetch_localizer_first_level() assert_true(isinstance(dataset['events'], _basestring)) assert_true(isinstance(dataset.epi_img, _basestring))
import numpy as np import pandas as pd from nilearn import plotting from nistats.first_level_model import FirstLevelModel from nistats import datasets ######################################################################### # Prepare data and analysis parameters # ------------------------------------- # Prepare timing t_r = 2.4 slice_time_ref = 0.5 # Prepare data data = datasets.fetch_localizer_first_level() paradigm_file = data.paradigm paradigm = pd.read_csv(paradigm_file, sep=' ', header=None, index_col=None) paradigm.columns = ['session', 'trial_type', 'onset'] fmri_img = data.epi_img ######################################################################### # Perform first level analysis # ---------------------------- # Setup and fit GLM first_level_model = FirstLevelModel(t_r, slice_time_ref, hrf_model='glover + derivative') first_level_model = first_level_model.fit(fmri_img, paradigm) ######################################################################### # Estimate contrasts
def test_fetch_localizer(): dataset = datasets.fetch_localizer_first_level(data_dir=tmpdir) assert_true(isinstance(dataset.paradigm, _basestring)) assert_true(isinstance(dataset.epi_img, _basestring))
from nilearn import plotting from nistats.glm import FirstLevelGLM from nistats.design_matrix import make_design_matrix from nistats import datasets ### Data and analysis parameters ####################################### # timing n_scans = 128 tr = 2.4 frame_times = np.linspace(0.5 * tr, (n_scans - .5) * tr, n_scans) # data data = datasets.fetch_localizer_first_level() paradigm_file = data.paradigm fmri_img = data.epi_img ### Design matrix ######################################## paradigm = pd.read_csv(paradigm_file, sep=' ', header=None, index_col=None) paradigm.columns = ['session', 'name', 'onset'] n_conditions = len(paradigm.name.unique()) design_matrix = make_design_matrix( frame_times, paradigm, hrf_model='glover + derivative', drift_model='cosine', period_cut=128) ### Perform a GLM analysis ######################################## fmri_glm = FirstLevelGLM().fit(fmri_img, design_matrix)
obviously less accurate than using a subject-tailored mesh. """ ######################################################################### # Prepare data and analysis parameters # ------------------------------------- # Prepare timing parameters t_r = 2.4 slice_time_ref = 0.5 ######################################################################### # Prepare data # First the volume-based fMRI data. from nistats.datasets import fetch_localizer_first_level data = fetch_localizer_first_level() fmri_img = data.epi_img ######################################################################### # Second the experimental paradigm. events_file = data['events'] import pandas as pd events = pd.read_table(events_file) ######################################################################### # Project the fMRI image to the surface # ------------------------------------- # # For this we need to get a mesh representing the geometry of the # surface. we could use an individual mesh, but we first resort to a # standard mesh, the so-called fsaverage5 template from the Freesurfer
obviously less accurate than using a subject-tailored mesh. """ ######################################################################### # Prepare data and analysis parameters # ------------------------------------- # Prepare timing parameters t_r = 2.4 slice_time_ref = 0.5 ######################################################################### # Prepare data # First the volume-based fMRI data. from nistats.datasets import fetch_localizer_first_level data = fetch_localizer_first_level() fmri_img = data.epi_img ######################################################################### # Second the experimental paradigm. events_file = data.events import pandas as pd events = pd.read_table(events_file) ######################################################################### # Project the fMRI image to the surface # ------------------------------------- # # For this we need to get a mesh representing the geometry of the # surface. we could use an individual mesh, but we first resort to a # standard mesh, the so-called fsaverage5 template from the Freesurfer