Skip to article frontmatterSkip to article content
Site not loading correctly?

This may be due to an incorrect BASE_URL configuration. See the MyST Documentation for reference.

QSIPrep

Run this notebook

Preprocessing diffusion MRI

Author: Monika Doerig

Date: 15 July 2026

License:

MIT License

Note: If this notebook uses neuroimaging tools from Neurocontainers, those tools retain their original licenses. Please see Neurodesk citation guidelines for details.

✨ Use of AI ▽

This notebook was drafted with assistance from an LLM (GLM-5.2, via Neurodesk) and then revised by the author. The author reviewed the final content and takes responsibility for it.

Citation and Resources:

Tools included in this workflow

QSIPrep:

  • Cieslak, M., Cook, P.A., He, X. et al. QSIPrep: an integrative platform for preprocessing and reconstructing diffusion MRI data. Nat Methods 18, 775–778 (2021). Cieslak et al. (2021)

Dataset

OpenNeuro:

Educational resources

Load software tools and import python libraries

We load QSIPrep through the Neurodesk module system. QSIPrep bundles its own environment (FSL, ANTs, MRtrix3, FreeSurfer), so a single module load is enough.

['qsiprep/1.0.1']

The base image already provides the common scientific Python packages (see the Neurodesktop Dockerfile). Only a few standard libraries are needed below.

FreeSurfer license

Introduction

Overview

QSIPrep configures and runs preprocessing pipelines for diffusion-weighted MRI (dMRI). It’s the diffusion counterpart to fMRIPrep: a BIDS-App that combines tools from FSL, ANTs, MRtrix3 and FreeSurfer to denoise (MP-PCA), correct for susceptibility and motion, coregister to the anatomical image, optionally normalise to a template, and produce a visual QC report.

A distinguishing feature is its motion-correction algorithm (SHORELine), which works even on DSI and random q-space sampling schemes. The pipeline is assembled automatically from your BIDS inputs, so fieldmaps and multi-scan acquisitions are grouped and handled correctly. Note that “assembled automatically from your BIDS inputs” assumes the inputs follow BIDS conventions correctly. This notebook includes a preparation step: a reverse phase-encoded b=0 scan has to be set up as a fieldmap so QSIPrep can use it for distortion correction (see Prepare the reverse-PE scan for QSIPrep).

Importantly, QSIPrep only preprocesses your data. Its outputs are the preprocessed DWI series, along with their gradient tables, a brain mask, tissue segmentations, confound/QC metrics, and an HTML report summarising each step. Reconstruction — ODF/FOD estimation, tractography, connectivity — is handed off to its companion tool, QSIRecon, which consumes these derivatives. Another notebook covers that step.

QSIPrep reuses much of the fMRIPrep codebase, but this does not imply endorsement by the fMRIPrep authors.

Workflow

QSIPrep preprocessing workflow

The full preprocessing and reconstruction workflow. Source: PennLINC/qsiprep.

Learning objectives

This notebook assumes a basic understanding of diffusion MRI and the BIDS layout, but no prior QSIPrep experience. By the end you will be able to:

  • Describe what QSIPrep does, what it deliberately leaves to reconstruction, and how it connects to QSIRecon

  • Load the QSIPrep module in Neurodesk and run it on a single BIDS subject

  • Locate and interpret the preprocessed outputs and the visual QC report

  • Understand how QSIPrep derivatives feed into QSIRecon for reconstruction

Data Preparation

We use the BTC preop dataset from OpenNeuro and fetch a single control subject (sub-CON01, session ses-preop). The subject contains a T1w MPRAGE (anat/), a resting-state BOLD (func/), and two DWI series in dwi/: a multi-shell HARDI acquisition (acq-AP, 101 directions, b = 0/700/1200/2800 s/mm²) and a short reverse phase-encoded scan (acq-PA, 2 volumes, both b = 0). Because the PA is a pure b0 fieldmap, QSIPrep expects it in fmap/ as an EPI file with an IntendedFor entry — we reorganise it before running QSIPrep (see below).

