Skip to content

Commit 0100a35

Browse files
committed
enh: add one test comparing to TOPUP's interpolator
1 parent f9498fa commit 0100a35

File tree

3 files changed

+34
-10
lines changed

3 files changed

+34
-10
lines changed

sdcflows/interfaces/bspline.py

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -130,12 +130,11 @@ def _run_interface(self, runtime):
130130
bs_levels.append(level)
131131
ncoeff.append(level.dataobj.size)
132132

133-
if regressors is None:
134-
regressors = bspline_weights(fmap_points, level)
135-
else:
136-
regressors = sparse_vstack(
137-
(regressors, bspline_weights(fmap_points, level))
138-
)
133+
regressors = (
134+
bspline_weights(fmap_points, level)
135+
if regressors is None
136+
else sparse_vstack((regressors, bspline_weights(fmap_points, level)))
137+
)
139138

140139
# Fit the model
141140
model = lm.Ridge(alpha=self.inputs.ridge_alpha, fit_intercept=False)
@@ -563,10 +562,11 @@ def bspline_weights(points, ctrl_nii, blocksize=None, mem_percent=None):
563562

564563
weights[weights < 1e-6] = 0.0
565564

566-
if wmatrix is None:
567-
wmatrix = csc_matrix(weights)
568-
else:
569-
wmatrix = hstack((wmatrix, csc_matrix(weights)))
565+
wmatrix = (
566+
csc_matrix(weights)
567+
if wmatrix is None
568+
else hstack((wmatrix, csc_matrix(weights)))
569+
)
570570
idx = end
571571
return wmatrix.tocsr()
572572

sdcflows/interfaces/tests/test_bspline.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,3 +84,27 @@ def test_topup_coeffs(tmpdir, testdata_dir):
8484
# Test automatic output file name generation, just for coverage
8585
with pytest.raises(ValueError):
8686
_fix_topup_fieldcoeff("failing.nii.gz", str(testdata_dir / "epi.nii.gz"))
87+
88+
89+
@pytest.mark.skipif(os.getenv("GITHUB_ACTIONS") == "true", reason="this is GH Actions")
90+
def test_topup_coeffs_interpolation(tmpdir, testdata_dir):
91+
"""Check that our interpolation is not far away from TOPUP's."""
92+
tmpdir.chdir()
93+
result = Coefficients2Warp(
94+
in_target=str(testdata_dir / "epi.nii.gz"),
95+
in_coeff=str(testdata_dir / "topup-coeff-fixed.nii.gz"),
96+
pe_dir="j-",
97+
ro_time=1.0,
98+
).run()
99+
assert (
100+
np.sqrt(
101+
np.mean(
102+
(
103+
nb.load(result.outputs.out_field).get_fdata()
104+
- nb.load(testdata_dir / "topup-field.nii.gz").get_fdata()
105+
)
106+
** 2
107+
)
108+
)
109+
< 3
110+
)
2.1 MB
Binary file not shown.

0 commit comments

Comments
 (0)