8.4. Computer Parcel Aggregation.

This example uses the ParcelAggregation marker to compute the mean of each parcel using the Schaefer parcellations (100 rois, 7 Yeo networks) for both 3D and 4D NIfTI.

Authors: Federico Raimondo, Synchon Mandal

License: BSD 3 clause

from junifer.testing.datagrabbers import (
    OasisVBMTestingDataGrabber,
    SPMAuditoryTestingDataGrabber,
)
from junifer.datareader import DefaultDataReader
from junifer.markers import ParcelAggregation
from junifer.utils import configure_logging

Set the logging level to info to see extra information

configure_logging(level="INFO")
2026-10-07 20:09:55 [info     ] ===== Lib Versions =====       [junifer]
2026-10-07 20:09:55 [info     ] click: 8.1.8                   [junifer]
2026-10-07 20:09:55 [info     ] numpy: 1.26.4                  [junifer]
2026-10-07 20:09:55 [info     ] scipy: 1.15.0                  [junifer]
2026-10-07 20:09:55 [info     ] datalad: 1.1.6                 [junifer]
2026-10-07 20:09:55 [info     ] pandas: 2.1.4                  [junifer]
2026-10-07 20:09:55 [info     ] nibabel: 5.3.3                 [junifer]
2026-10-07 20:09:55 [info     ] nilearn: 0.10.4                [junifer]
2026-10-07 20:09:55 [info     ] sqlalchemy: 2.1.0              [junifer]
2026-10-07 20:09:55 [info     ] ruamel.yaml: 0.18.17           [junifer]
2026-10-07 20:09:55 [info     ] tqdm: 4.66.6                   [junifer]
2026-10-07 20:09:55 [info     ] templateflow: 24.2.2           [junifer]
2026-10-07 20:09:55 [info     ] junifer_data: None             [junifer]
2026-10-07 20:09:55 [info     ] junifer: 0.0.7                 [junifer]
2026-10-07 20:09:55 [info     ] ========================       [junifer]

Perform parcel aggregation on VBM GM data (3D) from OASIS dataset

with OasisVBMTestingDataGrabber() as dg:
    # Get the first element
    element = dg.get_elements()[0]
    # Read the element
    element_data = DefaultDataReader().fit_transform(dg[element])
    # Initialize marker
    marker = ParcelAggregation(parcellation="Schaefer100x7", method="mean")
    # Compute feature
    feature = marker.fit_transform(element_data)
    # Print the output
    print(feature.keys())
    print(feature["VBM_GM"]["aggregation"]["data"].shape)  # Shape is (1 x parcels)
2026-10-07 20:09:55 [info     ] Getting element sub-01         [junifer]
2026-10-07 20:09:55 [info     ] Reading VBM_GM from /home/docker/nilearn_data/oasis1/OAS1_0001_MR1/mwrc1OAS1_0001_MR1_mpr_anon_fslswapdim_bet.nii.gz [junifer]
2026-10-07 20:09:55 [info     ] VBM_GM is of type NIFTI        [junifer]
2026-10-07 20:09:55 [info     ] Computing VBM_GM               [junifer]
2026-10-07 20:09:55 [info     ] Parcellation will be warped from MNI152NLin6Asym to MNI152Lin using highest resolution [junifer]
2026-10-07 20:09:55 [info     ] Parcellation parameters:       [junifer]
2026-10-07 20:09:55 [info     ]         resolution: None              [junifer]
2026-10-07 20:09:55 [info     ]         n_rois: 100                   [junifer]
2026-10-07 20:09:55 [info     ]         yeo_networks: 7               [junifer]
2026-10-07 20:09:55 [info     ] Resolution set to None, using highest resolution. [junifer]
2026-10-07 20:09:56 [info     ] Loading parcellation: /home/docker/junifer_data/v7/parcellations/Schaefer2018/Yeo2011/Schaefer2018_100Parcels_7Networks_order_FSLMNI152_1mm.nii.gz [junifer]
2026-10-07 20:10:02 [info     ] Downloading template MNI152Lin (T1w in resolution 1) [junifer]
2026-10-07 20:10:03 [info     ] antsApplyTransforms command to be executed:
antsApplyTransforms -d 3 -e 3 -n 'GenericLabel[NearestNeighbor]' -i /tmp/junifer/tmpj4k0plxs/ants_parcellation_warper_Schaefer100x7_from_MNI152NLin6Asym_to_MNI152Lin_10f36668-c28b-11f1-9c61-c662fa6c424381mxio9x/prewarp_parcellation.nii.gz -r /tmp/junifer/tmpj4k0plxs/ants_parcellation_warper_Schaefer100x7_from_MNI152NLin6Asym_to_MNI152Lin_10f36668-c28b-11f1-9c61-c662fa6c424381mxio9x/MNI152Lin_T1w.nii.gz -t /home/docker/junifer_data/v7/.git/annex/objects/JQ/Pp/SHA256E-s145422752--5091350b36f951d455dabd429ebe86c493c75a0217dca311ae355f1d62e080b0.h5/SHA256E-s145422752--5091350b36f951d455dabd429ebe86c493c75a0217dca311ae355f1d62e080b0.h5 -o /tmp/junifer/tmpj4k0plxs/ants_parcellation_warper_Schaefer100x7_from_MNI152NLin6Asym_to_MNI152Lin_10f36668-c28b-11f1-9c61-c662fa6c424381mxio9x/parcellation_warped.nii.gz [junifer]
2026-10-07 20:10:21 [info     ] antsApplyTransforms command succeeded with the following output:
 [junifer]
