8.5. Extracting root sum of squares from edge-wise timeseries.

This example uses a RSSETSMarker to compute root sum of squares of the edge-wise timeseries using the Schaefer parcellation (100 rois and 200 rois, 17 Yeo networks) for a 4D nifti BOLD file.

Authors: Leonard Sasse, Sami Hamdan, Nicolas Nieto, Synchon Mandal

License: BSD 3 clause

import tempfile

import junifer.testing.registry  # noqa: F401
from junifer.api import collect, run
from junifer.storage import SQLiteFeatureStorage
from junifer.utils import configure_logging

Set the logging level to info to see extra information:

configure_logging(level="INFO")
2025-11-26 08:41:40,902 - JUNIFER - INFO - ===== Lib Versions =====
2025-11-26 08:41:40,902 - JUNIFER - INFO - numpy: 1.26.4
2025-11-26 08:41:40,902 - JUNIFER - INFO - scipy: 1.15.0
2025-11-26 08:41:40,902 - JUNIFER - INFO - pandas: 2.1.4
2025-11-26 08:41:40,902 - JUNIFER - INFO - nilearn: 0.10.4
2025-11-26 08:41:40,902 - JUNIFER - INFO - nibabel: 5.3.2
2025-11-26 08:41:40,902 - JUNIFER - INFO - junifer: 0.0.6
2025-11-26 08:41:40,902 - JUNIFER - INFO - ========================

Define the DataGrabber interface

datagrabber = {
    "kind": "SPMAuditoryTestingDataGrabber",
}

Define the markers interface

markers = [
    {
        "name": "Schaefer100x17_RSSETS",
        "kind": "RSSETSMarker",
        "parcellation": "Schaefer100x17",
    },
    {
        "name": "Schaefer200x17_RSSETS",
        "kind": "RSSETSMarker",
        "parcellation": "Schaefer200x17",
    },
]

Create a temporary directory for junifer feature extraction: At the end you can read the extracted data into a pandas.DataFrame.

with tempfile.TemporaryDirectory() as tmpdir:
    # Define the storage interface
    storage = {
        "kind": "SQLiteFeatureStorage",
        "uri": f"{tmpdir}/test.sqlite",
    }
    # Run the defined junifer feature extraction pipeline
    run(
        workdir=tmpdir,
        datagrabber=datagrabber,
        markers=markers,
        storage=storage,
        elements=["sub001"],  # we calculate for one subject only
    )
    # Collect extracted features data
    collect(storage=storage)
    # Create storage object to read in extracted features
    db = SQLiteFeatureStorage(uri=storage["uri"])

    # List all the features
    print(db.list_features())
    # Read extracted features
    df_rssets = db.read_df(feature_name="BOLD_Schaefer200x17_RSSETS_rss_ets")
