1919from nipype .interfaces .fsl .base import FSLCommand , FSLCommandInputSpec , Info
2020from nipype .interfaces .base import (traits , TraitedSpec , OutputMultiPath , File ,
2121 isdefined )
22+
23+
2224from nipype .utils .filemanip import load_json , save_json , split_filename , fname_presuffix
2325
2426warn = warnings .warn
@@ -34,14 +36,14 @@ class PrepareFieldmapInputSpec(FSLCommandInputSpec):
3436 desc = 'Magnitude difference map, brain extracted' ,
3537 mandatory = True
3638 )
37- out_fieldmap = File ()
39+ out_fieldmap = File ( desc = 'output name for prepared fieldmap' , position = 3 )
3840 delta_TE = traits .Float (2.46 ,desc = 'echo time difference of the fielmap sequence in ms. (usually 2.46ms in Siemens)' ,
39- usedefault = True )
41+ position = 4 , usedefault = True )
4042 nocheck = traits .Bool (False ,desc = 'do not perform sanity checks for image size/range/dimensions' ,
41- argstr = '--nocheck' )
43+ position = 5 , argstr = '--nocheck' )
4244
43- class PrepareFieldmapOutputSpec ( FSLCommandOutputSpec ):
44- out_fieldmap = File ( exists = True )
45+ class PrepareFieldmapOutputSpec ( TraitedSpec ):
46+ out_fieldmap = File ( exists = True , desc = 'output name for prepared fieldmap' )
4547
4648class PrepareFieldmap (FSLCommand ):
4749 """ Interface for the fsl_prepare_fielmap script
@@ -63,117 +65,132 @@ class PrepareFieldmap(FSLCommand):
6365 input_spec = PrepareFieldmapInputSpec
6466 output_spec = PrepareFieldmapOutputSpec
6567
66- def _list_outputs (self ):
67- outputs = self .output_spec ().get ()
68-
69- return outputs
70-
71-
72- class TOPUPInputSpec ( FSLCommandInputSpec ):
73- in_file = File ( exists = True , mandatory = True , desc = 'name of 4D file with images' , argstr = '--imain %s' )
74- encoding_file = File ( exists = True , mandatory = True , desc = 'name of text file with PE directions/times' , argstr = '--datain %s' )
75- out_base = File ( desc = 'base-name of output files (spline coefficients (Hz) and movement parameters)' , argstr = '--out %s' )
76- out_field = File ( argstr = '--fout %s' , desc = 'name of image file with field (Hz)' )
77- out_corrected = File ( argstr = '--iout %s' , desc = 'name of 4D image file with unwarped images' )
78- out_logfile = File ( argstr = '--logout %s' , desc = 'name of log-file' )
79- warp_res = traits .Float ( 10.0 , argstr = '--warpres %f' , desc = '(approximate) resolution (in mm) of warp basis for the different sub-sampling levels' )
80- subsamp = traits .Int ( 1 , argstr = '--subsamp %d' , desc = 'sub-sampling scheme, default 1' )
81- fwhm = traits .Float ( 8.0 , argstr = '--fwhm %f' , desc = 'FWHM (in mm) of gaussian smoothing kernel' )
82- config = File ( desc = 'Name of config file specifying command line arguments' , argstr = '--config %s' )
83- max_iter = traits .Int ( 5 , argstr = '--miter %d' , desc = 'max # of non-linear iterations' )
84- #lambda Weight of regularisation, default depending on --ssqlambda and --regmod switches. See user documetation.
85- #ssqlambda If set (=1), lambda is weighted by current ssq, default 1
86- #regmod Model for regularisation of warp-field [membrane_energy bending_energy], default bending_energy
87- estmov = traits .Either ( (0 ,1 ), desc = 'estimate movements if set' , argstr = '--estmov %d' )
88- minmet = traits .Either ( (0 ,1 ), desc = 'Minimisation method 0=Levenberg-Marquardt, 1=Scaled Conjugate Gradient' , argstr = '--minmet %d' )
89- splineorder = traits .Int ( 3 , argstr = '--splineorder %d' , desc = 'order of spline, 2->Qadratic spline, 3->Cubic spline' )
90- numprec = traits .Either ( ('float' ,'double' ), argstr = '--numprec %s' , desc = 'Precision for representing Hessian, double or float.' )
91- interp = traits .Either ( ('linear' ,'spline' ), argstr = '--interp %s' , desc = 'Image interpolation model, linear or spline.' )
92- scale = traits .Either ( (0 ,1 ), argstr = '--scale %d' , desc = 'If set (=1), the images are individually scaled to a common mean' )
93- regrid = traits .Either ( (0 ,1 ), argstr = '--regrid %d' , desc = 'If set (=1), the calculations are done in a different grid' )
94-
68+ def _parse_inputs ( self , skip = None ):
69+ if skip is None :
70+ skip = []
71+
72+ if not isdefined (self .inputs .out_fieldmap ):
73+ self .inputs .out_fieldmap = self ._gen_fname (
74+ self .inputs .in_phase , suffix = '_fslprepared' )
9575
76+ if not isdefined (self .inputs .nocheck ) or not self .inputs .nocheck :
77+ skip += ['nocheck' ]
9678
97- class TOPUPOutputSpec ( FSLCommandOutputSpec ):
98- out_field = File ( argstr = '--fout %s' , desc = 'name of image file with field (Hz)' )
99- out_corrected = File ( argstr = '--iout %s' , desc = 'name of 4D image file with unwarped images' )
100- out_logfile = File ( argstr = '--logout %s' , desc = 'name of log-file' )
79+ return super (PrepareFieldmap , self )._parse_inputs (skip = skip )
10180
10281
103-
104- class TOPUP ( FSLCommand ):
105- """ Interface for FSL topup, a tool for estimating and correcting susceptibility induced distortions
106- Reference: http://fsl.fmrib.ox.ac.uk/fsl/fslwiki/TOPUP
107- Example: http://fsl.fmrib.ox.ac.uk/fsl/fslwiki/topup/ExampleTopupFollowedByApplytopup
108-
109- topup --imain=<some 4D image> --datain=<text file> --config=<text file with parameters> --coutname=my_field
110-
111-
112- Examples
113- --------
114- >>> topup = TOPUP()
115- >>> topup.inputs.in_file = "dwi_combined.nii"
116- >>> topup.inputs.encoding_file = "encoding.txt"
117- >>> res = topup.run() # doctest: +SKIP
118-
119- """
120- _cmd = 'topup'
121- input_spec = TOPUPInputSpec
122- output_spec = TOPUPOutputSpec
123-
12482 def _list_outputs (self ):
12583 outputs = self .output_spec ().get ()
84+ outputs ['out_fieldmap' ] = self .inputs .out_fieldmap
12685
12786 return outputs
12887
12988
130-
131- class ApplyTOPUPInputSpec ( FSLCommandInputSpec ):
132- in_file = File ( exists = True , mandatory = True , desc = 'name of 4D file with images' , argstr = '--imain %s' )
133- encoding_file = File ( exists = True , mandatory = True , desc = 'name of text file with PE directions/times' , argstr = '--datain %s' )
134- in_index = traits .List ( argstr = '-x %s' , mandatory = True , desc = 'comma separated list of indicies into --datain of the input image (to be corrected)' )
135- in_topup = File ( mandatory = True , desc = 'basename of field/movements (from topup)' , argstr = '-t %s' )
136-
137- out_base = File ( desc = 'basename for output (warped) image' , argstr = '-o %s' )
138- method = traits .Either ( ('jac' ,'lsr' ), argstr = '-m %s' , desc = 'use jacobian modulation (jac) or least-squares resampling (lsr)' )
139- interp = traits .Either ( ('trilinear' ,'spline' ), argstr = '-n %s' , desc = 'interpolation method' )
140- datatype = traits .Either ( ('char' , 'short' , 'int' , 'float' , 'double' ), argstr = '-d %s' , desc = 'force output data type' )
141-
142-
143- class ApplyTOPUPOutputSpec ( FSLCommandOutputSpec ):
144- out_corrected = File ( argstr = '--iout %s' , desc = 'name of 4D image file with unwarped images' )
145- out_logfile = File ( argstr = '--logout %s' , desc = 'name of log-file' )
146-
147- class ApplyTOPUP ( FSLCommand ):
148- """ Interface for FSL topup, a tool for estimating and correcting susceptibility induced distortions
149- Reference: http://fsl.fmrib.ox.ac.uk/fsl/fslwiki/topup/ApplytopupUsersGuide
150- Example: http://fsl.fmrib.ox.ac.uk/fsl/fslwiki/topup/ExampleTopupFollowedByApplytopup
151-
152- topup --imain=<some 4D image> --datain=<text file> --config=<text file with parameters> --coutname=my_field
153-
154-
155- Examples
156- --------
157- >>> applytopup = ApplyTOPUP()
158- >>> applytopup.inputs.in_file = "dwi_combined.nii"
159- >>> applytopup.inputs.encoding_file = "encoding.txt"
160- >>> applytopup.inputs.in_index = 1,2
161- >>> applytopup.inputs.in_topup = "my_topup_results"
162- >>> res = applytopup.run() # doctest: +SKIP
163-
164- """
165- _cmd = 'topup'
166- input_spec = ApplyTOPUPInputSpec
167- output_spec = ApplyTOPUPOutputSpec
168-
169- def _list_outputs (self ):
170- outputs = self .output_spec ().get ()
171-
172- return outputs
173-
174-
175-
176-
89+ # class TOPUPInputSpec( FSLCommandInputSpec ):
90+ # in_file = File( exists=True, mandatory=True, desc='name of 4D file with images', argstr='--imain %s' )
91+ # encoding_file = File( exists=True, mandatory=True, desc='name of text file with PE directions/times', argstr='--datain %s' )
92+ # out_base = File( desc='base-name of output files (spline coefficients (Hz) and movement parameters)', argstr='--out %s' )
93+ # out_field = File( argstr='--fout %s', desc='name of image file with field (Hz)' )
94+ # out_corrected = File( argstr='--iout %s', desc='name of 4D image file with unwarped images' )
95+ # out_logfile = File( argstr='--logout %s', desc='name of log-file' )
96+ # warp_res = traits.Float( 10.0, argstr='--warpres %f', desc='(approximate) resolution (in mm) of warp basis for the different sub-sampling levels' )
97+ # subsamp = traits.Int( 1, argstr='--subsamp %d', desc='sub-sampling scheme, default 1' )
98+ # fwhm = traits.Float( 8.0, argstr='--fwhm %f', desc='FWHM (in mm) of gaussian smoothing kernel' )
99+ # config = File( desc='Name of config file specifying command line arguments', argstr='--config %s' )
100+ # max_iter = traits.Int( 5, argstr='--miter %d', desc='max # of non-linear iterations')
101+ # #lambda Weight of regularisation, default depending on --ssqlambda and --regmod switches. See user documetation.
102+ # #ssqlambda If set (=1), lambda is weighted by current ssq, default 1
103+ # #regmod Model for regularisation of warp-field [membrane_energy bending_energy], default bending_energy
104+ # estmov = traits.Either( (0,1), desc='estimate movements if set', argstr='--estmov %d' )
105+ # minmet = traits.Either( (0,1), desc='Minimisation method 0=Levenberg-Marquardt, 1=Scaled Conjugate Gradient', argstr='--minmet %d' )
106+ # splineorder = traits.Int( 3, argstr='--splineorder %d', desc='order of spline, 2->Qadratic spline, 3->Cubic spline' )
107+ # numprec = traits.Either( ('float','double'), argstr='--numprec %s', desc='Precision for representing Hessian, double or float.' )
108+ # interp = traits.Either( ('linear','spline'), argstr='--interp %s', desc='Image interpolation model, linear or spline.' )
109+ # scale = traits.Either( (0,1), argstr='--scale %d', desc='If set (=1), the images are individually scaled to a common mean' )
110+ # regrid = traits.Either( (0,1), argstr='--regrid %d', desc='If set (=1), the calculations are done in a different grid' )
111+ #
112+ #
113+ #
114+ # class TOPUPOutputSpec( TraitedSpec ):
115+ # out_field = File( argstr='--fout %s', desc='name of image file with field (Hz)' )
116+ # out_corrected = File( argstr='--iout %s', desc='name of 4D image file with unwarped images' )
117+ # out_logfile = File( argstr='--logout %s', desc='name of log-file' )
118+ #
119+ #
120+ #
121+ # class TOPUP( FSLCommand ):
122+ # """ Interface for FSL topup, a tool for estimating and correcting susceptibility induced distortions
123+ # Reference: http://fsl.fmrib.ox.ac.uk/fsl/fslwiki/TOPUP
124+ # Example: http://fsl.fmrib.ox.ac.uk/fsl/fslwiki/topup/ExampleTopupFollowedByApplytopup
125+ #
126+ # topup --imain=<some 4D image> --datain=<text file> --config=<text file with parameters> --coutname=my_field
127+ #
128+ #
129+ # Examples
130+ # --------
131+ # >>> topup = TOPUP()
132+ # >>> topup.inputs.in_file = "dwi_combined.nii"
133+ # >>> topup.inputs.encoding_file = "encoding.txt"
134+ # >>> res = topup.run() # doctest: +SKIP
135+ #
136+ # """
137+ # _cmd = 'topup'
138+ # input_spec = TOPUPInputSpec
139+ # output_spec = TOPUPOutputSpec
140+ #
141+ # def _list_outputs(self):
142+ # outputs = self.output_spec().get()
143+ #
144+ # return outputs
145+ #
146+ #
147+ #
148+ # class ApplyTOPUPInputSpec( FSLCommandInputSpec ):
149+ # in_file = File( exists=True, mandatory=True, desc='name of 4D file with images', argstr='--imain %s' )
150+ # encoding_file = File( exists=True, mandatory=True, desc='name of text file with PE directions/times', argstr='--datain %s' )
151+ # in_index = traits.List( argstr='-x %s', mandatory=True, desc='comma separated list of indicies into --datain of the input image (to be corrected)' )
152+ # in_topup = File( mandatory=True, desc='basename of field/movements (from topup)', argstr='-t %s' )
153+ #
154+ # out_base = File( desc='basename for output (warped) image', argstr='-o %s' )
155+ # method = traits.Either( ('jac','lsr'), argstr='-m %s', desc='use jacobian modulation (jac) or least-squares resampling (lsr)' )
156+ # interp = traits.Either( ('trilinear','spline'), argstr='-n %s', desc='interpolation method' )
157+ # datatype = traits.Either( ('char', 'short', 'int', 'float', 'double' ), argstr='-d %s', desc='force output data type' )
158+ #
159+ #
160+ # class ApplyTOPUPOutputSpec( TraitedSpec ):
161+ # out_corrected = File( argstr='--iout %s', desc='name of 4D image file with unwarped images' )
162+ # out_logfile = File( argstr='--logout %s', desc='name of log-file' )
163+ #
164+ # class ApplyTOPUP( FSLCommand ):
165+ # """ Interface for FSL topup, a tool for estimating and correcting susceptibility induced distortions
166+ # Reference: http://fsl.fmrib.ox.ac.uk/fsl/fslwiki/topup/ApplytopupUsersGuide
167+ # Example: http://fsl.fmrib.ox.ac.uk/fsl/fslwiki/topup/ExampleTopupFollowedByApplytopup
168+ #
169+ # topup --imain=<some 4D image> --datain=<text file> --config=<text file with parameters> --coutname=my_field
170+ #
171+ #
172+ # Examples
173+ # --------
174+ # >>> applytopup = ApplyTOPUP()
175+ # >>> applytopup.inputs.in_file = "dwi_combined.nii"
176+ # >>> applytopup.inputs.encoding_file = "encoding.txt"
177+ # >>> applytopup.inputs.in_index = 1,2
178+ # >>> applytopup.inputs.in_topup = "my_topup_results"
179+ # >>> res = applytopup.run() # doctest: +SKIP
180+ #
181+ # """
182+ # _cmd = 'topup'
183+ # input_spec = ApplyTOPUPInputSpec
184+ # output_spec = ApplyTOPUPOutputSpec
185+ #
186+ # def _list_outputs(self):
187+ # outputs = self.output_spec().get()
188+ #
189+ # return outputs
190+ #
191+ #
192+ #
193+ #
177194
178195
179196class EPIDeWarpInputSpec (FSLCommandInputSpec ):
0 commit comments