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")
2025-11-07 13:19:42 [info     ] ===== Lib Versions =====       [junifer]
2025-11-07 13:19:42 [info     ] click: 8.1.8                   [junifer]
2025-11-07 13:19:42 [info     ] numpy: 1.26.4                  [junifer]
2025-11-07 13:19:42 [info     ] scipy: 1.16.3                  [junifer]
2025-11-07 13:19:42 [info     ] datalad: 1.1.6                 [junifer]
2025-11-07 13:19:42 [info     ] pandas: 2.1.4                  [junifer]
2025-11-07 13:19:42 [info     ] nibabel: 5.3.2                 [junifer]
2025-11-07 13:19:42 [info     ] nilearn: 0.10.4                [junifer]
2025-11-07 13:19:42 [info     ] sqlalchemy: 2.0.44             [junifer]
2025-11-07 13:19:42 [info     ] ruamel.yaml: 0.18.16           [junifer]
2025-11-07 13:19:42 [info     ] tqdm: 4.67.1                   [junifer]
2025-11-07 13:19:42 [info     ] templateflow: 24.2.2           [junifer]
2025-11-07 13:19:42 [info     ] junifer_data: None             [junifer]
2025-11-07 13:19:42 [info     ] junifer: 0.0.7.dev259          [junifer]
2025-11-07 13:19:42 [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)
2025-11-07 13:19:42 [info     ] Getting element sub-01         [junifer]
2025-11-07 13:19:42 [info     ] Reading VBM_GM from /github/home/nilearn_data/oasis1/OAS1_0001_MR1/mwrc1OAS1_0001_MR1_mpr_anon_fslswapdim_bet.nii.gz [junifer]
2025-11-07 13:19:42 [info     ] VBM_GM is of type NIFTI        [junifer]
2025-11-07 13:19:42 [info     ] Computing VBM_GM               [junifer]
2025-11-07 13:19:42 [info     ] Parcellation will be warped from MNI152NLin6Asym to MNI152Lin using highest resolution [junifer]
2025-11-07 13:19:42 [info     ] Parcellation parameters:       [junifer]
2025-11-07 13:19:42 [info     ]         resolution: None              [junifer]
2025-11-07 13:19:42 [info     ]         n_rois: 100                   [junifer]
2025-11-07 13:19:42 [info     ]         yeo_networks: 7               [junifer]
2025-11-07 13:19:42 [info     ] Resolution set to None, using highest resolution. [junifer]
2025-11-07 13:19:42 [info     ] Start annex operation          [datalad.annex] dlm_progress=annexprogress-139803712501184 dlm_progress_label=Total dlm_progress_noninteractive_level=5 dlm_progress_total=233605 dlm_progress_unit=' Bytes'
2025-11-07 13:19:43 [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-139803712501184--604475539370811862 dlm_progress_label='Get parcella .. 2_1mm.nii.gz' dlm_progress_noninteractive_level=5 dlm_progress_total=233605.0 dlm_progress_unit=' Bytes'
2025-11-07 13:19:43 [info     ] 14.03%                         [datalad.annex] dlm_progress=annexprogress-139803712501184--604475539370811862 dlm_progress_noninteractive_level=5 dlm_progress_update=32768.0
2025-11-07 13:19:44 [info     ] 98.19%                         [datalad.annex] dlm_progress=annexprogress-139803712501184--604475539370811862 dlm_progress_noninteractive_level=5 dlm_progress_update=229376.0
2025-11-07 13:19:44 [info     ] Finished annex action: None    [datalad.annex] dlm_progress=annexprogress-139803712501184--604475539370811862 dlm_progress_noninteractive_level=5
2025-11-07 13:19:44 [info     ] Finished annex get             [datalad.annex] dlm_progress=annexprogress-139803712501184 dlm_progress_noninteractive_level=5
2025-11-07 13:19:44 [info     ] Loading parcellation: /github/home/junifer_data/v5/parcellations/Schaefer2018/Yeo2011/Schaefer2018_100Parcels_7Networks_order_FSLMNI152_1mm.nii.gz [junifer]
2025-11-07 13:19:47 [info     ] Downloading template MNI152Lin (T1w in resolution 1) [junifer]
2025-11-07 13:19:47 [info     ] antsApplyTransforms command to be executed:
antsApplyTransforms -d 3 -e 3 -n 'GenericLabel[NearestNeighbor]' -i /tmp/junifer/tmpoz1fonrh/ants_parcellation_warper_Schaefer100x7_from_MNI152NLin6Asym_to_MNI152Lin_6d65af84-bbdc-11f0-88c6-e6459467a3c0obr1ofwm/prewarp_parcellation.nii.gz -r /tmp/junifer/tmpoz1fonrh/ants_parcellation_warper_Schaefer100x7_from_MNI152NLin6Asym_to_MNI152Lin_6d65af84-bbdc-11f0-88c6-e6459467a3c0obr1ofwm/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/tmpoz1fonrh/ants_parcellation_warper_Schaefer100x7_from_MNI152NLin6Asym_to_MNI152Lin_6d65af84-bbdc-11f0-88c6-e6459467a3c0obr1ofwm/parcellation_warped.nii.gz [junifer]
2025-11-07 13:19:54 [info     ] antsApplyTransforms command succeeded with the following output:
 [junifer]
2025-11-07 13:19:55 [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)
2025-11-07 13:19:55 [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 3104768 of 34212021 bytes (9.1%,   10.1s remaining)
Downloaded 8691712 of 34212021 bytes (25.4%,    6.0s remaining)
Downloaded 13500416 of 34212021 bytes (39.5%,    4.7s remaining)
Downloaded 18104320 of 34212021 bytes (52.9%,    3.6s remaining)
Downloaded 22904832 of 34212021 bytes (66.9%,    2.5s remaining)
Downloaded 27820032 of 34212021 bytes (81.3%,    1.4s remaining)
Downloaded 32768000 of 34212021 bytes (95.8%,    0.3s remaining) ...done. (8 seconds, 0 min)
Extracting data from /github/home/nilearn_data/spm_auditory/sub001/MoAEpilot.zip..... done.
2025-11-07 13:20:06 [info     ] Reading BOLD from /tmp/tmpa4u3hu6r/sub001_bold.nii.gz [junifer]
2025-11-07 13:20:06 [info     ] BOLD is of type NIFTI          [junifer]
2025-11-07 13:20:06 [info     ] Reading T1w from /tmp/tmpa4u3hu6r/sub001_T1w.nii.gz [junifer]
2025-11-07 13:20:06 [info     ] T1w is of type NIFTI           [junifer]
2025-11-07 13:20:06 [info     ] Computing BOLD                 [junifer]
2025-11-07 13:20:06 [info     ] Parcellation will be warped from MNI152NLin6Asym to MNI152Lin using highest resolution [junifer]
2025-11-07 13:20:06 [info     ] Parcellation parameters:       [junifer]
2025-11-07 13:20:06 [info     ]         resolution: None              [junifer]
2025-11-07 13:20:06 [info     ]         n_rois: 100                   [junifer]
2025-11-07 13:20:06 [info     ]         yeo_networks: 7               [junifer]
2025-11-07 13:20:06 [info     ] Resolution set to None, using highest resolution. [junifer]
2025-11-07 13:20:06 [info     ] Loading parcellation: /github/home/junifer_data/v5/parcellations/Schaefer2018/Yeo2011/Schaefer2018_100Parcels_7Networks_order_FSLMNI152_1mm.nii.gz [junifer]
2025-11-07 13:20:09 [info     ] Downloading template MNI152Lin (T1w in resolution 1) [junifer]
2025-11-07 13:20:09 [info     ] antsApplyTransforms command to be executed:
antsApplyTransforms -d 3 -e 3 -n 'GenericLabel[NearestNeighbor]' -i /tmp/junifer/tmpoz1fonrh/ants_parcellation_warper_Schaefer100x7_from_MNI152NLin6Asym_to_MNI152Lin_7a7c8af8-bbdc-11f0-88c6-e6459467a3c0pwwi2ojb/prewarp_parcellation.nii.gz -r /tmp/junifer/tmpoz1fonrh/ants_parcellation_warper_Schaefer100x7_from_MNI152NLin6Asym_to_MNI152Lin_7a7c8af8-bbdc-11f0-88c6-e6459467a3c0pwwi2ojb/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/tmpoz1fonrh/ants_parcellation_warper_Schaefer100x7_from_MNI152NLin6Asym_to_MNI152Lin_7a7c8af8-bbdc-11f0-88c6-e6459467a3c0pwwi2ojb/parcellation_warped.nii.gz [junifer]
2025-11-07 13:20:16 [info     ] antsApplyTransforms command succeeded with the following output:
 [junifer]
2025-11-07 13:20:19 [info     ] No storage specified, returning dictionary [junifer]
dict_keys(['BOLD'])
(96, 100)

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

Gallery generated by Sphinx-Gallery