2025-11-26 08:41:40,907 - JUNIFER - INFO - Registering RSSETSMarker in marker
2025-11-26 08:41:40,908 - JUNIFER - INFO - Validating Marker Collection
2025-11-26 08:41:40,908 - JUNIFER - INFO - DataGrabber output type: ['BOLD', 'T1w']
2025-11-26 08:41:40,908 - JUNIFER - INFO - Validating Data Reader:
2025-11-26 08:41:40,908 - JUNIFER - INFO - Data Reader output type: ['BOLD', 'T1w']
2025-11-26 08:41:40,908 - JUNIFER - INFO - Validating Marker: Schaefer100x17_RSSETS
2025-11-26 08:41:40,908 - JUNIFER - INFO - Marker output type: ['timeseries']
2025-11-26 08:41:40,908 - JUNIFER - INFO - Validating storage for Schaefer100x17_RSSETS
2025-11-26 08:41:40,908 - JUNIFER - INFO - Validating Marker: Schaefer200x17_RSSETS
2025-11-26 08:41:40,908 - JUNIFER - INFO - Marker output type: ['timeseries']
2025-11-26 08:41:40,908 - JUNIFER - INFO - Validating storage for Schaefer200x17_RSSETS
2025-11-26 08:41:40,908 - JUNIFER - INFO - Getting element sub001
2025-11-26 08:41:45,472 - JUNIFER - INFO - Fitting pipeline
2025-11-26 08:41:45,472 - JUNIFER - INFO - Reading BOLD from /tmp/tmpjldvjx8x/sub001_bold.nii.gz
2025-11-26 08:41:45,472 - JUNIFER - INFO - BOLD is of type NIFTI
2025-11-26 08:41:45,473 - JUNIFER - INFO - Reading T1w from /tmp/tmpjldvjx8x/sub001_T1w.nii.gz
2025-11-26 08:41:45,473 - JUNIFER - INFO - T1w is of type NIFTI
2025-11-26 08:41:45,474 - JUNIFER - INFO - Fitting marker Schaefer100x17_RSSETS
2025-11-26 08:41:45,474 - JUNIFER - INFO - Computing BOLD
2025-11-26 08:41:45,474 - JUNIFER - INFO - Parcellation will be warped from MNI152NLin6Asym to MNI152Lin using highest resolution
2025-11-26 08:41:45,474 - JUNIFER - INFO - Parcellation parameters:
2025-11-26 08:41:45,474 - JUNIFER - INFO -      resolution: None
2025-11-26 08:41:45,474 - JUNIFER - INFO -      n_rois: 100
2025-11-26 08:41:45,474 - JUNIFER - INFO -      yeo_networks: 17
2025-11-26 08:41:45,474 - JUNIFER - INFO - Resolution set to None, using highest resolution.
2025-11-26 08:41:45,601 - JUNIFER - INFO - Loading parcellation: /home/synchon/junifer_data/v2/parcellations/Schaefer2018/Yeo2011/Schaefer2018_100Parcels_17Networks_order_FSLMNI152_1mm.nii.gz
2025-11-26 08:41:47,417 - JUNIFER - INFO - Downloading template MNI152Lin (T1w in resolution 1)
2025-11-26 08:41:48,515 - JUNIFER - INFO - antsApplyTransforms command to be executed:
antsApplyTransforms -d 3 -e 3 -n 'GenericLabel[NearestNeighbor]' -i /tmp/junifer/tmp1g0ya1u3/ants_parcellation_warper_Schaefer100x17_from_MNI152NLin6Asym_to_MNI152Lin_5be06cc2-ca9b-11f0-a076-ebd5e38fbbd3pb4zf30h/prewarp_parcellation.nii.gz -r /tmp/junifer/tmp1g0ya1u3/ants_parcellation_warper_Schaefer100x17_from_MNI152NLin6Asym_to_MNI152Lin_5be06cc2-ca9b-11f0-a076-ebd5e38fbbd3pb4zf30h/MNI152Lin_T1w.nii.gz -t /home/synchon/junifer_data/v2/.git/annex/objects/JQ/Pp/SHA256E-s145422752--5091350b36f951d455dabd429ebe86c493c75a0217dca311ae355f1d62e080b0.h5/SHA256E-s145422752--5091350b36f951d455dabd429ebe86c493c75a0217dca311ae355f1d62e080b0.h5 -o /tmp/junifer/tmp1g0ya1u3/ants_parcellation_warper_Schaefer100x17_from_MNI152NLin6Asym_to_MNI152Lin_5be06cc2-ca9b-11f0-a076-ebd5e38fbbd3pb4zf30h/parcellation_warped.nii.gz
2025-11-26 08:41:53,815 - JUNIFER - INFO - antsApplyTransforms command succeeded with the following output:
/tmp/junifer/tmp1g0ya1u3/ants_parcellation_warper_Schaefer100x17_from_MNI152NLin6Asym_to_MNI152Lin_5be06cc2-ca9b-11f0-a076-ebd5e38fbbd3pb4zf30h/prewarp_parcellation.nii.gz is a file
/tmp/junifer/tmp1g0ya1u3/ants_parcellation_warper_Schaefer100x17_from_MNI152NLin6Asym_to_MNI152Lin_5be06cc2-ca9b-11f0-a076-ebd5e38fbbd3pb4zf30h/MNI152Lin_T1w.nii.gz is a file
/home/synchon/junifer_data/v2/.git/annex/objects/JQ/Pp/SHA256E-s145422752--5091350b36f951d455dabd429ebe86c493c75a0217dca311ae355f1d62e080b0.h5/SHA256E-s145422752--5091350b36f951d455dabd429ebe86c493c75a0217dca311ae355f1d62e080b0.h5 is a file
/tmp/junifer/tmp1g0ya1u3/ants_parcellation_warper_Schaefer100x17_from_MNI152NLin6Asym_to_MNI152Lin_5be06cc2-ca9b-11f0-a076-ebd5e38fbbd3pb4zf30h/parcellation_warped.nii.gz is a prefix
Singularity args: --bind /tmp/junifer/tmp1g0ya1u3/ants_parcellation_warper_Schaefer100x17_from_MNI152NLin6Asym_to_MNI152Lin_5be06cc2-ca9b-11f0-a076-ebd5e38fbbd3pb4zf30h:/data/mount_1 --bind /tmp/junifer/tmp1g0ya1u3/ants_parcellation_warper_Schaefer100x17_from_MNI152NLin6Asym_to_MNI152Lin_5be06cc2-ca9b-11f0-a076-ebd5e38fbbd3pb4zf30h:/data/mount_2 --bind /home/synchon/junifer_data/v2/.git/annex/objects/JQ/Pp/SHA256E-s145422752--5091350b36f951d455dabd429ebe86c493c75a0217dca311ae355f1d62e080b0.h5:/data/mount_3 --bind /tmp/junifer/tmp1g0ya1u3/ants_parcellation_warper_Schaefer100x17_from_MNI152NLin6Asym_to_MNI152Lin_5be06cc2-ca9b-11f0-a076-ebd5e38fbbd3pb4zf30h:/data/mount_4
Corrected args for ANTS: antsApplyTransforms -d 3 -e 3 -n GenericLabel[NearestNeighbor] -i /data/mount_1/prewarp_parcellation.nii.gz -r /data/mount_2/MNI152Lin_T1w.nii.gz -t /data/mount_3/SHA256E-s145422752--5091350b36f951d455dabd429ebe86c493c75a0217dca311ae355f1d62e080b0.h5 -o /data/mount_4/parcellation_warped.nii.gz
Running command: /data/group/appliedml/tools/ants_2.5.0/singularity_cmd exec --cleanenv --bind /tmp/junifer/tmp1g0ya1u3/ants_parcellation_warper_Schaefer100x17_from_MNI152NLin6Asym_to_MNI152Lin_5be06cc2-ca9b-11f0-a076-ebd5e38fbbd3pb4zf30h:/data/mount_1 --bind /tmp/junifer/tmp1g0ya1u3/ants_parcellation_warper_Schaefer100x17_from_MNI152NLin6Asym_to_MNI152Lin_5be06cc2-ca9b-11f0-a076-ebd5e38fbbd3pb4zf30h:/data/mount_2 --bind /home/synchon/junifer_data/v2/.git/annex/objects/JQ/Pp/SHA256E-s145422752--5091350b36f951d455dabd429ebe86c493c75a0217dca311ae355f1d62e080b0.h5:/data/mount_3 --bind /tmp/junifer/tmp1g0ya1u3/ants_parcellation_warper_Schaefer100x17_from_MNI152NLin6Asym_to_MNI152Lin_5be06cc2-ca9b-11f0-a076-ebd5e38fbbd3pb4zf30h:/data/mount_4 /data/group/appliedml/tools/ants_2.5.0/ants_v2.5.0.sif antsApplyTransforms -d 3 -e 3 -n GenericLabel[NearestNeighbor] -i /data/mount_1/prewarp_parcellation.nii.gz -r /data/mount_2/MNI152Lin_T1w.nii.gz -t /data/mount_3/SHA256E-s145422752--5091350b36f951d455dabd429ebe86c493c75a0217dca311ae355f1d62e080b0.h5 -o /data/mount_4/parcellation_warped.nii.gz

