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-26 08:41:14,662 - JUNIFER - INFO - ===== Lib Versions =====
2025-11-26 08:41:14,662 - JUNIFER - INFO - numpy: 1.26.4
2025-11-26 08:41:14,662 - JUNIFER - INFO - scipy: 1.15.0
2025-11-26 08:41:14,662 - JUNIFER - INFO - pandas: 2.1.4
2025-11-26 08:41:14,662 - JUNIFER - INFO - nilearn: 0.10.4
2025-11-26 08:41:14,662 - JUNIFER - INFO - nibabel: 5.3.2
2025-11-26 08:41:14,662 - JUNIFER - INFO - junifer: 0.0.6
2025-11-26 08:41:14,662 - JUNIFER - INFO - ========================

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-26 08:41:14,671 - JUNIFER - INFO - Getting element sub-01
2025-11-26 08:41:14,671 - JUNIFER - INFO - Reading VBM_GM from /home/synchon/nilearn_data/oasis1/OAS1_0001_MR1/mwrc1OAS1_0001_MR1_mpr_anon_fslswapdim_bet.nii.gz
2025-11-26 08:41:14,671 - JUNIFER - INFO - VBM_GM is of type NIFTI
2025-11-26 08:41:14,673 - JUNIFER - INFO - Computing VBM_GM
2025-11-26 08:41:14,673 - JUNIFER - INFO - Parcellation will be warped from MNI152NLin6Asym to MNI152Lin using highest resolution
2025-11-26 08:41:14,673 - JUNIFER - INFO - Parcellation parameters:
2025-11-26 08:41:14,673 - JUNIFER - INFO -      resolution: None
2025-11-26 08:41:14,673 - JUNIFER - INFO -      n_rois: 100
2025-11-26 08:41:14,673 - JUNIFER - INFO -      yeo_networks: 7
2025-11-26 08:41:14,673 - JUNIFER - INFO - Resolution set to None, using highest resolution.
2025-11-26 08:41:14,900 - JUNIFER - INFO - Loading parcellation: /home/synchon/junifer_data/v2/parcellations/Schaefer2018/Yeo2011/Schaefer2018_100Parcels_7Networks_order_FSLMNI152_1mm.nii.gz
2025-11-26 08:41:16,692 - JUNIFER - INFO - Downloading template MNI152Lin (T1w in resolution 1)
2025-11-26 08:41:17,782 - JUNIFER - INFO - antsApplyTransforms command to be executed:
antsApplyTransforms -d 3 -e 3 -n 'GenericLabel[NearestNeighbor]' -i /tmp/junifer/tmp1g0ya1u3/ants_parcellation_warper_Schaefer100x7_from_MNI152NLin6Asym_to_MNI152Lin_4990aaf0-ca9b-11f0-a076-ebd5e38fbbd31c0vhmjl/prewarp_parcellation.nii.gz -r /tmp/junifer/tmp1g0ya1u3/ants_parcellation_warper_Schaefer100x7_from_MNI152NLin6Asym_to_MNI152Lin_4990aaf0-ca9b-11f0-a076-ebd5e38fbbd31c0vhmjl/MNI152Lin_T1w.nii.gz -t /home/synchon/junifer_data/v2/.git/annex/objects/JQ/Pp/SHA256E-s145422752--5091350b36f951d455dabd429ebe86c493c75a0217dca311ae355f1d62e080b0.h5/SHA256E-s145422752--5091350b36f951d455dabd429ebe86c493c75a0217dca311ae355f1d62e080b0.h5 -o /tmp/junifer/tmp1g0ya1u3/ants_parcellation_warper_Schaefer100x7_from_MNI152NLin6Asym_to_MNI152Lin_4990aaf0-ca9b-11f0-a076-ebd5e38fbbd31c0vhmjl/parcellation_warped.nii.gz
2025-11-26 08:41:23,023 - JUNIFER - INFO - antsApplyTransforms command succeeded with the following output:
/tmp/junifer/tmp1g0ya1u3/ants_parcellation_warper_Schaefer100x7_from_MNI152NLin6Asym_to_MNI152Lin_4990aaf0-ca9b-11f0-a076-ebd5e38fbbd31c0vhmjl/prewarp_parcellation.nii.gz is a file
/tmp/junifer/tmp1g0ya1u3/ants_parcellation_warper_Schaefer100x7_from_MNI152NLin6Asym_to_MNI152Lin_4990aaf0-ca9b-11f0-a076-ebd5e38fbbd31c0vhmjl/MNI152Lin_T1w.nii.gz is a file
/home/synchon/junifer_data/v2/.git/annex/objects/JQ/Pp/SHA256E-s145422752--5091350b36f951d455dabd429ebe86c493c75a0217dca311ae355f1d62e080b0.h5/SHA256E-s145422752--5091350b36f951d455dabd429ebe86c493c75a0217dca311ae355f1d62e080b0.h5 is a file
/tmp/junifer/tmp1g0ya1u3/ants_parcellation_warper_Schaefer100x7_from_MNI152NLin6Asym_to_MNI152Lin_4990aaf0-ca9b-11f0-a076-ebd5e38fbbd31c0vhmjl/parcellation_warped.nii.gz is a prefix
Singularity args: --bind /tmp/junifer/tmp1g0ya1u3/ants_parcellation_warper_Schaefer100x7_from_MNI152NLin6Asym_to_MNI152Lin_4990aaf0-ca9b-11f0-a076-ebd5e38fbbd31c0vhmjl:/data/mount_1 --bind /tmp/junifer/tmp1g0ya1u3/ants_parcellation_warper_Schaefer100x7_from_MNI152NLin6Asym_to_MNI152Lin_4990aaf0-ca9b-11f0-a076-ebd5e38fbbd31c0vhmjl:/data/mount_2 --bind /home/synchon/junifer_data/v2/.git/annex/objects/JQ/Pp/SHA256E-s145422752--5091350b36f951d455dabd429ebe86c493c75a0217dca311ae355f1d62e080b0.h5:/data/mount_3 --bind /tmp/junifer/tmp1g0ya1u3/ants_parcellation_warper_Schaefer100x7_from_MNI152NLin6Asym_to_MNI152Lin_4990aaf0-ca9b-11f0-a076-ebd5e38fbbd31c0vhmjl:/data/mount_4
Corrected args for ANTS: antsApplyTransforms -d 3 -e 3 -n GenericLabel[NearestNeighbor] -i /data/mount_1/prewarp_parcellation.nii.gz -r /data/mount_2/MNI152Lin_T1w.nii.gz -t /data/mount_3/SHA256E-s145422752--5091350b36f951d455dabd429ebe86c493c75a0217dca311ae355f1d62e080b0.h5 -o /data/mount_4/parcellation_warped.nii.gz
Running command: /data/group/appliedml/tools/ants_2.5.0/singularity_cmd exec --cleanenv --bind /tmp/junifer/tmp1g0ya1u3/ants_parcellation_warper_Schaefer100x7_from_MNI152NLin6Asym_to_MNI152Lin_4990aaf0-ca9b-11f0-a076-ebd5e38fbbd31c0vhmjl:/data/mount_1 --bind /tmp/junifer/tmp1g0ya1u3/ants_parcellation_warper_Schaefer100x7_from_MNI152NLin6Asym_to_MNI152Lin_4990aaf0-ca9b-11f0-a076-ebd5e38fbbd31c0vhmjl:/data/mount_2 --bind /home/synchon/junifer_data/v2/.git/annex/objects/JQ/Pp/SHA256E-s145422752--5091350b36f951d455dabd429ebe86c493c75a0217dca311ae355f1d62e080b0.h5:/data/mount_3 --bind /tmp/junifer/tmp1g0ya1u3/ants_parcellation_warper_Schaefer100x7_from_MNI152NLin6Asym_to_MNI152Lin_4990aaf0-ca9b-11f0-a076-ebd5e38fbbd31c0vhmjl:/data/mount_4 /data/group/appliedml/tools/ants_2.5.0/ants_v2.5.0.sif antsApplyTransforms -d 3 -e 3 -n GenericLabel[NearestNeighbor] -i /data/mount_1/prewarp_parcellation.nii.gz -r /data/mount_2/MNI152Lin_T1w.nii.gz -t /data/mount_3/SHA256E-s145422752--5091350b36f951d455dabd429ebe86c493c75a0217dca311ae355f1d62e080b0.h5 -o /data/mount_4/parcellation_warped.nii.gz

