Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FIX: Integration test with B0 (trivial) model #85

Merged
merged 1 commit into from
Aug 26, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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