def test_fetch_spm_auditory(request_mocker, tmp_path): import nibabel as nib import shutil saf = ["fM00223/fM00223_%03i.img" % index for index in range(4, 100)] saf_ = ["fM00223/fM00223_%03i.hdr" % index for index in range(4, 100)] data_dir = str(tmp_path / 'spm_auditory') os.mkdir(data_dir) subject_dir = os.path.join(data_dir, 'sub001') os.mkdir(subject_dir) os.mkdir(os.path.join(subject_dir, 'fM00223')) os.mkdir(os.path.join(subject_dir, 'sM00223')) path_img = str(tmp_path / 'tmp.img') path_hdr = str(tmp_path / 'tmp.hdr') nib.save(nib.Nifti1Image(np.zeros((2, 3, 4)), np.eye(4)), path_img) shutil.copy(path_img, os.path.join(subject_dir, "sM00223/sM00223_002.img")) shutil.copy(path_hdr, os.path.join(subject_dir, "sM00223/sM00223_002.hdr")) for file_ in saf: shutil.copy(path_img, os.path.join(subject_dir, file_)) for file_ in saf_: shutil.copy(path_hdr, os.path.join(subject_dir, file_)) dataset = func.fetch_spm_auditory(data_dir=tmp_path) assert isinstance(dataset.anat, str) assert isinstance(dataset.func[0], str) assert len(dataset.func) == 96
Here we fit a First Level GLM with the `minimize_memory`-argument set to `False`. By doing so, the `FirstLevelModel`-object stores the residuals, which we can then inspect. Also, the predicted time series can be extracted, which is useful to assess the quality of the model fit. """ ######################################################################### # Import modules # -------------- from nilearn.datasets.func import fetch_spm_auditory from nilearn import image from nilearn import masking import pandas as pd # load fMRI data subject_data = fetch_spm_auditory() fmri_img = image.concat_imgs(subject_data.func) # Make an average mean_img = image.mean_img(fmri_img) mask = masking.compute_epi_mask(mean_img) # Clean and smooth data fmri_img = image.clean_img(fmri_img, standardize=False) fmri_img = image.smooth_img(fmri_img, 5.) # load events events = pd.read_table(subject_data['events']) ######################################################################### # Fit model