2025-11-26 08:41:57,455 - JUNIFER - INFO - Storing in <SQLiteFeatureStorage @ /tmp/tmpi_npyl4h/test.sqlite (multiple output)>
2025-11-26 08:41:57,476 - JUNIFER - INFO - Fitting marker Schaefer200x17_RSSETS
2025-11-26 08:41:57,476 - JUNIFER - INFO - Computing BOLD
2025-11-26 08:41:57,476 - JUNIFER - INFO - Parcellation will be warped from MNI152NLin6Asym to MNI152Lin using highest resolution
2025-11-26 08:41:57,476 - JUNIFER - INFO - Parcellation parameters:
2025-11-26 08:41:57,476 - JUNIFER - INFO -      resolution: None
2025-11-26 08:41:57,476 - JUNIFER - INFO -      n_rois: 200
2025-11-26 08:41:57,476 - JUNIFER - INFO -      yeo_networks: 17
2025-11-26 08:41:57,476 - JUNIFER - INFO - Resolution set to None, using highest resolution.
2025-11-26 08:41:57,602 - JUNIFER - INFO - Loading parcellation: /home/synchon/junifer_data/v2/parcellations/Schaefer2018/Yeo2011/Schaefer2018_200Parcels_17Networks_order_FSLMNI152_1mm.nii.gz
2025-11-26 08:41:59,402 - JUNIFER - INFO - Downloading template MNI152Lin (T1w in resolution 1)
2025-11-26 08:42:00,513 - JUNIFER - INFO - antsApplyTransforms command to be executed:
antsApplyTransforms -d 3 -e 3 -n 'GenericLabel[NearestNeighbor]' -i /tmp/junifer/tmp1g0ya1u3/ants_parcellation_warper_Schaefer200x17_from_MNI152NLin6Asym_to_MNI152Lin_63057ad8-ca9b-11f0-a076-ebd5e38fbbd3l9zogdmz/prewarp_parcellation.nii.gz -r /tmp/junifer/tmp1g0ya1u3/ants_parcellation_warper_Schaefer200x17_from_MNI152NLin6Asym_to_MNI152Lin_63057ad8-ca9b-11f0-a076-ebd5e38fbbd3l9zogdmz/MNI152Lin_T1w.nii.gz -t /home/synchon/junifer_data/v2/.git/annex/objects/JQ/Pp/SHA256E-s145422752--5091350b36f951d455dabd429ebe86c493c75a0217dca311ae355f1d62e080b0.h5/SHA256E-s145422752--5091350b36f951d455dabd429ebe86c493c75a0217dca311ae355f1d62e080b0.h5 -o /tmp/junifer/tmp1g0ya1u3/ants_parcellation_warper_Schaefer200x17_from_MNI152NLin6Asym_to_MNI152Lin_63057ad8-ca9b-11f0-a076-ebd5e38fbbd3l9zogdmz/parcellation_warped.nii.gz
2025-11-26 08:42:09,742 - JUNIFER - INFO - antsApplyTransforms command succeeded with the following output:
/tmp/junifer/tmp1g0ya1u3/ants_parcellation_warper_Schaefer200x17_from_MNI152NLin6Asym_to_MNI152Lin_63057ad8-ca9b-11f0-a076-ebd5e38fbbd3l9zogdmz/prewarp_parcellation.nii.gz is a file
/tmp/junifer/tmp1g0ya1u3/ants_parcellation_warper_Schaefer200x17_from_MNI152NLin6Asym_to_MNI152Lin_63057ad8-ca9b-11f0-a076-ebd5e38fbbd3l9zogdmz/MNI152Lin_T1w.nii.gz is a file
/home/synchon/junifer_data/v2/.git/annex/objects/JQ/Pp/SHA256E-s145422752--5091350b36f951d455dabd429ebe86c493c75a0217dca311ae355f1d62e080b0.h5/SHA256E-s145422752--5091350b36f951d455dabd429ebe86c493c75a0217dca311ae355f1d62e080b0.h5 is a file
/tmp/junifer/tmp1g0ya1u3/ants_parcellation_warper_Schaefer200x17_from_MNI152NLin6Asym_to_MNI152Lin_63057ad8-ca9b-11f0-a076-ebd5e38fbbd3l9zogdmz/parcellation_warped.nii.gz is a prefix
Singularity args: --bind /tmp/junifer/tmp1g0ya1u3/ants_parcellation_warper_Schaefer200x17_from_MNI152NLin6Asym_to_MNI152Lin_63057ad8-ca9b-11f0-a076-ebd5e38fbbd3l9zogdmz:/data/mount_1 --bind /tmp/junifer/tmp1g0ya1u3/ants_parcellation_warper_Schaefer200x17_from_MNI152NLin6Asym_to_MNI152Lin_63057ad8-ca9b-11f0-a076-ebd5e38fbbd3l9zogdmz:/data/mount_2 --bind /home/synchon/junifer_data/v2/.git/annex/objects/JQ/Pp/SHA256E-s145422752--5091350b36f951d455dabd429ebe86c493c75a0217dca311ae355f1d62e080b0.h5:/data/mount_3 --bind /tmp/junifer/tmp1g0ya1u3/ants_parcellation_warper_Schaefer200x17_from_MNI152NLin6Asym_to_MNI152Lin_63057ad8-ca9b-11f0-a076-ebd5e38fbbd3l9zogdmz:/data/mount_4
Corrected args for ANTS: antsApplyTransforms -d 3 -e 3 -n GenericLabel[NearestNeighbor] -i /data/mount_1/prewarp_parcellation.nii.gz -r /data/mount_2/MNI152Lin_T1w.nii.gz -t /data/mount_3/SHA256E-s145422752--5091350b36f951d455dabd429ebe86c493c75a0217dca311ae355f1d62e080b0.h5 -o /data/mount_4/parcellation_warped.nii.gz
Running command: /data/group/appliedml/tools/ants_2.5.0/singularity_cmd exec --cleanenv --bind /tmp/junifer/tmp1g0ya1u3/ants_parcellation_warper_Schaefer200x17_from_MNI152NLin6Asym_to_MNI152Lin_63057ad8-ca9b-11f0-a076-ebd5e38fbbd3l9zogdmz:/data/mount_1 --bind /tmp/junifer/tmp1g0ya1u3/ants_parcellation_warper_Schaefer200x17_from_MNI152NLin6Asym_to_MNI152Lin_63057ad8-ca9b-11f0-a076-ebd5e38fbbd3l9zogdmz:/data/mount_2 --bind /home/synchon/junifer_data/v2/.git/annex/objects/JQ/Pp/SHA256E-s145422752--5091350b36f951d455dabd429ebe86c493c75a0217dca311ae355f1d62e080b0.h5:/data/mount_3 --bind /tmp/junifer/tmp1g0ya1u3/ants_parcellation_warper_Schaefer200x17_from_MNI152NLin6Asym_to_MNI152Lin_63057ad8-ca9b-11f0-a076-ebd5e38fbbd3l9zogdmz:/data/mount_4 /data/group/appliedml/tools/ants_2.5.0/ants_v2.5.0.sif antsApplyTransforms -d 3 -e 3 -n GenericLabel[NearestNeighbor] -i /data/mount_1/prewarp_parcellation.nii.gz -r /data/mount_2/MNI152Lin_T1w.nii.gz -t /data/mount_3/SHA256E-s145422752--5091350b36f951d455dabd429ebe86c493c75a0217dca311ae355f1d62e080b0.h5 -o /data/mount_4/parcellation_warped.nii.gz

