11# -*- coding: utf-8 -*-
2- import os
2+ """
3+ Interfaces to the reconstruction algorithms in dipy
4+
5+ """
36import os .path as op
47
58import numpy as np
6- from dipy .core .gradients import GradientTable
79import nibabel as nb
810
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
1813
1914from nipype import logging
20- iflogger = logging .getLogger ('interface' )
15+ IFLOGGER = logging .getLogger ('interface' )
2116
2217
2318class RESTOREInputSpec (DipyBaseInterfaceInputSpec ):
@@ -27,20 +22,20 @@ class RESTOREInputSpec(DipyBaseInterfaceInputSpec):
2722
2823
2924class 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' )
3631 mode = File (desc = ('output mode (MO) map computed from the fitted DTI' ))
3732 trace = File (desc = ('output the tensor trace map computed from the '
3833 'fitted DTI' ))
3934 evals = File (desc = ('output the eigenvalues of the fitted DTI' ))
4035 evecs = File (desc = ('output the eigenvectors of the fitted DTI' ))
4136
4237
43- class RESTORE (DipyBaseInterface ):
38+ class RESTORE (DipyDiffusionInterface ):
4439
4540 """
4641 Uses RESTORE [Chang2005]_ to perform DTI fitting with outlier detection.
@@ -92,7 +87,7 @@ def _run_interface(self, runtime):
9287 noise_msk = noise_msk .astype (np .uint8 )
9388 try_b0 = False
9489 elif np .all (data [msk == 0 , 0 ] == 0 ):
95- iflogger .info ('Input data are masked.' )
90+ IFLOGGER .info ('Input data are masked.' )
9691 noise_msk = msk .reshape (- 1 ).astype (np .uint8 )
9792 else :
9893 noise_msk = (1 - msk ).reshape (- 1 ).astype (np .uint8 )
@@ -123,18 +118,18 @@ def _run_interface(self, runtime):
123118 sigma = mean_std * (1 + bias )
124119
125120 if sigma == 0 :
126- iflogger .warn (
121+ IFLOGGER .warn (
127122 ('Noise std is 0.0, looks like data was masked and noise'
128123 ' cannot be estimated correctly. Using default tensor '
129124 'model instead of RESTORE.' ))
130125 dti = TensorModel (gtab )
131126 else :
132- iflogger .info (('Performing RESTORE with noise std=%.4f.' ) % sigma )
127+ IFLOGGER .info (('Performing RESTORE with noise std=%.4f.' ) % sigma )
133128 dti = TensorModel (gtab , fit_method = 'RESTORE' , sigma = sigma )
134129
135130 try :
136131 fit_restore = dti .fit (data , msk )
137- except TypeError as e :
132+ except TypeError :
138133 dti = TensorModel (gtab )
139134 fit_restore = dti .fit (data , msk )
140135
@@ -181,7 +176,7 @@ class EstimateResponseSHOutputSpec(TraitedSpec):
181176 out_mask = File (exists = True , desc = ('output wm mask' ))
182177
183178
184- class EstimateResponseSH (DipyBaseInterface ):
179+ class EstimateResponseSH (DipyDiffusionInterface ):
185180
186181 """
187182 Uses dipy to compute the single fiber response to be used in spherical
@@ -253,14 +248,14 @@ def _run_interface(self, runtime):
253248 ratio = abs (response [1 ] / response [0 ])
254249
255250 if ratio > 0.25 :
256- iflogger .warn (('Estimated response is not prolate enough. '
251+ IFLOGGER .warn (('Estimated response is not prolate enough. '
257252 'Ratio=%0.3f.' ) % ratio )
258253 elif ratio < 1.e-5 or np .any (np .isnan (response )):
259254 response = np .array ([1.8e-3 , 3.6e-4 , 3.6e-4 , S0 ])
260- iflogger .warn (
255+ IFLOGGER .warn (
261256 ('Estimated response is not valid, using a default one' ))
262257 else :
263- iflogger .info (('Estimated response: %s' ) % str (response [:3 ]))
258+ IFLOGGER .info (('Estimated response: %s' ) % str (response [:3 ]))
264259
265260 np .savetxt (op .abspath (self .inputs .response ), response )
266261
@@ -293,7 +288,7 @@ class CSDOutputSpec(TraitedSpec):
293288 out_fods = File (desc = ('fODFs output file name' ))
294289
295290
296- class CSD (DipyBaseInterface ):
291+ class CSD (DipyDiffusionInterface ):
297292
298293 """
299294 Uses CSD [Tournier2007]_ to generate the fODF of DWIs. The interface uses
@@ -344,13 +339,13 @@ def _run_interface(self, runtime):
344339 ratio = response [0 ][1 ] / response [0 ][0 ]
345340
346341 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. '
348343 'Ratio=%0.3f.' ) % ratio )
349344
350345 csd_model = ConstrainedSphericalDeconvModel (
351346 gtab , response , sh_order = self .inputs .sh_order )
352347
353- iflogger .info ('Fitting CSD model' )
348+ IFLOGGER .info ('Fitting CSD model' )
354349 csd_fit = csd_model .fit (data , msk )
355350
356351 f = gzip .open (self ._gen_filename ('csdmodel' , ext = '.pklz' ), 'wb' )
0 commit comments