1
1
# -*- coding: utf-8 -*-
2
- import os
2
+ """
3
+ Interfaces to the reconstruction algorithms in dipy
4
+
5
+ """
3
6
import os .path as op
4
7
5
8
import numpy as np
6
- from dipy .core .gradients import GradientTable
7
9
import nibabel as nb
8
10
9
- from nipype .interfaces .base import (TraitedSpec , File , InputMultiPath ,
10
- OutputMultiPath , Undefined , traits ,
11
- isdefined , OutputMultiPath ,
12
- CommandLineInputSpec , CommandLine ,
13
- BaseInterface , BaseInterfaceInputSpec ,
14
- traits )
15
- from nipype .utils .filemanip import split_filename , fname_presuffix
16
-
17
- from .base import DipyBaseInterface , DipyBaseInterfaceInputSpec
11
+ from nipype .interfaces .base import TraitedSpec , File , traits , isdefined
12
+ from .base import DipyDiffusionInterface , DipyBaseInterfaceInputSpec
18
13
19
14
from nipype import logging
20
- iflogger = logging .getLogger ('interface' )
15
+ IFLOGGER = logging .getLogger ('interface' )
21
16
22
17
23
18
class RESTOREInputSpec (DipyBaseInterfaceInputSpec ):
@@ -27,20 +22,20 @@ class RESTOREInputSpec(DipyBaseInterfaceInputSpec):
27
22
28
23
29
24
class RESTOREOutputSpec (TraitedSpec ):
30
- fa = File (desc = ( 'output fractional anisotropy (FA) map computed from '
31
- 'the fitted DTI' ) )
32
- md = File (desc = ( 'output mean diffusivity (MD) map computed from the '
33
- 'fitted DTI' ) )
34
- rd = File (desc = ( 'output radial diffusivity (RD) map computed from '
35
- 'the fitted DTI' ) )
25
+ fa = File (desc = 'output fractional anisotropy (FA) map computed from '
26
+ 'the fitted DTI' )
27
+ md = File (desc = 'output mean diffusivity (MD) map computed from the '
28
+ 'fitted DTI' )
29
+ rd = File (desc = 'output radial diffusivity (RD) map computed from '
30
+ 'the fitted DTI' )
36
31
mode = File (desc = ('output mode (MO) map computed from the fitted DTI' ))
37
32
trace = File (desc = ('output the tensor trace map computed from the '
38
33
'fitted DTI' ))
39
34
evals = File (desc = ('output the eigenvalues of the fitted DTI' ))
40
35
evecs = File (desc = ('output the eigenvectors of the fitted DTI' ))
41
36
42
37
43
- class RESTORE (DipyBaseInterface ):
38
+ class RESTORE (DipyDiffusionInterface ):
44
39
45
40
"""
46
41
Uses RESTORE [Chang2005]_ to perform DTI fitting with outlier detection.
@@ -92,7 +87,7 @@ def _run_interface(self, runtime):
92
87
noise_msk = noise_msk .astype (np .uint8 )
93
88
try_b0 = False
94
89
elif np .all (data [msk == 0 , 0 ] == 0 ):
95
- iflogger .info ('Input data are masked.' )
90
+ IFLOGGER .info ('Input data are masked.' )
96
91
noise_msk = msk .reshape (- 1 ).astype (np .uint8 )
97
92
else :
98
93
noise_msk = (1 - msk ).reshape (- 1 ).astype (np .uint8 )
@@ -123,18 +118,18 @@ def _run_interface(self, runtime):
123
118
sigma = mean_std * (1 + bias )
124
119
125
120
if sigma == 0 :
126
- iflogger .warn (
121
+ IFLOGGER .warn (
127
122
('Noise std is 0.0, looks like data was masked and noise'
128
123
' cannot be estimated correctly. Using default tensor '
129
124
'model instead of RESTORE.' ))
130
125
dti = TensorModel (gtab )
131
126
else :
132
- iflogger .info (('Performing RESTORE with noise std=%.4f.' ) % sigma )
127
+ IFLOGGER .info (('Performing RESTORE with noise std=%.4f.' ) % sigma )
133
128
dti = TensorModel (gtab , fit_method = 'RESTORE' , sigma = sigma )
134
129
135
130
try :
136
131
fit_restore = dti .fit (data , msk )
137
- except TypeError as e :
132
+ except TypeError :
138
133
dti = TensorModel (gtab )
139
134
fit_restore = dti .fit (data , msk )
140
135
@@ -181,7 +176,7 @@ class EstimateResponseSHOutputSpec(TraitedSpec):
181
176
out_mask = File (exists = True , desc = ('output wm mask' ))
182
177
183
178
184
- class EstimateResponseSH (DipyBaseInterface ):
179
+ class EstimateResponseSH (DipyDiffusionInterface ):
185
180
186
181
"""
187
182
Uses dipy to compute the single fiber response to be used in spherical
@@ -253,14 +248,14 @@ def _run_interface(self, runtime):
253
248
ratio = abs (response [1 ] / response [0 ])
254
249
255
250
if ratio > 0.25 :
256
- iflogger .warn (('Estimated response is not prolate enough. '
251
+ IFLOGGER .warn (('Estimated response is not prolate enough. '
257
252
'Ratio=%0.3f.' ) % ratio )
258
253
elif ratio < 1.e-5 or np .any (np .isnan (response )):
259
254
response = np .array ([1.8e-3 , 3.6e-4 , 3.6e-4 , S0 ])
260
- iflogger .warn (
255
+ IFLOGGER .warn (
261
256
('Estimated response is not valid, using a default one' ))
262
257
else :
263
- iflogger .info (('Estimated response: %s' ) % str (response [:3 ]))
258
+ IFLOGGER .info (('Estimated response: %s' ) % str (response [:3 ]))
264
259
265
260
np .savetxt (op .abspath (self .inputs .response ), response )
266
261
@@ -293,7 +288,7 @@ class CSDOutputSpec(TraitedSpec):
293
288
out_fods = File (desc = ('fODFs output file name' ))
294
289
295
290
296
- class CSD (DipyBaseInterface ):
291
+ class CSD (DipyDiffusionInterface ):
297
292
298
293
"""
299
294
Uses CSD [Tournier2007]_ to generate the fODF of DWIs. The interface uses
@@ -344,13 +339,13 @@ def _run_interface(self, runtime):
344
339
ratio = response [0 ][1 ] / response [0 ][0 ]
345
340
346
341
if abs (ratio - 0.2 ) > 0.1 :
347
- iflogger .warn (('Estimated response is not prolate enough. '
342
+ IFLOGGER .warn (('Estimated response is not prolate enough. '
348
343
'Ratio=%0.3f.' ) % ratio )
349
344
350
345
csd_model = ConstrainedSphericalDeconvModel (
351
346
gtab , response , sh_order = self .inputs .sh_order )
352
347
353
- iflogger .info ('Fitting CSD model' )
348
+ IFLOGGER .info ('Fitting CSD model' )
354
349
csd_fit = csd_model .fit (data , msk )
355
350
356
351
f = gzip .open (self ._gen_filename ('csdmodel' , ext = '.pklz' ), 'wb' )
0 commit comments