From 63f2f13347153c41c2749b54307af05e3e3d5f74 Mon Sep 17 00:00:00 2001 From: Paul McCarthy <pauldmccarthy@gmail.com> Date: Thu, 7 Dec 2023 16:50:57 +0000 Subject: [PATCH] Basic unit test for vecreg --- unit_tests/fdt/vecreg/feedsInputs | 1 + unit_tests/fdt/vecreg/feedsRun | 65 +++++++++++++++++++++++++++++++ 2 files changed, 66 insertions(+) create mode 100644 unit_tests/fdt/vecreg/feedsInputs create mode 100755 unit_tests/fdt/vecreg/feedsRun diff --git a/unit_tests/fdt/vecreg/feedsInputs b/unit_tests/fdt/vecreg/feedsInputs new file mode 100644 index 0000000..33b70e2 --- /dev/null +++ b/unit_tests/fdt/vecreg/feedsInputs @@ -0,0 +1 @@ +fsl_course_data/fdt2 diff --git a/unit_tests/fdt/vecreg/feedsRun b/unit_tests/fdt/vecreg/feedsRun new file mode 100755 index 0000000..773f06c --- /dev/null +++ b/unit_tests/fdt/vecreg/feedsRun @@ -0,0 +1,65 @@ +#!/usr/bin/env fslpython + +import os +import sys + +sys.path.append('/home/paulmc/Projects/fslpy/') + +from pathlib import Path + +import numpy as np + +from fsl.data.image import Image +from fsl.wrappers import vecreg, concatxfm, invxfm, convertwarp + +from pyfeeds.evaluate import cmpVectorArrays + + +def main(): + fsldir = Path(os.environ['FSLDIR']) + outdir = Path(sys.argv[1]) + indir = Path(sys.argv[2])/'fsl_course_data'/'fdt2' + dyads = indir/'diffusion.bedpostX'/'dyads1.nii.gz' + std = fsldir/'data'/'standard'/'MNI152_T1_2mm.nii.gz' + str2std = indir/'diffusion.bedpostX'/'xfms'/'str2standard.mat' + diff2str = indir/'structural'/'xfms'/'diff2str.mat' + diff2std_warp = indir/'structural'/'xfms'/'diff2standard_warp.nii.gz' + + # Create diff2std/std2diff affines + std2diff = outdir/'std2diff.mat' + diff2std = outdir/'diff2std.mat' + concatxfm(diff2str, str2std, diff2std) + invxfm(diff2std, std2diff) + + # create a copy of the diff2std warp + # which does not encode the diff2std + # affine + diff2std_warp_no_premat = outdir/'diff2std_no_pm_warp.nii.gz' + convertwarp(diff2std_warp_no_premat, std, + warp1=diff2std_warp, + premat=std2diff, + relout=True) + + # Transform dyads with the full diff2std + # warp (which encodes the diff->standard + # affine transform) - this will be used + # as a benchmark + dyads_std = outdir/'dyads1_std.nii.gz' + vecreg(dyads, dyads_std, std, warpfield=diff2std_warp) + + # Transform dyads with the raw diff2std + # warp, and specify the diff2std affine + # as premat. The result should match + # that from the first vecreg call above. + dyads_std_with_premat = outdir/'dyads1_std_with_premat.nii.gz' + vecreg(dyads, dyads_std_with_premat, std, + warpfield=diff2std_warp_no_premat, + premat=diff2std) + + dyads1 = Image(dyads_std).data + dyads2 = Image(dyads_std_with_premat).data + assert np.isclose(cmpVectorArrays(dyads1, dyads2), 0) + + +if __name__ == '__main__': + main() -- GitLab