Skip to content

Commit 5d13425

Browse files
committed
Add test for new function.
1 parent 45b256a commit 5d13425

File tree

1 file changed

+20
-2
lines changed

1 file changed

+20
-2
lines changed

sdcflows/utils/tests/test_phasemanip.py

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,11 @@
2424
import numpy as np
2525
import nibabel as nb
2626

27-
from ..phasemanip import au2rads, phdiff2fmap
27+
from ..phasemanip import au2rads, au2rads2, phdiff2fmap
2828

2929

3030
def test_au2rads(tmp_path):
31-
"""Check the conversion."""
31+
"""Check the conversion from arbitrary units to 0 to 2pi."""
3232
data = np.random.randint(0, high=4096, size=(5, 5, 5))
3333
data[0, 0, 0] = 0
3434
data[-1, -1, -1] = 4096
@@ -45,6 +45,24 @@ def test_au2rads(tmp_path):
4545
)
4646

4747

48+
def test_au2rads2(tmp_path):
49+
"""Check the conversion from arbitrary units to -pi to pi."""
50+
data = np.random.randint(0, high=4096, size=(5, 5, 5))
51+
data[0, 0, 0] = 0
52+
data[-1, -1, -1] = 4096
53+
54+
nb.Nifti1Image(data.astype("int16"), np.eye(4)).to_filename(
55+
tmp_path / "testdata.nii.gz"
56+
)
57+
58+
out_file = au2rads2(tmp_path / "testdata.nii.gz")
59+
60+
assert np.allclose(
61+
((data / 4096).astype("float32") * 2.0 * np.pi) - np.pi,
62+
nb.load(out_file).get_fdata(dtype="float32"),
63+
)
64+
65+
4866
def test_phdiff2fmap(tmp_path):
4967
"""Check the conversion."""
5068
nb.Nifti1Image(

0 commit comments

Comments
 (0)