Skip to content

Commit e035cfb

Browse files
committed
Add DenseField transform mapping test against ANTs
1 parent d5a30c0 commit e035cfb

File tree

1 file changed

+30
-0
lines changed

1 file changed

+30
-0
lines changed

nitransforms/tests/test_nonlinear.py

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
"""Tests of nonlinear transforms."""
44

55
import os
6+
from subprocess import check_call
7+
import shutil
68
import pytest
79

810
import numpy as np
@@ -243,3 +245,31 @@ def manual_map(x):
243245
pts = np.array([[1.2, 1.5, 2.0], [3.3, 1.7, 2.4]])
244246
expected = np.vstack([manual_map(p) for p in pts])
245247
assert np.allclose(bspline.map(pts), expected, atol=1e-6)
248+
249+
250+
def test_densefield_map_against_ants(data_path, tmp_path):
251+
"""Map points with DenseFieldTransform and compare to ANTs."""
252+
warpfile = data_path / "regressions" / (
253+
"01_ants_t1_to_mniComposite_DisplacementFieldTransform.nii.gz"
254+
)
255+
if not warpfile.exists():
256+
pytest.skip("Composite transform test data not available")
257+
258+
points = np.array([[0.0, 0.0, 0.0], [1.0, 2.0, 3.0]])
259+
csvin = tmp_path / "points.csv"
260+
np.savetxt(csvin, points, delimiter=",", header="x,y,z", comments="")
261+
262+
csvout = tmp_path / "out.csv"
263+
cmd = f"antsApplyTransformsToPoints -d 3 -i {csvin} -o {csvout} -t {warpfile}"
264+
exe = cmd.split()[0]
265+
if not shutil.which(exe):
266+
pytest.skip(f"Command {exe} not found on host")
267+
check_call(cmd, shell=True)
268+
269+
ants_res = np.genfromtxt(csvout, delimiter=",", names=True)
270+
ants_pts = np.vstack([ants_res[n] for n in ("x", "y", "z")]).T
271+
272+
xfm = DenseFieldTransform(warpfile)
273+
mapped = xfm.map(points)
274+
275+
assert np.allclose(mapped, ants_pts, atol=1e-6)

0 commit comments

Comments
 (0)