Skip to content

Commit 4e33304

Browse files
committed
Review FSL eddy interface
Just fixed PEP8 errors in the interface and reviewed the solution for the bugs, that were already solved. Please, close #769.
1 parent e815741 commit 4e33304

File tree

1 file changed

+72
-84
lines changed

1 file changed

+72
-84
lines changed

nipype/interfaces/fsl/epi.py

Lines changed: 72 additions & 84 deletions
Original file line numberDiff line numberDiff line change
@@ -327,77 +327,81 @@ def _format_arg(self, name, spec, value):
327327
return super(ApplyTOPUP, self)._format_arg(name, spec, value)
328328

329329

330-
class EddyInputSpec( FSLCommandInputSpec ):
331-
in_file = File(exists=True, mandatory=True,
332-
desc=('File containing all the images to estimate '
333-
'distortions for'), argstr='--imain=%s')
334-
in_mask = File(exists=True, mandatory=True,
335-
desc='Mask to indicate brain', argstr='--mask=%s')
336-
in_index = File(exists=True, mandatory=True,
330+
class EddyInputSpec(FSLCommandInputSpec):
331+
in_file = File(exists=True, mandatory=True, argstr='--imain=%s',
332+
desc=('File containing all the images to estimate '
333+
'distortions for'))
334+
in_mask = File(exists=True, mandatory=True, argstr='--mask=%s',
335+
desc='Mask to indicate brain')
336+
in_index = File(exists=True, mandatory=True, argstr='--index=%s',
337337
desc=('File containing indices for all volumes in --imain '
338-
'into --acqp and --topup'), argstr='--index=%s')
339-
in_acqp = File(exists=True, mandatory=True,
340-
desc='File containing acquisition parameters',
341-
argstr='--acqp=%s' )
342-
in_bvec = File(exists=True, mandatory=True,
343-
desc=('File containing the b-vectors for all volumes in '
344-
'--imain'), argstr='--bvecs=%s')
345-
in_bval = File(exists=True, mandatory=True,
346-
desc=('File containing the b-values for all volumes in '
347-
'--imain'), argstr='--bvals=%s')
348-
out_base = File( desc='basename for output (warped) image',
349-
argstr='--out=%s' )
350-
session = File(exists=True,
351-
desc=('File containing session indices for all volumes in '
352-
'--imain'), argstr='--session=%s')
353-
in_topup_fieldcoef = File(exists=True, argstr="--topup=%s", copyfile=False,
338+
'into --acqp and --topup'))
339+
in_acqp = File(exists=True, mandatory=True, argstr='--acqp=%s',
340+
desc='File containing acquisition parameters')
341+
in_bvec = File(exists=True, mandatory=True, argstr='--bvecs=%s',
342+
desc=('File containing the b-vectors for all volumes in '
343+
'--imain'))
344+
in_bval = File(exists=True, mandatory=True, argstr='--bvals=%s',
345+
desc=('File containing the b-values for all volumes in '
346+
'--imain'))
347+
out_base = File(argstr='--out=%s',
348+
desc=('basename for output (warped) image'))
349+
350+
session = File(exists=True, argstr='--session=%s',
351+
desc=('File containing session indices for all volumes in '
352+
'--imain'))
353+
in_topup_fieldcoef = File(exists=True, argstr="--topup=%s",
354354
requires=['in_topup_movpar'],
355355
desc=('topup file containing the field '
356356
'coefficients'))
357357
in_topup_movpar = File(exists=True, requires=['in_topup_fieldcoef'],
358-
copyfile=False, desc='topup movpar.txt file')
359-
flm = traits.Enum(('linear','quadratic','cubic'),
360-
desc='First level EC model', argstr='--flm=%s' )
358+
desc='topup movpar.txt file')
359+
360+
flm = traits.Enum('linear', 'quadratic', 'cubic', argstr='--flm=%s',
361+
desc='First level EC model')
362+
361363
fwhm = traits.Float(desc=('FWHM for conditioning filter when estimating '
362364
'the parameters'), argstr='--fwhm=%s')
363-
niter = traits.Int( 5, desc='Number of iterations', argstr='--niter=%s')
364-
method = traits.Enum(('jac','lsr'), argstr='--resamp=%s',
365+
366+
niter = traits.Int(5, argstr='--niter=%s', desc='Number of iterations')
367+
368+
method = traits.Enum('jac', 'lsr', argstr='--resamp=%s',
365369
desc=('Final resampling method (jacobian/least '
366-
'squeares)'))
367-
repol = traits.Bool( False, desc='Detect and replace outlier slices',
368-
argstr='--repol' )
370+
'squares)'))
371+
repol = traits.Bool(False, argstr='--repol',
372+
desc='Detect and replace outlier slices')
369373

370374

371-
class EddyOutputSpec( TraitedSpec ):
375+
class EddyOutputSpec(TraitedSpec):
372376
out_corrected = File(exists=True,
373-
desc=('4D image file containing all the corrected '
374-
'volumes'))
377+
desc=('4D image file containing all the corrected '
378+
'volumes'))
375379
out_parameter = File(exists=True,
376-
desc=('text file with parameters definining the field '
377-
'and movement for each scan'))
380+
desc=('text file with parameters definining the '
381+
'field and movement for each scan'))
378382

