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.

NiWrap and Connectome Workbench

Run this notebook

Surface-Based Visualization Workflow for Single-Subject CIFTI

Author: Monika Doerig

Date: 23 July 2025

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.

Citation and Resources:

Tools included in this workflow

NiWrap:

@software{niwrap,
  author = {The NiWrap Contributors},
  title = {NiWrap: Type-Safe Neuroimaging Tool Wrappers},
  url = {https://github.com/styx-api/niwrap},
  note = {Preprint in preparation},
  year = {2025}

Connectome Workbench:

  • Marcus, D. S., Harwell, J., Olsen, T., Hodge, M., Glasser, M. F., Prior, F., Jenkinson, M., Laumann, T., Curtiss, S. W., & Van Essen, D. C. (2011). Informatics and data mining tools and strategies for the human connectome project. Frontiers in neuroinformatics, 5, 4. Marcus et al. (2011)

  • Workbench Command Documentation

Dataset

  • Zhengxin Gong and Ming Zhou and Yuxuan Dai and Yushan Wen and Youyi Liu and Zonglei Zhen (2023). A large-scale fMRI dataset for the visual processing of naturalistic scenes. OpenNeuro. [Dataset] doi: doi:10.18112/openneuro.ds004496.v2.1.2

Load software tools and import python libraries

['connectomeworkbench/2.1.0']

Data download and preparation

Datalad

[INFO] Attempting a clone into /home/jovyan/workspace/books/examples/functional_imaging/ds004496 
[INFO] Attempting to clone from https://github.com/OpenNeuroDatasets/ds004496.git to /home/jovyan/workspace/books/examples/functional_imaging/ds004496 
[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/functional_imaging/ds004496) 
[INFO] Remote origin not usable by git-annex; setting annex-ignore 
[INFO] https://github.com/OpenNeuroDatasets/ds004496.git/config download failed: Not Found 
install(ok): /home/jovyan/workspace/books/examples/functional_imaging/ds004496 (dataset)
Downloading Ciftify derivative files for sub-01 from ds004496...
get(ok): derivatives/ciftify/sub-01/results/ses-floc_task-floc/ses-floc_task-floc_beta.dscalar.nii (file) [from s3-PUBLIC...]
get(ok): derivatives/ciftify/sub-01/standard_fsLR_surface/sub-01.ArealDistortion_FS.32k_fs_LR.dscalar.nii (file) [from s3-PUBLIC...]
get(ok): derivatives/ciftify/sub-01/standard_fsLR_surface/sub-01.ArealDistortion_MSMSulc.32k_fs_LR.dscalar.nii (file) [from s3-PUBLIC...]
get(ok): derivatives/ciftify/sub-01/standard_fsLR_surface/sub-01.BA_exvivo.32k_fs_LR.dlabel.nii (file) [from s3-PUBLIC...]
get(ok): derivatives/ciftify/sub-01/standard_fsLR_surface/sub-01.EdgeDistortion_MSMSulc.32k_fs_LR.dscalar.nii (file) [from s3-PUBLIC...]
get(ok): derivatives/ciftify/sub-01/standard_fsLR_surface/sub-01.L.inflated.32k_fs_LR.surf.gii (file) [from s3-PUBLIC...]
get(ok): derivatives/ciftify/sub-01/standard_fsLR_surface/sub-01.L.midthickness.32k_fs_LR.surf.gii (file) [from s3-PUBLIC...]
get(ok): derivatives/ciftify/sub-01/standard_fsLR_surface/sub-01.L.pial.32k_fs_LR.surf.gii (file) [from s3-PUBLIC...]
get(ok): derivatives/ciftify/sub-01/standard_fsLR_surface/sub-01.L.very_inflated.32k_fs_LR.surf.gii (file) [from s3-PUBLIC...]
get(ok): derivatives/ciftify/sub-01/standard_fsLR_surface/sub-01.L.white.32k_fs_LR.surf.gii (file) [from s3-PUBLIC...]
get(ok): derivatives/ciftify/sub-01/standard_fsLR_surface/sub-01.R.inflated.32k_fs_LR.surf.gii (file) [from s3-PUBLIC...]
get(ok): derivatives/ciftify/sub-01/standard_fsLR_surface/sub-01.R.midthickness.32k_fs_LR.surf.gii (file) [from s3-PUBLIC...]
get(ok): derivatives/ciftify/sub-01/standard_fsLR_surface/sub-01.R.pial.32k_fs_LR.surf.gii (file) [from s3-PUBLIC...]
get(ok): derivatives/ciftify/sub-01/standard_fsLR_surface/sub-01.R.very_inflated.32k_fs_LR.surf.gii (file) [from s3-PUBLIC...]
get(ok): derivatives/ciftify/sub-01/standard_fsLR_surface/sub-01.R.white.32k_fs_LR.surf.gii (file) [from s3-PUBLIC...]
get(ok): derivatives/ciftify/sub-01/standard_fsLR_surface/sub-01.aparc.32k_fs_LR.dlabel.nii (file) [from s3-PUBLIC...]
get(ok): derivatives/ciftify/sub-01/standard_fsLR_surface/sub-01.aparc.DKTatlas.32k_fs_LR.dlabel.nii (file) [from s3-PUBLIC...]
get(ok): derivatives/ciftify/sub-01/standard_fsLR_surface/sub-01.aparc.a2009s.32k_fs_LR.dlabel.nii (file) [from s3-PUBLIC...]
get(ok): derivatives/ciftify/sub-01/standard_fsLR_surface/sub-01.curvature.32k_fs_LR.dscalar.nii (file) [from s3-PUBLIC...]
get(ok): derivatives/ciftify/sub-01/standard_fsLR_surface/sub-01.sulc.32k_fs_LR.dscalar.nii (file) [from s3-PUBLIC...]
get(ok): derivatives/ciftify/sub-01/standard_fsLR_surface/sub-01.thickness.32k_fs_LR.dscalar.nii (file) [from s3-PUBLIC...]
get(ok): derivatives/ciftify/sub-01/standard_fsLR_surface (directory)
action summary:
  get (ok: 21)
Datalad download complete for ds004496.
✅ All necessary files found. Ready for analysis.
Schaefer2018_400Par 100%[===================>] 667.06K  --.-KB/s    in 0.007s  

Surface-Based Visualization Workflow

This workflow demonstrates a surface-based approach for processing and visualizing single-subject CIFTI contrast data using niwrap and Connectome Workbench. These cifti files consist of 91,282 grayordinates: 32,492 cortical vertices per hemisphere and 26,298 subcortical voxels with approximately 2 mm spatial resolution. In this notebook we are focusing on the cortical vertices. The goal is to showcase how multi-contrast CIFTI data can be extracted, thresholded, separated by hemisphere, smoothed, and parcellated for comprehensive visualization and analysis on the cortical surface.

⚠️ Important Note: This tutorial uses niwrap, which at the time of creating this example is in early release stage. It is not recommended for production use unless you are willing to debug, fix, and contribute descriptors. Due to version compatibility issues between niwrap and different Connectome Workbench installations, some steps in this workflow fall back to direct wb_command calls where niwrap functions were not compatible with the available Workbench version.

Therefore, this example is not intended for statistical inference but serves to demonstrate how niwrap can be used alongside Connectome Workbench for surface-based processing and visualization. The selected steps highlight a practical path for extracting, thresholding, separating, and smoothing single-subject contrast data to create interpretable visual outputs:

  1. Split Maps

  2. Thresholding

  3. Surface Separation

  4. Sulcal Depth Separation

  5. Statistical Summary

  6. Surface Smoothing

  7. Parcellation

1. Split Maps

A multi-map statistical image containing 5 different contrast maps is separated into individual maps using wb_command -cifti-merge. In this example, the “Face - others” contrast (column 3) is extracted from the original multi-map CIFTI file to create a single contrast map for focused analysis and visualization.

Note: These steps use direct wb_command due to compatibility issues with the current niwrap implementation.

Character - others
Body - others
Face - others
Place - others
Object - others
Face - others

2. Thresholding a CIFTI map - cifti_math

The “Face - others” contrast map is thresholded using a data-driven approach rather than a fixed value. The 95th percentile of non-NaN values is computed and used as the threshold, retaining only the strongest contrast values while preserving their original magnitudes (rather than creating a binary mask). This approach adapts to the actual data distribution and highlights the top 5% of contrast values.

95th percentile value: 1.081139940023422
[D] Running command: wb_command -cifti-math 'x * (x > 1.081139940023422)' /home/jovyan/workspace/books/examples/functional_imaging/niwrap_results/beta_face_thresholded.dscalar.nii -var x /home/jovyan/workspace/books/examples/functional_imaging/niwrap_results/beta_face.dscalar.nii
[I] parsed 'x * (x > 1.081139940023422)' as 'x * (x > 1.08113994002342)'
[I] Executed cifti-math in 0:00:00.365303

3. Surface separation - cifti_separate

The thresholded CIFTI map is separated into left and right hemisphere GIFTI metric files. This step allows independent processing and visualization of each cortical hemisphere using standard surface templates.

[D] Running command: wb_command -cifti-separate /home/jovyan/workspace/books/examples/functional_imaging/niwrap_results/beta_face_thresholded.dscalar.nii COLUMN -metric CORTEX_LEFT /home/jovyan/workspace/books/examples/functional_imaging/niwrap_results/sub-01_thresh_lh.func.gii -metric CORTEX_RIGHT /home/jovyan/workspace/books/examples/functional_imaging/niwrap_results/sub-01_thresh_rh.func.gii
[I] Executed cifti-separate in 0:00:00.338143

4. Sulcal Depth Separation

A sulcal depth map in CIFTI format is split into left and right hemisphere GIFTI metric files. These depth maps are used as anatomical underlays to provide context for the overlaid activation maps during surface visualization.

[D] Running command: wb_command -cifti-separate /home/jovyan/workspace/books/examples/functional_imaging/ds004496/derivatives/ciftify/sub-01/standard_fsLR_surface/sub-01.sulc.32k_fs_LR.dscalar.nii COLUMN -metric CORTEX_LEFT /home/jovyan/workspace/books/examples/functional_imaging/niwrap_results/sub-01.L.sulc.func.gii -metric CORTEX_RIGHT /home/jovyan/workspace/books/examples/functional_imaging/niwrap_results/sub-01.R.sulc.func.gii
[I] Executed cifti-separate in 0:00:00.345497

Surface Plotting with Nilearn

1. Interactive Visualization with view_surf
Loading...
2. Static Visualization with plot_surf_stat_map on inflated surface with sulcal depth background
<Figure size 470x500 with 2 Axes>

5. Statistical Summary - cifti_stats

The number of non-zero vertices in the thresholded data is counted to give a basic indication of how widespread the supra-threshold signal is across the cortical surface. This helps quantify the spatial extent of the contrast effect.

[D] Running command: wb_command -cifti-stats /home/jovyan/workspace/books/examples/functional_imaging/niwrap_results/beta_face_thresholded.dscalar.nii -reduce COUNT_NONZERO -show-map-name
[I] 1:	Face - others:	2971
[I] Executed cifti-stats in 0:00:00.304578

6. Surface Smoothing - metric_smoothing

A 2mm FWHM Gaussian kernel is applied to the hemisphere-separated thresholded metric files. Smoothing is often used to improve visualization by reducing noise and enhancing spatial coherence of the surface data. Here, the smoothed data will only be plotted for comparison purposes.

[D] Running command: wb_command -metric-smoothing /home/jovyan/workspace/books/examples/functional_imaging/ds004496/derivatives/ciftify/sub-01/standard_fsLR_surface/sub-01.L.midthickness.32k_fs_LR.surf.gii /home/jovyan/workspace/books/examples/functional_imaging/niwrap_results/sub-01_thresh_lh.func.gii 2.0 /home/jovyan/workspace/books/examples/functional_imaging/niwrap_results/sub-01_thresh_smooth.L.func.gii
[I] Executed metric-smoothing in 0:00:00.930857
[D] Running command: wb_command -metric-smoothing /home/jovyan/workspace/books/examples/functional_imaging/ds004496/derivatives/ciftify/sub-01/standard_fsLR_surface/sub-01.R.midthickness.32k_fs_LR.surf.gii /home/jovyan/workspace/books/examples/functional_imaging/niwrap_results/sub-01_thresh_rh.func.gii 2.0 /home/jovyan/workspace/books/examples/functional_imaging/niwrap_results/sub-01_thresh_smooth.R.func.gii
[I] Executed metric-smoothing in 0:00:00.832373

Visualization of the smoothed map

<Figure size 470x500 with 2 Axes>

7. Parcellation

The unsmoothed thresholded CIFTI file (.dscalar.nii) is parcellated using the Schaefer 400-region, 17-network functional atlas. This parcellation process averages the surface activation values within each predefined region, transforming dense vertex-wise maps (∼64k vertices) into compact, interpretable regional summaries (400 parcels). The resulting parcellated data enables network-level analysis and region-of-interest comparisons, while the exported parcellation labels provide anatomical context for interpreting the results.

[D] Running command: wb_command -cifti-parcellate /home/jovyan/workspace/books/examples/functional_imaging/niwrap_results/beta_face_thresholded.dscalar.nii /home/jovyan/workspace/books/examples/functional_imaging/Schaefer2018_400Parcels_17Networks_order.dlabel.nii COLUMN /home/jovyan/workspace/books/examples/functional_imaging/niwrap_results/sub-01_parcellated.pscalar.nii
[I] Executed cifti-parcellate in 0:00:00.547517
[D] Running command: wb_command -cifti-label-export-table /home/jovyan/workspace/books/examples/functional_imaging/Schaefer2018_400Parcels_17Networks_order.dlabel.nii parcels /home/jovyan/workspace/books/examples/functional_imaging/niwrap_results/schaefer_labels.txt
[I] Executed cifti-label-export-table in 0:00:00.351744

Parcellated results

The parcellated results are visualized to identify regions with the strongest “Face > Others” contrast effects. First, the Schaefer atlas labels are parsed from the exported text file to create a lookup table linking parcel indices to anatomical region names and color information. The parcellated contrast values are then plotted as a bar chart showing all 400 regions. Additionally, a focused visualization displays the top 10 regions with their anatomical labels for easier interpretation of which brain areas show the strongest face-selective responses.

Get Schefer atlas labels and colors

Loading...

Load parcellated activation data

Number of parcels with positive activation: 182/400

Extract network information for visualization

Found networks: ['DorsAttnB', 'DefaultC', 'SalVentAttnB', 'VisCent', 'SomMotB', 'SalVentAttnA', 'ContB', 'SomMotA', 'ContA', 'DefaultA', 'DefaultB', 'TempPar', 'ContC', 'VisPeri', 'LimbicA', 'LimbicB', 'DorsAttnA']

Create network-colored bar plot of all parcels

<Figure size 1400x800 with 1 Axes>

Analyze and visualize top 10 face-selective Parcels

<Figure size 1400x800 with 1 Axes>

Top 10 Face-Selective Parcels:
------------------------------------------------------------
 1. 17Networks_RH_DorsAttnA_TempOcc_2        |  2.771 | DorsAttnA
 2. 17Networks_RH_VisCent_ExStr_5            |  2.302 | VisCent
 3. 17Networks_RH_DorsAttnA_ParOcc_2         |  2.202 | DorsAttnA
 4. 17Networks_RH_VisCent_ExStr_1            |  1.498 | VisCent
 5. 17Networks_LH_VisCent_ExStr_3            |  1.389 | VisCent
 6. 17Networks_LH_TempPar_4                  |  1.251 | TempPar
 7. 17Networks_LH_VisPeri_ExStrInf_3         |  1.148 | VisPeri
 8. 17Networks_LH_VisCent_ExStr_1            |  1.094 | VisCent
 9. 17Networks_RH_DorsAttnA_TempOcc_3        |  1.087 | DorsAttnA
10. 17Networks_LH_DorsAttnA_TempOcc_4        |  0.816 | DorsAttnA

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-04-09T05:56:38.954693+00:00

Python implementation: CPython
Python version       : 3.13.9
IPython version      : 9.7.0

Compiler    : GCC 14.3.0
OS          : Linux
Release     : 5.15.0-171-generic
Machine     : x86_64
Processor   : x86_64
CPU cores   : 32
Architecture: 64bit

matplotlib      : 3.10.8
nibabel         : 5.3.2
nilearn         : 0.12.0
niwrap_workbench: 0.6.1
numpy           : 2.3.5
pandas          : 2.2.3
re              : 2.2.1

Neurodesktop version: 2025-12-20
References
  1. Marcus, D. S., Harwell, J., Olsen, T., Hodge, M., Glasser, M. F., Prior, F., Jenkinson, M., Laumann, T., Curtiss, S. W., & Van Essen, D. C. (2011). Informatics and Data Mining Tools and Strategies for the Human Connectome Project. Frontiers in Neuroinformatics, 5. 10.3389/fninf.2011.00004