Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixing the skip_b0_check function #1113

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 20 additions & 8 deletions scilpy/gradients/bvec_bval_tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,8 @@ def normalize_bvecs(bvecs):
return bvecs


def check_b0_threshold(min_bval, b0_thr, skip_b0_check):
def check_b0_threshold(min_bval, b0_thr, skip_b0_check,
overwrite_with_min=True):
"""
Check if the minimal bvalue is under the threshold. If not, raise an
error to ask user to update the b0_thr.
Expand All @@ -72,6 +73,10 @@ def check_b0_threshold(min_bval, b0_thr, skip_b0_check):
skip_b0_check: bool
If True, and no b0 is found, only print a warning, do not raise
an error.
overwrite_with_min: bool, optional
If True, no b0 is found, and skip_b0_check is True, the script will
proceed with a new b0 threshold equal to the minimal b-value. Else, the
script will proceed with the original b0 threshold.

Returns
-------
Expand Down Expand Up @@ -101,18 +106,25 @@ def check_b0_threshold(min_bval, b0_thr, skip_b0_check):
if min_bval > b0_thr:
if skip_b0_check:
logging.warning(
'Your minimal bvalue ({}), is above the threshold ({})\n'
'Since --skip_b0_check was specified, the script will '
'proceed with a b0 threshold of {}.'
.format(min_bval, b0_thr, min_bval))
return min_bval
'The minimal bvalue ({}) is above the b0 threshold ({}).'
.format(min_bval, b0_thr))
if overwrite_with_min:
logging.warning(
'Since --skip_b0_check was specified, the script will '
'proceed with a b0 threshold of {}'.format(min_bval))
return min_bval
else:
logging.warning(
'Since --skip_b0_check was specified, the script will '
'proceed without b0 volumes.')
return b0_thr
else:
raise ValueError(
'The minimal bvalue ({}) is above the threshold ({})\n'
'The minimal bvalue ({}) is above the b0 threshold ({}).\n'
'No b0 volumes can be found.\n'
'Please check your data to ensure everything is correct.\n'
'You may also increase the threshold or use '
'--skip_b0_check'
'--skip_b0_check.'
.format(min_bval, b0_thr))
return b0_thr

Expand Down
3 changes: 2 additions & 1 deletion scilpy/io/btensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,8 @@ def generate_btensor_input(in_dwis, in_bvals, in_bvecs, in_bdeltas,
vol = nib.load(inputf)
bvals, bvecs = read_bvals_bvecs(bvalsf, bvecsf)
_ = check_b0_threshold(bvals.min(), b0_thr=tol,
skip_b0_check=skip_b0_check)
skip_b0_check=skip_b0_check,
overwrite_with_min=False)
if np.sum([bvals > tol]) != 0:
bvals = np.round(bvals)
if not is_normalized_bvecs(bvecs):
Expand Down
4 changes: 4 additions & 0 deletions scilpy/io/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -272,6 +272,10 @@ def add_skip_b0_check_arg(parser, will_overwrite_with_min,
msg += ('If no b-value is found below the threshold, the script will '
'continue \nwith your minimal b-value as new {}.\n'
.format(b0_tol_name))
else:
msg += ('If no b-value is found below the threshold, the script will '
'continue \nwith the original {} and no b0 volumes.\n'
.format(b0_tol_name))
msg += 'Use with care, and only if you understand your data.'

parser.add_argument(
Expand Down
3 changes: 2 additions & 1 deletion scripts/scil_NODDI_maps.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,8 @@ def main():
# Generate a scheme file from the bvals and bvecs files
bvals, _ = read_bvals_bvecs(args.in_bval, args.in_bvec)
_ = check_b0_threshold(bvals.min(), b0_thr=args.tolerance,
skip_b0_check=args.skip_b0_check)
skip_b0_check=args.skip_b0_check,
overwrite_with_min=False)
shells_centroids, indices_shells = identify_shells(bvals, args.tolerance,
round_centroids=True)

Expand Down
3 changes: 2 additions & 1 deletion scripts/scil_dki_metrics.py
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,8 @@ def main():
# b0_threshold option in gradient_table probably unused, except below with
# option dki_residual.
_ = check_b0_threshold(bvals.min(), b0_thr=args.tolerance,
skip_b0_check=args.skip_b0_check)
skip_b0_check=args.skip_b0_check,
overwrite_with_min=False)
gtab = gradient_table(bvals, bvecs, b0_threshold=args.tolerance)

# Processing
Expand Down
3 changes: 2 additions & 1 deletion scripts/scil_fodf_msmt.py
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,8 @@ def main():
# https://github.com/dipy/dipy/issues/3015
# b0_threshold option in gradient_table probably unused.
_ = check_b0_threshold(bvals.min(), b0_thr=args.tolerance,
skip_b0_check=args.skip_b0_check)
skip_b0_check=args.skip_b0_check,
overwrite_with_min=False)
gtab = gradient_table(bvals, bvecs, b0_threshold=args.tolerance)

# Loading spheres
Expand Down
3 changes: 2 additions & 1 deletion scripts/scil_frf_msmt.py
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,8 @@ def main():
# for the b0s. Using the tolerance. To fix this, we would need to change
# the unique_bvals_tolerance and extract_dwi_shell methods.
_ = check_b0_threshold(bvals.min(), b0_thr=args.tolerance,
skip_b0_check=args.skip_b0_check)
skip_b0_check=args.skip_b0_check,
overwrite_with_min=False)
list_bvals = unique_bvals_tolerance(bvals, tol=args.tolerance)
if not np.all(list_bvals <= dti_lim):
_, data_dti, bvals_dti, bvecs_dti = extract_dwi_shell(
Expand Down
Loading