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")
/__w/junifer/junifer/junifer/utils/logging.py:193: UserWarning: The '__version__' attribute is deprecated and will be removed in MarkupSafe 3.1. Use feature detection, or `importlib.metadata.version("markupsafe")`, instead.
  vstring = str(getattr(module, "__version__", None))
2025-01-29 11:00:59,923 - JUNIFER - INFO - ===== Lib Versions =====
2025-01-29 11:00:59,923 - JUNIFER - INFO - numpy: 1.26.4
2025-01-29 11:00:59,923 - JUNIFER - INFO - scipy: 1.15.0
2025-01-29 11:00:59,923 - JUNIFER - INFO - pandas: 2.1.4
2025-01-29 11:00:59,923 - JUNIFER - INFO - nilearn: 0.10.4
2025-01-29 11:00:59,923 - JUNIFER - INFO - nibabel: 5.3.2
2025-01-29 11:00:59,923 - JUNIFER - INFO - junifer: 0.0.6.dev429
2025-01-29 11:00:59,923 - 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-01-29 11:00:59,929 - JUNIFER - INFO - Getting element sub-01
2025-01-29 11:00:59,929 - JUNIFER - INFO - Reading VBM_GM from /github/home/nilearn_data/oasis1/OAS1_0001_MR1/mwrc1OAS1_0001_MR1_mpr_anon_fslswapdim_bet.nii.gz
2025-01-29 11:00:59,929 - JUNIFER - INFO - VBM_GM is of type NIFTI
2025-01-29 11:00:59,930 - JUNIFER - INFO - Computing VBM_GM
2025-01-29 11:00:59,930 - JUNIFER - INFO - Parcellation will be warped from MNI152NLin6Asym to MNI152Lin using highest resolution
2025-01-29 11:00:59,930 - JUNIFER - INFO - Fetching one of Schaefer parcellations.
2025-01-29 11:00:59,930 - JUNIFER - INFO - Parcellation parameters:
2025-01-29 11:00:59,930 - JUNIFER - INFO -      resolution: None
2025-01-29 11:00:59,930 - JUNIFER - INFO -      n_rois: 100
2025-01-29 11:00:59,930 - JUNIFER - INFO -      yeo_networks: 7
2025-01-29 11:00:59,930 - JUNIFER - INFO - Resolution set to None, using highest resolution.
2025-01-29 11:00:59,931 - JUNIFER - INFO - At least one of the parcellation files are missing. Fetching using nilearn.
Downloading data from https://raw.githubusercontent.com/ThomasYeoLab/CBIG/v0.14.3-Update_Yeo2011_Schaefer2018_labelname/stable_projects/brain_parcellation/Schaefer2018_LocalGlobal/Parcellations/MNI/Schaefer2018_100Parcels_7Networks_order.txt ...
 ...done. (0 seconds, 0 min)
Downloading data from https://raw.githubusercontent.com/ThomasYeoLab/CBIG/v0.14.3-Update_Yeo2011_Schaefer2018_labelname/stable_projects/brain_parcellation/Schaefer2018_LocalGlobal/Parcellations/MNI/Schaefer2018_100Parcels_7Networks_order_FSLMNI152_1mm.nii.gz ...
 ...done. (0 seconds, 0 min)