2026-10-07 20:10:24 [info     ] No storage specified, returning dictionary [junifer]
dict_keys(['VBM_GM'])
(1, 100)

Perform parcel aggregation on BOLD data (4D) from SPM Auditory dataset

with SPMAuditoryTestingDataGrabber() as dg:
    # Get the first element
    element = dg.get_elements()[0]
    # Read the element
    element_data = DefaultDataReader().fit_transform(dg[element])
    # Initialize marker
    marker = ParcelAggregation(
        parcellation="Schaefer100x7", method="mean", on="BOLD"
    )
    # Compute feature
    feature = marker.fit_transform(element_data)
    # Print the output
    print(feature.keys())
    print(feature["BOLD"]["aggregation"]["data"].shape)  # Shape is (timepoints x parcels)
2026-10-07 20:10:24 [info     ] Getting element sub001         [junifer]
2026-10-07 20:10:28 [info     ] Reading BOLD from /tmp/tmpulptoot9/sub001_bold.nii.gz [junifer]
2026-10-07 20:10:28 [info     ] BOLD is of type NIFTI          [junifer]
2026-10-07 20:10:28 [info     ] Reading T1w from /tmp/tmpulptoot9/sub001_T1w.nii.gz [junifer]
2026-10-07 20:10:28 [info     ] T1w is of type NIFTI           [junifer]
2026-10-07 20:10:28 [info     ] Computing BOLD                 [junifer]
2026-10-07 20:10:28 [info     ] Parcellation will be warped from MNI152NLin6Asym to MNI152Lin using highest resolution [junifer]
2026-10-07 20:10:28 [info     ] Parcellation parameters:       [junifer]
2026-10-07 20:10:28 [info     ]         resolution: None              [junifer]
2026-10-07 20:10:28 [info     ]         n_rois: 100                   [junifer]
2026-10-07 20:10:28 [info     ]         yeo_networks: 7               [junifer]
2026-10-07 20:10:28 [info     ] Resolution set to None, using highest resolution. [junifer]
2026-10-07 20:10:29 [info     ] Loading parcellation: /home/docker/junifer_data/v7/parcellations/Schaefer2018/Yeo2011/Schaefer2018_100Parcels_7Networks_order_FSLMNI152_1mm.nii.gz [junifer]
2026-10-07 20:10:34 [info     ] Downloading template MNI152Lin (T1w in resolution 1) [junifer]
2026-10-07 20:10:35 [info     ] antsApplyTransforms command to be executed:
antsApplyTransforms -d 3 -e 3 -n 'GenericLabel[NearestNeighbor]' -i /tmp/junifer/tmpj4k0plxs/ants_parcellation_warper_Schaefer100x7_from_MNI152NLin6Asym_to_MNI152Lin_249e7b9e-c28b-11f1-9c61-c662fa6c4243iy74en8k/prewarp_parcellation.nii.gz -r /tmp/junifer/tmpj4k0plxs/ants_parcellation_warper_Schaefer100x7_from_MNI152NLin6Asym_to_MNI152Lin_249e7b9e-c28b-11f1-9c61-c662fa6c4243iy74en8k/MNI152Lin_T1w.nii.gz -t /home/docker/junifer_data/v7/.git/annex/objects/JQ/Pp/SHA256E-s145422752--5091350b36f951d455dabd429ebe86c493c75a0217dca311ae355f1d62e080b0.h5/SHA256E-s145422752--5091350b36f951d455dabd429ebe86c493c75a0217dca311ae355f1d62e080b0.h5 -o /tmp/junifer/tmpj4k0plxs/ants_parcellation_warper_Schaefer100x7_from_MNI152NLin6Asym_to_MNI152Lin_249e7b9e-c28b-11f1-9c61-c662fa6c4243iy74en8k/parcellation_warped.nii.gz [junifer]
2026-10-07 20:10:50 [info     ] antsApplyTransforms command succeeded with the following output:
 [junifer]
2026-10-07 20:11:00 [info     ] No storage specified, returning dictionary [junifer]
dict_keys(['BOLD'])
(96, 100)

Total running time of the script: (1 minutes 4.528 seconds)

Gallery generated by Sphinx-Gallery