2025-11-26 08:42:12,162 - JUNIFER - INFO - Storing in <SQLiteFeatureStorage @ /tmp/tmpi_npyl4h/test.sqlite (multiple output)>
2025-11-26 08:42:12,181 - JUNIFER - INFO - Marker collection fitting done
2025-11-26 08:42:12,187 - JUNIFER - INFO - Collecting data using SQLiteFeatureStorage
2025-11-26 08:42:12,187 - JUNIFER - INFO - Collecting data from /tmp/tmpi_npyl4h/*test.sqlite

file: 0it [00:00, ?it/s]

feature:   0%|          | 0/2 [00:00<?, ?it/s]
feature: 100%|██████████| 2/2 [00:00<00:00, 88.66it/s]

file: 1it [00:00, 31.49it/s]
2025-11-26 08:42:12,219 - JUNIFER - INFO - Collect done
{'de47d0513cf22df792d264ecc363085a': {'datagrabber': {'class': 'SPMAuditoryTestingDataGrabber', 'types': ['BOLD', 'T1w']}, 'dependencies': {'nilearn': '0.10.4'}, 'datareader': {'class': 'DefaultDataReader'}, 'type': 'BOLD', 'marker': {'agg_method': 'mean', 'agg_method_params': None, 'class': 'RSSETSMarker', 'masks': None, 'name': 'Schaefer100x17_RSSETS_rss_ets', 'parcellation': 'Schaefer100x17'}, '_element_keys': ['subject'], 'name': 'BOLD_Schaefer100x17_RSSETS_rss_ets'}, '0ff7a9e8f65fc25885bd0cd4936f87a4': {'datagrabber': {'class': 'SPMAuditoryTestingDataGrabber', 'types': ['BOLD', 'T1w']}, 'dependencies': {'nilearn': '0.10.4'}, 'datareader': {'class': 'DefaultDataReader'}, 'type': 'BOLD', 'marker': {'agg_method': 'mean', 'agg_method_params': None, 'class': 'RSSETSMarker', 'masks': None, 'name': 'Schaefer200x17_RSSETS_rss_ets', 'parcellation': 'Schaefer200x17'}, '_element_keys': ['subject'], 'name': 'BOLD_Schaefer200x17_RSSETS_rss_ets'}}

Now we take a look at the dataframe

root_sum_of_squares_ets
subject timepoint
sub001 0 2502.888057
1 168.174038
2 102.849715
3 132.639660
4 109.615993


Total running time of the script: (0 minutes 31.342 seconds)

Gallery generated by Sphinx-Gallery