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))
2024-12-09 11:21:18,037 - JUNIFER - INFO - ===== Lib Versions =====
2024-12-09 11:21:18,037 - JUNIFER - INFO - numpy: 1.26.4
2024-12-09 11:21:18,037 - JUNIFER - INFO - scipy: 1.14.1
2024-12-09 11:21:18,037 - JUNIFER - INFO - pandas: 2.1.4
2024-12-09 11:21:18,037 - JUNIFER - INFO - nilearn: 0.10.4
2024-12-09 11:21:18,037 - JUNIFER - INFO - nibabel: 5.3.2
2024-12-09 11:21:18,037 - JUNIFER - INFO - junifer: 0.0.6.dev366
2024-12-09 11:21:18,037 - 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)
2024-12-09 11:21:18,043 - JUNIFER - INFO - Getting element sub-01
2024-12-09 11:21:18,043 - JUNIFER - INFO - Reading VBM_GM from /github/home/nilearn_data/oasis1/OAS1_0001_MR1/mwrc1OAS1_0001_MR1_mpr_anon_fslswapdim_bet.nii.gz
2024-12-09 11:21:18,043 - JUNIFER - INFO - VBM_GM is of type NIFTI
2024-12-09 11:21:18,044 - JUNIFER - INFO - Computing VBM_GM
2024-12-09 11:21:18,044 - JUNIFER - INFO - Parcellation will be warped from MNI152NLin6Asym to MNI152Lin using highest resolution
2024-12-09 11:21:18,044 - JUNIFER - INFO - Fetching one of Schaefer parcellations.
2024-12-09 11:21:18,044 - JUNIFER - INFO - Parcellation parameters:
2024-12-09 11:21:18,044 - JUNIFER - INFO -      resolution: None
2024-12-09 11:21:18,044 - JUNIFER - INFO -      n_rois: 100
2024-12-09 11:21:18,044 - JUNIFER - INFO -      yeo_networks: 7
2024-12-09 11:21:18,044 - JUNIFER - INFO - Resolution set to None, using highest resolution.
2024-12-09 11:21:18,045 - 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)
2024-12-09 11:21:18,610 - JUNIFER - INFO - Loading parcellation: /github/home/junifer/data/parcellations/schaefer_2018/Schaefer2018_100Parcels_7Networks_order_FSLMNI152_1mm.nii.gz
2024-12-09 11:21:18,882 - JUNIFER - INFO - Found existing xfm file for MNI152NLin6Asym to MNI152Lin at /github/home/junifer/data/xfms/.git/annex/objects/80/1W/SHA256E-s151956315--b80fd5f087580ecbbb212d1ece24c12f1ce448ca4912c1ea739eb8e84b6f418a.h5/SHA256E-s151956315--b80fd5f087580ecbbb212d1ece24c12f1ce448ca4912c1ea739eb8e84b6f418a.h5
2024-12-09 11:21:19,969 - JUNIFER - INFO - Downloading template MNI152Lin in resolution 1
2024-12-09 11:21:20,473 - JUNIFER - INFO - antsApplyTransforms command to be executed:
antsApplyTransforms -d 3 -e 3 -n 'GenericLabel[NearestNeighbor]' -i /tmp/junifer/tmpmvdfxj1i/ants_parcellation_warper_Schaefer100x7_from_MNI152NLin6Asym_to_MNI152Lin_b62f2448-b61f-11ef-88f6-0242ac120002u9m96_4v/prewarp_parcellation.nii.gz -r /tmp/junifer/tmpmvdfxj1i/ants_parcellation_warper_Schaefer100x7_from_MNI152NLin6Asym_to_MNI152Lin_b62f2448-b61f-11ef-88f6-0242ac120002u9m96_4v/MNI152Lin_T1w.nii.gz -t /github/home/junifer/data/xfms/.git/annex/objects/80/1W/SHA256E-s151956315--b80fd5f087580ecbbb212d1ece24c12f1ce448ca4912c1ea739eb8e84b6f418a.h5/SHA256E-s151956315--b80fd5f087580ecbbb212d1ece24c12f1ce448ca4912c1ea739eb8e84b6f418a.h5 -o /tmp/junifer/tmpmvdfxj1i/ants_parcellation_warper_Schaefer100x7_from_MNI152NLin6Asym_to_MNI152Lin_b62f2448-b61f-11ef-88f6-0242ac120002u9m96_4v/parcellation_warped.nii.gz
2024-12-09 11:21:29,506 - JUNIFER - INFO - antsApplyTransforms command succeeded with the following output:

