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-07 13:20:19 [info     ] ===== Lib Versions =====       [junifer]
2025-11-07 13:20:19 [info     ] click: 8.1.8                   [junifer]
2025-11-07 13:20:19 [info     ] numpy: 1.26.4                  [junifer]
2025-11-07 13:20:19 [info     ] scipy: 1.16.3                  [junifer]
2025-11-07 13:20:19 [info     ] datalad: 1.1.6                 [junifer]
2025-11-07 13:20:19 [info     ] pandas: 2.1.4                  [junifer]
2025-11-07 13:20:19 [info     ] nibabel: 5.3.2                 [junifer]
2025-11-07 13:20:19 [info     ] nilearn: 0.10.4                [junifer]
2025-11-07 13:20:19 [info     ] sqlalchemy: 2.0.44             [junifer]
2025-11-07 13:20:19 [info     ] ruamel.yaml: 0.18.16           [junifer]
2025-11-07 13:20:19 [info     ] tqdm: 4.67.1                   [junifer]
2025-11-07 13:20:19 [info     ] templateflow: 24.2.2           [junifer]
2025-11-07 13:20:19 [info     ] junifer_data: None             [junifer]
2025-11-07 13:20:19 [info     ] junifer: 0.0.7.dev259          [junifer]
2025-11-07 13:20:19 [info     ] ========================       [junifer]

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-07 13:20:19 [info     ] Registering RSSETSMarker in marker [junifer]
2025-11-07 13:20:19 [info     ] Validating Marker Collection   [junifer]
2025-11-07 13:20:19 [info     ] DataGrabber output type: ['BOLD', 'T1w'] [junifer]
2025-11-07 13:20:19 [info     ] Validating Data Reader:        [junifer]
2025-11-07 13:20:19 [info     ] Data Reader output type: ['BOLD', 'T1w'] [junifer]
2025-11-07 13:20:19 [info     ] Validating Marker: Schaefer100x17_RSSETS [junifer]
2025-11-07 13:20:19 [info     ] Marker output type: ['timeseries'] [junifer]
2025-11-07 13:20:19 [info     ] Validating storage for Schaefer100x17_RSSETS [junifer]
2025-11-07 13:20:19 [info     ] Validating Marker: Schaefer200x17_RSSETS [junifer]
2025-11-07 13:20:19 [info     ] Marker output type: ['timeseries'] [junifer]
2025-11-07 13:20:19 [info     ] Validating storage for Schaefer200x17_RSSETS [junifer]
2025-11-07 13:20:19 [info     ] Getting element sub001         [junifer]
2025-11-07 13:20:21 [info     ] Fitting pipeline               [junifer]
2025-11-07 13:20:21 [info     ] Reading BOLD from /tmp/tmpfqiawjf9/sub001_bold.nii.gz [junifer]
2025-11-07 13:20:21 [info     ] BOLD is of type NIFTI          [junifer]
2025-11-07 13:20:21 [info     ] Reading T1w from /tmp/tmpfqiawjf9/sub001_T1w.nii.gz [junifer]
2025-11-07 13:20:21 [info     ] T1w is of type NIFTI           [junifer]
2025-11-07 13:20:21 [info     ] Fitting marker Schaefer100x17_RSSETS [junifer]
2025-11-07 13:20:21 [info     ] Computing BOLD                 [junifer]
2025-11-07 13:20:21 [info     ] Parcellation will be warped from MNI152NLin6Asym to MNI152Lin using highest resolution [junifer]
2025-11-07 13:20:21 [info     ] Parcellation parameters:       [junifer]
2025-11-07 13:20:21 [info     ]         resolution: None              [junifer]
2025-11-07 13:20:21 [info     ]         n_rois: 100                   [junifer]
2025-11-07 13:20:21 [info     ]         yeo_networks: 17              [junifer]
2025-11-07 13:20:21 [info     ] Resolution set to None, using highest resolution. [junifer]
2025-11-07 13:20:21 [info     ] Start annex operation          [datalad.annex] dlm_progress=annexprogress-139803712493792 dlm_progress_label=Total dlm_progress_noninteractive_level=5 dlm_progress_total=233863 dlm_progress_unit=' Bytes'
2025-11-07 13:20:22 [info     ] Start annex action: {'command': 'get', 'file': 'parcellations/Schaefer2018/Yeo2011/Schaefer2018_100Parcels_17Networks_order_FSLMNI152_1mm.nii.gz', 'input': ['parcellations/Schaefer2018/Yeo2011/Schaefer2018_100Parcels_17Networks_order_FSLMNI152_1mm.nii.gz'], 'key': 'MD5E-s233863--52fdf9073096aa55b7196e41619442bb.nii.gz', 'note': 'from gin-src...'} [datalad.annex] dlm_progress=annexprogress-139803712493792-2595519665051047798 dlm_progress_label='Get parcella .. 2_1mm.nii.gz' dlm_progress_noninteractive_level=5 dlm_progress_total=233863.0 dlm_progress_unit=' Bytes'
2025-11-07 13:20:22 [info     ] 38.33%                         [datalad.annex] dlm_progress=annexprogress-139803712493792-2595519665051047798 dlm_progress_noninteractive_level=5 dlm_progress_update=89633.0
2025-11-07 13:20:22 [info     ] Finished annex action: None    [datalad.annex] dlm_progress=annexprogress-139803712493792-2595519665051047798 dlm_progress_noninteractive_level=5
2025-11-07 13:20:22 [info     ] Finished annex get             [datalad.annex] dlm_progress=annexprogress-139803712493792 dlm_progress_noninteractive_level=5
2025-11-07 13:20:23 [info     ] Loading parcellation: /github/home/junifer_data/v5/parcellations/Schaefer2018/Yeo2011/Schaefer2018_100Parcels_17Networks_order_FSLMNI152_1mm.nii.gz [junifer]
2025-11-07 13:20:25 [info     ] Downloading template MNI152Lin (T1w in resolution 1) [junifer]
2025-11-07 13:20:25 [info     ] antsApplyTransforms command to be executed:
antsApplyTransforms -d 3 -e 3 -n 'GenericLabel[NearestNeighbor]' -i /tmp/junifer/tmpoz1fonrh/ants_parcellation_warper_Schaefer100x17_from_MNI152NLin6Asym_to_MNI152Lin_84246472-bbdc-11f0-88c6-e6459467a3c0okmi7ud9/prewarp_parcellation.nii.gz -r /tmp/junifer/tmpoz1fonrh/ants_parcellation_warper_Schaefer100x17_from_MNI152NLin6Asym_to_MNI152Lin_84246472-bbdc-11f0-88c6-e6459467a3c0okmi7ud9/MNI152Lin_T1w.nii.gz -t /github/home/junifer_data/v5/.git/annex/objects/JQ/Pp/SHA256E-s145422752--5091350b36f951d455dabd429ebe86c493c75a0217dca311ae355f1d62e080b0.h5/SHA256E-s145422752--5091350b36f951d455dabd429ebe86c493c75a0217dca311ae355f1d62e080b0.h5 -o /tmp/junifer/tmpoz1fonrh/ants_parcellation_warper_Schaefer100x17_from_MNI152NLin6Asym_to_MNI152Lin_84246472-bbdc-11f0-88c6-e6459467a3c0okmi7ud9/parcellation_warped.nii.gz [junifer]
2025-11-07 13:20:32 [info     ] antsApplyTransforms command succeeded with the following output:
 [junifer]
