Note
This page is a reference documentation. It only explains the function signature, and not how to use it. Please refer to the user guide for the big picture.
nilearn.glm.first_level.first_level_from_bids¶
- nilearn.glm.first_level.first_level_from_bids(dataset_path, task_label, space_label=None, sub_labels=None, exclude_subjects=None, img_filters=None, t_r=None, slice_time_ref=None, hrf_model='glover', drift_model='cosine', high_pass=0.01, drift_order=1, fir_delays=None, min_onset=-24, mask_img=None, target_affine=None, target_shape=None, smoothing_fwhm=None, memory=None, memory_level=1, standardize=False, signal_scaling=0, noise_model='ar1', verbose=0, n_jobs=1, minimize_memory=True, derivatives_folder='derivatives', **kwargs)[source]¶
Create FirstLevelModel objects and fit arguments from a BIDS dataset.
If
t_risNone, this function will attempt to load it from abold.json. Ifslice_time_refisNone, this function will attempt to infer it from abold.json. Otherwise,t_randslice_time_refare taken as given, but a warning may be raised if they are not consistent with thebold.json.All parameters not described here are passed to
FirstLevelModel.The subject label of the model will be determined directly from the BIDS dataset.
- Parameters:
- dataset_path
strorpathlib.Path Directory of the highest level folder of the BIDS dataset. Should contain subject folders and a derivatives folder.
- task_label
str Task_label as specified in the file names like
_task-<task_label>_.- space_label
stror None, default=None Specifies the space label of the preprocessed bold.nii images. As they are specified in the file names like
_space-<space_label>_. If “fsaverage5” is passed as a value then the GLM will be run on pial surface data.- sub_labels
listofstror None, default=None Specifies the subset of subject labels to model. If
None, will model all subjects in the dataset.Added in Nilearn 0.10.1.
- exclude_subjects
listofstror None, default=None Specifies the subset of subject labels to skip.
Added in Nilearn 0.13.0dev.
- img_filters
listoftuple(str,str), default=None Filters are of the form
(field, label). Only one filter per field allowed. A file that does not match a filter will be discarded. Possible filters are'acq','ce','dir','rec','run','echo','res','den', and'desc'. Filter examples would be('desc', 'preproc'),('dir', 'pa')and('run', '10').- slice_time_ref
floatbetween0.0and1.0, or None, default= None This parameter indicates the time of the reference slice used in the slice timing preprocessing step of the experimental runs. It is expressed as a fraction of the
t_r(time repetition), so it can have values between0.and1.Ifslice_time_refisNone, this function will attempt to infer it from the metadata found in abold.json. If it cannot be inferred from metadata, it will be set to 0.- derivatives_folder
str, default="derivatives". derivatives and app folder path containing preprocessed files. Like
"derivatives/FMRIPREP".- kwargs
dict Keyword arguments to be passed to functions called within this function.
Kwargs prefixed with
confounds_will be passed toload_confounds. This allowsfirst_level_from_bidsto return a specific set of confounds by relying on confound loading strategies defined inload_confounds. If no kwargs are passed,first_level_from_bidswill return all the confounds available in the confounds TSV files.Added in Nilearn 0.10.3.
- dataset_path
- Returns:
- modelslist of
FirstLevelModelobjects Each
FirstLevelModelobject corresponds to a subject. All runs from different sessions are considered together for the same subject to run a fixed effects analysis on them.- models_run_imgs
listof list of Niimg-like objects, Items for the
FirstLevelModelfit function of their respective model.- models_events
listof list of pandas DataFrames, Items for the
FirstLevelModelfit function of their respective model.- models_confounds
listof list of pandas DataFrames orNone, Items for the
FirstLevelModelfit function of their respective model.
- modelslist of
Examples
If you want to only load the rotation and translation motion parameters confounds:
models, imgs, events, confounds = first_level_from_bids( dataset_path=path_to_a_bids_dataset, task_label="TaskName", space_label="MNI", img_filters=[("desc", "preproc")], confounds_strategy=("motion"), confounds_motion="basic", )
If you want to load the motion parameters confounds with their derivatives:
models, imgs, events, confounds = first_level_from_bids( dataset_path=path_to_a_bids_dataset, task_label="TaskName", space_label="MNI", img_filters=[("desc", "preproc")], confounds_strategy=("motion"), confounds_motion="derivatives", )
If you additionally want to load the confounds with CSF and white matter signal:
models, imgs, events, confounds = first_level_from_bids( dataset_path=path_to_a_bids_dataset, task_label="TaskName", space_label="MNI", img_filters=[("desc", "preproc")], confounds_strategy=("motion", "wm_csf"), confounds_motion="derivatives", confounds_wm_csf="basic", )
If you also want to scrub high-motion timepoints:
models, imgs, events, confounds = first_level_from_bids( dataset_path=path_to_a_bids_dataset, task_label="TaskName", space_label="MNI", img_filters=[("desc", "preproc")], confounds_strategy=("motion", "wm_csf", "scrub"), confounds_motion="derivatives", confounds_wm_csf="basic", confounds_scrub=1, confounds_fd_threshold=0.2, confounds_std_dvars_threshold=0, )
Please refer to the documentation of
load_confoundsfor more details on the confounds loading strategies.
Examples using nilearn.glm.first_level.first_level_from_bids¶
First level analysis of a complete BIDS dataset from openneuro
Beta-Series Modeling for Task-Based Functional Connectivity and Decoding
Surface-based dataset first and second level analysis of a dataset