Skip to content

Commit 842cfb4

Browse files
committed
Added interface for topup
1 parent 08cae16 commit 842cfb4

File tree

1 file changed

+89
-64
lines changed

1 file changed

+89
-64
lines changed

nipype/interfaces/fsl/epi.py

Lines changed: 89 additions & 64 deletions
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
"""The fsl module provides classes for interfacing with the `FSL
44
<http://www.fmrib.ox.ac.uk/fsl/index.html>`_ command line tools. This
5-
was written to work with FSL version 4.1.4.
5+
was written to work with FSL version 5.0.4.
66
77
Examples
88
--------
@@ -45,7 +45,7 @@ class PrepareFieldmapOutputSpec( TraitedSpec ):
4545
out_fieldmap = File( exists=True, desc='output name for prepared fieldmap' )
4646

4747
class PrepareFieldmap(FSLCommand):
48-
""" Interface for the fsl_prepare_fieldmap script
48+
""" Interface for the fsl_prepare_fieldmap script (FSL 5.0)
4949
5050
Prepares a fieldmap suitable for FEAT from SIEMENS data - saves output in rad/s format
5151
e.g. fsl_prepare_fieldmap SIEMENS images_3_gre_field_mapping images_4_gre_field_mapping fmap_rads 2.65
@@ -84,75 +84,100 @@ def _list_outputs(self):
8484

8585

8686

87-
# class TOPUPInputSpec( FSLCommandInputSpec ):
88-
# in_file = File( exists=True, mandatory=True, desc='name of 4D file with images', argstr='--imain %s' )
89-
# encoding_file = File( exists=True, mandatory=True, desc='name of text file with PE directions/times', argstr='--datain %s' )
90-
# out_base = File( desc='base-name of output files (spline coefficients (Hz) and movement parameters)', argstr='--out %s' )
91-
# out_field = File( argstr='--fout %s', desc='name of image file with field (Hz)' )
92-
# out_corrected = File( argstr='--iout %s', desc='name of 4D image file with unwarped images' )
93-
# out_logfile = File( argstr='--logout %s', desc='name of log-file' )
94-
# warp_res = traits.Float( 10.0, argstr='--warpres %f', desc='(approximate) resolution (in mm) of warp basis for the different sub-sampling levels' )
95-
# subsamp = traits.Int( 1, argstr='--subsamp %d', desc='sub-sampling scheme, default 1' )
96-
# fwhm = traits.Float( 8.0, argstr='--fwhm %f', desc='FWHM (in mm) of gaussian smoothing kernel' )
97-
# config = File( desc='Name of config file specifying command line arguments', argstr='--config %s' )
98-
# max_iter = traits.Int( 5, argstr='--miter %d', desc='max # of non-linear iterations')
99-
# #lambda Weight of regularisation, default depending on --ssqlambda and --regmod switches. See user documetation.
100-
# #ssqlambda If set (=1), lambda is weighted by current ssq, default 1
101-
# #regmod Model for regularisation of warp-field [membrane_energy bending_energy], default bending_energy
102-
# estmov = traits.Either( (0,1), desc='estimate movements if set', argstr='--estmov %d' )
103-
# minmet = traits.Either( (0,1), desc='Minimisation method 0=Levenberg-Marquardt, 1=Scaled Conjugate Gradient', argstr='--minmet %d' )
104-
# splineorder = traits.Int( 3, argstr='--splineorder %d', desc='order of spline, 2->Qadratic spline, 3->Cubic spline' )
105-
# numprec = traits.Either( ('float','double'), argstr='--numprec %s', desc='Precision for representing Hessian, double or float.' )
106-
# interp = traits.Either( ('linear','spline'), argstr='--interp %s', desc='Image interpolation model, linear or spline.' )
107-
# scale = traits.Either( (0,1), argstr='--scale %d', desc='If set (=1), the images are individually scaled to a common mean' )
108-
# regrid = traits.Either( (0,1), argstr='--regrid %d', desc='If set (=1), the calculations are done in a different grid' )
109-
#
110-
#
111-
#
112-
# class TOPUPOutputSpec( TraitedSpec ):
113-
# out_field = File( argstr='--fout %s', desc='name of image file with field (Hz)' )
114-
# out_corrected = File( argstr='--iout %s', desc='name of 4D image file with unwarped images' )
115-
# out_logfile = File( argstr='--logout %s', desc='name of log-file' )
116-
#
117-
#
118-
#
119-
# class TOPUP( FSLCommand ):
120-
# """ Interface for FSL topup, a tool for estimating and correcting susceptibility induced distortions
121-
# Reference: http://fsl.fmrib.ox.ac.uk/fsl/fslwiki/TOPUP
122-
# Example: http://fsl.fmrib.ox.ac.uk/fsl/fslwiki/topup/ExampleTopupFollowedByApplytopup
123-
#
124-
# topup --imain=<some 4D image> --datain=<text file> --config=<text file with parameters> --coutname=my_field
125-
#
126-
#
127-
# Examples
128-
# --------
129-
# >>> topup = TOPUP()
130-
# >>> topup.inputs.in_file = "dwi_combined.nii"
131-
# >>> topup.inputs.encoding_file = "encoding.txt"
132-
# >>> res = topup.run() # doctest: +SKIP
133-
#
134-
# """
135-
# _cmd = 'topup'
136-
# input_spec = TOPUPInputSpec
137-
# output_spec = TOPUPOutputSpec
138-
#
139-
# def _list_outputs(self):
140-
# outputs = self.output_spec().get()
141-
#
142-
# return outputs
143-
#
144-
#
145-
#
87+
class TOPUPInputSpec( FSLCommandInputSpec ):
88+
in_file = File( exists=True, mandatory=True, desc='name of 4D file with images', argstr='--imain %s' )
89+
encoding_file = File( exists=True, mandatory=True, desc='name of text file with PE directions/times', argstr='--datain %s' )
90+
out_base = File( desc='base-name of output files (spline coefficients (Hz) and movement parameters)', argstr='--out %s' )
91+
out_field = File( argstr='--fout %s', desc='name of image file with field (Hz)' )
92+
out_corrected = File( argstr='--iout %s', desc='name of 4D image file with unwarped images' )
93+
out_logfile = File( argstr='--logout %s', desc='name of log-file' )
94+
warp_res = traits.Float( 10.0, argstr='--warpres %f', desc='(approximate) resolution (in mm) of warp basis for the different sub-sampling levels' )
95+
subsamp = traits.Int( 1, argstr='--subsamp %d', desc='sub-sampling scheme, default 1' )
96+
fwhm = traits.Float( 8.0, argstr='--fwhm %f', desc='FWHM (in mm) of gaussian smoothing kernel' )
97+
config = traits.String('b02b0.cnf' desc='Name of config file specifying command line arguments', argstr='--config %s' )
98+
max_iter = traits.Int( 5, argstr='--miter %d', desc='max # of non-linear iterations')
99+
#lambda Weight of regularisation, default depending on --ssqlambda and --regmod switches. See user documetation.
100+
#ssqlambda If set (=1), lambda is weighted by current ssq, default 1
101+
#regmod Model for regularisation of warp-field [membrane_energy bending_energy], default bending_energy
102+
estmov = traits.Enum( 1, 0, desc='estimate movements if set', argstr='--estmov %d' )
103+
minmet = traits.Enum( 0, 1, desc='Minimisation method 0=Levenberg-Marquardt, 1=Scaled Conjugate Gradient', argstr='--minmet %d' )
104+
splineorder = traits.Int( 3, argstr='--splineorder %d', desc='order of spline, 2->Qadratic spline, 3->Cubic spline' )
105+
numprec = traits.Enum( 'double', 'float', argstr='--numprec %s', desc='Precision for representing Hessian, double or float.' )
106+
interp = traits.Enum( 'spline', 'linear' , argstr='--interp %s', desc='Image interpolation model, linear or spline.' )
107+
scale = traits.Enum( 0, 1, argstr='--scale %d', desc='If set (=1), the images are individually scaled to a common mean' )
108+
regrid = traits.Enum( 1, 0, argstr='--regrid %d', desc='If set (=1), the calculations are done in a different grid' )
109+
110+
class TOPUPOutputSpec( TraitedSpec ):
111+
out_field = File( exists=True, desc='file containing the field coefficients' )
112+
out_movpar = File( exists=True, desc='movpar.txt output file' )
113+
114+
out_topup = File( desc='basename for the <out_base>_fieldcoef.nii.gz and <out_base>_movpar.txt files' )
115+
out_field = File( desc='name of image file with field (Hz)' )
116+
out_corrected = File( desc='name of 4D image file with unwarped images' )
117+
out_logfile = File( desc='name of log-file' )
118+
119+
class TOPUP( FSLCommand ):
120+
""" Interface for FSL topup, a tool for estimating and correcting susceptibility induced distortions
121+
Reference: http://fsl.fmrib.ox.ac.uk/fsl/fslwiki/TOPUP
122+
Example: http://fsl.fmrib.ox.ac.uk/fsl/fslwiki/topup/ExampleTopupFollowedByApplytopup
123+
124+
topup --imain=<some 4D image> --datain=<text file> --config=<text file with parameters> --coutname=my_field
125+
126+
127+
Examples
128+
--------
129+
>>> topup = TOPUP()
130+
>>> topup.inputs.in_file = "b0_b0rev.nii"
131+
>>> topup.inputs.encoding_file = "encoding.txt"
132+
>>> res = topup.run() # doctest: +SKIP
133+
134+
"""
135+
_cmd = 'topup'
136+
input_spec = TOPUPInputSpec
137+
output_spec = TOPUPOutputSpec
138+
139+
def _parse_inputs( self, skip=None ):
140+
if skip is None:
141+
skip = []
142+
143+
if not isdefined(self.inputs.out_base ):
144+
self.inputs.out_base = os.path.abspath( './nipype_topup' )
145+
146+
return super(TOPUP, self)._parse_inputs(skip=skip)
147+
148+
def _list_outputs(self):
149+
outputs = self.output_spec().get()
150+
outputs['out_topup'] = self.inputs.out_base
151+
outputs['out_field'] = '%s_%s.nii.gz' % (self.inputs.out_base, 'fieldcoef' )
152+
outputs['out_movpar'] = '%s_%s.txt' % (self.inputs.out_base, 'movpar' )
153+
154+
if isdefined( self.inputs.out_field ):
155+
outputs['out_field'] = self.inputs.out_field
156+
else:
157+
outputs['out_field'] = None
158+
159+
if isdefined( self.inputs.out_corrected ):
160+
outputs['out_corrected'] = self.inputs.out_corrected
161+
else:
162+
outputs['out_corrected'] = None
163+
164+
if isdefined( self.inputs.out_logfile ):
165+
outputs['out_logfile'] = self.inputs.out_logfile
166+
else:
167+
outputs['out_logfile'] = None
168+
169+
return outputs
170+
146171
# class ApplyTOPUPInputSpec( FSLCommandInputSpec ):
147172
# in_file = File( exists=True, mandatory=True, desc='name of 4D file with images', argstr='--imain %s' )
148173
# encoding_file = File( exists=True, mandatory=True, desc='name of text file with PE directions/times', argstr='--datain %s' )
149174
# in_index = traits.List( argstr='-x %s', mandatory=True, desc='comma separated list of indicies into --datain of the input image (to be corrected)' )
150175
# in_topup = File( mandatory=True, desc='basename of field/movements (from topup)', argstr='-t %s' )
151176
#
152177
# out_base = File( desc='basename for output (warped) image', argstr='-o %s' )
153-
# method = traits.Either( ('jac','lsr'), argstr='-m %s', desc='use jacobian modulation (jac) or least-squares resampling (lsr)' )
154-
# interp = traits.Either( ('trilinear','spline'), argstr='-n %s', desc='interpolation method' )
155-
# datatype = traits.Either( ('char', 'short', 'int', 'float', 'double' ), argstr='-d %s', desc='force output data type' )
178+
# method = traits.Enum( ('jac','lsr'), argstr='-m %s', desc='use jacobian modulation (jac) or least-squares resampling (lsr)' )
179+
# interp = traits.Enum( ('trilinear','spline'), argstr='-n %s', desc='interpolation method' )
180+
# datatype = traits.Enum( ('char', 'short', 'int', 'float', 'double' ), argstr='-d %s', desc='force output data type' )
156181
#
157182
#
158183
# class ApplyTOPUPOutputSpec( TraitedSpec ):

0 commit comments

Comments
 (0)