From 61ea9bda4ad32f7929d07b77fc34b7002e0c5729 Mon Sep 17 00:00:00 2001 From: Philippe Karan Date: Wed, 18 Dec 2024 16:22:15 -0500 Subject: [PATCH] Adding overwrite_with_min option --- scilpy/gradients/bvec_bval_tools.py | 28 ++++++++++++++++++++-------- scilpy/io/btensor.py | 3 ++- scilpy/io/utils.py | 4 ++++ scripts/scil_NODDI_maps.py | 3 ++- scripts/scil_dki_metrics.py | 3 ++- scripts/scil_fodf_msmt.py | 3 ++- scripts/scil_frf_msmt.py | 3 ++- 7 files changed, 34 insertions(+), 13 deletions(-) diff --git a/scilpy/gradients/bvec_bval_tools.py b/scilpy/gradients/bvec_bval_tools.py index 2bcf53848..ba99c3e3a 100644 --- a/scilpy/gradients/bvec_bval_tools.py +++ b/scilpy/gradients/bvec_bval_tools.py @@ -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. @@ -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 ------- @@ -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 diff --git a/scilpy/io/btensor.py b/scilpy/io/btensor.py index f8c120d5a..3ddb194ff 100644 --- a/scilpy/io/btensor.py +++ b/scilpy/io/btensor.py @@ -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): diff --git a/scilpy/io/utils.py b/scilpy/io/utils.py index 9fd6ed351..e41009b80 100644 --- a/scilpy/io/utils.py +++ b/scilpy/io/utils.py @@ -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( diff --git a/scripts/scil_NODDI_maps.py b/scripts/scil_NODDI_maps.py index 2d067c5ff..7ee298e5d 100755 --- a/scripts/scil_NODDI_maps.py +++ b/scripts/scil_NODDI_maps.py @@ -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) diff --git a/scripts/scil_dki_metrics.py b/scripts/scil_dki_metrics.py index 5b56982fe..bbe834a8a 100755 --- a/scripts/scil_dki_metrics.py +++ b/scripts/scil_dki_metrics.py @@ -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 diff --git a/scripts/scil_fodf_msmt.py b/scripts/scil_fodf_msmt.py index 5e8db5829..235cd8476 100755 --- a/scripts/scil_fodf_msmt.py +++ b/scripts/scil_fodf_msmt.py @@ -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 diff --git a/scripts/scil_frf_msmt.py b/scripts/scil_frf_msmt.py index ce9bc3fcd..25bde5925 100755 --- a/scripts/scil_frf_msmt.py +++ b/scripts/scil_frf_msmt.py @@ -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(