Skip to content

Commit

Permalink
Add test for new function.
Browse files Browse the repository at this point in the history
  • Loading branch information
tsalo committed Dec 12, 2024
1 parent 45b256a commit 5d13425
Showing 1 changed file with 20 additions and 2 deletions.
22 changes: 20 additions & 2 deletions sdcflows/utils/tests/test_phasemanip.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,11 @@
import numpy as np
import nibabel as nb

from ..phasemanip import au2rads, phdiff2fmap
from ..phasemanip import au2rads, au2rads2, phdiff2fmap


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


def test_au2rads2(tmp_path):
"""Check the conversion from arbitrary units to -pi to pi."""
data = np.random.randint(0, high=4096, size=(5, 5, 5))
data[0, 0, 0] = 0
data[-1, -1, -1] = 4096

nb.Nifti1Image(data.astype("int16"), np.eye(4)).to_filename(
tmp_path / "testdata.nii.gz"
)

out_file = au2rads2(tmp_path / "testdata.nii.gz")

assert np.allclose(
((data / 4096).astype("float32") * 2.0 * np.pi) - np.pi,
nb.load(out_file).get_fdata(dtype="float32"),
)


def test_phdiff2fmap(tmp_path):
"""Check the conversion."""
nb.Nifti1Image(
Expand Down

0 comments on commit 5d13425

Please sign in to comment.