Note
Go to the end to download the full example code
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-10-17 10:30:52,423 - JUNIFER - INFO - ===== Lib Versions =====
2023-10-17 10:30:52,423 - JUNIFER - INFO - numpy: 1.25.2
2023-10-17 10:30:52,423 - JUNIFER - INFO - scipy: 1.11.3
2023-10-17 10:30:52,423 - JUNIFER - INFO - pandas: 2.0.3
2023-10-17 10:30:52,423 - JUNIFER - INFO - nilearn: 0.10.2
2023-10-17 10:30:52,423 - JUNIFER - INFO - nibabel: 5.1.0
2023-10-17 10:30:52,423 - JUNIFER - INFO - junifer: 0.0.4.dev96
2023-10-17 10:30:52,423 - 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 53739520 of 905208634 bytes (5.9%, 15.9s remaining)
Downloaded 139264000 of 905208634 bytes (15.4%, 11.0s remaining)
Downloaded 223109120 of 905208634 bytes (24.6%, 9.2s remaining)
Downloaded 305127424 of 905208634 bytes (33.7%, 7.9s remaining)
Downloaded 389144576 of 905208634 bytes (43.0%, 6.6s remaining)
Downloaded 473464832 of 905208634 bytes (52.3%, 5.5s remaining)
Downloaded 557449216 of 905208634 bytes (61.6%, 4.4s remaining)
Downloaded 640221184 of 905208634 bytes (70.7%, 3.3s remaining)
Downloaded 722305024 of 905208634 bytes (79.8%, 2.3s remaining)
Downloaded 802594816 of 905208634 bytes (88.7%, 1.3s remaining)
Downloaded 886128640 of 905208634 bytes (97.9%, 0.2s remaining) ...done. (12 seconds, 0 min)
Extracting data from /home/runner/nilearn_data/oasis1/6d19418bccb98b1333309bd8baa05152/archive_dartel.tgz..... done.
/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)
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 https://www.fil.ion.ucl.ac.uk/spm/download/data/MoAEpilot/MoAEpilot.zip ...
Downloaded 2719744 of 34212021 bytes (7.9%, 12.0s remaining)
Downloaded 6430720 of 34212021 bytes (18.8%, 8.8s remaining)
Downloaded 9306112 of 34212021 bytes (27.2%, 8.2s remaining)
Downloaded 12378112 of 34212021 bytes (36.2%, 7.2s remaining)
Downloaded 15548416 of 34212021 bytes (45.4%, 6.1s remaining)
Downloaded 18743296 of 34212021 bytes (54.8%, 5.1s remaining)
Downloaded 21938176 of 34212021 bytes (64.1%, 4.0s remaining)
Downloaded 25141248 of 34212021 bytes (73.5%, 3.0s remaining)
Downloaded 27959296 of 34212021 bytes (81.7%, 2.1s remaining)
Downloaded 30580736 of 34212021 bytes (89.4%, 1.2s remaining)
Downloaded 33439744 of 34212021 bytes (97.7%, 0.3s remaining) ...done. (13 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
Fit transform the data
out = marker.fit_transform(input)
2023-10-17 10:31:26,562 - JUNIFER - INFO - Computing BOLD
2023-10-17 10:31:26,562 - JUNIFER - INFO - Fetching one of Schaefer parcellations.
2023-10-17 10:31:26,562 - JUNIFER - INFO - Parcellation parameters:
2023-10-17 10:31:26,562 - JUNIFER - INFO - resolution: 3.0
2023-10-17 10:31:26,562 - JUNIFER - INFO - n_rois: 100
2023-10-17 10:31:26,563 - JUNIFER - INFO - yeo_networks: 7
2023-10-17 10:31:26,563 - 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-10-17 10:31:26,824 - JUNIFER - INFO - Loading parcellation /home/runner/junifer/data/parcellations/schaefer_2018/Schaefer2018_100Parcels_7Networks_order_FSLMNI152_2mm.nii.gz
2023-10-17 10:31:28,465 - JUNIFER - INFO - No storage specified, returning dictionary
2023-10-17 10:31:28,465 - JUNIFER - INFO - Computing VBM_GM
2023-10-17 10:31:28,465 - JUNIFER - INFO - Fetching one of Schaefer parcellations.
2023-10-17 10:31:28,465 - JUNIFER - INFO - Parcellation parameters:
2023-10-17 10:31:28,465 - JUNIFER - INFO - resolution: 2.0
2023-10-17 10:31:28,465 - JUNIFER - INFO - n_rois: 100
2023-10-17 10:31:28,465 - JUNIFER - INFO - yeo_networks: 7
2023-10-17 10:31:28,468 - JUNIFER - INFO - Loading parcellation /home/runner/junifer/data/parcellations/schaefer_2018/Schaefer2018_100Parcels_7Networks_order_FSLMNI152_2mm.nii.gz
2023-10-17 10:31:29,151 - JUNIFER - INFO - No storage specified, returning dictionary
Check the results
dict_keys(['BOLD', 'VBM_GM'])
(1, 100)
dict_keys(['BOLD', 'VBM_GM'])
(96, 100)
Total running time of the script: (0 minutes 36.735 seconds)