2025-01-29 11:01:00,332 - JUNIFER - INFO - Loading parcellation: /github/home/junifer/data/parcellations/schaefer_2018/Schaefer2018_100Parcels_7Networks_order_FSLMNI152_1mm.nii.gz
2025-01-29 11:01:00,599 - JUNIFER - INFO - Found existing xfm file for MNI152NLin6Asym to MNI152Lin at /github/home/junifer/data/xfms/.git/annex/objects/JQ/Pp/SHA256E-s145422752--5091350b36f951d455dabd429ebe86c493c75a0217dca311ae355f1d62e080b0.h5/SHA256E-s145422752--5091350b36f951d455dabd429ebe86c493c75a0217dca311ae355f1d62e080b0.h5
2025-01-29 11:01:01,689 - JUNIFER - INFO - Downloading template MNI152Lin (T1w in resolution 1
2025-01-29 11:01:02,191 - JUNIFER - INFO - antsApplyTransforms command to be executed:
antsApplyTransforms -d 3 -e 3 -n 'GenericLabel[NearestNeighbor]' -i /tmp/junifer/tmpv6a7pc_7/ants_parcellation_warper_Schaefer100x7_from_MNI152NLin6Asym_to_MNI152Lin_53191a10-de30-11ef-acef-0242ac120002nlimgnf8/prewarp_parcellation.nii.gz -r /tmp/junifer/tmpv6a7pc_7/ants_parcellation_warper_Schaefer100x7_from_MNI152NLin6Asym_to_MNI152Lin_53191a10-de30-11ef-acef-0242ac120002nlimgnf8/MNI152Lin_T1w.nii.gz -t /github/home/junifer/data/xfms/.git/annex/objects/JQ/Pp/SHA256E-s145422752--5091350b36f951d455dabd429ebe86c493c75a0217dca311ae355f1d62e080b0.h5/SHA256E-s145422752--5091350b36f951d455dabd429ebe86c493c75a0217dca311ae355f1d62e080b0.h5 -o /tmp/junifer/tmpv6a7pc_7/ants_parcellation_warper_Schaefer100x7_from_MNI152NLin6Asym_to_MNI152Lin_53191a10-de30-11ef-acef-0242ac120002nlimgnf8/parcellation_warped.nii.gz
2025-01-29 11:01:08,412 - JUNIFER - INFO - antsApplyTransforms command succeeded with the following output:

2025-01-29 11:01:09,738 - 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-01-29 11:01:09,739 - JUNIFER - INFO - Getting element sub001

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 3907584 of 34212021 bytes (11.4%,    7.9s remaining)
Downloaded 9322496 of 34212021 bytes (27.2%,    5.4s remaining)
Downloaded 15540224 of 34212021 bytes (45.4%,    3.7s remaining)
Downloaded 21569536 of 34212021 bytes (63.0%,    2.4s remaining)
Downloaded 28155904 of 34212021 bytes (82.3%,    1.1s remaining) ...done. (7 seconds, 0 min)
Extracting data from /github/home/nilearn_data/spm_auditory/sub001/MoAEpilot.zip..... done.
2025-01-29 11:01:19,587 - JUNIFER - INFO - Reading BOLD from /tmp/tmpu6nf7p96/sub001_bold.nii.gz
2025-01-29 11:01:19,587 - JUNIFER - INFO - BOLD is of type NIFTI
2025-01-29 11:01:19,588 - JUNIFER - INFO - Reading T1w from /tmp/tmpu6nf7p96/sub001_T1w.nii.gz
2025-01-29 11:01:19,588 - JUNIFER - INFO - T1w is of type NIFTI
2025-01-29 11:01:19,589 - JUNIFER - INFO - Computing BOLD
2025-01-29 11:01:19,589 - JUNIFER - INFO - Parcellation will be warped from MNI152NLin6Asym to MNI152Lin using highest resolution
2025-01-29 11:01:19,589 - JUNIFER - INFO - Fetching one of Schaefer parcellations.
2025-01-29 11:01:19,589 - JUNIFER - INFO - Parcellation parameters:
2025-01-29 11:01:19,589 - JUNIFER - INFO -      resolution: None
2025-01-29 11:01:19,589 - JUNIFER - INFO -      n_rois: 100
2025-01-29 11:01:19,589 - JUNIFER - INFO -      yeo_networks: 7
2025-01-29 11:01:19,589 - JUNIFER - INFO - Resolution set to None, using highest resolution.
2025-01-29 11:01:19,591 - JUNIFER - INFO - Loading parcellation: /github/home/junifer/data/parcellations/schaefer_2018/Schaefer2018_100Parcels_7Networks_order_FSLMNI152_1mm.nii.gz
2025-01-29 11:01:19,858 - JUNIFER - INFO - Found existing xfm file for MNI152NLin6Asym to MNI152Lin at /github/home/junifer/data/xfms/.git/annex/objects/JQ/Pp/SHA256E-s145422752--5091350b36f951d455dabd429ebe86c493c75a0217dca311ae355f1d62e080b0.h5/SHA256E-s145422752--5091350b36f951d455dabd429ebe86c493c75a0217dca311ae355f1d62e080b0.h5
2025-01-29 11:01:20,923 - JUNIFER - INFO - Downloading template MNI152Lin (T1w in resolution 1
2025-01-29 11:01:21,424 - JUNIFER - INFO - antsApplyTransforms command to be executed:
antsApplyTransforms -d 3 -e 3 -n 'GenericLabel[NearestNeighbor]' -i /tmp/junifer/tmpv6a7pc_7/ants_parcellation_warper_Schaefer100x7_from_MNI152NLin6Asym_to_MNI152Lin_5e93c8b8-de30-11ef-acef-0242ac120002_73f5mrx/prewarp_parcellation.nii.gz -r /tmp/junifer/tmpv6a7pc_7/ants_parcellation_warper_Schaefer100x7_from_MNI152NLin6Asym_to_MNI152Lin_5e93c8b8-de30-11ef-acef-0242ac120002_73f5mrx/MNI152Lin_T1w.nii.gz -t /github/home/junifer/data/xfms/.git/annex/objects/JQ/Pp/SHA256E-s145422752--5091350b36f951d455dabd429ebe86c493c75a0217dca311ae355f1d62e080b0.h5/SHA256E-s145422752--5091350b36f951d455dabd429ebe86c493c75a0217dca311ae355f1d62e080b0.h5 -o /tmp/junifer/tmpv6a7pc_7/ants_parcellation_warper_Schaefer100x7_from_MNI152NLin6Asym_to_MNI152Lin_5e93c8b8-de30-11ef-acef-0242ac120002_73f5mrx/parcellation_warped.nii.gz
2025-01-29 11:01:27,554 - JUNIFER - INFO - antsApplyTransforms command succeeded with the following output:

2025-01-29 11:01:30,374 - JUNIFER - INFO - No storage specified, returning dictionary
dict_keys(['BOLD'])
(96, 100)

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

Gallery generated by Sphinx-Gallery