Skip to content

Commit ab3aa0c

Browse files
committed
New dipy interfaces
1 parent 4d0d309 commit ab3aa0c

File tree

7 files changed

+690
-67
lines changed

7 files changed

+690
-67
lines changed

nipype/interfaces/dipy/__init__.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1-
from .tracks import TrackDensityMap
1+
from .tracks import StreamlineTractography, TrackDensityMap
22
from .tensors import TensorMode
33
from .preprocess import Resample, Denoise
4+
from .reconstruction import RESTORE, EstimateResponseSH, CSD

nipype/interfaces/dipy/base.py

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
# -*- coding: utf-8 -*-
2+
3+
4+
class DipyBaseInterfaceInputSpec(BaseInterfaceInputSpec):
5+
in_file = File(exists=True, mandatory=True, desc=('input diffusion data'))
6+
in_bval = File(exists=True, mandatory=True, desc=('input b-values table'))
7+
in_bvec = File(exists=True, mandatory=True, desc=('input b-vectors table'))
8+
out_prefix = traits.Str(desc=('output prefix for file names'))
9+
10+
11+
class DipyBaseInterface(BaseInterface):
12+
13+
"""
14+
A base interface for py:mod:`dipy` computations
15+
"""
16+
input_spec = DipyBaseInterfaceInputSpec
17+
18+
def _get_gradient_table(self):
19+
gtab = GradientTable(np.loadtxt(self.inputs.in_bvec).T)
20+
gtab.b0_threshold = 700
21+
gtab.bvals = np.loadtxt(self.inputs.in_bval)
22+
return gtab
23+
24+
def _gen_filename(self, name, ext=None):
25+
fname, fext = op.splitext(op.basename(self.inputs.in_file))
26+
if fext == '.gz':
27+
fname, fext2 = op.splitext(fname)
28+
fext = fext2 + fext
29+
30+
if not isdefined(self.inputs.out_prefix):
31+
out_prefix = op.abspath(fname)
32+
else:
33+
out_prefix = self.inputs.out_prefix
34+
35+
if ext is None:
36+
ext = fext
37+
38+
return out_prefix + '_' + name + ext

nipype/interfaces/dipy/preprocess.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#!/usr/bin/env python
22
# -*- coding: utf-8 -*-
3-
"""Change directory to provide relative paths for doctests
3+
"""
4+
Change directory to provide relative paths for doctests
45
>>> import os
56
>>> filepath = os.path.dirname( os.path.realpath( __file__ ) )
67
>>> datadir = os.path.realpath(os.path.join(filepath, '../../testing/data'))
@@ -36,15 +37,17 @@ class ResampleInputSpec(TraitedSpec):
3637
' is set, then isotropic regridding will '
3738
'be performed, with spacing equal to the '
3839
'smallest current zoom.'))
39-
interp = traits.Int(1, mandatory=True, usedefault=True, desc=('order of '
40-
'the interpolator (0 = nearest, 1 = linear, etc.'))
40+
interp = traits.Int(
41+
1, mandatory=True, usedefault=True,
42+
desc=('order of the interpolator (0 = nearest, 1 = linear, etc.'))
4143

4244

4345
class ResampleOutputSpec(TraitedSpec):
4446
out_file = File(exists=True)
4547

4648

4749
class Resample(BaseInterface):
50+
4851
"""
4952
An interface to reslicing diffusion datasets.
5053
See
@@ -106,6 +109,7 @@ class DenoiseOutputSpec(TraitedSpec):
106109

107110

108111
class Denoise(BaseInterface):
112+
109113
"""
110114
An interface to denoising diffusion datasets [Coupe2008]_.
111115
See
@@ -152,7 +156,7 @@ def _run_interface(self, runtime):
152156
noise_mask=noise_mask,
153157
out_file=out_file)
154158
iflogger.info(('Denoised image saved as {i}, estimated '
155-
'sigma={s}').format(i=out_file, s=s))
159+
'sigma={s}').format(i=out_file, s=s))
156160
return runtime
157161

158162
def _list_outputs(self):

0 commit comments

Comments
 (0)