Skip to content

Commit

Permalink
ENH: more tests
Browse files Browse the repository at this point in the history
  • Loading branch information
AntoineTheb committed Jul 31, 2024
1 parent 082b8d5 commit 917e029
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 2 deletions.
24 changes: 22 additions & 2 deletions scilpy/image/tests/test_volume_operations.py
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ def test_resample_volume():


def test_reshape_volume_pad():

# 3D img
img = nib.Nifti1Image(
np.arange(1, (3**3)+1).reshape((3, 3, 3)).astype(float),
np.eye(4))
Expand All @@ -223,9 +223,18 @@ def test_reshape_volume_pad():
reshaped_img = reshape_volume(img, (4, 4, 4), mode='edge')
assert_equal(reshaped_img.get_fdata()[0, 0, 0], 1)

# 4D img
img = nib.Nifti1Image(
np.arange(1, ((3**3) * 2)+1).reshape((3, 3, 3, 2)).astype(float),
np.eye(4))

def test_reshape_volume_crop():
# 2) Reshaping to 5x5x5, padding with 0
reshaped_img = reshape_volume(img, (5, 5, 5))
assert_equal(reshaped_img.get_fdata()[0, 0, 0, 0], 0)


def test_reshape_volume_crop():
# 3D img
img = nib.Nifti1Image(
np.arange(1, (3**3)+1).reshape((3, 3, 3)).astype(float),
np.eye(4))
Expand All @@ -242,6 +251,17 @@ def test_reshape_volume_crop():
assert_equal(reshaped_img.affine[:, -1], [0, 0, 0, 1])
assert_equal(reshaped_img.get_fdata()[0, 0, 0], 1)

# 4D img
img = nib.Nifti1Image(
np.arange(1, ((3**3) * 2)+1).reshape((3, 3, 3, 2)).astype(float),
np.eye(4))

# 2) Cropping to 2x2x2
reshaped_img = reshape_volume(img, (2, 2, 2))
assert_equal(reshaped_img.get_fdata().shape, (2, 2, 2, 2))
assert_equal(reshaped_img.affine[:, -1], [0, 0, 0, 1])
assert_equal(reshaped_img.get_fdata()[0, 0, 0, 0], 1)


def test_normalize_metric_basic():
metric = np.array([1, 2, 3, 4, 5])
Expand Down
8 changes: 8 additions & 0 deletions scripts/tests/test_volume_reshape.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,14 @@ def test_execution_pad(script_runner, monkeypatch):
assert ret.success


def test_execution_full_size(script_runner, monkeypatch):
monkeypatch.chdir(os.path.expanduser(tmp_dir.name))
ret = script_runner.run('scil_volume_reshape.py', in_img,
'fa_reshape.nii.gz', '--volume_size',
'164', '164', '164', '-f')
assert ret.success


def test_execution_ref(script_runner, monkeypatch):
monkeypatch.chdir(os.path.expanduser(tmp_dir.name))
ref = os.path.join(SCILPY_HOME, 'others', 'fa_resample.nii.gz')
Expand Down

0 comments on commit 917e029

Please sign in to comment.