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-03-31 13:28:25,310 - JUNIFER - INFO - ===== Lib Versions =====
2023-03-31 13:28:25,311 - JUNIFER - INFO - numpy: 1.23.5
2023-03-31 13:28:25,311 - JUNIFER - INFO - scipy: 1.10.1
2023-03-31 13:28:25,311 - JUNIFER - INFO - pandas: 1.5.3
2023-03-31 13:28:25,311 - JUNIFER - INFO - nilearn: 0.10.0
2023-03-31 13:28:25,311 - JUNIFER - INFO - nibabel: 4.0.2
2023-03-31 13:28:25,311 - JUNIFER - INFO - junifer: 0.0.2
2023-03-31 13:28:25,311 - 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 40787968 of 905208634 bytes (4.5%,   21.7s remaining)
Downloaded 95592448 of 905208634 bytes (10.6%,   17.4s remaining)
Downloaded 153739264 of 905208634 bytes (17.0%,   15.0s remaining)
Downloaded 206675968 of 905208634 bytes (22.8%,   13.8s remaining)
Downloaded 264716288 of 905208634 bytes (29.2%,   12.4s remaining)
Downloaded 323264512 of 905208634 bytes (35.7%,   11.1s remaining)
Downloaded 377405440 of 905208634 bytes (41.7%,   10.0s remaining)
Downloaded 439631872 of 905208634 bytes (48.6%,    8.7s remaining)
Downloaded 474292224 of 905208634 bytes (52.4%,    8.4s remaining)
Downloaded 548421632 of 905208634 bytes (60.6%,    6.7s remaining)
Downloaded 620920832 of 905208634 bytes (68.6%,    5.1s remaining)
Downloaded 696918016 of 905208634 bytes (77.0%,    3.7s remaining)
Downloaded 771555328 of 905208634 bytes (85.2%,    2.3s remaining)
Downloaded 844652544 of 905208634 bytes (93.3%,    1.0s remaining) ...done. (16 seconds, 0 min)
Extracting data from /home/runner/nilearn_data/oasis1/6d19418bccb98b1333309bd8baa05152/archive_dartel.tgz..... done.
/opt/hostedtoolcache/Python/3.10.10/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 3391488 of 34212021 bytes (9.9%,    9.6s remaining)
Downloaded 9281536 of 34212021 bytes (27.1%,    5.6s remaining)
Downloaded 15532032 of 34212021 bytes (45.4%,    3.7s remaining)
Downloaded 21487616 of 34212021 bytes (62.8%,    2.4s remaining)
Downloaded 28123136 of 34212021 bytes (82.2%,    1.1s remaining)
Downloaded 32808960 of 34212021 bytes (95.9%,    0.3s remaining) ...done. (8 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-03-31 13:28:59,072 - JUNIFER - INFO - Computing BOLD
2023-03-31 13:28:59,072 - JUNIFER - INFO - Fetching one of Schaefer parcellations.
2023-03-31 13:28:59,073 - JUNIFER - INFO - Parcellation parameters:
2023-03-31 13:28:59,073 - JUNIFER - INFO -      n_rois: 100
2023-03-31 13:28:59,073 - JUNIFER - INFO -      yeo_networks: 7
2023-03-31 13:28:59,073 - JUNIFER - INFO -      resolution: 3.0
2023-03-31 13:28:59,073 - 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-03-31 13:28:59,555 - JUNIFER - INFO - Loading parcellation /home/runner/junifer/data/parcellations/schaefer_2018/Schaefer2018_100Parcels_7Networks_order_FSLMNI152_2mm.nii.gz
2023-03-31 13:29:00,978 - JUNIFER - INFO - No storage specified, returning dictionary
2023-03-31 13:29:00,978 - JUNIFER - INFO - Computing VBM_GM
2023-03-31 13:29:00,978 - JUNIFER - INFO - Fetching one of Schaefer parcellations.
2023-03-31 13:29:00,978 - JUNIFER - INFO - Parcellation parameters:
2023-03-31 13:29:00,978 - JUNIFER - INFO -      n_rois: 100
2023-03-31 13:29:00,978 - JUNIFER - INFO -      yeo_networks: 7
2023-03-31 13:29:00,978 - JUNIFER - INFO -      resolution: 2.0
2023-03-31 13:29:00,981 - JUNIFER - INFO - Loading parcellation /home/runner/junifer/data/parcellations/schaefer_2018/Schaefer2018_100Parcels_7Networks_order_FSLMNI152_2mm.nii.gz
2023-03-31 13:29:01,554 - 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 36.248 seconds)

Gallery generated by Sphinx-Gallery