8.3. Computer Parcel Aggregation.#

This example uses a ParcelAggregation marker to compute the mean of each parcel using the Schaefer parcellations (100 rois, 7 Yeo networks) for both a 3D and 4D nifti

Authors: Federico Raimondo

License: BSD 3 clause

import nilearn

from junifer.markers.parcel_aggregation import ParcelAggregation
from junifer.utils import configure_logging

Set the logging level to info to see extra information

configure_logging(level="INFO")
2023-05-16 14:13:56,143 - JUNIFER - INFO - ===== Lib Versions =====
2023-05-16 14:13:56,143 - JUNIFER - INFO - numpy: 1.23.5
2023-05-16 14:13:56,143 - JUNIFER - INFO - scipy: 1.10.1
2023-05-16 14:13:56,143 - JUNIFER - INFO - pandas: 1.5.3
2023-05-16 14:13:56,143 - JUNIFER - INFO - nilearn: 0.10.0
2023-05-16 14:13:56,143 - JUNIFER - INFO - nibabel: 4.0.2
2023-05-16 14:13:56,143 - JUNIFER - INFO - junifer: 0.0.3.dev79
2023-05-16 14:13:56,143 - JUNIFER - INFO - ========================

Load the VBM GM data (3d): - Fetch the Oasis dataset

Dataset created in /home/runner/nilearn_data/oasis1

Downloading data from https://www.nitrc.org/frs/download.php/6364/archive_dartel.tgz ...

Downloaded 19988480 of 905208634 bytes (2.2%,   44.3s remaining)
Downloaded 61087744 of 905208634 bytes (6.7%,   27.6s remaining)
Downloaded 103088128 of 905208634 bytes (11.4%,   23.5s remaining)
Downloaded 142901248 of 905208634 bytes (15.8%,   21.4s remaining)
Downloaded 184385536 of 905208634 bytes (20.4%,   19.7s remaining)
Downloaded 226238464 of 905208634 bytes (25.0%,   18.1s remaining)
Downloaded 267329536 of 905208634 bytes (29.5%,   16.8s remaining)
Downloaded 307535872 of 905208634 bytes (34.0%,   15.6s remaining)
Downloaded 349167616 of 905208634 bytes (38.6%,   14.4s remaining)
Downloaded 389447680 of 905208634 bytes (43.0%,   13.3s remaining)
Downloaded 431226880 of 905208634 bytes (47.6%,   12.1s remaining)
Downloaded 473006080 of 905208634 bytes (52.3%,   11.0s remaining)
Downloaded 515391488 of 905208634 bytes (56.9%,    9.9s remaining)
Downloaded 557301760 of 905208634 bytes (61.6%,    8.8s remaining)
Downloaded 599203840 of 905208634 bytes (66.2%,    7.7s remaining)
Downloaded 641048576 of 905208634 bytes (70.8%,    6.6s remaining)
Downloaded 682876928 of 905208634 bytes (75.4%,    5.6s remaining)
Downloaded 724541440 of 905208634 bytes (80.0%,    4.5s remaining)
Downloaded 765755392 of 905208634 bytes (84.6%,    3.5s remaining)
Downloaded 786767872 of 905208634 bytes (86.9%,    3.0s remaining)
Downloaded 828489728 of 905208634 bytes (91.5%,    2.0s remaining)
Downloaded 867926016 of 905208634 bytes (95.9%,    1.0s remaining) ...done. (24 seconds, 0 min)
Extracting data from /home/runner/nilearn_data/oasis1/6d19418bccb98b1333309bd8baa05152/archive_dartel.tgz..... done.
/opt/hostedtoolcache/Python/3.10.11/x64/lib/python3.10/site-packages/nilearn/datasets/struct.py:733: 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)

Load the functional data (4d): - Fetch the SPM auditory dataset - Concatenate the functional data into one 4D image

Dataset created in /home/runner/nilearn_data/spm_auditory

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

Downloaded 1286144 of 34212021 bytes (3.8%,   26.1s remaining)
Downloaded 5931008 of 34212021 bytes (17.3%,    9.7s remaining)
Downloaded 10813440 of 34212021 bytes (31.6%,    6.6s remaining)
Downloaded 15966208 of 34212021 bytes (46.7%,    4.7s remaining)
Downloaded 21266432 of 34212021 bytes (62.2%,    3.1s remaining)
Downloaded 25862144 of 34212021 bytes (75.6%,    2.0s remaining)
Downloaded 29802496 of 34212021 bytes (87.1%,    1.1s remaining)
Downloaded 34045952 of 34212021 bytes (99.5%,    0.0s remaining) ...done. (10 seconds, 0 min)
Extracting data from /home/runner/nilearn_data/spm_auditory/sub001/MoAEpilot.zip..... done.

Define the marker

marker = ParcelAggregation(parcellation="Schaefer100x7", method="mean")

Prepare the input

input = {
    "BOLD": {"data": fmri_img, "meta": {"element": "subject1"}},
    "VBM_GM": {"data": vbm_img, "meta": {"element": "subject1"}},
}

Fit transform the data

out = marker.fit_transform(input)
2023-05-16 14:14:40,092 - JUNIFER - INFO - Computing BOLD
2023-05-16 14:14:40,093 - JUNIFER - INFO - Fetching one of Schaefer parcellations.
2023-05-16 14:14:40,093 - JUNIFER - INFO - Parcellation parameters:
2023-05-16 14:14:40,093 - JUNIFER - INFO -      n_rois: 100
2023-05-16 14:14:40,093 - JUNIFER - INFO -      yeo_networks: 7
2023-05-16 14:14:40,093 - JUNIFER - INFO -      resolution: 3.0
2023-05-16 14:14:40,093 - JUNIFER - INFO - At least one of the parcellation files are missing. Fetching using nilearn.

Dataset created in /home/runner/junifer/data/parcellations/schaefer_2018

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)
2023-05-16 14:14:40,537 - JUNIFER - INFO - Loading parcellation /home/runner/junifer/data/parcellations/schaefer_2018/Schaefer2018_100Parcels_7Networks_order_FSLMNI152_2mm.nii.gz
2023-05-16 14:14:42,272 - JUNIFER - INFO - No storage specified, returning dictionary
2023-05-16 14:14:42,272 - JUNIFER - INFO - Computing VBM_GM
2023-05-16 14:14:42,272 - JUNIFER - INFO - Fetching one of Schaefer parcellations.
2023-05-16 14:14:42,272 - JUNIFER - INFO - Parcellation parameters:
2023-05-16 14:14:42,272 - JUNIFER - INFO -      n_rois: 100
2023-05-16 14:14:42,272 - JUNIFER - INFO -      yeo_networks: 7
2023-05-16 14:14:42,272 - JUNIFER - INFO -      resolution: 2.0
2023-05-16 14:14:42,275 - JUNIFER - INFO - Loading parcellation /home/runner/junifer/data/parcellations/schaefer_2018/Schaefer2018_100Parcels_7Networks_order_FSLMNI152_2mm.nii.gz
2023-05-16 14:14:43,088 - JUNIFER - INFO - No storage specified, returning dictionary

Check the results

print(out.keys())
print(out["VBM_GM"]["data"].shape)  # Shape is (1 x parcels)

print(out.keys())
print(out["BOLD"]["data"].shape)  # Shape is (timepoints x parcels)
dict_keys(['BOLD', 'VBM_GM'])
(1, 100)
dict_keys(['BOLD', 'VBM_GM'])
(96, 100)

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

Gallery generated by Sphinx-Gallery