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")
/home/runner/work/junifer/junifer/junifer/utils/logging.py:139: 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-10-10 16:05:35,709 - JUNIFER - INFO - ===== Lib Versions =====
2024-10-10 16:05:35,709 - JUNIFER - INFO - numpy: 1.26.4
2024-10-10 16:05:35,709 - JUNIFER - INFO - scipy: 1.14.1
2024-10-10 16:05:35,709 - JUNIFER - INFO - pandas: 2.1.4
2024-10-10 16:05:35,709 - JUNIFER - INFO - nilearn: 0.10.4
2024-10-10 16:05:35,710 - JUNIFER - INFO - nibabel: 5.3.0
2024-10-10 16:05:35,710 - JUNIFER - INFO - junifer: 0.0.6.dev116
2024-10-10 16:05:35,710 - 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-10-10 16:05:35,715 - JUNIFER - INFO - Getting element sub-01
2024-10-10 16:05:35,715 - JUNIFER - INFO - Reading VBM_GM from /home/runner/nilearn_data/oasis1/OAS1_0001_MR1/mwrc1OAS1_0001_MR1_mpr_anon_fslswapdim_bet.nii.gz
2024-10-10 16:05:35,715 - JUNIFER - INFO - VBM_GM is of type NIFTI
2024-10-10 16:05:35,716 - JUNIFER - INFO - Computing VBM_GM
2024-10-10 16:05:35,717 - JUNIFER - INFO - Fetching one of Schaefer parcellations.
2024-10-10 16:05:35,717 - JUNIFER - INFO - Parcellation parameters:
2024-10-10 16:05:35,717 - JUNIFER - INFO -      resolution: 2.0
2024-10-10 16:05:35,717 - JUNIFER - INFO -      n_rois: 100
2024-10-10 16:05:35,717 - JUNIFER - INFO -      yeo_networks: 7
2024-10-10 16:05:35,717 - 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_2mm.nii.gz ...
 ...done. (0 seconds, 0 min)
2024-10-10 16:05:35,885 - JUNIFER - INFO - Loading parcellation /home/runner/junifer/data/parcellations/schaefer_2018/Schaefer2018_100Parcels_7Networks_order_FSLMNI152_2mm.nii.gz
2024-10-10 16:05:35,919 - JUNIFER - INFO - Found existing xfm file for MNI152NLin6Asym to MNI152Lin at /home/runner/junifer/data/xfms/MNI152NLin6Asym_to_MNI152Lin/MNI152NLin6Asym_to_MNI152Lin_Composite.h5
2024-10-10 16:05:37,027 - JUNIFER - INFO - Downloading template MNI152Lin in resolution 2
2024-10-10 16:05:37,122 - JUNIFER - INFO - antsApplyTransforms command to be executed:
antsApplyTransforms -d 3 -e 3 -n 'GenericLabel[NearestNeighbor]' -i /tmp/tmpxfnbpk9d/parcellationsgszzorgh/Schaefer100x7.nii.gz -r /tmp/tmpxfnbpk9d/parcellationsgszzorgh/MNI152Lin_T1w_2.0.nii.gz -t /home/runner/junifer/data/xfms/MNI152NLin6Asym_to_MNI152Lin/MNI152NLin6Asym_to_MNI152Lin_Composite.h5 -o /tmp/tmpmij59df9/parcellationsem_gv1e1/Schaefer100x7_warped_from_MNI152NLin6Asym_to_MNI152Lin.nii.gz
2024-10-10 16:05:38,513 - JUNIFER - INFO - antsApplyTransforms command succeeded with the following output:

2024-10-10 16:05:39,562 - 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-10-10 16:05:39,562 - JUNIFER - INFO - Getting element sub001

Dataset created in /home/runner/nilearn_data/spm_auditory

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

Downloaded 4759552 of 34212021 bytes (13.9%,    6.4s remaining)
Downloaded 9519104 of 34212021 bytes (27.8%,    5.3s remaining)
Downloaded 15007744 of 34212021 bytes (43.9%,    4.0s remaining)
Downloaded 20717568 of 34212021 bytes (60.6%,    2.7s remaining)
Downloaded 26107904 of 34212021 bytes (76.3%,    1.6s remaining)
Downloaded 30728192 of 34212021 bytes (89.8%,    0.7s remaining) ...done. (8 seconds, 0 min)
Extracting data from /home/runner/nilearn_data/spm_auditory/sub001/MoAEpilot.zip..... done.
2024-10-10 16:05:50,628 - JUNIFER - INFO - Reading BOLD from /tmp/tmp_nlmjuh2/sub001_bold.nii.gz
2024-10-10 16:05:50,628 - JUNIFER - INFO - BOLD is of type NIFTI
2024-10-10 16:05:50,629 - JUNIFER - INFO - Reading T1w from /tmp/tmp_nlmjuh2/sub001_T1w.nii.gz
2024-10-10 16:05:50,629 - JUNIFER - INFO - T1w is of type NIFTI
2024-10-10 16:05:50,630 - JUNIFER - INFO - Computing BOLD
2024-10-10 16:05:50,631 - JUNIFER - INFO - Fetching one of Schaefer parcellations.
2024-10-10 16:05:50,631 - JUNIFER - INFO - Parcellation parameters:
2024-10-10 16:05:50,631 - JUNIFER - INFO -      resolution: 3.0
2024-10-10 16:05:50,631 - JUNIFER - INFO -      n_rois: 100
2024-10-10 16:05:50,631 - JUNIFER - INFO -      yeo_networks: 7
2024-10-10 16:05:50,633 - JUNIFER - INFO - Loading parcellation /home/runner/junifer/data/parcellations/schaefer_2018/Schaefer2018_100Parcels_7Networks_order_FSLMNI152_2mm.nii.gz
2024-10-10 16:05:50,662 - JUNIFER - INFO - Found existing xfm file for MNI152NLin6Asym to MNI152Lin at /home/runner/junifer/data/xfms/MNI152NLin6Asym_to_MNI152Lin/MNI152NLin6Asym_to_MNI152Lin_Composite.h5
2024-10-10 16:05:51,739 - JUNIFER - INFO - Downloading template MNI152Lin in resolution 2
2024-10-10 16:05:51,835 - JUNIFER - INFO - antsApplyTransforms command to be executed:
antsApplyTransforms -d 3 -e 3 -n 'GenericLabel[NearestNeighbor]' -i /tmp/tmpxfnbpk9d/parcellationsgmncgz0o/Schaefer100x7.nii.gz -r /tmp/tmpxfnbpk9d/parcellationsgmncgz0o/MNI152Lin_T1w_3.0.nii.gz -t /home/runner/junifer/data/xfms/MNI152NLin6Asym_to_MNI152Lin/MNI152NLin6Asym_to_MNI152Lin_Composite.h5 -o /tmp/tmpmij59df9/parcellationsx7r5b16h/Schaefer100x7_warped_from_MNI152NLin6Asym_to_MNI152Lin.nii.gz
2024-10-10 16:05:53,237 - JUNIFER - INFO - antsApplyTransforms command succeeded with the following output:

2024-10-10 16:05:55,930 - JUNIFER - INFO - No storage specified, returning dictionary
dict_keys(['BOLD'])
(96, 100)

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

Gallery generated by Sphinx-Gallery