From 382ec92efa92f8d6c4e65d607853f5b13b7b6f1f Mon Sep 17 00:00:00 2001 From: Oscar Esteban Date: Thu, 25 Aug 2022 14:17:41 +0200 Subject: [PATCH] FIX: Integration test with B0 (trivial) model Drops the use of a real AFNI series of transforms. Instead, generate a number of large-yet-plausible transformations for head motion. Follow-up: #84. Part-of: #40. --- test/test_integration.py | 49 ++++++++++++++++++++++++++++++++++------ 1 file changed, 42 insertions(+), 7 deletions(-) diff --git a/test/test_integration.py b/test/test_integration.py index b8d04e47..0cb1b3e1 100644 --- a/test/test_integration.py +++ b/test/test_integration.py @@ -36,18 +36,47 @@ def test_proximity_estimator_trivial_model(datadir, tmp_path): dwdata = DWI.from_filename(datadir / "dwi.h5") b0nii = nb.Nifti1Image(dwdata.bzero, dwdata.affine, None) - xfms = nt.linear.load( - datadir / "head-motion-parameters.aff12.1D", - fmt="afni", + # Generate a list of large-yet-plausible bulk-head motion. + xfms = nt.linear.LinearTransformsMapping( + [ + nb.affines.from_matvec( + nb.eulerangles.euler2mat(x=0.03, z=0.005), (0.8, 0.2, 0.2) + ), + nb.affines.from_matvec( + nb.eulerangles.euler2mat(x=0.02, z=0.005), (0.8, 0.2, 0.2) + ), + nb.affines.from_matvec( + nb.eulerangles.euler2mat(x=0.02, z=0.02), (0.4, 0.2, 0.2) + ), + nb.affines.from_matvec( + nb.eulerangles.euler2mat(x=-0.02, z=0.02), (0.4, 0.2, 0.2) + ), + nb.affines.from_matvec( + nb.eulerangles.euler2mat(x=-0.02, z=0.002), (0.0, 0.2, 0.2) + ), + nb.affines.from_matvec( + nb.eulerangles.euler2mat(y=-0.02, z=0.002), (0.0, 0.2, 0.2) + ), + nb.affines.from_matvec( + nb.eulerangles.euler2mat(y=-0.01, z=0.002), (0.0, 0.4, 0.2) + ), + ], + reference=b0nii, ) - xfms.reference = b0nii - # Generate a dataset with 10 b-zeros and motion + # Induce motion into dataset (i.e., apply the inverse transforms) + moved_nii = (~xfms).apply(b0nii, reference=b0nii) + + # Uncomment to see the moved dataset + # moved_nii.to_filename(tmp_path / "test.nii.gz") + # xfms.apply(moved_nii).to_filename(tmp_path / "ground_truth.nii.gz") + + # Wrap into dataset object dwi_motion = DWI( - dataobj=(~xfms).apply(b0nii, reference=b0nii).dataobj, + dataobj=moved_nii.dataobj, affine=b0nii.affine, bzero=dwdata.bzero, - gradients=dwdata.gradients[..., :10], + gradients=dwdata.gradients[..., : len(xfms)], brainmask=dwdata.brainmask, ) @@ -56,6 +85,12 @@ def test_proximity_estimator_trivial_model(datadir, tmp_path): dwdata=dwi_motion, n_iter=1, model="b0", align_kwargs=None, seed=None ) + # Uncomment to see the realigned dataset + # nt.linear.LinearTransformsMapping( + # em_affines, + # reference=b0nii, + # ).apply(moved_nii).to_filename(tmp_path / "realigned.nii.gz") + # For each moved b0 volume coords = xfms.reference.ndcoords.T for i, est in enumerate(em_affines):