Skip to content

Commit ca19159

Browse files
committed
New interface for Camino dtshape. Minor correction to Camino ComputeEigensystem
1 parent 38e1cc4 commit ca19159

File tree

5 files changed

+104
-14
lines changed

5 files changed

+104
-14
lines changed

nipype/interfaces/camino/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,6 @@
99
from .dti import (DTIFit, ModelFit, DTLUTGen, PicoPDFs, Track, TrackPICo,
1010
TrackBayesDirac, TrackDT, TrackBallStick, TrackBootstrap,
1111
ComputeFractionalAnisotropy, ComputeMeanDiffusivity,
12-
ComputeTensorTrace, ComputeEigensystem)
12+
ComputeTensorTrace, ComputeEigensystem, DTMetric)
1313
from .calib import (SFPICOCalibData, SFLUTGen)
1414
from .odf import (QBallMX, LinRecon, SFPeaks)

nipype/interfaces/camino/convert.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -563,7 +563,7 @@ class AnalyzeHeader(StdOutCommandLine):
563563
564564
>>> import nipype.interfaces.camino as cmon
565565
>>> hdr = cmon.AnalyzeHeader()
566-
>>> hdr.inputs.in_file = 'tensor_fitted_data.Bfloat'
566+
>>> hdr.inputs.in_file = 'tensor_fitted_data.Bdouble'
567567
>>> hdr.inputs.scheme_file = 'A.scheme'
568568
>>> hdr.inputs.data_dims = [256,256,256]
569569
>>> hdr.inputs.voxel_dims = [1,1,1]

nipype/interfaces/camino/dti.py

