Skip to content

Commit

Permalink
Add unit test
Browse files Browse the repository at this point in the history
  • Loading branch information
EmmaRenauld committed Feb 29, 2024
1 parent b1ae3e2 commit 3ce0db0
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 6 deletions.
8 changes: 7 additions & 1 deletion scilpy/gradients/bvec_bval_tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,13 @@ def check_b0_threshold(min_bval, b0_thr, skip_b0_check):
If True, and no b0 is found, only print a warning, do not raise
an error.
Returns
-------
b0_thr: float
Either the unmodified b0_thr, or, in the case where the minimal b-value
is larger than b0_thr, and skip_b0_check is set to True, then returns
min_bval.
Raises
------
ValueError
Expand All @@ -93,7 +100,6 @@ def check_b0_threshold(min_bval, b0_thr, skip_b0_check):

if min_bval > b0_thr:
if skip_b0_check:
logging.warning("GOT {} > {}".format(min_bval, b0_thr))
logging.warning(
'Your minimal bvalue ({}), is above the threshold ({})\n'
'Since --skip_b0_check was specified, the script will '
Expand Down
18 changes: 13 additions & 5 deletions scilpy/gradients/tests/test_bvec_bval_tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
import numpy as np

from scilpy.gradients.bvec_bval_tools import (
identify_shells, is_normalized_bvecs, flip_gradient_sampling,
normalize_bvecs, round_bvals_to_shell, str_to_axis_index,
swap_gradient_axis)
check_b0_threshold, identify_shells, is_normalized_bvecs,
flip_gradient_sampling, normalize_bvecs, round_bvals_to_shell,
str_to_axis_index, swap_gradient_axis)

bvecs = np.asarray([[1.0, 1.0, 1.0],
[1.0, 0.0, 1.0],
Expand All @@ -23,8 +23,16 @@ def test_normalize_bvecs():


def test_check_b0_threshold():
# toDo To be modified (see PR#867).
pass
assert check_b0_threshold(min_bval=0, b0_thr=0, skip_b0_check=False) == 0
assert check_b0_threshold(min_bval=0, b0_thr=20, skip_b0_check=False) == 20
assert check_b0_threshold(min_bval=20, b0_thr=0, skip_b0_check=True) == 20

error_raised = False
try:
_ = check_b0_threshold(min_bval=20, b0_thr=0, skip_b0_check=False)
except ValueError:
error_raised = True
assert error_raised


def test_identify_shells():
Expand Down

0 comments on commit 3ce0db0

Please sign in to comment.