@@ -15,44 +15,57 @@ class DiffusionGradientTable:
1515
1616 __slots__ = [
1717 "_affine" ,
18- "_gradients " ,
18+ "_b0_thres " ,
1919 "_b_scale" ,
20- "_bvecs" ,
2120 "_bvals" ,
21+ "_bvec_norm_epsilon" ,
22+ "_bvecs" ,
23+ "_gradients" ,
2224 "_normalized" ,
25+ "_raise_inconsistent" ,
2326 "_transforms" ,
24- "_b0_thres" ,
25- "_bvec_norm_epsilon" ,
2627 ]
2728
2829 def __init__ (
2930 self ,
30- dwi_file = None ,
31- bvecs = None ,
31+ b0_threshold = B0_THRESHOLD ,
32+ b_scale = True ,
3233 bvals = None ,
34+ bvec_norm_epsilon = BVEC_NORM_EPSILON ,
35+ bvecs = None ,
36+ dwi_file = None ,
37+ raise_inconsistent = False ,
3338 rasb_file = None ,
34- b_scale = True ,
3539 transforms = None ,
36- b0_threshold = B0_THRESHOLD ,
37- bvec_norm_epsilon = BVEC_NORM_EPSILON ,
3840 ):
3941 """
4042 Create a new table of diffusion gradients.
4143
4244 Parameters
4345 ----------
44- dwi_file : str or os.pathlike or nibabel.spatialimage
45- File path to the diffusion-weighted image series to which the
46- bvecs/bvals correspond.
46+ b0_threshold : :obj:`float`
47+ The upper threshold to consider a low-b shell as :math:`b=0`.
48+ b_scale : :obj:`bool`
49+ Automatically scale the *b*-values with the norm of the corresponding
50+ *b*-vectors before the latter are normalized.
4751 bvals : str or os.pathlike or numpy.ndarray
4852 File path of the b-values.
53+ b_vec_norm_epsilon : :obj:`float`
54+ The minimum difference in the norm of two *b*-vectors to consider them different.
4955 bvecs : str or os.pathlike or numpy.ndarray
5056 File path of the b-vectors.
57+ dwi_file : str or os.pathlike or nibabel.spatialimage
58+ File path to the diffusion-weighted image series to which the
59+ bvecs/bvals correspond.
60+ raise_inconsistent : :obj:`bool`
61+ If ``True``, a :obj:`ValueError` is raised when discrepancies are found between the
62+ :math:`b=0` lists calculated from the *b*-vectors and *b*-values, respectively.
63+ If ``False``, inconsistencies will be mended (if possible).
5164 rasb_file : str or os.pathlike
5265 File path to a RAS-B gradient table. If rasb_file is provided,
5366 then bvecs and bvals will be dismissed.
54- b_scale : bool
55- Whether b-values should be normalized .
67+ transforms : :obj:`list` of :obj:`numpy.ndarray`
68+ A list of affine transforms to rotate the list of vectors .
5669
5770 Example
5871 -------
@@ -75,16 +88,18 @@ def __init__(
7588 >>> out_rasb_mat = check.reorient_rasb()
7689 >>> np.allclose(old_rasb_mat, out_rasb_mat)
7790 True
91+
7892 """
79- self ._transforms = transforms
80- self ._b_scale = b_scale
93+ self ._affine = None
8194 self ._b0_thres = b0_threshold
82- self ._bvec_norm_epsilon = bvec_norm_epsilon
83- self ._gradients = None
95+ self ._b_scale = b_scale
8496 self ._bvals = None
97+ self ._bvec_norm_epsilon = bvec_norm_epsilon
8598 self ._bvecs = None
86- self ._affine = None
99+ self ._gradients = None
87100 self ._normalized = False
101+ self ._raise_inconsistent = raise_inconsistent
102+ self ._transforms = transforms
88103
89104 if dwi_file is not None :
90105 self .affine = dwi_file
@@ -175,6 +190,7 @@ def normalize(self):
175190 b0_threshold = self ._b0_thres ,
176191 bvec_norm_epsilon = self ._bvec_norm_epsilon ,
177192 b_scale = self ._b_scale ,
193+ raise_error = self ._raise_inconsistent ,
178194 )
179195 self ._normalized = True
180196
@@ -295,7 +311,7 @@ def normalize_gradients(bvecs, bvals, b0_threshold=B0_THRESHOLD,
295311 --------
296312 >>> bvecs = np.vstack((np.zeros(3), 2.0 * np.eye(3), -0.8 * np.eye(3), np.ones(3)))
297313 >>> bvals = np.array([1000] * bvecs.shape[0])
298- >>> normalize_gradients(bvecs, bvals, 50) # doctest: +IGNORE_EXCEPTION_DETAIL
314+ >>> normalize_gradients(bvecs, bvals, 50, raise_error=True)
299315 Traceback (most recent call last):
300316 ValueError:
301317
0 commit comments