|
7 | 7 | """
|
8 | 8 |
|
9 | 9 | from nipype.interfaces.base import (
|
10 |
| - TraitedSpec, BaseInterface, File) |
| 10 | + TraitedSpec, BaseInterface, BaseInterfaceInputSpec, File) |
11 | 11 | from nipype.utils.filemanip import split_filename
|
12 | 12 | import os.path as op
|
13 | 13 | import nibabel as nb
|
|
29 | 29 | all_tensor_evecs)
|
30 | 30 |
|
31 | 31 |
|
32 |
| -class SimulateDWIInputSpec(BaseInterfaceInputSpec): |
| 32 | +class SimulateMultiTensorInputSpec(BaseInterfaceInputSpec): |
33 | 33 | fibers = InputMultiPath(File(exists=True), mandatory=True,
|
34 | 34 | desc='list of fibers principal directions')
|
35 | 35 | vfractions = File(exists=True, mandatory=True,
|
36 | 36 | 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') |
40 | 38 | gradients = File(exists=True, desc='gradients file')
|
41 | 39 | bvec = File(exists=True, desc='bvecs file')
|
42 | 40 | 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