@@ -15,44 +15,57 @@ class DiffusionGradientTable:
15
15
16
16
__slots__ = [
17
17
"_affine" ,
18
- "_gradients " ,
18
+ "_b0_thres " ,
19
19
"_b_scale" ,
20
- "_bvecs" ,
21
20
"_bvals" ,
21
+ "_bvec_norm_epsilon" ,
22
+ "_bvecs" ,
23
+ "_gradients" ,
22
24
"_normalized" ,
25
+ "_raise_inconsistent" ,
23
26
"_transforms" ,
24
- "_b0_thres" ,
25
- "_bvec_norm_epsilon" ,
26
27
]
27
28
28
29
def __init__ (
29
30
self ,
30
- dwi_file = None ,
31
- bvecs = None ,
31
+ b0_threshold = B0_THRESHOLD ,
32
+ b_scale = True ,
32
33
bvals = None ,
34
+ bvec_norm_epsilon = BVEC_NORM_EPSILON ,
35
+ bvecs = None ,
36
+ dwi_file = None ,
37
+ raise_inconsistent = False ,
33
38
rasb_file = None ,
34
- b_scale = True ,
35
39
transforms = None ,
36
- b0_threshold = B0_THRESHOLD ,
37
- bvec_norm_epsilon = BVEC_NORM_EPSILON ,
38
40
):
39
41
"""
40
42
Create a new table of diffusion gradients.
41
43
42
44
Parameters
43
45
----------
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.
47
51
bvals : str or os.pathlike or numpy.ndarray
48
52
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.
49
55
bvecs : str or os.pathlike or numpy.ndarray
50
56
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).
51
64
rasb_file : str or os.pathlike
52
65
File path to a RAS-B gradient table. If rasb_file is provided,
53
66
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 .
56
69
57
70
Example
58
71
-------
@@ -75,16 +88,18 @@ def __init__(
75
88
>>> out_rasb_mat = check.reorient_rasb()
76
89
>>> np.allclose(old_rasb_mat, out_rasb_mat)
77
90
True
91
+
78
92
"""
79
- self ._transforms = transforms
80
- self ._b_scale = b_scale
93
+ self ._affine = None
81
94
self ._b0_thres = b0_threshold
82
- self ._bvec_norm_epsilon = bvec_norm_epsilon
83
- self ._gradients = None
95
+ self ._b_scale = b_scale
84
96
self ._bvals = None
97
+ self ._bvec_norm_epsilon = bvec_norm_epsilon
85
98
self ._bvecs = None
86
- self ._affine = None
99
+ self ._gradients = None
87
100
self ._normalized = False
101
+ self ._raise_inconsistent = raise_inconsistent
102
+ self ._transforms = transforms
88
103
89
104
if dwi_file is not None :
90
105
self .affine = dwi_file
@@ -175,6 +190,7 @@ def normalize(self):
175
190
b0_threshold = self ._b0_thres ,
176
191
bvec_norm_epsilon = self ._bvec_norm_epsilon ,
177
192
b_scale = self ._b_scale ,
193
+ raise_error = self ._raise_inconsistent ,
178
194
)
179
195
self ._normalized = True
180
196
@@ -295,7 +311,7 @@ def normalize_gradients(bvecs, bvals, b0_threshold=B0_THRESHOLD,
295
311
--------
296
312
>>> bvecs = np.vstack((np.zeros(3), 2.0 * np.eye(3), -0.8 * np.eye(3), np.ones(3)))
297
313
>>> 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)
299
315
Traceback (most recent call last):
300
316
ValueError:
301
317
0 commit comments