29
29
from dipy .io .utils import nifti1_symmat
30
30
31
31
32
- def tensor_fitting (in_file , bvals , bvecs , mask_file = None )
32
+ def tensor_fitting (data , bvals , bvecs , mask_file = None ):
33
33
"""
34
34
Use dipy to fit DTI
35
35
36
36
Parameters
37
37
----------
38
38
in_file : str
39
- Full path to a DWI data file
39
+ Full path to a DWI data file.
40
40
bvals : str
41
- Full path to a file containing gradient magnitude information (b-values)
41
+ Full path to a file containing gradient magnitude information (b-values).
42
42
bvecs : str
43
- Full path to a file containing gradient direction information (b-vectors)
43
+ Full path to a file containing gradient direction information (b-vectors).
44
44
mask_file : str, optional
45
45
Full path to a file containing a binary mask. Defaults to use the entire volume.
46
46
47
47
Returns
48
48
-------
49
- TensorFit object
49
+ TensorFit object, affine
50
50
"""
51
- img = nb .load (in_file )
51
+ img = nb .load (in_file ). get_data ()
52
52
data = img .get_data ()
53
53
affine = img .get_affine ()
54
54
if mask_file is not None :
@@ -58,11 +58,10 @@ def tensor_fitting(in_file, bvals, bvecs, mask_file=None)
58
58
59
59
# Load information about the gradients:
60
60
gtab = grad .gradient_table (self .inputs .bvals , self .inputs .bvecs )
61
- gtab .bvals = bvals
62
61
63
62
# Fit it
64
63
tenmodel = dti .TensorModel (gtab )
65
- return tenmodel .fit (data , mask )
64
+ return tenmodel .fit (data , mask ), affine
66
65
67
66
68
67
class DTIInputSpec (TraitedSpec ):
@@ -90,19 +89,21 @@ class DTI(BaseInterface):
90
89
-------
91
90
92
91
>>> import nipype.interfaces.dipy as dipy
93
- >>> mode = dipy.DTI()
94
- >>> mode .inputs.in_file = 'diffusion.nii'
95
- >>> mode .inputs.bvecs = 'bvecs'
96
- >>> mode .inputs.bvals = 'bvals'
97
- >>> mode .inputs.mask_file = 'wm_mask.nii'
98
- >>> mode .run() # doctest: +SKIP
92
+ >>> dti = dipy.DTI()
93
+ >>> dti .inputs.in_file = 'diffusion.nii'
94
+ >>> dti .inputs.bvecs = 'bvecs'
95
+ >>> dti .inputs.bvals = 'bvals'
96
+ >>> dti .inputs.mask_file = 'wm_mask.nii'
97
+ >>> dti .run() # doctest: +SKIP
99
98
"""
100
99
input_spec = DTIInputSpec
101
100
output_spec = DTIOutputSpec
102
101
103
102
def _run_interface (self , runtime ):
104
- ten_fit = tensor_fitting (self .inputs .in_file , self .inputs .bvals , self .inputs .bvecs ,
105
- self .inputs .mask_file )
103
+ ten_fit , affine = tensor_fitting (self .inputs .in_file ,
104
+ self .inputs .bvals ,
105
+ self .inputs .bvecs ,
106
+ self .inputs .mask_file )
106
107
lower_triangular = tenfit .lower_triangular ()
107
108
img = nifti1_symmat (lower_triangular , affine )
108
109
out_file = op .abspath (self ._gen_outfilename ())
0 commit comments