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-07-24 05:08:00,643 - JUNIFER - INFO - ===== Lib Versions =====
2023-07-24 05:08:00,644 - JUNIFER - INFO - numpy: 1.25.1
2023-07-24 05:08:00,644 - JUNIFER - INFO - scipy: 1.11.1
2023-07-24 05:08:00,644 - JUNIFER - INFO - pandas: 1.5.3
2023-07-24 05:08:00,644 - JUNIFER - INFO - nilearn: 0.10.0
2023-07-24 05:08:00,644 - JUNIFER - INFO - nibabel: 4.0.2
2023-07-24 05:08:00,644 - JUNIFER - INFO - junifer: 0.0.3
2023-07-24 05:08:00,644 - 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 132120576 of 905208634 bytes (14.6%,    5.9s remaining)
Downloaded 272982016 of 905208634 bytes (30.2%,    4.6s remaining)
Downloaded 429752320 of 905208634 bytes (47.5%,    3.3s remaining)
Downloaded 610140160 of 905208634 bytes (67.4%,    1.9s remaining)
Downloaded 779706368 of 905208634 bytes (86.1%,    0.8s remaining) ...done. (6 seconds, 0 min)
Extracting data from /home/runner/nilearn_data/oasis1/6d19418bccb98b1333309bd8baa05152/archive_dartel.tgz..... done.
/opt/hostedtoolcache/Python/3.10.12/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 2244608 of 34212021 bytes (6.6%,   14.8s remaining)
Downloaded 3751936 of 34212021 bytes (11.0%,   16.9s remaining)
Downloaded 5128192 of 34212021 bytes (15.0%,   17.6s remaining)
Downloaded 6553600 of 34212021 bytes (19.2%,   17.4s remaining)
Downloaded 8044544 of 34212021 bytes (23.5%,   16.7s remaining)
Downloaded 9510912 of 34212021 bytes (27.8%,   15.9s remaining)
Downloaded 10625024 of 34212021 bytes (31.1%,   15.9s remaining)
Downloaded 11345920 of 34212021 bytes (33.2%,   16.4s remaining)
Downloaded 12148736 of 34212021 bytes (35.5%,   16.7s remaining)
Downloaded 12910592 of 34212021 bytes (37.7%,   16.8s remaining)
Downloaded 13680640 of 34212021 bytes (40.0%,   16.8s remaining)
Downloaded 14557184 of 34212021 bytes (42.5%,   16.5s remaining)
Downloaded 15474688 of 34212021 bytes (45.2%,   16.0s remaining)
Downloaded 16441344 of 34212021 bytes (48.1%,   15.4s remaining)
Downloaded 17285120 of 34212021 bytes (50.5%,   14.9s remaining)
Downloaded 17907712 of 34212021 bytes (52.3%,   14.8s remaining)
Downloaded 18481152 of 34212021 bytes (54.0%,   14.7s remaining)
Downloaded 18956288 of 34212021 bytes (55.4%,   14.8s remaining)
Downloaded 19267584 of 34212021 bytes (56.3%,   15.1s remaining)
Downloaded 19652608 of 34212021 bytes (57.4%,   15.2s remaining)
Downloaded 20037632 of 34212021 bytes (58.6%,   15.2s remaining)
Downloaded 20488192 of 34212021 bytes (59.9%,   15.1s remaining)
Downloaded 20905984 of 34212021 bytes (61.1%,   15.0s remaining)
Downloaded 21340160 of 34212021 bytes (62.4%,   14.8s remaining)
Downloaded 21757952 of 34212021 bytes (63.6%,   14.7s remaining)
Downloaded 22142976 of 34212021 bytes (64.7%,   14.5s remaining)
Downloaded 22568960 of 34212021 bytes (66.0%,   14.3s remaining)
Downloaded 22937600 of 34212021 bytes (67.0%,   14.1s remaining)
Downloaded 23306240 of 34212021 bytes (68.1%,   13.9s remaining)
Downloaded 23683072 of 34212021 bytes (69.2%,   13.7s remaining)
Downloaded 24109056 of 34212021 bytes (70.5%,   13.3s remaining)
Downloaded 24592384 of 34212021 bytes (71.9%,   12.8s remaining)
Downloaded 25214976 of 34212021 bytes (73.7%,   12.1s remaining)
Downloaded 25935872 of 34212021 bytes (75.8%,   11.1s remaining)
Downloaded 26624000 of 34212021 bytes (77.8%,   10.2s remaining)
Downloaded 26976256 of 34212021 bytes (78.9%,    9.9s remaining)
Downloaded 27402240 of 34212021 bytes (80.1%,    9.4s remaining)
Downloaded 27885568 of 34212021 bytes (81.5%,    8.8s remaining)
Downloaded 28352512 of 34212021 bytes (82.9%,    8.3s remaining)
Downloaded 28893184 of 34212021 bytes (84.5%,    7.6s remaining)
Downloaded 29507584 of 34212021 bytes (86.2%,    6.7s remaining)
Downloaded 30212096 of 34212021 bytes (88.3%,    5.7s remaining)
Downloaded 30818304 of 34212021 bytes (90.1%,    4.9s remaining)
Downloaded 31555584 of 34212021 bytes (92.2%,    3.8s remaining)
Downloaded 32186368 of 34212021 bytes (94.1%,    2.9s remaining)
Downloaded 32882688 of 34212021 bytes (96.1%,    1.9s remaining)
Downloaded 33472512 of 34212021 bytes (97.8%,    1.1s remaining)
Downloaded 34127872 of 34212021 bytes (99.8%,    0.1s remaining) ...done. (50 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-07-24 05:09:06,949 - JUNIFER - INFO - Computing BOLD
2023-07-24 05:09:06,949 - JUNIFER - INFO - Fetching one of Schaefer parcellations.
2023-07-24 05:09:06,949 - JUNIFER - INFO - Parcellation parameters:
2023-07-24 05:09:06,949 - JUNIFER - INFO -      resolution: 3.0
2023-07-24 05:09:06,949 - JUNIFER - INFO -      n_rois: 100
2023-07-24 05:09:06,949 - JUNIFER - INFO -      yeo_networks: 7
2023-07-24 05:09:06,950 - 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-07-24 05:09:07,280 - JUNIFER - INFO - Loading parcellation /home/runner/junifer/data/parcellations/schaefer_2018/Schaefer2018_100Parcels_7Networks_order_FSLMNI152_2mm.nii.gz
2023-07-24 05:09:08,937 - JUNIFER - INFO - No storage specified, returning dictionary
2023-07-24 05:09:08,937 - JUNIFER - INFO - Computing VBM_GM
2023-07-24 05:09:08,938 - JUNIFER - INFO - Fetching one of Schaefer parcellations.
2023-07-24 05:09:08,938 - JUNIFER - INFO - Parcellation parameters:
2023-07-24 05:09:08,938 - JUNIFER - INFO -      resolution: 2.0
2023-07-24 05:09:08,938 - JUNIFER - INFO -      n_rois: 100
2023-07-24 05:09:08,938 - JUNIFER - INFO -      yeo_networks: 7
2023-07-24 05:09:08,940 - JUNIFER - INFO - Loading parcellation /home/runner/junifer/data/parcellations/schaefer_2018/Schaefer2018_100Parcels_7Networks_order_FSLMNI152_2mm.nii.gz
2023-07-24 05:09:09,711 - 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: ( 1 minutes 9.073 seconds)

Gallery generated by Sphinx-Gallery