[INFO] Attempting a clone into /home/jovyan/workspace/books/examples/diffusion_imaging/ds001226 
[INFO] Attempting to clone from https://github.com/OpenNeuroDatasets/ds001226.git to /home/jovyan/workspace/books/examples/diffusion_imaging/ds001226 
[INFO] Start enumerating objects 
[INFO] Start counting objects 
[INFO] Start compressing objects 
[INFO] Start receiving objects 
[INFO] Start resolving deltas 
[INFO] Completed clone attempts for Dataset(/home/jovyan/workspace/books/examples/diffusion_imaging/ds001226) 
[INFO] Remote origin not usable by git-annex; setting annex-ignore 
[INFO] https://github.com/OpenNeuroDatasets/ds001226.git/config download failed: Not Found 
[INFO] access to 1 dataset sibling s3-BACKUP not auto-enabled, enable with:
| 		datalad siblings -d "/home/jovyan/workspace/books/examples/diffusion_imaging/ds001226" enable -s s3-BACKUP 
install(ok): /home/jovyan/workspace/books/examples/diffusion_imaging/ds001226 (dataset)
get(ok): sub-CON01/ses-preop/anat/sub-CON01_ses-preop_T1w.nii.gz (file) [from s3-PUBLIC...]
get(ok): sub-CON01/ses-preop/dwi/sub-CON01_ses-preop_acq-AP_dwi.nii.gz (file) [from s3-PUBLIC...]
get(ok): sub-CON01/ses-preop/dwi/sub-CON01_ses-preop_acq-PA_dwi.nii.gz (file) [from s3-PUBLIC...]
get(ok): sub-CON01/ses-preop/func/sub-CON01_ses-preop_task-rest_bold.nii.gz (file) [from s3-PUBLIC...]
get(ok): sub-CON01 (directory)
action summary:
  get (ok: 5)

Inspect the BIDS layout

Confirm the on-disk structure of sub-CON01/ses-preop and the DWI phase-encoding sidecars. These sidecars are what QSIPrep reads to decide how to perform susceptibility distortion correction (SDC).

=== directory layout ===
anat/
    sub-CON01_ses-preop_T1w.json
    sub-CON01_ses-preop_T1w.nii.gz
dwi/
    sub-CON01_ses-preop_acq-AP_dwi.bval
    sub-CON01_ses-preop_acq-AP_dwi.bvec
    sub-CON01_ses-preop_acq-AP_dwi.json
    sub-CON01_ses-preop_acq-AP_dwi.nii.gz
    sub-CON01_ses-preop_acq-PA_dwi.bval
    sub-CON01_ses-preop_acq-PA_dwi.bvec
    sub-CON01_ses-preop_acq-PA_dwi.json
    sub-CON01_ses-preop_acq-PA_dwi.nii.gz
func/
    sub-CON01_ses-preop_task-rest_bold.json
    sub-CON01_ses-preop_task-rest_bold.nii.gz

=== DWI phase-encoding sidecars ===
acq-AP: PhaseEncodingDirection='j-'  TotalReadoutTime=0.0266003  num_volumes=102  bvals=['0', '0', '700', '2800', '1200', '2800', '1200', '2800', '2800', '1200', '700', '2800', '2800', '1200', '2800', '700', '1200', '2800', '2800', '1200', '2800', '700', '2800', '1200', '2800', '1200', '0', '2800', '700', '2800', '1200', '2800', '2800', '1200', '700', '2800', '1200', '2800', '2800', '1200', '2800', '700', '2800', '1200', '2800', '1200', '2800', '700', '2800', '1200', '2800', '0', '700', '2800', '1200', '2800', '1200', '2800', '2800', '1200', '700', '2800', '2800', '1200', '2800', '700', '1200', '2800', '2800', '1200', '2800', '700', '2800', '1200', '2800', '1200', '0', '2800', '700', '2800', '1200', '2800', '2800', '1200', '700', '2800', '1200', '2800', '2800', '1200', '2800', '700', '2800', '1200', '2800', '1200', '2800', '700', '2800', '1200', '2800', '0']
acq-PA: PhaseEncodingDirection='j'  TotalReadoutTime=0.0266003  num_volumes=2  bvals=['0', '0']

