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-01-29 12:40:33 [info     ] ===== Lib Versions =====       [junifer]
2026-01-29 12:40:33 [info     ] click: 8.1.8                   [junifer]
2026-01-29 12:40:33 [info     ] numpy: 1.26.4                  [junifer]
2026-01-29 12:40:33 [info     ] scipy: 1.15.0                  [junifer]
2026-01-29 12:40:33 [info     ] datalad: 1.1.6                 [junifer]
2026-01-29 12:40:33 [info     ] pandas: 2.1.4                  [junifer]
2026-01-29 12:40:33 [info     ] nibabel: 5.3.3                 [junifer]
2026-01-29 12:40:33 [info     ] nilearn: 0.10.4                [junifer]
2026-01-29 12:40:33 [info     ] sqlalchemy: 2.0.46             [junifer]
2026-01-29 12:40:33 [info     ] ruamel.yaml: 0.18.17           [junifer]
2026-01-29 12:40:33 [info     ] tqdm: 4.66.6                   [junifer]
2026-01-29 12:40:33 [info     ] templateflow: 24.2.2           [junifer]
2026-01-29 12:40:33 [info     ] junifer_data: None             [junifer]
2026-01-29 12:40:33 [info     ] junifer: 0.0.7.dev310          [junifer]
2026-01-29 12:40:33 [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-01-29 12:40:33 [info     ] Getting element sub-01         [junifer]
2026-01-29 12:40:33 [info     ] Reading VBM_GM from /github/home/nilearn_data/oasis1/OAS1_0001_MR1/mwrc1OAS1_0001_MR1_mpr_anon_fslswapdim_bet.nii.gz [junifer]
2026-01-29 12:40:33 [info     ] VBM_GM is of type NIFTI        [junifer]
2026-01-29 12:40:33 [info     ] Computing VBM_GM               [junifer]
2026-01-29 12:40:33 [info     ] Parcellation will be warped from MNI152NLin6Asym to MNI152Lin using highest resolution [junifer]
2026-01-29 12:40:33 [info     ] Parcellation parameters:       [junifer]
2026-01-29 12:40:33 [info     ]         resolution: None              [junifer]
2026-01-29 12:40:33 [info     ]         n_rois: 100                   [junifer]
2026-01-29 12:40:33 [info     ]         yeo_networks: 7               [junifer]
2026-01-29 12:40:33 [info     ] Resolution set to None, using highest resolution. [junifer]
2026-01-29 12:40:33 [info     ] Start annex operation          [datalad.annex] dlm_progress=annexprogress-139808610960928 dlm_progress_label=Total dlm_progress_noninteractive_level=5 dlm_progress_total=233605 dlm_progress_unit=' Bytes'
2026-01-29 12:40:34 [info     ] Start annex action: {'command': 'get', 'file': 'parcellations/Schaefer2018/Yeo2011/Schaefer2018_100Parcels_7Networks_order_FSLMNI152_1mm.nii.gz', 'input': ['parcellations/Schaefer2018/Yeo2011/Schaefer2018_100Parcels_7Networks_order_FSLMNI152_1mm.nii.gz'], 'key': 'MD5E-s233605--0709e73f84a0cd60687ff4add7f8fd05.nii.gz', 'note': 'from gin-src...'} [datalad.annex] dlm_progress=annexprogress-139808610960928--3636483356103479566 dlm_progress_label='Get parcella .. 2_1mm.nii.gz' dlm_progress_noninteractive_level=5 dlm_progress_total=233605.0 dlm_progress_unit=' Bytes'
2026-01-29 12:40:34 [info     ] 38.57%                         [datalad.annex] dlm_progress=annexprogress-139808610960928--3636483356103479566 dlm_progress_noninteractive_level=5 dlm_progress_update=90112.0
2026-01-29 12:40:35 [info     ] Finished annex action: None    [datalad.annex] dlm_progress=annexprogress-139808610960928--3636483356103479566 dlm_progress_noninteractive_level=5
2026-01-29 12:40:35 [info     ] Finished annex get             [datalad.annex] dlm_progress=annexprogress-139808610960928 dlm_progress_noninteractive_level=5
2026-01-29 12:40:35 [info     ] Loading parcellation: /github/home/junifer_data/v5/parcellations/Schaefer2018/Yeo2011/Schaefer2018_100Parcels_7Networks_order_FSLMNI152_1mm.nii.gz [junifer]
2026-01-29 12:40:37 [info     ] Downloading template MNI152Lin (T1w in resolution 1) [junifer]
2026-01-29 12:40:37 [info     ] antsApplyTransforms command to be executed:
antsApplyTransforms -d 3 -e 3 -n 'GenericLabel[NearestNeighbor]' -i /tmp/junifer/tmpxx0_ayke/ants_parcellation_warper_Schaefer100x7_from_MNI152NLin6Asym_to_MNI152Lin_b522f998-fd0f-11f0-9821-7a325534a278ym5vlv52/prewarp_parcellation.nii.gz -r /tmp/junifer/tmpxx0_ayke/ants_parcellation_warper_Schaefer100x7_from_MNI152NLin6Asym_to_MNI152Lin_b522f998-fd0f-11f0-9821-7a325534a278ym5vlv52/MNI152Lin_T1w.nii.gz -t /github/home/junifer_data/v5/.git/annex/objects/JQ/Pp/SHA256E-s145422752--5091350b36f951d455dabd429ebe86c493c75a0217dca311ae355f1d62e080b0.h5/SHA256E-s145422752--5091350b36f951d455dabd429ebe86c493c75a0217dca311ae355f1d62e080b0.h5 -o /tmp/junifer/tmpxx0_ayke/ants_parcellation_warper_Schaefer100x7_from_MNI152NLin6Asym_to_MNI152Lin_b522f998-fd0f-11f0-9821-7a325534a278ym5vlv52/parcellation_warped.nii.gz [junifer]
2026-01-29 12:40:44 [info     ] antsApplyTransforms command succeeded with the following output:
 [junifer]
2026-01-29 12:40:45 [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-01-29 12:40:45 [info     ] Getting element sub001         [junifer]

Dataset created in /github/home/nilearn_data/spm_auditory

Data absent, downloading...
Downloading data from https://www.fil.ion.ucl.ac.uk/spm/download/data/MoAEpilot/MoAEpilot.zip ...

Downloaded 4521984 of 34212021 bytes (13.2%,    7.0s remaining)
Downloaded 9297920 of 34212021 bytes (27.2%,    5.5s remaining)
Downloaded 14401536 of 34212021 bytes (42.1%,    4.2s remaining)
Downloaded 19111936 of 34212021 bytes (55.9%,    3.2s remaining)
Downloaded 24207360 of 34212021 bytes (70.8%,    2.1s remaining)
Downloaded 29130752 of 34212021 bytes (85.1%,    1.1s remaining) ...done. (8 seconds, 0 min)
Extracting data from /github/home/nilearn_data/spm_auditory/sub001/MoAEpilot.zip..... done.
2026-01-29 12:40:56 [info     ] Reading BOLD from /tmp/tmp570v4z8o/sub001_bold.nii.gz [junifer]
2026-01-29 12:40:56 [info     ] BOLD is of type NIFTI          [junifer]
2026-01-29 12:40:56 [info     ] Reading T1w from /tmp/tmp570v4z8o/sub001_T1w.nii.gz [junifer]
2026-01-29 12:40:56 [info     ] T1w is of type NIFTI           [junifer]
2026-01-29 12:40:56 [info     ] Computing BOLD                 [junifer]
2026-01-29 12:40:56 [info     ] Parcellation will be warped from MNI152NLin6Asym to MNI152Lin using highest resolution [junifer]
2026-01-29 12:40:56 [info     ] Parcellation parameters:       [junifer]
2026-01-29 12:40:56 [info     ]         resolution: None              [junifer]
2026-01-29 12:40:56 [info     ]         n_rois: 100                   [junifer]
2026-01-29 12:40:56 [info     ]         yeo_networks: 7               [junifer]
2026-01-29 12:40:56 [info     ] Resolution set to None, using highest resolution. [junifer]
2026-01-29 12:40:56 [info     ] Loading parcellation: /github/home/junifer_data/v5/parcellations/Schaefer2018/Yeo2011/Schaefer2018_100Parcels_7Networks_order_FSLMNI152_1mm.nii.gz [junifer]
2026-01-29 12:40:59 [info     ] Downloading template MNI152Lin (T1w in resolution 1) [junifer]
2026-01-29 12:40:59 [info     ] antsApplyTransforms command to be executed:
antsApplyTransforms -d 3 -e 3 -n 'GenericLabel[NearestNeighbor]' -i /tmp/junifer/tmpxx0_ayke/ants_parcellation_warper_Schaefer100x7_from_MNI152NLin6Asym_to_MNI152Lin_c217c7e6-fd0f-11f0-9821-7a325534a27847xv1fyu/prewarp_parcellation.nii.gz -r /tmp/junifer/tmpxx0_ayke/ants_parcellation_warper_Schaefer100x7_from_MNI152NLin6Asym_to_MNI152Lin_c217c7e6-fd0f-11f0-9821-7a325534a27847xv1fyu/MNI152Lin_T1w.nii.gz -t /github/home/junifer_data/v5/.git/annex/objects/JQ/Pp/SHA256E-s145422752--5091350b36f951d455dabd429ebe86c493c75a0217dca311ae355f1d62e080b0.h5/SHA256E-s145422752--5091350b36f951d455dabd429ebe86c493c75a0217dca311ae355f1d62e080b0.h5 -o /tmp/junifer/tmpxx0_ayke/ants_parcellation_warper_Schaefer100x7_from_MNI152NLin6Asym_to_MNI152Lin_c217c7e6-fd0f-11f0-9821-7a325534a27847xv1fyu/parcellation_warped.nii.gz [junifer]
2026-01-29 12:41:05 [info     ] antsApplyTransforms command succeeded with the following output:
 [junifer]
2026-01-29 12:41:08 [info     ] No storage specified, returning dictionary [junifer]
dict_keys(['BOLD'])
(96, 100)

Total running time of the script: (0 minutes 35.214 seconds)

Gallery generated by Sphinx-Gallery