Lines changed: 102 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ class DTIFit(StdOutCommandLine):
4949
>>> import nipype.interfaces.camino as cmon
5050
>>> fit = cmon.DTIFit()
5151
>>> fit.inputs.scheme_file = 'A.scheme'
52-
>>> fit.inputs.in_file = 'tensor_fitted_data.Bfloat'
52+
>>> fit.inputs.in_file = 'tensor_fitted_data.Bdouble'
5353
>>> fit.run() # doctest: +SKIP
5454
"""
5555
_cmd = 'dtfit'
@@ -65,6 +65,85 @@ def _gen_outfilename(self):
6565
_, name , _ = split_filename(self.inputs.in_file)
6666
return name + '_DT.Bdouble'
6767

68+
class DTMetricInputSpec(StdOutCommandLineInputSpec):
69+
eigen_data = File(exists=True, argstr='-inputfile %s', mandatory=True,
70+
desc='voxel-order data filename')
71+
72+
metric = traits.Enum('fa','md','rd','l1', 'l2', 'l3', 'tr', 'ra', '2dfa','cl','cp','cs',
73+
argstr='-stat %s', mandatory=True,
74+
desc=('Specifies the metric to compute. Possible choices are: '
75+
'"fa", "md", "rd", "l1", "l2", "l3", "tr", "ra", "2dfa", "cl", "cp" or "cs".'))
76+
77+
inputdatatype = traits.Enum('double', 'float', 'long', 'int', 'short', 'char',
78+
argstr='-inputdatatype %s', usedefault=True,
79+
desc=('Specifies the data type of the input data. '
80+
'The data type can be any of the following strings: '
81+
'"char", "short", "int", "long", "float" or "double".'
82+
'Default is double data type'))
83+
84+
outputdatatype = traits.Enum('double', 'float', 'long', 'int', 'short', 'char',
85+
argstr='-outputdatatype %s', usedefault=True,
86+
desc=('Specifies the data type of the output data. '
87+
'The data type can be any of the following strings: '
88+
'"char", "short", "int", "long", "float" or "double".'
89+
'Default is double data type'))
90+
91+
class DTMetricOutputSpec(TraitedSpec):
92+
metric_stats = File(exists=True, desc='Diffusion Tensor statistics of the chosen metric')
93+
94+
class DTMetric(StdOutCommandLine):
95+
"""
96+
Computes tensor metric statistics based on the eigenvalues l1 >= l2 >= l3
97+
typically obtained from ComputeEigensystem.
98+
99+
The full list of statistics is:
100+
101+
<cl> = (l1 - l2) / l1 , a measure of linearity
102+
<cp> = (l2 - l3) / l1 , a measure of planarity
103+
<cs> = l3 / l1 , a measure of isotropy
104+
with: cl + cp + cs = 1
105+
106+
<l1> = first eigenvalue
107+
<l2> = second eigenvalue
108+
<l3> = third eigenvalue
109+
110+
<tr> = l1 + l2 + l3
111+
<md> = tr / 3
112+
<rd> = (l2 + l3) / 2
113+
<fa> = fractional anisotropy. (Basser et al, J Magn Reson B 1996)
114+
<ra> = relative anisotropy (Basser et al, J Magn Reson B 1996)
115+
116+
<2dfa> = 2D FA of the two minor eigenvalues l2 and l3
117+
i.e. sqrt( 2 * [(l2 - <l>)^2 + (l3 - <l>)^2] / (l2^2 + l3^2) )
118+
with: <l> = (l2 + l3) / 2
119+
120+
Example
121+
-------
122+
Compute the CP planar metric as float data type.
123+
124+
>>> import nipype.interfaces.camino as cam
125+
>>> dtmetric = cam.DTMetric()
126+
>>> dtmetric.inputs.eigen_data = 'dteig.Bdouble'
127+
>>> dtmetric.inputs.metric = 'cp'
128+
>>> dtmetric.inputs.outputdatatype = 'float'
129+
>>> dtmetric.run() # doctest: +SKIP
130+
"""
131+
_cmd = 'dtshape'
132+
input_spec=DTMetricInputSpec
133+
output_spec=DTMetricOutputSpec
134+
135+
def _list_outputs(self):
136+
outputs = self.output_spec().get()
137+
outputs['metric_stats'] = os.path.abspath(self._gen_outfilename())
138+
return outputs
139+
140+
def _gen_outfilename(self):
141+
_, name , _ = split_filename(self.inputs.eigen_data)
142+
metric = self.inputs.metric
143+
datatype= self.inputs.outputdatatype
144+
return name + '_' + metric + '.B' + datatype
145+
146+
68147
class ModelFitInputSpec(StdOutCommandLineInputSpec):
69148
def _gen_model_options(): #@NoSelf
70149
"""
@@ -134,7 +213,7 @@ class ModelFit(StdOutCommandLine):
134213
>>> fit = cmon.ModelFit()
135214
>>> fit.model = 'dt'
136215
>>> fit.inputs.scheme_file = 'A.scheme'
137-
>>> fit.inputs.in_file = 'tensor_fitted_data.Bfloat'
216+
>>> fit.inputs.in_file = 'tensor_fitted_data.Bdouble'
138217
>>> fit.run() # doctest: +SKIP
139218
"""
140219
_cmd = 'modelfit'
@@ -381,7 +460,7 @@ class TrackDT(Track):
381460
382461
>>> import nipype.interfaces.camino as cmon
383462
>>> track = cmon.TrackDT()
384-
>>> track.inputs.in_file = 'tensor_fitted_data.Bfloat'
463+
>>> track.inputs.in_file = 'tensor_fitted_data.Bdouble'
385464
>>> track.inputs.seed_file = 'seed_mask.nii'
386465
>>> track.run() # doctest: +SKIP
387466
"""
@@ -447,7 +526,7 @@ class TrackBayesDirac(Track):
447526
448527
>>> import nipype.interfaces.camino as cmon
449528
>>> track = cmon.TrackBayesDirac()
450-
>>> track.inputs.in_file = 'tensor_fitted_data.Bfloat'
529+
>>> track.inputs.in_file = 'tensor_fitted_data.Bdouble'
451530
>>> track.inputs.seed_file = 'seed_mask.nii'
452531
>>> track.inputs.scheme_file = 'bvecs.scheme'
453532
>>> track.run() # doctest: +SKIP
@@ -547,7 +626,7 @@ class ComputeMeanDiffusivity(StdOutCommandLine):
547626
548627
>>> import nipype.interfaces.camino as cmon
549628
>>> md = cmon.ComputeMeanDiffusivity()
550-
>>> md.inputs.in_file = 'tensor_fitted_data.Bfloat'
629+
>>> md.inputs.in_file = 'tensor_fitted_data.Bdouble'
551630
>>> md.inputs.scheme_file = 'A.scheme'
552631
>>> md.run() # doctest: +SKIP
553632
"""
@@ -606,7 +685,7 @@ class ComputeFractionalAnisotropy(StdOutCommandLine):
606685
607686
>>> import nipype.interfaces.camino as cmon
608687
>>> fa = cmon.ComputeFractionalAnisotropy()
609-
>>> fa.inputs.in_file = 'tensor_fitted_data.Bfloat'
688+
>>> fa.inputs.in_file = 'tensor_fitted_data.Bdouble'
610689
>>> fa.inputs.scheme_file = 'A.scheme'
611690
>>> fa.run() # doctest: +SKIP
612691
"""
@@ -667,7 +746,7 @@ class ComputeTensorTrace(StdOutCommandLine):
667746
668747
>>> import nipype.interfaces.camino as cmon
669748
>>> trace = cmon.ComputeTensorTrace()
670-
>>> trace.inputs.in_file = 'tensor_fitted_data.Bfloat'
749+
>>> trace.inputs.in_file = 'tensor_fitted_data.Bdouble'
671750
>>> trace.inputs.scheme_file = 'A.scheme'
672751
>>> trace.run() # doctest: +SKIP
673752
"""
@@ -690,11 +769,21 @@ class ComputeEigensystemInputSpec(StdOutCommandLineInputSpec):
690769

691770
inputmodel = traits.Enum('dt', 'multitensor', argstr='-inputmodel %s', desc='Specifies the model that the input data contains parameters for. Possible model types are: "dt" (diffusion-tensor data) and "multitensor"')
692771

693-
maxcomponents = traits.Int(argstr='-maxcomponents %s', desc='The maximum number of tensor components in a voxel of the input data.')
772+
maxcomponents = traits.Int(argstr='-maxcomponents %d', desc='The maximum number of tensor components in a voxel of the input data.')
694773

695-
inputdatatype = traits.Enum("double", "char", "short", "int", "long", "float", argstr='-inputdatatype %s', desc='Specifies the data type of the input file. The data type can be any of the following strings: "char", "short", "int", "long", "float" or "double".')
774+
inputdatatype = traits.Enum('double', 'float', 'long', 'int', 'short', 'char',
775+
argstr='-inputdatatype %s', usedefault=True,
776+
desc=('Specifies the data type of the input data. '
777+
'The data type can be any of the following strings: '
778+
'"char", "short", "int", "long", "float" or "double".'
779+
'Default is double data type'))
696780

697-
outputdatatype = traits.Enum("double", "char", "short", "int", "long", "float", argstr='-outputdatatype %s', desc='Specifies the data type of the output data. The data type can be any of the following strings: "char", "short", "int", "long", "float" or "double".')
781+
outputdatatype = traits.Enum('double', 'float', 'long', 'int', 'short', 'char',
782+
argstr='-outputdatatype %s', usedefault=True,
783+
desc=('Specifies the data type of the output data. '
784+
'The data type can be any of the following strings: '
785+
'"char", "short", "int", "long", "float" or "double".'
786+
'Default is double data type'))
698787

699788
class ComputeEigensystemOutputSpec(TraitedSpec):
700789
eigen = File(exists=True, desc='Trace of the diffusion tensor')
@@ -716,7 +805,7 @@ class ComputeEigensystem(StdOutCommandLine):
716805
717806
>>> import nipype.interfaces.camino as cmon
718807
>>> dteig = cmon.ComputeEigensystem()
719-
>>> dteig.inputs.in_file = 'tensor_fitted_data.Bfloat'
808+
>>> dteig.inputs.in_file = 'tensor_fitted_data.Bdouble'
720809
>>> dteig.run() # doctest: +SKIP
721810
"""
722811
_cmd = 'dteig'
@@ -730,4 +819,5 @@ def _list_outputs(self):
730819

731820
def _gen_outfilename(self):
732821
_, name , _ = split_filename(self.inputs.in_file)
733-
return name + "_Eigen.img" #Need to change to self.inputs.outputdatatype
822+
datatype= self.inputs.outputdatatype
823+
return name + '_eig.B' + datatype

nipype/testing/data/tensor_fitted_data.Bdouble

Whitespace-only changes.

0 commit comments

Comments
 (0)