Note
Go to the end to download the full example code.
8.4. 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-18 17:36:19 [info ] ===== Lib Versions ===== [junifer]
2025-11-18 17:36:19 [info ] click: 8.1.8 [junifer]
2025-11-18 17:36:19 [info ] numpy: 1.26.4 [junifer]
2025-11-18 17:36:19 [info ] scipy: 1.15.0 [junifer]
2025-11-18 17:36:19 [info ] datalad: 1.1.6 [junifer]
2025-11-18 17:36:19 [info ] pandas: 2.1.4 [junifer]
2025-11-18 17:36:19 [info ] nibabel: 5.3.2 [junifer]
2025-11-18 17:36:19 [info ] nilearn: 0.10.4 [junifer]
2025-11-18 17:36:19 [info ] sqlalchemy: 2.0.44 [junifer]
2025-11-18 17:36:19 [info ] ruamel.yaml: 0.18.16 [junifer]
2025-11-18 17:36:19 [info ] tqdm: 4.66.6 [junifer]
2025-11-18 17:36:19 [info ] templateflow: 24.2.2 [junifer]
2025-11-18 17:36:19 [info ] junifer_data: None [junifer]
2025-11-18 17:36:19 [info ] junifer: 0.0.7.dev401 [junifer]
2025-11-18 17:36: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-18 17:36:19 [info ] Registering RSSETSMarker in marker [junifer]
2025-11-18 17:36:19 [info ] Validating Marker Collection [junifer]
2025-11-18 17:36:19 [info ] DataGrabber output type: ['BOLD', 'T1w'] [junifer]
2025-11-18 17:36:19 [info ] Validating Data Reader: [junifer]
2025-11-18 17:36:19 [info ] Data Reader output type: ['BOLD', 'T1w'] [junifer]
2025-11-18 17:36:19 [info ] Validating Marker: Schaefer100x17_RSSETS [junifer]
2025-11-18 17:36:19 [info ] Marker output type: [<StorageType.Timeseries: 'timeseries'>] [junifer]
2025-11-18 17:36:19 [info ] Validating storage for Schaefer100x17_RSSETS [junifer]
2025-11-18 17:36:19 [info ] Validating Marker: Schaefer200x17_RSSETS [junifer]
2025-11-18 17:36:19 [info ] Marker output type: [<StorageType.Timeseries: 'timeseries'>] [junifer]
2025-11-18 17:36:19 [info ] Validating storage for Schaefer200x17_RSSETS [junifer]
2025-11-18 17:36:19 [info ] Getting element ('sub001',) [junifer]
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 1286144 of 34212021 bytes (3.8%, 26.8s remaining)
Downloaded 6463488 of 34212021 bytes (18.9%, 8.9s remaining)
Downloaded 11272192 of 34212021 bytes (32.9%, 6.3s remaining)
Downloaded 16375808 of 34212021 bytes (47.9%, 4.5s remaining)
Downloaded 21626880 of 34212021 bytes (63.2%, 3.0s remaining)
Downloaded 26968064 of 34212021 bytes (78.8%, 1.7s remaining)
Downloaded 32358400 of 34212021 bytes (94.6%, 0.4s remaining) ...done. (9 seconds, 0 min)
Extracting data from /github/home/nilearn_data/spm_auditory/sub001/MoAEpilot.zip..... done.
2025-11-18 17:36:30 [info ] Fitting pipeline [junifer]
2025-11-18 17:36:30 [info ] Reading BOLD from /tmp/tmpf7c8v3r_/sub001_bold.nii.gz [junifer]
2025-11-18 17:36:30 [info ] BOLD is of type NIFTI [junifer]
2025-11-18 17:36:30 [info ] Reading T1w from /tmp/tmpf7c8v3r_/sub001_T1w.nii.gz [junifer]
2025-11-18 17:36:30 [info ] T1w is of type NIFTI [junifer]
2025-11-18 17:36:30 [info ] Fitting marker Schaefer100x17_RSSETS [junifer]
2025-11-18 17:36:30 [info ] Computing DataType.BOLD [junifer]
2025-11-18 17:36:30 [info ] Parcellation will be warped from MNI152NLin6Asym to MNI152Lin using highest resolution [junifer]
2025-11-18 17:36:30 [info ] Parcellation parameters: [junifer]
2025-11-18 17:36:30 [info ] resolution: None [junifer]
2025-11-18 17:36:30 [info ] n_rois: 100 [junifer]
2025-11-18 17:36:30 [info ] yeo_networks: 17 [junifer]
2025-11-18 17:36:30 [info ] Resolution set to None, using highest resolution. [junifer]
2025-11-18 17:36:31 [info ] Start annex operation [datalad.annex] dlm_progress=annexprogress-139689173937296 dlm_progress_label=Total dlm_progress_noninteractive_level=5 dlm_progress_total=233863 dlm_progress_unit=' Bytes'
2025-11-18 17:36:32 [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-139689173937296-6360479011626891260 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-18 17:36:32 [info ] 35.03% [datalad.annex] dlm_progress=annexprogress-139689173937296-6360479011626891260 dlm_progress_noninteractive_level=5 dlm_progress_update=81920.0
2025-11-18 17:36:33 [info ] 63.05% [datalad.annex] dlm_progress=annexprogress-139689173937296-6360479011626891260 dlm_progress_noninteractive_level=5 dlm_progress_update=147456.0
2025-11-18 17:36:33 [info ] Finished annex action: None [datalad.annex] dlm_progress=annexprogress-139689173937296-6360479011626891260 dlm_progress_noninteractive_level=5
2025-11-18 17:36:33 [info ] Finished annex get [datalad.annex] dlm_progress=annexprogress-139689173937296 dlm_progress_noninteractive_level=5
2025-11-18 17:36:33 [info ] Loading parcellation: /github/home/junifer_data/v5/parcellations/Schaefer2018/Yeo2011/Schaefer2018_100Parcels_17Networks_order_FSLMNI152_1mm.nii.gz [junifer]
2025-11-18 17:36:35 [info ] Downloading template MNI152Lin (T1w in resolution 1) [junifer]
2025-11-18 17:36:36 [info ] antsApplyTransforms command to be executed:
antsApplyTransforms -d 3 -e 3 -n 'GenericLabel[NearestNeighbor]' -i /tmp/tmpsmu00wqv/ants_parcellation_warper_Schaefer100x17_from_MNI152NLin6Asym_to_MNI152Lin_2011a2a2-c4a5-11f0-a26b-be2f509f929d55fq4q0p/prewarp_parcellation.nii.gz -r /tmp/tmpsmu00wqv/ants_parcellation_warper_Schaefer100x17_from_MNI152NLin6Asym_to_MNI152Lin_2011a2a2-c4a5-11f0-a26b-be2f509f929d55fq4q0p/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/tmpsmu00wqv/ants_parcellation_warper_Schaefer100x17_from_MNI152NLin6Asym_to_MNI152Lin_2011a2a2-c4a5-11f0-a26b-be2f509f929d55fq4q0p/parcellation_warped.nii.gz [junifer]
2025-11-18 17:36:42 [info ] antsApplyTransforms command succeeded with the following output:
[junifer]
2025-11-18 17:36:45 [info ] Storing in <SQLiteFeatureStorage @ /tmp/tmpee2ytr3a/test.sqlite (multiple output)> [junifer]
2025-11-18 17:36:45 [info ] Fitting marker Schaefer200x17_RSSETS [junifer]
2025-11-18 17:36:45 [info ] Computing DataType.BOLD [junifer]
2025-11-18 17:36:45 [info ] Parcellation will be warped from MNI152NLin6Asym to MNI152Lin using highest resolution [junifer]
2025-11-18 17:36:45 [info ] Parcellation parameters: [junifer]
2025-11-18 17:36:45 [info ] resolution: None [junifer]
2025-11-18 17:36:45 [info ] n_rois: 200 [junifer]
2025-11-18 17:36:45 [info ] yeo_networks: 17 [junifer]
2025-11-18 17:36:45 [info ] Resolution set to None, using highest resolution. [junifer]
2025-11-18 17:36:45 [info ] Start annex operation [datalad.annex] dlm_progress=annexprogress-139689188835696 dlm_progress_label=Total dlm_progress_noninteractive_level=5 dlm_progress_total=259405 dlm_progress_unit=' Bytes'
2025-11-18 17:36:46 [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-139689188835696--117506222202749244 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-18 17:36:46 [info ] 12.63% [datalad.annex] dlm_progress=annexprogress-139689188835696--117506222202749244 dlm_progress_noninteractive_level=5 dlm_progress_update=32768.0
2025-11-18 17:36:47 [info ] 72.63% [datalad.annex] dlm_progress=annexprogress-139689188835696--117506222202749244 dlm_progress_noninteractive_level=5 dlm_progress_update=188416.0
2025-11-18 17:36:47 [info ] Finished annex action: None [datalad.annex] dlm_progress=annexprogress-139689188835696--117506222202749244 dlm_progress_noninteractive_level=5
2025-11-18 17:36:47 [info ] Finished annex get [datalad.annex] dlm_progress=annexprogress-139689188835696 dlm_progress_noninteractive_level=5
2025-11-18 17:36:47 [info ] Loading parcellation: /github/home/junifer_data/v5/parcellations/Schaefer2018/Yeo2011/Schaefer2018_200Parcels_17Networks_order_FSLMNI152_1mm.nii.gz [junifer]
2025-11-18 17:36:49 [info ] Downloading template MNI152Lin (T1w in resolution 1) [junifer]
2025-11-18 17:36:50 [info ] antsApplyTransforms command to be executed:
antsApplyTransforms -d 3 -e 3 -n 'GenericLabel[NearestNeighbor]' -i /tmp/tmpsmu00wqv/ants_parcellation_warper_Schaefer200x17_from_MNI152NLin6Asym_to_MNI152Lin_288c7e5c-c4a5-11f0-a26b-be2f509f929dzn4hbpck/prewarp_parcellation.nii.gz -r /tmp/tmpsmu00wqv/ants_parcellation_warper_Schaefer200x17_from_MNI152NLin6Asym_to_MNI152Lin_288c7e5c-c4a5-11f0-a26b-be2f509f929dzn4hbpck/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/tmpsmu00wqv/ants_parcellation_warper_Schaefer200x17_from_MNI152NLin6Asym_to_MNI152Lin_288c7e5c-c4a5-11f0-a26b-be2f509f929dzn4hbpck/parcellation_warped.nii.gz [junifer]
2025-11-18 17:37:01 [info ] antsApplyTransforms command succeeded with the following output:
[junifer]
2025-11-18 17:37:04 [info ] Storing in <SQLiteFeatureStorage @ /tmp/tmpee2ytr3a/test.sqlite (multiple output)> [junifer]
2025-11-18 17:37:04 [info ] Marker collection fitting done [junifer]
2025-11-18 17:37:04 [info ] Collecting data using SQLiteFeatureStorage [junifer]
2025-11-18 17:37:04 [info ] Collecting data from /tmp/tmpee2ytr3a/*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, 66.46it/s]
file: 1it [00:00, 21.90it/s]
2025-11-18 17:37:04 [info ] Collect done [junifer]
{'38b29577c909f6d3e33a149f319d5ccc': {'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', 'on': ['BOLD'], 'parcellation': ['Schaefer100x17']}, '_element_keys': ['subject'], 'name': 'BOLD_Schaefer100x17_RSSETS_rss_ets'}, 'ed76fd21eaeade9503b38ec7767d4759': {'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', 'on': ['BOLD'], 'parcellation': ['Schaefer200x17']}, '_element_keys': ['subject'], 'name': 'BOLD_Schaefer200x17_RSSETS_rss_ets'}}
Now we take a look at the dataframe
Total running time of the script: (0 minutes 44.750 seconds)