Skip to content

Commit

Permalink
FIX: Integration test with B0 (trivial) model
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
oesteban committed Aug 25, 2022
1 parent 2824ceb commit 382ec92
Showing 1 changed file with 42 additions and 7 deletions.
49 changes: 42 additions & 7 deletions test/test_integration.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
)

Expand All @@ -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):
Expand Down

0 comments on commit 382ec92

Please sign in to comment.