Prepare the reverse-PE scan for QSIPrep

The PA acquisition is 2 pure b=0 volumes (both bval = 0) with the opposite phase-encoding direction ("j") to the AP HARDI ("j-") — it is a reverse phase-encoded fieldmap, not a diffusion scan. QSIPrep’s documentation is explicit: short reverse-PE b0 scans should live in fmap/ as _epi files with an IntendedFor field pointing at the DWI they correct. If left in dwi/ as a _dwi file, QSIPrep will try to physically concatenate it with the AP HARDI — which fails because the two series were acquired separately and have slightly different spatial affines.

The fix is a simple BIDS reorganisation: copy the PA files into fmap/, rename them from _dwi to _dir-PA_epi, and add IntendedFor to the JSON sidecar. After this, QSIPrep uses the PA as a topup fieldmap for PEPOLAR SDC instead of concatenating it.

PE: j | TRT: 0.0266003 | IntendedFor: ['ses-preop/dwi/sub-CON01_ses-preop_acq-AP_dwi.nii.gz']
Reorganisation complete. fmap/ contents:
sub-CON01_ses-preop_dir-PA_epi.json
sub-CON01_ses-preop_dir-PA_epi.nii.gz
dwi/ contents:
sub-CON01_ses-preop_acq-AP_dwi.bval
sub-CON01_ses-preop_acq-AP_dwi.bvec
sub-CON01_ses-preop_acq-AP_dwi.json
sub-CON01_ses-preop_acq-AP_dwi.nii.gz

Analysis

We will now run QSIPrep: the command takes the BIDS dataset, an output directory, the participant analysis level, the subject label, the FreeSurfer license, and the output voxel resolution. The work directory (-w) holds intermediate files and can be deleted once the run succeeds.

Fetching long content....
QSIPrep complete - preprocessed DWI found.

Where the outputs land

QSIPrep writes derivatives under qsiprep-output/:

  • qsiprep-output/sub-CON01.html — the visual QC report.

  • qsiprep-output/sub-CON01/ses-preop/dwi/sub-CON01_ses-preop_acq-AP_space-ACPC_desc-preproc_dwi.nii.gz — the preprocessed DWI (with matching .bval, .bvec, .json).

  • qsiprep-output/sub-CON01/ses-preop/dwi/sub-CON01_ses-preop_acq-AP_space-ACPC_desc-brain_mask.nii.gz — the DWI brain mask.

  • qsiprep-output/sub-CON01/anat/sub-CON01_space-ACPC_desc-preproc_T1w.nii.gz — the preprocessed T1w.

  • qsiprep-output/sub-CON01/anat/sub-CON01_space-ACPC_desc-aseg_dseg.nii.gz — the anatomical segmentation.

Results

We’ll display the full QC report qsiprep-output/sub-CON01.html below:

Loading...

Dependencies in Jupyter/Python

  • Using the package watermark to document system environment and software versions used in this notebook, alongside the Neurodesktop version extracted from the JUPYTER_IMAGE or NEURODESKTOP_VERSION environment variables.

Last updated: 2026-10-05T15:38:09.709169+00:00

Python implementation: CPython
Python version       : 3.13.15
IPython version      : 9.17.1

Compiler    : GCC 15.3.0
OS          : Linux
Release     : 6.8.0-111-generic
Machine     : x86_64
Processor   : x86_64
CPU cores   : 16
Architecture: 64bit

IPython: 9.17.1
bs4    : 4.15.0
json   : 2.0.9

Neurodesktop version: 2026-09-28
References
  1. Cieslak, M., Cook, P. A., He, X., Yeh, F.-C., Dhollander, T., Adebimpe, A., Aguirre, G. K., Bassett, D. S., Betzel, R. F., Bourque, J., Cabral, L. M., Davatzikos, C., Detre, J. A., Earl, E., Elliott, M. A., Fadnavis, S., Fair, D. A., Foran, W., Fotiadis, P., … Satterthwaite, T. D. (2021). QSIPrep: an integrative platform for preprocessing and reconstructing diffusion MRI data. Nature Methods, 18(7), 775–778. 10.1038/s41592-021-01185-5