|
3 | 3 | """Tests of nonlinear transforms."""
|
4 | 4 |
|
5 | 5 | import os
|
| 6 | +from subprocess import check_call |
| 7 | +import shutil |
6 | 8 | import pytest
|
7 | 9 |
|
8 | 10 | import numpy as np
|
@@ -243,3 +245,31 @@ def manual_map(x):
|
243 | 245 | pts = np.array([[1.2, 1.5, 2.0], [3.3, 1.7, 2.4]])
|
244 | 246 | expected = np.vstack([manual_map(p) for p in pts])
|
245 | 247 | 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