Skip to content

Commit 15dd7a8

Browse files
committed
Add TensorMetrics interface
1 parent 85a51a1 commit 15dd7a8

File tree

4 files changed

+113
-1
lines changed

4 files changed

+113
-1
lines changed

nipype/interfaces/mrtrix3/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
# vi: set ft=python sts=4 ts=4 sw=4 et:
33
# -*- coding: utf-8 -*-
44

5-
from utils import Mesh2PVE, Generate5tt, BrainMask
5+
from utils import Mesh2PVE, Generate5tt, BrainMask, TensorMetrics
66
from preprocess import ResponseSD, ACTPrepareFSL
77
from tracking import Tractography
88
from reconst import FitTensor, EstimateFOD
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
# AUTO-GENERATED by tools/checkspecs.py - DO NOT EDIT
2+
from nipype.testing import assert_equal
3+
from nipype.interfaces.mrtrix3.utils import TensorMetrics
4+
5+
def test_TensorMetrics_inputs():
6+
input_map = dict(args=dict(argstr='%s',
7+
),
8+
component=dict(argstr='-num %s',
9+
sep=',',
10+
),
11+
environ=dict(nohash=True,
12+
usedefault=True,
13+
),
14+
ignore_exception=dict(nohash=True,
15+
usedefault=True,
16+
),
17+
in_file=dict(argstr='%s',
18+
mandatory=True,
19+
position=-1,
20+
),
21+
in_mask=dict(argstr='-mask %s',
22+
),
23+
modulate=dict(argstr='-modulate %s',
24+
),
25+
out_adc=dict(argstr='-adc %s',
26+
),
27+
out_eval=dict(argstr='-value %s',
28+
),
29+
out_evec=dict(argstr='-vector %s',
30+
),
31+
out_fa=dict(argstr='-fa %s',
32+
),
33+
terminal_output=dict(nohash=True,
34+
),
35+
)
36+
inputs = TensorMetrics.input_spec()
37+
38+
for key, metadata in input_map.items():
39+
for metakey, value in metadata.items():
40+
yield assert_equal, getattr(inputs.traits()[key], metakey), value
41+
42+
def test_TensorMetrics_outputs():
43+
output_map = dict(out_adc=dict(),
44+
out_eval=dict(),
45+
out_evec=dict(),
46+
out_fa=dict(),
47+
)
48+
outputs = TensorMetrics.output_spec()
49+
50+
for key, metadata in output_map.items():
51+
for metakey, value in metadata.items():
52+
yield assert_equal, getattr(outputs.traits()[key], metakey), value
53+

nipype/interfaces/mrtrix3/utils.py

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,3 +167,62 @@ def _list_outputs(self):
167167
outputs = self.output_spec().get()
168168
outputs['out_file'] = op.abspath(self.inputs.out_file)
169169
return outputs
170+
171+
172+
class TensorMetricsInputSpec(CommandLineInputSpec):
173+
in_file = File(exists=True, argstr='%s', mandatory=True, position=-1,
174+
desc='input DTI image')
175+
176+
out_fa = File(argstr='-fa %s', desc='output FA file')
177+
out_adc = File(argstr='-adc %s', desc='output ADC file')
178+
out_evec = File(argstr='-vector %s',
179+
desc='output selected eigenvector(s) file')
180+
out_eval = File(argstr='-value %s',
181+
desc='output selected eigenvalue(s) file')
182+
component = traits.List(
183+
[1, 2, 3], argstr='-num %s', sep=',',
184+
desc=('specify the desired eigenvalue/eigenvector(s). Note that '
185+
'several eigenvalues can be specified as a number sequence'))
186+
in_mask = File(exists=True, argstr='-mask %s',
187+
desc=('only perform computation within the specified binary '
188+
'brain mask image'))
189+
modulate = traits.Enum('FA', 'none', 'eval', argstr='-modulate %s',
190+
desc='how to modulate the magnitude of the eigenvectors')
191+
192+
class TensorMetricsOutputSpec(TraitedSpec):
193+
out_fa = File(desc='output FA file')
194+
out_adc = File(desc='output ADC file')
195+
out_evec = File(desc='output selected eigenvector(s) file')
196+
out_eval = File(desc='output selected eigenvalue(s) file')
197+
198+
199+
class TensorMetrics(CommandLine):
200+
201+
"""
202+
Convert a mesh surface to a partial volume estimation image
203+
204+
205+
Example
206+
-------
207+
208+
>>> import nipype.interfaces.mrtrix3 as mrt
209+
>>> comp = mrt.TensorMetrics()
210+
>>> comp.inputs.in_file = 'dti.mif'
211+
>>> comp.inputs.out_fa = 'fa.mif'
212+
>>> comp.cmdline # doctest: +ELLIPSIS
213+
'tensor2metric -fa fa.mif dti.mif'
214+
>>> comp.run() # doctest: +SKIP
215+
"""
216+
217+
_cmd = 'tensor2metric'
218+
input_spec = TensorMetricsInputSpec
219+
output_spec = TensorMetricsOutputSpec
220+
221+
def _list_outputs(self):
222+
outputs = self.output_spec().get()
223+
224+
for k in outputs.keys():
225+
if isdefined(getattr(self.inputs, k)):
226+
outputs[k] = op.abspath(getattr(self.inputs, k))
227+
228+
return outputs

nipype/testing/data/dti.mif

Whitespace-only changes.

0 commit comments

Comments
 (0)