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")
2024-02-09 10:11:50,087 - JUNIFER - INFO - ===== Lib Versions =====
2024-02-09 10:11:50,087 - JUNIFER - INFO - numpy: 1.26.4
2024-02-09 10:11:50,087 - JUNIFER - INFO - scipy: 1.11.4
2024-02-09 10:11:50,087 - JUNIFER - INFO - pandas: 2.1.4
2024-02-09 10:11:50,087 - JUNIFER - INFO - nilearn: 0.10.2
2024-02-09 10:11:50,087 - JUNIFER - INFO - nibabel: 5.2.0
2024-02-09 10:11:50,087 - JUNIFER - INFO - junifer: 0.0.4.dev563
2024-02-09 10:11:50,087 - 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"]["data"].shape)  # Shape is (1 x parcels)
/opt/hostedtoolcache/Python/3.10.13/x64/lib/python3.10/site-packages/nilearn/datasets/struct.py:852: UserWarning: `legacy_format` will default to `False` in release 0.11. Dataset fetchers will then return pandas dataframes by default instead of recarrays.
  warnings.warn(_LEGACY_FORMAT_MSG)
2024-02-09 10:11:50,093 - JUNIFER - INFO - Getting element sub-01
2024-02-09 10:11:50,093 - JUNIFER - INFO - Reading VBM_GM from /home/runner/nilearn_data/oasis1/OAS1_0001_MR1/mwrc1OAS1_0001_MR1_mpr_anon_fslswapdim_bet.nii.gz
2024-02-09 10:11:50,093 - JUNIFER - INFO - VBM_GM is type NIFTI
2024-02-09 10:11:50,094 - JUNIFER - INFO - Computing VBM_GM
2024-02-09 10:11:50,095 - JUNIFER - INFO - Fetching one of Schaefer parcellations.
2024-02-09 10:11:50,095 - JUNIFER - INFO - Parcellation parameters:
2024-02-09 10:11:50,095 - JUNIFER - INFO -      resolution: 2.0
2024-02-09 10:11:50,095 - JUNIFER - INFO -      n_rois: 100
2024-02-09 10:11:50,095 - JUNIFER - INFO -      yeo_networks: 7
2024-02-09 10:11:50,095 - 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-02-09 10:11:50,148 - JUNIFER - INFO - Loading parcellation /home/runner/junifer/data/parcellations/schaefer_2018/Schaefer2018_100Parcels_7Networks_order_FSLMNI152_2mm.nii.gz
2024-02-09 10:11:50,820 - 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"]["data"].shape)  # Shape is (timepoints x parcels)
2024-02-09 10:11:50,821 - 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 3473408 of 34212021 bytes (10.2%,    8.9s remaining)
Downloaded 8085504 of 34212021 bytes (23.6%,    6.5s remaining)
Downloaded 13066240 of 34212021 bytes (38.2%,    4.9s remaining)
Downloaded 18407424 of 34212021 bytes (53.8%,    3.5s remaining)
Downloaded 23756800 of 34212021 bytes (69.4%,    2.2s remaining)
Downloaded 28893184 of 34212021 bytes (84.5%,    1.1s remaining)
Downloaded 33488896 of 34212021 bytes (97.9%,    0.2s remaining) ...done. (8 seconds, 0 min)
Extracting data from /home/runner/nilearn_data/spm_auditory/sub001/MoAEpilot.zip..... done.
2024-02-09 10:12:02,620 - JUNIFER - INFO - Reading BOLD from /tmp/tmp43j9kx1g/sub001_bold.nii.gz
2024-02-09 10:12:02,620 - JUNIFER - INFO - BOLD is type NIFTI
2024-02-09 10:12:02,621 - JUNIFER - INFO - Reading T1w from /tmp/tmp43j9kx1g/sub001_T1w.nii.gz
2024-02-09 10:12:02,621 - JUNIFER - INFO - T1w is type NIFTI
2024-02-09 10:12:02,622 - JUNIFER - INFO - Computing BOLD
2024-02-09 10:12:02,622 - JUNIFER - INFO - Fetching one of Schaefer parcellations.
2024-02-09 10:12:02,622 - JUNIFER - INFO - Parcellation parameters:
2024-02-09 10:12:02,622 - JUNIFER - INFO -      resolution: 3.0
2024-02-09 10:12:02,622 - JUNIFER - INFO -      n_rois: 100
2024-02-09 10:12:02,622 - JUNIFER - INFO -      yeo_networks: 7
2024-02-09 10:12:02,624 - JUNIFER - INFO - Loading parcellation /home/runner/junifer/data/parcellations/schaefer_2018/Schaefer2018_100Parcels_7Networks_order_FSLMNI152_2mm.nii.gz
2024-02-09 10:12:05,186 - JUNIFER - INFO - No storage specified, returning dictionary
dict_keys(['BOLD'])
(96, 100)

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

Gallery generated by Sphinx-Gallery