Skip to content

Commit 27ab170

Browse files
committed
advance new interface
1 parent b7ca804 commit 27ab170

File tree

1 file changed

+49
-5
lines changed

1 file changed

+49
-5
lines changed

nipype/interfaces/dipy/simulate.py

Lines changed: 49 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
"""
88

99
from nipype.interfaces.base import (
10-
TraitedSpec, BaseInterface, File)
10+
TraitedSpec, BaseInterface, BaseInterfaceInputSpec, File)
1111
from nipype.utils.filemanip import split_filename
1212
import os.path as op
1313
import nibabel as nb
@@ -29,14 +29,58 @@
2929
all_tensor_evecs)
3030

3131

32-
class SimulateDWIInputSpec(BaseInterfaceInputSpec):
32+
class SimulateMultiTensorInputSpec(BaseInterfaceInputSpec):
3333
fibers = InputMultiPath(File(exists=True), mandatory=True,
3434
desc='list of fibers principal directions')
3535
vfractions = File(exists=True, mandatory=True,
3636
desc='volume fractions')
37-
S0 = File(exists=True, mandatory=True, desc='baseline T2 signal')
38-
out_file = File('sim_dwi.nii.gz', usedefault=True,
39-
desc='output file with fractions to be simluated')
37+
baseline = File(exists=True, mandatory=True, desc='baseline T2 signal')
4038
gradients = File(exists=True, desc='gradients file')
4139
bvec = File(exists=True, desc='bvecs file')
4240
bval = File(exists=True, desc='bvals file')
41+
out_file = File('sim_dwi.nii.gz', usedefault=True,
42+
desc='output file with fractions to be simluated')
43+
44+
45+
class SimulateMultiTensorOutputSpec(TraitedSpec):
46+
out_file = File(exists=True)
47+
48+
49+
class SimulateMultiTensor(BaseInterface):
50+
51+
"""
52+
Interface to MultiTensor model simulator in dipy
53+
http://nipy.org/dipy/examples_built/simulate_multi_tensor.html
54+
55+
Example
56+
-------
57+
58+
>>> import nipype.interfaces.dipy as dipy
59+
>>> sim = dipy.SimulateMultiTensor()
60+
>>> sim.inputs.fibers = 'fibers.nii'
61+
>>> sim.inputs.vfractions = 'fractions.nii'
62+
>>> sim.inputs.baseline = 'S0.nii'
63+
>>> sim.inputs.bvecs = 'bvecs'
64+
>>> sim.inputs.bvals = 'bvals'
65+
>>> sim.run() # doctest: +SKIP
66+
"""
67+
input_spec = SimulateMultiTensorInputSpec
68+
output_spec = SimulateMultiTensorOutputSpec
69+
70+
def _run_interface(self, runtime):
71+
# Load the 4D image files
72+
img = nb.load(self.inputs.fibers)
73+
fibers = img.get_data()
74+
fractions = nb.load(self.inputs.vfractions).get_data()
75+
affine = img.get_affine()
76+
77+
# Load the baseline b0 signal
78+
b0 = nb.load(self.inputs.baseline).get_data()
79+
80+
# Load the gradient strengths and directions
81+
bvals = np.loadtxt(self.inputs.bvals)
82+
gradients = np.loadtxt(self.inputs.bvecs).T
83+
84+
# Place in Dipy's preferred format
85+
gtab = GradientTable(gradients)
86+
gtab.bvals = bvals

0 commit comments

Comments
 (0)