A modular Python pipeline for loading, processing, and visualizing naturalistic fMRI data. Dataset: OpenNeuro ds002345 · Subject: sub-005 · Task: Pieman Run-1
"Narratives: fMRI data for evaluating models of naturalistic language comprehension" Nastase et al. (2019) — Princeton Neuroscience Institute
Participants listened to spoken audio stories while lying in an MRI scanner. Files used in this project:
| File | Description |
|---|---|
sub-005_task-pieman_run-1_bold.nii.gz |
4D BOLD fMRI data (64×64×27×300) |
sub-005_task-pieman_run-1_bold.json |
Acquisition parameters (TR, TE, etc.) |
sub-005_task-pieman_run-1_events.tsv |
Task blocks (music + story) |
Scan parameters: TR = 1.5 s · TE = 28 ms · 3T Siemens Skyra · 27 slices · 3 mm isotropic
neuroscience/
│
├── config.py # File paths, TR, color and style definitions
├── load_data.py # NIfTI, TSV and JSON loading functions
├── visualize_brain.py # Brain anatomy visualizations
├── visualize_timeseries.py # BOLD time series plots
├── visualize_signal.py # Histogram and summary statistics table
├── run_all.py # Main script that runs the full pipeline
│
├── fmri_visualization.ipynb # Annotated Jupyter notebook
├── fmri_visualization_executed.ipynb # Executed notebook with outputs
│
├── ds002345_sub005_pieman1/ # Downloaded BIDS dataset
│ ├── dataset_description.json
│ ├── participants.tsv
│ └── sub-005/func/
│
└── outputs/ # Generated figures
├── mean_epi_mosaic.png
├── mean_epi_ortho.png
├── axial_slices.png
├── std_map.png
├── bold_timeseries.png
├── task_comparison.png
├── frame_diff.png
├── bold_histogram.png
└── summary_table.png
python -m venv .venv
source .venv/bin/activate # Windows: .venv\Scripts\activatepip install nibabel nilearn matplotlib numpy pandas seaborn openneuro-py jupyteropenneuro-py download \
--dataset ds002345 \
--include sub-005/func/sub-005_task-pieman_run-1_bold.nii.gz \
--include sub-005/func/sub-005_task-pieman_run-1_bold.json \
--include sub-005/func/sub-005_task-pieman_run-1_events.tsv \
--target-dir ./ds002345_sub005_pieman1python run_all.pyAll outputs are automatically saved to the outputs/ folder.
python run_all.py --no-savepython load_data.py # Print dataset info and task events
python visualize_brain.py # Brain slice figures
python visualize_timeseries.py # Time series plots
python visualize_signal.py # Histogram and summary tablejupyter notebook fmri_visualization.ipynb| Figure | Description |
|---|---|
mean_epi_mosaic.png |
Average of all TRs — mosaic view |
mean_epi_ortho.png |
Mean BOLD — axial / sagittal / coronal |
axial_slices.png |
Axial slices at 6 different z-levels |
std_map.png |
Standard deviation over time (higher = more active) |
bold_timeseries.png |
Global mean + center voxel time series |
task_comparison.png |
Music vs. story period signal comparison |
frame_diff.png |
Volume-to-volume change — head motion proxy |
bold_histogram.png |
Distribution of BOLD signal values across brain voxels |
summary_table.png |
Summary statistics table per task condition |
- Dimensions: 64 × 64 × 27 voxels × 300 TRs (7.5 minutes)
- Active voxels: ~47,961 (after brain masking)
- Global SNR: ~493 (high-quality data)
- Task breakdown: 8 TRs music · 281 TRs story listening · 11 TRs rest
| Library | Version | Purpose |
|---|---|---|
nibabel |
≥ 5.0 | NIfTI file reading/writing |
nilearn |
≥ 0.10 | Brain visualization and image processing |
numpy |
≥ 1.24 | Numerical array operations |
pandas |
≥ 2.0 | TSV/CSV data handling |
matplotlib |
≥ 3.7 | Figure rendering |
seaborn |
≥ 0.12 | Statistical plot styling |
openneuro-py |
≥ 2024.0 | Dataset download |
Nastase, S. A., Liu, Y.-F., Hillman, H., Zadbood, A., Hasenfratz, L.,
Keshavarzian, N., Chen, J., Honey, C. J., Yeshurun, Y., Regev, M.,
Nguyen, M., Chang, C. H. C., Baldassano, C., Lositsky, O., Simony, E.,
Chow, M. A., Leong, Y. C., Brooks, P. P., Micciche, E., Choe, G.,
Goldstein, A., Vanderwal, T., Halchenko, Y. O., Norman, K. A., & Hasson, U.
(2019). Narratives: fMRI data for evaluating models of naturalistic language
comprehension. OpenNeuro, ds002345.
https://doi.org/10.18112/openneuro.ds002345.v1.1.4
The dataset is released under the CC0 (public domain) license. The code in this repository is distributed under the MIT license.