Note
Click here 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-05-16 14:00:32,769 - JUNIFER - INFO - ===== Lib Versions =====
2023-05-16 14:00:32,770 - JUNIFER - INFO - numpy: 1.23.5
2023-05-16 14:00:32,770 - JUNIFER - INFO - scipy: 1.10.1
2023-05-16 14:00:32,770 - JUNIFER - INFO - pandas: 1.5.3
2023-05-16 14:00:32,770 - JUNIFER - INFO - nilearn: 0.10.0
2023-05-16 14:00:32,770 - JUNIFER - INFO - nibabel: 4.0.2
2023-05-16 14:00:32,770 - JUNIFER - INFO - junifer: 0.0.3.dev104
2023-05-16 14:00:32,770 - 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 253566976 of 905208634 bytes (28.0%, 2.6s remaining)
Downloaded 514875392 of 905208634 bytes (56.9%, 1.5s remaining)
Downloaded 778870784 of 905208634 bytes (86.0%, 0.5s remaining) ...done. (4 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 548864 of 34212021 bytes (1.6%, 1.1min remaining)
Downloaded 1040384 of 34212021 bytes (3.0%, 1.1min remaining)
Downloaded 1327104 of 34212021 bytes (3.9%, 1.3min remaining)
Downloaded 1630208 of 34212021 bytes (4.8%, 1.4min remaining)
Downloaded 1933312 of 34212021 bytes (5.7%, 1.4min remaining)
Downloaded 2326528 of 34212021 bytes (6.8%, 1.4min remaining)
Downloaded 2727936 of 34212021 bytes (8.0%, 1.4min remaining)
Downloaded 3194880 of 34212021 bytes (9.3%, 1.3min remaining)
Downloaded 3645440 of 34212021 bytes (10.7%, 1.3min remaining)
Downloaded 4022272 of 34212021 bytes (11.8%, 1.3min remaining)
Downloaded 4481024 of 34212021 bytes (13.1%, 1.3min remaining)
Downloaded 5079040 of 34212021 bytes (14.8%, 1.2min remaining)
Downloaded 5595136 of 34212021 bytes (16.4%, 1.1min remaining)
Downloaded 6053888 of 34212021 bytes (17.7%, 1.1min remaining)
Downloaded 6553600 of 34212021 bytes (19.2%, 1.1min remaining)
Downloaded 7077888 of 34212021 bytes (20.7%, 1.1min remaining)
Downloaded 7659520 of 34212021 bytes (22.4%, 1.0min remaining)
Downloaded 8110080 of 34212021 bytes (23.7%, 59.9s remaining)
Downloaded 8585216 of 34212021 bytes (25.1%, 58.6s remaining)
Downloaded 9035776 of 34212021 bytes (26.4%, 57.6s remaining)
Downloaded 9576448 of 34212021 bytes (28.0%, 55.9s remaining)
Downloaded 10092544 of 34212021 bytes (29.5%, 54.4s remaining)
Downloaded 10682368 of 34212021 bytes (31.2%, 52.4s remaining)
Downloaded 11362304 of 34212021 bytes (33.2%, 49.9s remaining)
Downloaded 12050432 of 34212021 bytes (35.2%, 47.6s remaining)
Downloaded 12541952 of 34212021 bytes (36.7%, 46.4s remaining)
Downloaded 12951552 of 34212021 bytes (37.9%, 45.8s remaining)
Downloaded 13271040 of 34212021 bytes (38.8%, 45.7s remaining)
Downloaded 13639680 of 34212021 bytes (39.9%, 45.2s remaining)
Downloaded 14024704 of 34212021 bytes (41.0%, 44.6s remaining)
Downloaded 14409728 of 34212021 bytes (42.1%, 44.1s remaining)
Downloaded 14704640 of 34212021 bytes (43.0%, 43.9s remaining)
Downloaded 15106048 of 34212021 bytes (44.2%, 43.2s remaining)
Downloaded 15630336 of 34212021 bytes (45.7%, 41.8s remaining)
Downloaded 16179200 of 34212021 bytes (47.3%, 40.4s remaining)
Downloaded 16760832 of 34212021 bytes (49.0%, 38.8s remaining)
Downloaded 17358848 of 34212021 bytes (50.7%, 37.2s remaining)
Downloaded 17768448 of 34212021 bytes (51.9%, 36.4s remaining)
Downloaded 18235392 of 34212021 bytes (53.3%, 35.3s remaining)
Downloaded 18653184 of 34212021 bytes (54.5%, 34.5s remaining)
Downloaded 18948096 of 34212021 bytes (55.4%, 34.1s remaining)
Downloaded 19308544 of 34212021 bytes (56.4%, 33.5s remaining)
Downloaded 19783680 of 34212021 bytes (57.8%, 32.4s remaining)
Downloaded 20324352 of 34212021 bytes (59.4%, 31.0s remaining)
Downloaded 20660224 of 34212021 bytes (60.4%, 30.5s remaining)
Downloaded 21020672 of 34212021 bytes (61.4%, 29.8s remaining)
Downloaded 21495808 of 34212021 bytes (62.8%, 28.7s remaining)
Downloaded 21987328 of 34212021 bytes (64.3%, 27.6s remaining)
Downloaded 22528000 of 34212021 bytes (65.8%, 26.2s remaining)
Downloaded 23085056 of 34212021 bytes (67.5%, 24.9s remaining)
Downloaded 23666688 of 34212021 bytes (69.2%, 23.5s remaining)
Downloaded 24150016 of 34212021 bytes (70.6%, 22.4s remaining)
Downloaded 24453120 of 34212021 bytes (71.5%, 21.8s remaining)
Downloaded 24854528 of 34212021 bytes (72.6%, 21.0s remaining)
Downloaded 25313280 of 34212021 bytes (74.0%, 20.0s remaining)
Downloaded 25681920 of 34212021 bytes (75.1%, 19.2s remaining)
Downloaded 26116096 of 34212021 bytes (76.3%, 18.2s remaining)
Downloaded 26632192 of 34212021 bytes (77.8%, 17.0s remaining)
Downloaded 27049984 of 34212021 bytes (79.1%, 16.1s remaining)
Downloaded 27426816 of 34212021 bytes (80.2%, 15.3s remaining)
Downloaded 27738112 of 34212021 bytes (81.1%, 14.7s remaining)
Downloaded 28065792 of 34212021 bytes (82.0%, 14.0s remaining)
Downloaded 28368896 of 34212021 bytes (82.9%, 13.4s remaining)
Downloaded 28778496 of 34212021 bytes (84.1%, 12.5s remaining)
Downloaded 29278208 of 34212021 bytes (85.6%, 11.3s remaining)
Downloaded 29761536 of 34212021 bytes (87.0%, 10.2s remaining)
Downloaded 30277632 of 34212021 bytes (88.5%, 9.0s remaining)
Downloaded 30638080 of 34212021 bytes (89.6%, 8.2s remaining)
Downloaded 31031296 of 34212021 bytes (90.7%, 7.3s remaining)
Downloaded 31399936 of 34212021 bytes (91.8%, 6.5s remaining)
Downloaded 31793152 of 34212021 bytes (92.9%, 5.6s remaining)
Downloaded 32161792 of 34212021 bytes (94.0%, 4.7s remaining)
Downloaded 32464896 of 34212021 bytes (94.9%, 4.1s remaining)
Downloaded 32776192 of 34212021 bytes (95.8%, 3.3s remaining)
Downloaded 33071104 of 34212021 bytes (96.7%, 2.7s remaining)
Downloaded 33349632 of 34212021 bytes (97.5%, 2.0s remaining)
Downloaded 33677312 of 34212021 bytes (98.4%, 1.3s remaining)
Downloaded 33980416 of 34212021 bytes (99.3%, 0.5s remaining) ...done. (82 seconds, 1 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-05-16 14:02:07,978 - JUNIFER - INFO - Computing BOLD
2023-05-16 14:02:07,978 - JUNIFER - INFO - Fetching one of Schaefer parcellations.
2023-05-16 14:02:07,978 - JUNIFER - INFO - Parcellation parameters:
2023-05-16 14:02:07,978 - JUNIFER - INFO - n_rois: 100
2023-05-16 14:02:07,978 - JUNIFER - INFO - yeo_networks: 7
2023-05-16 14:02:07,978 - JUNIFER - INFO - resolution: 3.0
2023-05-16 14:02:07,979 - 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:02:08,115 - JUNIFER - INFO - Loading parcellation /home/runner/junifer/data/parcellations/schaefer_2018/Schaefer2018_100Parcels_7Networks_order_FSLMNI152_2mm.nii.gz
2023-05-16 14:02:09,404 - JUNIFER - INFO - No storage specified, returning dictionary
2023-05-16 14:02:09,404 - JUNIFER - INFO - Computing VBM_GM
2023-05-16 14:02:09,404 - JUNIFER - INFO - Fetching one of Schaefer parcellations.
2023-05-16 14:02:09,404 - JUNIFER - INFO - Parcellation parameters:
2023-05-16 14:02:09,404 - JUNIFER - INFO - n_rois: 100
2023-05-16 14:02:09,404 - JUNIFER - INFO - yeo_networks: 7
2023-05-16 14:02:09,404 - JUNIFER - INFO - resolution: 2.0
2023-05-16 14:02:09,406 - JUNIFER - INFO - Loading parcellation /home/runner/junifer/data/parcellations/schaefer_2018/Schaefer2018_100Parcels_7Networks_order_FSLMNI152_2mm.nii.gz
2023-05-16 14:02:09,944 - 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: ( 1 minutes 37.178 seconds)