.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "auto_examples/run_compute_parcel_mean.py" .. LINE NUMBERS ARE GIVEN BELOW. .. only:: html .. note:: :class: sphx-glr-download-link-note :ref:`Go to the end ` to download the full example code. .. rst-class:: sphx-glr-example-title .. _sphx_glr_auto_examples_run_compute_parcel_mean.py: Computer Parcel Aggregation. ============================ This example uses the ``ParcelAggregation`` marker to compute the mean of each parcel using the Schaefer parcellations (100 rois, 7 Yeo networks) for both 3D and 4D NIfTI. Authors: Federico Raimondo, Synchon Mandal License: BSD 3 clause .. GENERATED FROM PYTHON SOURCE LINES 13-23 .. code-block:: Python from junifer.testing.datagrabbers import ( OasisVBMTestingDataGrabber, SPMAuditoryTestingDataGrabber, ) from junifer.datareader import DefaultDataReader from junifer.markers import ParcelAggregation from junifer.utils import configure_logging .. GENERATED FROM PYTHON SOURCE LINES 24-25 Set the logging level to info to see extra information .. GENERATED FROM PYTHON SOURCE LINES 25-27 .. code-block:: Python configure_logging(level="INFO") .. rst-class:: sphx-glr-script-out .. code-block:: none /__w/junifer/junifer/junifer/utils/logging.py:193: UserWarning: The '__version__' attribute is deprecated and will be removed in MarkupSafe 3.1. Use feature detection, or `importlib.metadata.version("markupsafe")`, instead. vstring = str(getattr(module, "__version__", None)) 2024-12-06 13:54:33,189 - JUNIFER - INFO - ===== Lib Versions ===== 2024-12-06 13:54:33,189 - JUNIFER - INFO - numpy: 1.26.4 2024-12-06 13:54:33,189 - JUNIFER - INFO - scipy: 1.14.1 2024-12-06 13:54:33,189 - JUNIFER - INFO - pandas: 2.1.4 2024-12-06 13:54:33,189 - JUNIFER - INFO - nilearn: 0.10.4 2024-12-06 13:54:33,189 - JUNIFER - INFO - nibabel: 5.3.2 2024-12-06 13:54:33,190 - JUNIFER - INFO - junifer: 0.0.6.dev358 2024-12-06 13:54:33,190 - JUNIFER - INFO - ======================== .. GENERATED FROM PYTHON SOURCE LINES 28-29 Perform parcel aggregation on VBM GM data (3D) from OASIS dataset .. GENERATED FROM PYTHON SOURCE LINES 29-42 .. code-block:: Python with OasisVBMTestingDataGrabber() as dg: # Get the first element element = dg.get_elements()[0] # Read the element element_data = DefaultDataReader().fit_transform(dg[element]) # Initialize marker marker = ParcelAggregation(parcellation="Schaefer100x7", method="mean") # Compute feature feature = marker.fit_transform(element_data) # Print the output print(feature.keys()) print(feature["VBM_GM"]["aggregation"]["data"].shape) # Shape is (1 x parcels) .. rst-class:: sphx-glr-script-out .. code-block:: none 2024-12-06 13:54:33,195 - JUNIFER - INFO - Getting element sub-01 2024-12-06 13:54:33,196 - JUNIFER - INFO - Reading VBM_GM from /github/home/nilearn_data/oasis1/OAS1_0001_MR1/mwrc1OAS1_0001_MR1_mpr_anon_fslswapdim_bet.nii.gz 2024-12-06 13:54:33,196 - JUNIFER - INFO - VBM_GM is of type NIFTI 2024-12-06 13:54:33,197 - JUNIFER - INFO - Computing VBM_GM 2024-12-06 13:54:33,197 - JUNIFER - INFO - Parcellation will be warped from MNI152NLin6Asym to MNI152Lin using highest resolution 2024-12-06 13:54:33,197 - JUNIFER - INFO - Fetching one of Schaefer parcellations. 2024-12-06 13:54:33,197 - JUNIFER - INFO - Parcellation parameters: 2024-12-06 13:54:33,197 - JUNIFER - INFO - resolution: None 2024-12-06 13:54:33,197 - JUNIFER - INFO - n_rois: 100 2024-12-06 13:54:33,197 - JUNIFER - INFO - yeo_networks: 7 2024-12-06 13:54:33,197 - JUNIFER - INFO - Resolution set to None, using highest resolution. 2024-12-06 13:54:33,197 - JUNIFER - INFO - At least one of the parcellation files are missing. Fetching using nilearn. 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_1mm.nii.gz ... ...done. (0 seconds, 0 min) 2024-12-06 13:54:33,602 - JUNIFER - INFO - Loading parcellation: /github/home/junifer/data/parcellations/schaefer_2018/Schaefer2018_100Parcels_7Networks_order_FSLMNI152_1mm.nii.gz 2024-12-06 13:54:33,870 - JUNIFER - INFO - Found existing xfm file for MNI152NLin6Asym to MNI152Lin at /github/home/junifer/data/xfms/.git/annex/objects/80/1W/SHA256E-s151956315--b80fd5f087580ecbbb212d1ece24c12f1ce448ca4912c1ea739eb8e84b6f418a.h5/SHA256E-s151956315--b80fd5f087580ecbbb212d1ece24c12f1ce448ca4912c1ea739eb8e84b6f418a.h5 2024-12-06 13:54:34,985 - JUNIFER - INFO - Downloading template MNI152Lin in resolution 1 2024-12-06 13:54:35,488 - JUNIFER - INFO - antsApplyTransforms command to be executed: antsApplyTransforms -d 3 -e 3 -n 'GenericLabel[NearestNeighbor]' -i /tmp/junifer/tmp28sxvvtd/ants_parcellation_warper_Schaefer100x7_from_MNI152NLin6Asym_to_MNI152Lin_9f95af6a-b3d9-11ef-9645-0242ac1200022dss0j1g/prewarp_parcellation.nii.gz -r /tmp/junifer/tmp28sxvvtd/ants_parcellation_warper_Schaefer100x7_from_MNI152NLin6Asym_to_MNI152Lin_9f95af6a-b3d9-11ef-9645-0242ac1200022dss0j1g/MNI152Lin_T1w.nii.gz -t /github/home/junifer/data/xfms/.git/annex/objects/80/1W/SHA256E-s151956315--b80fd5f087580ecbbb212d1ece24c12f1ce448ca4912c1ea739eb8e84b6f418a.h5/SHA256E-s151956315--b80fd5f087580ecbbb212d1ece24c12f1ce448ca4912c1ea739eb8e84b6f418a.h5 -o /tmp/junifer/tmp28sxvvtd/ants_parcellation_warper_Schaefer100x7_from_MNI152NLin6Asym_to_MNI152Lin_9f95af6a-b3d9-11ef-9645-0242ac1200022dss0j1g/parcellation_warped.nii.gz 2024-12-06 13:54:44,568 - JUNIFER - INFO - antsApplyTransforms command succeeded with the following output: 2024-12-06 13:54:45,864 - JUNIFER - INFO - No storage specified, returning dictionary dict_keys(['VBM_GM']) (1, 100) .. GENERATED FROM PYTHON SOURCE LINES 43-44 Perform parcel aggregation on BOLD data (4D) from SPM Auditory dataset .. GENERATED FROM PYTHON SOURCE LINES 44-58 .. code-block:: Python with SPMAuditoryTestingDataGrabber() as dg: # Get the first element element = dg.get_elements()[0] # Read the element element_data = DefaultDataReader().fit_transform(dg[element]) # Initialize marker marker = ParcelAggregation( parcellation="Schaefer100x7", method="mean", on="BOLD" ) # Compute feature feature = marker.fit_transform(element_data) # Print the output print(feature.keys()) print(feature["BOLD"]["aggregation"]["data"].shape) # Shape is (timepoints x parcels) .. rst-class:: sphx-glr-script-out .. code-block:: none 2024-12-06 13:54:45,865 - JUNIFER - INFO - Getting element sub001 Dataset created in /github/home/nilearn_data/spm_auditory Data absent, downloading... Downloading data from https://www.fil.ion.ucl.ac.uk/spm/download/data/MoAEpilot/MoAEpilot.zip ... Downloaded 1499136 of 34212021 bytes (4.4%, 22.2s remaining) Downloaded 6324224 of 34212021 bytes (18.5%, 9.1s remaining) Downloaded 13352960 of 34212021 bytes (39.0%, 4.8s remaining) Downloaded 18505728 of 34212021 bytes (54.1%, 3.5s remaining) Downloaded 20856832 of 34212021 bytes (61.0%, 3.3s remaining) Downloaded 22880256 of 34212021 bytes (66.9%, 3.0s remaining) Downloaded 25026560 of 34212021 bytes (73.2%, 2.6s remaining) Downloaded 27230208 of 34212021 bytes (79.6%, 2.1s remaining) Downloaded 29433856 of 34212021 bytes (86.0%, 1.5s remaining) Downloaded 31645696 of 34212021 bytes (92.5%, 0.8s remaining) Downloaded 33857536 of 34212021 bytes (99.0%, 0.1s remaining) ...done. (13 seconds, 0 min) Extracting data from /github/home/nilearn_data/spm_auditory/sub001/MoAEpilot.zip..... done. 2024-12-06 13:55:01,408 - JUNIFER - INFO - Reading BOLD from /tmp/tmpwfx19g14/sub001_bold.nii.gz 2024-12-06 13:55:01,408 - JUNIFER - INFO - BOLD is of type NIFTI 2024-12-06 13:55:01,409 - JUNIFER - INFO - Reading T1w from /tmp/tmpwfx19g14/sub001_T1w.nii.gz 2024-12-06 13:55:01,409 - JUNIFER - INFO - T1w is of type NIFTI 2024-12-06 13:55:01,410 - JUNIFER - INFO - Computing BOLD 2024-12-06 13:55:01,410 - JUNIFER - INFO - Parcellation will be warped from MNI152NLin6Asym to MNI152Lin using highest resolution 2024-12-06 13:55:01,410 - JUNIFER - INFO - Fetching one of Schaefer parcellations. 2024-12-06 13:55:01,410 - JUNIFER - INFO - Parcellation parameters: 2024-12-06 13:55:01,410 - JUNIFER - INFO - resolution: None 2024-12-06 13:55:01,410 - JUNIFER - INFO - n_rois: 100 2024-12-06 13:55:01,410 - JUNIFER - INFO - yeo_networks: 7 2024-12-06 13:55:01,410 - JUNIFER - INFO - Resolution set to None, using highest resolution. 2024-12-06 13:55:01,412 - JUNIFER - INFO - Loading parcellation: /github/home/junifer/data/parcellations/schaefer_2018/Schaefer2018_100Parcels_7Networks_order_FSLMNI152_1mm.nii.gz 2024-12-06 13:55:01,682 - JUNIFER - INFO - Found existing xfm file for MNI152NLin6Asym to MNI152Lin at /github/home/junifer/data/xfms/.git/annex/objects/80/1W/SHA256E-s151956315--b80fd5f087580ecbbb212d1ece24c12f1ce448ca4912c1ea739eb8e84b6f418a.h5/SHA256E-s151956315--b80fd5f087580ecbbb212d1ece24c12f1ce448ca4912c1ea739eb8e84b6f418a.h5 2024-12-06 13:55:02,799 - JUNIFER - INFO - Downloading template MNI152Lin in resolution 1 2024-12-06 13:55:03,304 - JUNIFER - INFO - antsApplyTransforms command to be executed: antsApplyTransforms -d 3 -e 3 -n 'GenericLabel[NearestNeighbor]' -i /tmp/junifer/tmp28sxvvtd/ants_parcellation_warper_Schaefer100x7_from_MNI152NLin6Asym_to_MNI152Lin_b02969ca-b3d9-11ef-9645-0242ac120002efcxyjrw/prewarp_parcellation.nii.gz -r /tmp/junifer/tmp28sxvvtd/ants_parcellation_warper_Schaefer100x7_from_MNI152NLin6Asym_to_MNI152Lin_b02969ca-b3d9-11ef-9645-0242ac120002efcxyjrw/MNI152Lin_T1w.nii.gz -t /github/home/junifer/data/xfms/.git/annex/objects/80/1W/SHA256E-s151956315--b80fd5f087580ecbbb212d1ece24c12f1ce448ca4912c1ea739eb8e84b6f418a.h5/SHA256E-s151956315--b80fd5f087580ecbbb212d1ece24c12f1ce448ca4912c1ea739eb8e84b6f418a.h5 -o /tmp/junifer/tmp28sxvvtd/ants_parcellation_warper_Schaefer100x7_from_MNI152NLin6Asym_to_MNI152Lin_b02969ca-b3d9-11ef-9645-0242ac120002efcxyjrw/parcellation_warped.nii.gz 2024-12-06 13:55:12,330 - JUNIFER - INFO - antsApplyTransforms command succeeded with the following output: /__t/Python/3.12.7/x64/lib/python3.12/site-packages/nilearn/maskers/nifti_masker.py:110: UserWarning: imgs are being resampled to the mask_img resolution. This process is memory intensive. You might want to provide a target_affine that is equal to the affine of the imgs or resample the mask beforehand to save memory and computation time. warnings.warn( 2024-12-06 13:55:14,686 - JUNIFER - INFO - No storage specified, returning dictionary dict_keys(['BOLD']) (96, 100) .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 41.502 seconds) .. _sphx_glr_download_auto_examples_run_compute_parcel_mean.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: run_compute_parcel_mean.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: run_compute_parcel_mean.py ` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: run_compute_parcel_mean.zip ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_