Skip to content

Commit

Permalink
wip: add a test
Browse files Browse the repository at this point in the history
  • Loading branch information
oesteban committed Apr 27, 2023
1 parent 1f70c7b commit 0597421
Showing 1 changed file with 40 additions and 1 deletion.
41 changes: 40 additions & 1 deletion sdcflows/utils/tests/test_tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,50 @@
"""Test EPI manipulation routines."""
import numpy as np
import nibabel as nb
from ..tools import brain_masker
from sdcflows.utils.tools import brain_masker, deoblique_and_zooms


def test_epi_mask(tmpdir, testdata_dir):
"""Check mask algorithm."""
tmpdir.chdir()
mask = brain_masker(testdata_dir / "epi.nii.gz")[-1]
assert abs(np.asanyarray(nb.load(mask).dataobj).sum() - 166476) < 10


def test_deoblique_and_zooms():
"""Check deoblique and denser."""

# Generate an example reference image
ref_data = np.zeros((20, 30, 40), dtype=np.float32)
ref_affine = np.eye(4)
ref_affine[:3, :3] = np.diag([2, 3, 4]) # Set zooms to (2, 3, 4)
ref_img = nb.Nifti1Image(ref_data, ref_affine)

# Generate an example oblique image
ob_data = np.zeros((25, 35, 45), dtype=np.float32)
ob_affine = np.eye(4)

# Rotate 90 degrees around x-axis
ob_affine[:3, :3] = np.array([[0, 1, 0], [0, 0, 1], [1, 0, 0]])
ob_img = nb.Nifti1Image(ob_data, ob_affine)

# Call function with default parameters
out_img = deoblique_and_zooms(ref_img, ob_img)

# Check output shape and zooms
assert out_img.shape == (26, 36, 46)
assert np.allclose(out_img.header.get_zooms()[:3], (0.5, 1.0, 1.0))

# Call function with larger padding
out_img = deoblique_and_zooms(ref_img, ob_img, padding=3)

# Check output shape and zooms
assert out_img.shape == (32, 42, 52)
assert np.allclose(out_img.header.get_zooms()[:3], (0.4, 0.75, 0.8))

# Call function with larger factor
out_img = deoblique_and_zooms(ref_img, ob_img, factor=8)

# Check output shape and zooms
assert out_img.shape == (160, 240, 320)
assert np.allclose(out_img.header.get_zooms()[:3], (0.025, 0.0125, 0.0125))

0 comments on commit 0597421

Please sign in to comment.