2025-11-26 08:41:24,256 - JUNIFER - INFO - No storage specified, returning dictionary
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-26 08:41:24,257 - JUNIFER - INFO - Getting element sub001
2025-11-26 08:41:28,860 - JUNIFER - INFO - Reading BOLD from /tmp/tmp_k3iw8p8/sub001_bold.nii.gz
2025-11-26 08:41:28,860 - JUNIFER - INFO - BOLD is of type NIFTI
2025-11-26 08:41:28,861 - JUNIFER - INFO - Reading T1w from /tmp/tmp_k3iw8p8/sub001_T1w.nii.gz
2025-11-26 08:41:28,861 - JUNIFER - INFO - T1w is of type NIFTI
2025-11-26 08:41:28,862 - JUNIFER - INFO - Computing BOLD
2025-11-26 08:41:28,862 - JUNIFER - INFO - Parcellation will be warped from MNI152NLin6Asym to MNI152Lin using highest resolution
2025-11-26 08:41:28,862 - JUNIFER - INFO - Parcellation parameters:
2025-11-26 08:41:28,862 - JUNIFER - INFO -      resolution: None
2025-11-26 08:41:28,862 - JUNIFER - INFO -      n_rois: 100
2025-11-26 08:41:28,862 - JUNIFER - INFO -      yeo_networks: 7
2025-11-26 08:41:28,862 - JUNIFER - INFO - Resolution set to None, using highest resolution.
2025-11-26 08:41:28,992 - JUNIFER - INFO - Loading parcellation: /home/synchon/junifer_data/v2/parcellations/Schaefer2018/Yeo2011/Schaefer2018_100Parcels_7Networks_order_FSLMNI152_1mm.nii.gz
2025-11-26 08:41:30,785 - JUNIFER - INFO - Downloading template MNI152Lin (T1w in resolution 1)
2025-11-26 08:41:31,885 - JUNIFER - INFO - antsApplyTransforms command to be executed:
antsApplyTransforms -d 3 -e 3 -n 'GenericLabel[NearestNeighbor]' -i /tmp/junifer/tmp1g0ya1u3/ants_parcellation_warper_Schaefer100x7_from_MNI152NLin6Asym_to_MNI152Lin_51f6b6da-ca9b-11f0-a076-ebd5e38fbbd3a79eo9e_/prewarp_parcellation.nii.gz -r /tmp/junifer/tmp1g0ya1u3/ants_parcellation_warper_Schaefer100x7_from_MNI152NLin6Asym_to_MNI152Lin_51f6b6da-ca9b-11f0-a076-ebd5e38fbbd3a79eo9e_/MNI152Lin_T1w.nii.gz -t /home/synchon/junifer_data/v2/.git/annex/objects/JQ/Pp/SHA256E-s145422752--5091350b36f951d455dabd429ebe86c493c75a0217dca311ae355f1d62e080b0.h5/SHA256E-s145422752--5091350b36f951d455dabd429ebe86c493c75a0217dca311ae355f1d62e080b0.h5 -o /tmp/junifer/tmp1g0ya1u3/ants_parcellation_warper_Schaefer100x7_from_MNI152NLin6Asym_to_MNI152Lin_51f6b6da-ca9b-11f0-a076-ebd5e38fbbd3a79eo9e_/parcellation_warped.nii.gz
2025-11-26 08:41:37,143 - JUNIFER - INFO - antsApplyTransforms command succeeded with the following output:
/tmp/junifer/tmp1g0ya1u3/ants_parcellation_warper_Schaefer100x7_from_MNI152NLin6Asym_to_MNI152Lin_51f6b6da-ca9b-11f0-a076-ebd5e38fbbd3a79eo9e_/prewarp_parcellation.nii.gz is a file
/tmp/junifer/tmp1g0ya1u3/ants_parcellation_warper_Schaefer100x7_from_MNI152NLin6Asym_to_MNI152Lin_51f6b6da-ca9b-11f0-a076-ebd5e38fbbd3a79eo9e_/MNI152Lin_T1w.nii.gz is a file
/home/synchon/junifer_data/v2/.git/annex/objects/JQ/Pp/SHA256E-s145422752--5091350b36f951d455dabd429ebe86c493c75a0217dca311ae355f1d62e080b0.h5/SHA256E-s145422752--5091350b36f951d455dabd429ebe86c493c75a0217dca311ae355f1d62e080b0.h5 is a file
/tmp/junifer/tmp1g0ya1u3/ants_parcellation_warper_Schaefer100x7_from_MNI152NLin6Asym_to_MNI152Lin_51f6b6da-ca9b-11f0-a076-ebd5e38fbbd3a79eo9e_/parcellation_warped.nii.gz is a prefix
Singularity args: --bind /tmp/junifer/tmp1g0ya1u3/ants_parcellation_warper_Schaefer100x7_from_MNI152NLin6Asym_to_MNI152Lin_51f6b6da-ca9b-11f0-a076-ebd5e38fbbd3a79eo9e_:/data/mount_1 --bind /tmp/junifer/tmp1g0ya1u3/ants_parcellation_warper_Schaefer100x7_from_MNI152NLin6Asym_to_MNI152Lin_51f6b6da-ca9b-11f0-a076-ebd5e38fbbd3a79eo9e_:/data/mount_2 --bind /home/synchon/junifer_data/v2/.git/annex/objects/JQ/Pp/SHA256E-s145422752--5091350b36f951d455dabd429ebe86c493c75a0217dca311ae355f1d62e080b0.h5:/data/mount_3 --bind /tmp/junifer/tmp1g0ya1u3/ants_parcellation_warper_Schaefer100x7_from_MNI152NLin6Asym_to_MNI152Lin_51f6b6da-ca9b-11f0-a076-ebd5e38fbbd3a79eo9e_:/data/mount_4
Corrected args for ANTS: antsApplyTransforms -d 3 -e 3 -n GenericLabel[NearestNeighbor] -i /data/mount_1/prewarp_parcellation.nii.gz -r /data/mount_2/MNI152Lin_T1w.nii.gz -t /data/mount_3/SHA256E-s145422752--5091350b36f951d455dabd429ebe86c493c75a0217dca311ae355f1d62e080b0.h5 -o /data/mount_4/parcellation_warped.nii.gz
Running command: /data/group/appliedml/tools/ants_2.5.0/singularity_cmd exec --cleanenv --bind /tmp/junifer/tmp1g0ya1u3/ants_parcellation_warper_Schaefer100x7_from_MNI152NLin6Asym_to_MNI152Lin_51f6b6da-ca9b-11f0-a076-ebd5e38fbbd3a79eo9e_:/data/mount_1 --bind /tmp/junifer/tmp1g0ya1u3/ants_parcellation_warper_Schaefer100x7_from_MNI152NLin6Asym_to_MNI152Lin_51f6b6da-ca9b-11f0-a076-ebd5e38fbbd3a79eo9e_:/data/mount_2 --bind /home/synchon/junifer_data/v2/.git/annex/objects/JQ/Pp/SHA256E-s145422752--5091350b36f951d455dabd429ebe86c493c75a0217dca311ae355f1d62e080b0.h5:/data/mount_3 --bind /tmp/junifer/tmp1g0ya1u3/ants_parcellation_warper_Schaefer100x7_from_MNI152NLin6Asym_to_MNI152Lin_51f6b6da-ca9b-11f0-a076-ebd5e38fbbd3a79eo9e_:/data/mount_4 /data/group/appliedml/tools/ants_2.5.0/ants_v2.5.0.sif antsApplyTransforms -d 3 -e 3 -n GenericLabel[NearestNeighbor] -i /data/mount_1/prewarp_parcellation.nii.gz -r /data/mount_2/MNI152Lin_T1w.nii.gz -t /data/mount_3/SHA256E-s145422752--5091350b36f951d455dabd429ebe86c493c75a0217dca311ae355f1d62e080b0.h5 -o /data/mount_4/parcellation_warped.nii.gz

2025-11-26 08:41:40,773 - JUNIFER - INFO - No storage specified, returning dictionary
dict_keys(['BOLD'])
(96, 100)

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

Gallery generated by Sphinx-Gallery