2025-11-07 13:20:35 [info     ] Storing in <SQLiteFeatureStorage @ /tmp/tmp5w_3rphk/test.sqlite (multiple output)> [junifer]
2025-11-07 13:20:35 [info     ] Fitting marker Schaefer200x17_RSSETS [junifer]
2025-11-07 13:20:35 [info     ] Computing BOLD                 [junifer]
2025-11-07 13:20:35 [info     ] Parcellation will be warped from MNI152NLin6Asym to MNI152Lin using highest resolution [junifer]
2025-11-07 13:20:35 [info     ] Parcellation parameters:       [junifer]
2025-11-07 13:20:35 [info     ]         resolution: None              [junifer]
2025-11-07 13:20:35 [info     ]         n_rois: 200                   [junifer]
2025-11-07 13:20:35 [info     ]         yeo_networks: 17              [junifer]
2025-11-07 13:20:35 [info     ] Resolution set to None, using highest resolution. [junifer]
2025-11-07 13:20:35 [info     ] Start annex operation          [datalad.annex] dlm_progress=annexprogress-139803854373040 dlm_progress_label=Total dlm_progress_noninteractive_level=5 dlm_progress_total=259405 dlm_progress_unit=' Bytes'
2025-11-07 13:20:36 [info     ] Start annex action: {'command': 'get', 'file': 'parcellations/Schaefer2018/Yeo2011/Schaefer2018_200Parcels_17Networks_order_FSLMNI152_1mm.nii.gz', 'input': ['parcellations/Schaefer2018/Yeo2011/Schaefer2018_200Parcels_17Networks_order_FSLMNI152_1mm.nii.gz'], 'key': 'MD5E-s259405--74b10470e93053e255b8dad06d00c9c4.nii.gz', 'note': 'from gin-src...'} [datalad.annex] dlm_progress=annexprogress-139803854373040--7546306842323323750 dlm_progress_label='Get parcella .. 2_1mm.nii.gz' dlm_progress_noninteractive_level=5 dlm_progress_total=259405.0 dlm_progress_unit=' Bytes'
2025-11-07 13:20:36 [info     ] 12.63%                         [datalad.annex] dlm_progress=annexprogress-139803854373040--7546306842323323750 dlm_progress_noninteractive_level=5 dlm_progress_update=32768.0
2025-11-07 13:20:37 [info     ] Finished annex action: None    [datalad.annex] dlm_progress=annexprogress-139803854373040--7546306842323323750 dlm_progress_noninteractive_level=5
2025-11-07 13:20:37 [info     ] Finished annex get             [datalad.annex] dlm_progress=annexprogress-139803854373040 dlm_progress_noninteractive_level=5
2025-11-07 13:20:37 [info     ] Loading parcellation: /github/home/junifer_data/v5/parcellations/Schaefer2018/Yeo2011/Schaefer2018_200Parcels_17Networks_order_FSLMNI152_1mm.nii.gz [junifer]
2025-11-07 13:20:39 [info     ] Downloading template MNI152Lin (T1w in resolution 1) [junifer]
2025-11-07 13:20:40 [info     ] antsApplyTransforms command to be executed:
antsApplyTransforms -d 3 -e 3 -n 'GenericLabel[NearestNeighbor]' -i /tmp/junifer/tmpoz1fonrh/ants_parcellation_warper_Schaefer200x17_from_MNI152NLin6Asym_to_MNI152Lin_8cb7b0bc-bbdc-11f0-88c6-e6459467a3c0sk4qd2i9/prewarp_parcellation.nii.gz -r /tmp/junifer/tmpoz1fonrh/ants_parcellation_warper_Schaefer200x17_from_MNI152NLin6Asym_to_MNI152Lin_8cb7b0bc-bbdc-11f0-88c6-e6459467a3c0sk4qd2i9/MNI152Lin_T1w.nii.gz -t /github/home/junifer_data/v5/.git/annex/objects/JQ/Pp/SHA256E-s145422752--5091350b36f951d455dabd429ebe86c493c75a0217dca311ae355f1d62e080b0.h5/SHA256E-s145422752--5091350b36f951d455dabd429ebe86c493c75a0217dca311ae355f1d62e080b0.h5 -o /tmp/junifer/tmpoz1fonrh/ants_parcellation_warper_Schaefer200x17_from_MNI152NLin6Asym_to_MNI152Lin_8cb7b0bc-bbdc-11f0-88c6-e6459467a3c0sk4qd2i9/parcellation_warped.nii.gz [junifer]
2025-11-07 13:20:51 [info     ] antsApplyTransforms command succeeded with the following output:
 [junifer]
2025-11-07 13:20:54 [info     ] Storing in <SQLiteFeatureStorage @ /tmp/tmp5w_3rphk/test.sqlite (multiple output)> [junifer]
2025-11-07 13:20:54 [info     ] Marker collection fitting done [junifer]
2025-11-07 13:20:54 [info     ] Collecting data using SQLiteFeatureStorage [junifer]
2025-11-07 13:20:54 [info     ] Collecting data from /tmp/tmp5w_3rphk/*test.sqlite [junifer]

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

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

file: 1it [00:00, 25.89it/s]
2025-11-07 13:20:54 [info     ] Collect done                   [junifer]
{'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 35.239 seconds)

Gallery generated by Sphinx-Gallery