Is there an efficient way to check for the head motion summary estimates across the entire dataset

i’ve preprocessed my dataset with fmriprep. For the purpose of excluding subjects with excessive head motion, i’m wondering if there is an easy way to check for the head motion summary estimates (i.e. FD jenkinson or something similar) across the entire dataset?

Here is some code I use for that purpose. For data evaluation, you may also check out MRIqc

Imports

import pandas as pd
import numpy as np

from glob import glob
from os.path import join as opj
from bids.layout import BIDSLayout

import matplotlib.pyplot as plt
%matplotlib inline

Data folder / subjects

#Set data folders
data_dir = #pathtodata

layout = BIDSLayout(data_dir)

subj_list=layout.get_subjects()
task=layout.get_tasks()[0] #only one task

#print(subj_list)

Plot head motion parameters /FWD

for subject in subj_list:
    confound_file= opj(data_dir,'derivatives','fmriprep','sub-'+subject,'func','sub-'+subject+'_task-'+task+'_desc-confounds_timeseries.tsv')
    
#Data loading variables
    # load confounds 
    confs=sorted(glob(confound_file))
    confis=[pd.read_csv(df, sep= '\t') for df in confs]


    # select nuisance variables 
    confounds=[]
    for conf in range(len(confis)):
        confounds.append(confis[conf][['trans_x','trans_y','trans_z','rot_x','rot_y','rot_z','framewise_displacement']].fillna(0))
    print(len(confounds))
    
    
    translation_params = confis[conf][['trans_x','trans_y','trans_z']].fillna(0)
    rotation_params = confis[conf][['rot_x','rot_y','rot_z']].fillna(0)
    fwd_params = confis[conf][['framewise_displacement']].fillna(0)
    
    print('sub-'+subject)
    
    plt.figure(figsize=(15, 15))
    plt.subplot(3, 1, 1)
    plt.title('Translation', fontsize=25)
    plt.plot(translation_params)
    plt.xlim(0, translation_params.shape[0])
    plt.legend(['x', 'y', 'z'], fontsize=15)
    plt.ylabel('Translation in mm', fontsize=15)
    plt.grid()

    plt.subplot(3, 1, 2)
    plt.title('Rotation', fontsize=25)
    plt.plot(rotation_params)
    plt.legend(['x', 'y', 'z'], fontsize=15)
    plt.ylabel('Rotation in radians', fontsize=15)
    plt.xlim(0, rotation_params.shape[0])
    plt.xlabel('Time (TR)', fontsize=15)
    plt.grid()
    
    plt.subplot(3, 1, 3)
    plt.title('Displacement', fontsize=25)
    plt.plot(fwd_params)
    plt.xlim(0, fwd_params.shape[0])
    plt.hlines(1,xmin=0,xmax=len(fwd_params), colors='orange')
    plt.hlines(2,xmin=0,xmax=len(fwd_params), colors='red')
    plt.legend(['displacement', '1 mm', '2 mm'], fontsize=15, loc='upper left')
    plt.ylabel('Displacement in mm', fontsize=15)


    plt.tight_layout()
    
    plt.show()