Skip to content

Commit b0f543f

Browse files
committed
test: Verify motion parameter reconstruction
1 parent bb97d47 commit b0f543f

File tree

1 file changed

+35
-0
lines changed

1 file changed

+35
-0
lines changed

fmriprep/interfaces/tests/test_confounds.py

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
from pathlib import Path
22

3+
import numpy as np
4+
import pandas as pd
35
from nipype.pipeline import engine as pe
46

57
from fmriprep.interfaces import confounds
@@ -29,3 +31,36 @@ def test_FilterDropped(tmp_path, data_dir):
2931
target_meta = Path.read_text(data_dir / 'component_metadata_filtered.tsv')
3032
filtered_meta = Path(res.outputs.out_file).read_text()
3133
assert filtered_meta == target_meta
34+
35+
36+
def test_FSLMotionParams(tmp_path, data_dir):
37+
base = 'sub-01_task-mixedgamblestask_run-01'
38+
xfms = data_dir / f'{base}_from-orig_to-boldref_mode-image_desc-hmc_xfm.txt'
39+
boldref = data_dir / f'{base}_desc-hmc_boldref.nii.gz'
40+
orig_timeseries = data_dir / f'{base}_desc-motion_timeseries.tsv'
41+
42+
motion = pe.Node(
43+
confounds.FSLMotionParams(xfm_file=str(xfms), boldref_file=str(boldref)),
44+
name='fsl_motion',
45+
base_dir=str(tmp_path),
46+
)
47+
res = motion.run()
48+
49+
orig_params = pd.read_csv(orig_timeseries, sep='\t')
50+
derived_params = pd.read_csv(res.outputs.out_file, sep='\t')
51+
52+
# Motion parameters are in mm and rad
53+
# These are empirically determined bounds, but they seem reasonable
54+
# for the units
55+
limits = pd.DataFrame(
56+
{
57+
'trans_x': [1e-4],
58+
'trans_y': [1e-4],
59+
'trans_z': [1e-4],
60+
'rot_x': [1e-6],
61+
'rot_y': [1e-6],
62+
'rot_z': [1e-6],
63+
}
64+
)
65+
max_diff = (orig_params - derived_params).abs().max()
66+
assert np.all(max_diff < limits)

0 commit comments

Comments
 (0)