Skip to content

Commit d1b93aa

Browse files
committed
ENH: Do not raise error in all instances of b-vecs/vals inconsistencies
We raised a ValueError whenever the number of b-vals and all-zero b-vecs didn't match. Few lines later, we would overwrite nonzero b-vecs to match the b-vals, but that step was never reached. This PR allows the function to just throw a warning instead. Resolves: #82
1 parent 2802c50 commit d1b93aa

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed

dmriprep/utils/vectors.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
"""Utilities to operate on diffusion gradients."""
2+
from .. import config
23
from pathlib import Path
34
from itertools import permutations
45
import nibabel as nb
@@ -265,7 +266,8 @@ def to_filename(self, filename, filetype="rasb"):
265266

266267

267268
def normalize_gradients(bvecs, bvals, b0_threshold=B0_THRESHOLD,
268-
bvec_norm_epsilon=BVEC_NORM_EPSILON, b_scale=True):
269+
bvec_norm_epsilon=BVEC_NORM_EPSILON, b_scale=True,
270+
raise_error=False):
269271
"""
270272
Normalize b-vectors and b-values.
271273

@@ -329,9 +331,10 @@ def normalize_gradients(bvecs, bvals, b0_threshold=B0_THRESHOLD,
329331

330332
# Check for bval-bvec discrepancy.
331333
if not np.all(b0s == b0_vecs):
332-
raise ValueError(
333-
'Inconsistent bvals and bvecs (%d, %d low-b, respectively).' %
334-
(b0s.sum(), b0_vecs.sum()))
334+
msg = f"Inconsistent bvals and bvecs ({b0s.sum()}, {b0_vecs.sum()} low-b, respectively)."
335+
if raise_error:
336+
raise ValueError(msg)
337+
config.loggers.cli.warning(msg)
335338

336339
# Rescale b-vals if requested
337340
if b_scale:

0 commit comments

Comments
 (0)