Skip to content

Commit 67d5662

Browse files
committed
fix: actually enable the tests
1 parent 1112ac3 commit 67d5662

File tree

2 files changed

+51
-7
lines changed

2 files changed

+51
-7
lines changed

nitransforms/io/fsl.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -76,15 +76,15 @@ def from_string(cls, string):
7676

7777
def to_ras(self, moving=None, reference=None):
7878
"""Return a nitransforms internal RAS+ matrix."""
79+
if reference is None:
80+
raise ValueError("Cannot build FSL linear transform without a reference")
81+
7982
if moving is None:
8083
warnings.warn(
8184
"Converting FSL to RAS: moving image not provided, using reference."
8285
)
8386
moving = reference
8487

85-
if reference is None:
86-
raise ValueError("Cannot build FSL linear transform without a reference")
87-
8888
reference = _ensure_image(reference)
8989
moving = _ensure_image(moving)
9090

nitransforms/tests/test_linear.py

+48-4
Original file line numberDiff line numberDiff line change
@@ -82,18 +82,62 @@ def test_loadsave(tmp_path, data_path, testdata_path, fmt):
8282

8383
fname = tmp_path / ".".join(("transform-mapping", fmt))
8484
xfm.to_filename(fname, fmt=fmt)
85-
xfm == nitl.load(fname, fmt=fmt, reference=ref_file)
85+
86+
if fmt == "fsl":
87+
# FSL should not read a transform without reference
88+
with pytest.raises(ValueError):
89+
nitl.load(fname, fmt=fmt)
90+
nitl.load(fname, fmt=fmt, moving=ref_file)
91+
92+
with pytest.warns(UserWarning):
93+
assert np.allclose(
94+
xfm.matrix,
95+
nitl.load(fname, fmt=fmt, reference=ref_file).matrix,
96+
rtol=1e-2, # FSL incurs into large errors due to rounding
97+
)
98+
99+
assert np.allclose(
100+
xfm.matrix,
101+
nitl.load(fname, fmt=fmt, reference=ref_file, moving=ref_file).matrix,
102+
rtol=1e-2, # FSL incurs into large errors due to rounding
103+
)
104+
else:
105+
assert xfm == nitl.load(fname, fmt=fmt, reference=ref_file)
106+
86107
xfm.to_filename(fname, fmt=fmt, moving=ref_file)
87-
xfm == nitl.load(fname, fmt=fmt, reference=ref_file)
108+
109+
if fmt == "fsl":
110+
assert np.allclose(
111+
xfm.matrix,
112+
nitl.load(fname, fmt=fmt, reference=ref_file, moving=ref_file).matrix,
113+
rtol=1e-2, # FSL incurs into large errors due to rounding
114+
)
115+
else:
116+
assert xfm == nitl.load(fname, fmt=fmt, reference=ref_file)
88117

89118
ref_file = testdata_path / "someones_anatomy.nii.gz"
90119
xfm = nitl.load(data_path / "affine-LAS.itk.tfm", fmt="itk")
91120
xfm.reference = ref_file
92121
fname = tmp_path / ".".join(("single-transform", fmt))
93122
xfm.to_filename(fname, fmt=fmt)
94-
xfm == nitl.load(fname, fmt=fmt, reference=ref_file)
123+
if fmt == "fsl":
124+
assert np.allclose(
125+
xfm.matrix,
126+
nitl.load(fname, fmt=fmt, reference=ref_file, moving=ref_file).matrix,
127+
rtol=1e-2, # FSL incurs into large errors due to rounding
128+
)
129+
else:
130+
assert xfm == nitl.load(fname, fmt=fmt, reference=ref_file)
131+
95132
xfm.to_filename(fname, fmt=fmt, moving=ref_file)
96-
xfm == nitl.load(fname, fmt=fmt, reference=ref_file)
133+
if fmt == "fsl":
134+
assert np.allclose(
135+
xfm.matrix,
136+
nitl.load(fname, fmt=fmt, reference=ref_file, moving=ref_file).matrix,
137+
rtol=1e-2, # FSL incurs into large errors due to rounding
138+
)
139+
else:
140+
assert xfm == nitl.load(fname, fmt=fmt, reference=ref_file)
97141

98142

99143
@pytest.mark.xfail(reason="Not fully implemented")

0 commit comments

Comments
 (0)