2024-12-09 11:21:30,872 - 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)
2024-12-09 11:21:30,873 - 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 1122304 of 34212021 bytes (3.3%,   29.9s remaining)
Downloaded 5251072 of 34212021 bytes (15.3%,   11.1s remaining)
Downloaded 8175616 of 34212021 bytes (23.9%,    9.6s remaining)
Downloaded 11059200 of 34212021 bytes (32.3%,    8.4s remaining)
Downloaded 13426688 of 34212021 bytes (39.2%,    7.8s remaining)
Downloaded 15966208 of 34212021 bytes (46.7%,    6.9s remaining)
Downloaded 18595840 of 34212021 bytes (54.4%,    5.9s remaining)
Downloaded 21274624 of 34212021 bytes (62.2%,    4.9s remaining)
Downloaded 23961600 of 34212021 bytes (70.0%,    3.9s remaining)
Downloaded 26648576 of 34212021 bytes (77.9%,    2.9s remaining)
Downloaded 29351936 of 34212021 bytes (85.8%,    1.8s remaining)
Downloaded 32079872 of 34212021 bytes (93.8%,    0.8s remaining) ...done. (15 seconds, 0 min)
Extracting data from /github/home/nilearn_data/spm_auditory/sub001/MoAEpilot.zip..... done.
2024-12-09 11:21:48,540 - JUNIFER - INFO - Reading BOLD from /tmp/tmpc3m3pyan/sub001_bold.nii.gz
2024-12-09 11:21:48,540 - JUNIFER - INFO - BOLD is of type NIFTI
2024-12-09 11:21:48,541 - JUNIFER - INFO - Reading T1w from /tmp/tmpc3m3pyan/sub001_T1w.nii.gz
2024-12-09 11:21:48,541 - JUNIFER - INFO - T1w is of type NIFTI
2024-12-09 11:21:48,542 - JUNIFER - INFO - Computing BOLD
2024-12-09 11:21:48,542 - JUNIFER - INFO - Parcellation will be warped from MNI152NLin6Asym to MNI152Lin using highest resolution
2024-12-09 11:21:48,543 - JUNIFER - INFO - Fetching one of Schaefer parcellations.
2024-12-09 11:21:48,543 - JUNIFER - INFO - Parcellation parameters:
2024-12-09 11:21:48,543 - JUNIFER - INFO -      resolution: None
2024-12-09 11:21:48,543 - JUNIFER - INFO -      n_rois: 100
2024-12-09 11:21:48,543 - JUNIFER - INFO -      yeo_networks: 7
2024-12-09 11:21:48,543 - JUNIFER - INFO - Resolution set to None, using highest resolution.
2024-12-09 11:21:48,544 - JUNIFER - INFO - Loading parcellation: /github/home/junifer/data/parcellations/schaefer_2018/Schaefer2018_100Parcels_7Networks_order_FSLMNI152_1mm.nii.gz
2024-12-09 11:21:48,813 - JUNIFER - INFO - Found existing xfm file for MNI152NLin6Asym to MNI152Lin at /github/home/junifer/data/xfms/.git/annex/objects/80/1W/SHA256E-s151956315--b80fd5f087580ecbbb212d1ece24c12f1ce448ca4912c1ea739eb8e84b6f418a.h5/SHA256E-s151956315--b80fd5f087580ecbbb212d1ece24c12f1ce448ca4912c1ea739eb8e84b6f418a.h5
2024-12-09 11:21:49,896 - JUNIFER - INFO - Downloading template MNI152Lin in resolution 1
2024-12-09 11:21:50,398 - JUNIFER - INFO - antsApplyTransforms command to be executed:
antsApplyTransforms -d 3 -e 3 -n 'GenericLabel[NearestNeighbor]' -i /tmp/junifer/tmpmvdfxj1i/ants_parcellation_warper_Schaefer100x7_from_MNI152NLin6Asym_to_MNI152Lin_c8065aec-b61f-11ef-88f6-0242ac120002jpm2miyk/prewarp_parcellation.nii.gz -r /tmp/junifer/tmpmvdfxj1i/ants_parcellation_warper_Schaefer100x7_from_MNI152NLin6Asym_to_MNI152Lin_c8065aec-b61f-11ef-88f6-0242ac120002jpm2miyk/MNI152Lin_T1w.nii.gz -t /github/home/junifer/data/xfms/.git/annex/objects/80/1W/SHA256E-s151956315--b80fd5f087580ecbbb212d1ece24c12f1ce448ca4912c1ea739eb8e84b6f418a.h5/SHA256E-s151956315--b80fd5f087580ecbbb212d1ece24c12f1ce448ca4912c1ea739eb8e84b6f418a.h5 -o /tmp/junifer/tmpmvdfxj1i/ants_parcellation_warper_Schaefer100x7_from_MNI152NLin6Asym_to_MNI152Lin_c8065aec-b61f-11ef-88f6-0242ac120002jpm2miyk/parcellation_warped.nii.gz
2024-12-09 11:21:59,387 - JUNIFER - INFO - antsApplyTransforms command succeeded with the following output:

2024-12-09 11:22:02,336 - JUNIFER - INFO - No storage specified, returning dictionary
dict_keys(['BOLD'])
(96, 100)

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

Gallery generated by Sphinx-Gallery