7.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")
2022-12-20 14:33:00,902 - JUNIFER - INFO - ===== Lib Versions =====
2022-12-20 14:33:00,902 - JUNIFER - INFO - numpy: 1.23.5
2022-12-20 14:33:00,902 - JUNIFER - INFO - scipy: 1.9.3
2022-12-20 14:33:00,902 - JUNIFER - INFO - pandas: 1.5.2
2022-12-20 14:33:00,902 - JUNIFER - INFO - nilearn: 0.9.2
2022-12-20 14:33:00,902 - JUNIFER - INFO - nibabel: 4.0.2
2022-12-20 14:33:00,902 - JUNIFER - INFO - junifer: 0.0.1
2022-12-20 14:33:00,902 - 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 59138048 of 905208634 bytes (6.5%,   14.4s remaining)
Downloaded 136314880 of 905208634 bytes (15.1%,   11.4s remaining)
Downloaded 215277568 of 905208634 bytes (23.8%,    9.7s remaining)
Downloaded 293101568 of 905208634 bytes (32.4%,    8.4s remaining)
Downloaded 372137984 of 905208634 bytes (41.1%,    7.2s remaining)
Downloaded 450568192 of 905208634 bytes (49.8%,    6.1s remaining)
Downloaded 529408000 of 905208634 bytes (58.5%,    5.0s remaining)
Downloaded 600317952 of 905208634 bytes (66.3%,    4.3s remaining)
Downloaded 678952960 of 905208634 bytes (75.0%,    3.1s remaining)
Downloaded 758628352 of 905208634 bytes (83.8%,    2.0s remaining)
Downloaded 832454656 of 905208634 bytes (92.0%,    1.0s remaining) ...done. (13 seconds, 0 min)
Extracting data from /home/runner/nilearn_data/oasis1/6d19418bccb98b1333309bd8baa05152/archive_dartel.tgz..... done.
/opt/hostedtoolcache/Python/3.10.9/x64/lib/python3.10/site-packages/nilearn/datasets/struct.py:774: 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 3645440 of 34212021 bytes (10.7%,    9.0s remaining)
Downloaded 11870208 of 34212021 bytes (34.7%,    3.9s remaining)
Downloaded 16474112 of 34212021 bytes (48.2%,    3.3s remaining)
Downloaded 21241856 of 34212021 bytes (62.1%,    2.5s remaining)
Downloaded 26394624 of 34212021 bytes (77.2%,    1.5s remaining)
Downloaded 31744000 of 34212021 bytes (92.8%,    0.5s 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)
2022-12-20 14:33:30,643 - JUNIFER - INFO - Computing BOLD
2022-12-20 14:33:30,643 - JUNIFER - INFO - Fetching one of Schaefer parcellations.
2022-12-20 14:33:30,644 - JUNIFER - INFO - Parcellatikon parameters:
2022-12-20 14:33:30,644 - JUNIFER - INFO -      n_rois: 100
2022-12-20 14:33:30,644 - JUNIFER - INFO -      yeo_networks: 7
2022-12-20 14:33:30,644 - JUNIFER - INFO -      resolution: 3.0
2022-12-20 14:33:30,644 - 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)
2022-12-20 14:33:30,823 - JUNIFER - INFO - Loading parcellation /home/runner/junifer/data/parcellations/schaefer_2018/Schaefer2018_100Parcels_7Networks_order_FSLMNI152_2mm.nii.gz
2022-12-20 14:33:32,586 - JUNIFER - INFO - No storage specified, returning dictionary
2022-12-20 14:33:32,587 - JUNIFER - INFO - Computing VBM_GM
2022-12-20 14:33:32,587 - JUNIFER - INFO - Fetching one of Schaefer parcellations.
2022-12-20 14:33:32,587 - JUNIFER - INFO - Parcellatikon parameters:
2022-12-20 14:33:32,587 - JUNIFER - INFO -      n_rois: 100
2022-12-20 14:33:32,587 - JUNIFER - INFO -      yeo_networks: 7
2022-12-20 14:33:32,587 - JUNIFER - INFO -      resolution: 2.0
2022-12-20 14:33:32,589 - JUNIFER - INFO - Loading parcellation /home/runner/junifer/data/parcellations/schaefer_2018/Schaefer2018_100Parcels_7Networks_order_FSLMNI152_2mm.nii.gz
2022-12-20 14:33:33,370 - 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 32.473 seconds)

Gallery generated by Sphinx-Gallery