379-
class Eddy( FSLCommand ):
380-
""" Interface for FSL eddy, a tool for estimating and correcting eddy
381-
currents induced distortions. `User guide
382-
<http://fsl.fmrib.ox.ac.uk/fsl/fslwiki/Eddy/UsersGuide>`_ and
383-
`more info regarding acqp file
384-
<http://fsl.fmrib.ox.ac.uk/fsl/fslwiki/eddy/Faq#How_do_I_know_what_to_put_into_my_--acqp_file>`_.
385383

386-
Examples
387-
--------
388-
389-
>>> from nipype.interfaces.fsl import Eddy
390-
>>> eddy = Eddy()
391-
>>> eddy.inputs.in_file = 'epi.nii'
392-
>>> eddy.inputs.in_mask = 'epi_mask.nii'
393-
>>> eddy.inputs.in_index = 'epi_index.txt'
394-
>>> eddy.inputs.in_acqp = 'epi_acqp.txt'
395-
>>> eddy.inputs.in_bvec = 'bvecs.scheme'
396-
>>> eddy.inputs.in_bval = 'bvals.scheme'
397-
>>> eddy.cmdline #doctest: +ELLIPSIS
398-
'eddy --acqp=epi_acqp.txt --bvals=bvals.scheme --bvecs=bvecs.scheme --imain=epi.nii --index=epi_index.txt --mask=epi_mask.nii --out=.../eddy_corrected'
399-
>>> res = eddy.run() # doctest: +SKIP
384+
class Eddy(FSLCommand):
385+
"""
386+
Interface for FSL eddy, a tool for estimating and correcting eddy
387+
currents induced distortions. `User guide
388+
<http://fsl.fmrib.ox.ac.uk/fsl/fslwiki/Eddy/UsersGuide>`_ and
389+
`more info regarding acqp file
390+
<http://fsl.fmrib.ox.ac.uk/fsl/fslwiki/eddy/Faq#How_do_I_know_what_to_put_into_my_--acqp_file>`_.
400391
392+
Examples
393+
--------
394+
>>> from nipype.interfaces.fsl import Eddy
395+
>>> eddy = Eddy()
396+
>>> eddy.inputs.in_file = 'epi.nii'
397+
>>> eddy.inputs.in_mask = 'epi_mask.nii'
398+
>>> eddy.inputs.in_index = 'epi_index.txt'
399+
>>> eddy.inputs.in_acqp = 'epi_acqp.txt'
400+
>>> eddy.inputs.in_bvec = 'bvecs.scheme'
401+
>>> eddy.inputs.in_bval = 'bvals.scheme'
402+
>>> eddy.cmdline #doctest: +ELLIPSIS
403+
'eddy --acqp=epi_acqp.txt --bvals=bvals.scheme --bvecs=bvecs.scheme --imain=epi.nii --index=epi_index.txt --mask=epi_mask.nii --out=.../eddy_corrected'
404+
>>> res = eddy.run() # doctest: +SKIP
401405
402406
"""
403407
_cmd = 'eddy'
@@ -408,15 +412,14 @@ def _format_arg(self, name, spec, value):
408412
if name == 'in_topup_fieldcoef':
409413
return spec.argstr % value.split('_fieldcoef')[0]
410414
return super(Eddy, self)._format_arg(name, spec, value)
411-
412-
def _parse_inputs( self, skip=None ):
415+
416+
def _parse_inputs(self, skip=None):
413417
if skip is None:
414418
skip = []
415-
416-
if not isdefined(self.inputs.out_base ):
417-
self.inputs.out_base = os.path.abspath( './eddy_corrected' )
418-
return super(Eddy, self)._parse_inputs(skip=skip)
419419

420+
if not isdefined(self.inputs.out_base):
421+
self.inputs.out_base = os.path.abspath('eddy_corrected')
422+
return super(Eddy, self)._parse_inputs(skip=skip)
420423

421424
def _list_outputs(self):
422425
outputs = self.output_spec().get()
@@ -590,9 +593,13 @@ def _gen_filename(self, name):
590593
return None
591594

592595
class EddyCorrectInputSpec(FSLCommandInputSpec):
593-
in_file = File(exists=True, desc='4D input file', argstr='%s', position=0, mandatory=True)
594-
out_file = File(desc='4D output file', argstr='%s', position=1, genfile=True, hash_files=False)
595-
ref_num = traits.Int(argstr='%d', position=2, desc='reference number', mandatory=True)
596+
in_file = File(exists=True, desc='4D input file', argstr='%s', position=0,
597+
mandatory=True)
598+
out_file = File(desc='4D output file', argstr='%s', position=1,
599+
name_source=['in_file'], name_template='%s_edc',
600+
output_name='eddy_corrected')
601+
ref_num = traits.Int(0, argstr='%d', position=2, desc='reference number',
602+
mandatory=True, usedefault=True)
596603

597604

598605
class EddyCorrectOutputSpec(TraitedSpec):
@@ -620,26 +627,7 @@ def __init__(self, **inputs):
620627
return super(EddyCorrect, self).__init__(**inputs)
621628

622629
def _run_interface(self, runtime):
623-
if not isdefined(self.inputs.out_file):
624-
self.inputs.out_file = self._gen_fname(self.inputs.in_file, suffix='_edc')
625630
runtime = super(EddyCorrect, self)._run_interface(runtime)
626631
if runtime.stderr:
627632
self.raise_exception(runtime)
628633
return runtime
629-
630-
def _list_outputs(self):
631-
outputs = self.output_spec().get()
632-
outputs['eddy_corrected'] = self.inputs.out_file
633-
if not isdefined(outputs['eddy_corrected']):
634-
outputs['eddy_corrected'] = self._gen_fname(self.inputs.in_file, suffix='_edc')
635-
outputs['eddy_corrected'] = os.path.abspath(outputs['eddy_corrected'])
636-
return outputs
637-
638-
def _gen_filename(self, name):
639-
if name is 'out_file':
640-
return self._list_outputs()['eddy_corrected']
641-
else:
642-
return None
643-
644-
645-

0 commit comments

Comments
 (0)