Skip to content

Commit 807d0bb

Browse files
committed
fix: TOPUP naming and flexibility on extension overloading based on name
1 parent 0ba4b24 commit 807d0bb

File tree

6 files changed

+38
-18
lines changed

6 files changed

+38
-18
lines changed

nipype/interfaces/afni/base.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ def set_default_output_type(cls, outputtype):
144144
else:
145145
raise AttributeError('Invalid AFNI outputtype: %s' % outputtype)
146146

147-
def _overload_extension(self, value):
147+
def _overload_extension(self, value, name=None):
148148
path, base, _ = split_filename(value)
149149
return os.path.join(path, base + Info.outputtype_to_ext(self.inputs.outputtype))
150150

nipype/interfaces/afni/preprocess.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -367,7 +367,7 @@ class AutoTcorrelate(AFNICommand):
367367
output_spec = AFNICommandOutputSpec
368368
_cmd = '3dAutoTcorrelate'
369369

370-
def _overload_extension(self, value):
370+
def _overload_extension(self, value, name=None):
371371
path, base, ext = split_filename(value)
372372
if ext.lower() not in [".1d", ".nii.gz", ".nii"]:
373373
ext = ext + ".1D"
@@ -1924,7 +1924,7 @@ class AFNItoNIFTI(AFNICommand):
19241924
input_spec = AFNItoNIFTIInputSpec
19251925
output_spec = AFNICommandOutputSpec
19261926

1927-
def _overload_extension(self, value):
1927+
def _overload_extension(self, value, name=None):
19281928
path, base, ext = split_filename(value)
19291929
if ext.lower() not in [".1d", ".nii.gz", ".1D"]:
19301930
ext = ext + ".nii"

nipype/interfaces/base.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1480,13 +1480,13 @@ def _filename_from_source(self, name):
14801480
_, _, ext = split_filename(retval)
14811481
if trait_spec.keep_extension and ext:
14821482
return retval
1483-
return self._overload_extension(retval)
1483+
return self._overload_extension(retval, name)
14841484
return retval
14851485

14861486
def _gen_filename(self, name):
14871487
raise NotImplementedError
14881488

1489-
def _overload_extension(self, value):
1489+
def _overload_extension(self, value, name=None):
14901490
return value
14911491

14921492
def _list_outputs(self):

nipype/interfaces/fsl/base.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -239,7 +239,7 @@ def _gen_fname(self, basename, cwd=None, suffix=None, change_ext=True,
239239
use_ext=False, newpath=cwd)
240240
return fname
241241

242-
def _overload_extension(self, value):
242+
def _overload_extension(self, value, name=None):
243243
return value + Info.output_type_to_ext(self.inputs.output_type)
244244

245245

nipype/interfaces/fsl/epi.py

Lines changed: 31 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,6 @@ class TOPUPInputSpec(FSLCommandInputSpec):
124124
out_base = File(desc=('base-name of output files (spline '
125125
'coefficients (Hz) and movement parameters)'),
126126
name_source=['in_file'], name_template='%s_base',
127-
keep_extension=True,
128127
argstr='--out=%s', hash_files=False)
129128
out_field = File(argstr='--fout=%s', hash_files=False,
130129
name_source=['in_file'], name_template='%s_field',
@@ -254,16 +253,38 @@ def _generate_encfile(self):
254253
np.savetxt(out_file, np.array(lines), fmt='%d %d %d %.3f')
255254
return out_file
256255

257-
class ApplyTOPUPInputSpec( FSLCommandInputSpec ):
258-
in_files = InputMultiPath(File(exists=True), mandatory=True, desc='name of 4D file with images', argstr='%s' )
259-
encoding_file = File( exists=True, mandatory=True, desc='name of text file with PE directions/times', argstr='--datain=%s' )
260-
in_index = traits.List( argstr='%s', mandatory=True, desc='comma separated list of indicies into --datain of the input image (to be corrected)' )
261-
in_topup = File( mandatory=True, desc='basename of field/movements (from topup)', argstr='--topup=%s' )
256+
def _overload_extension(self, value, name=None):
257+
if name == 'out_base':
258+
return value
259+
return super(TOPUP, self)._overload_extension(value, name)
262260

263-
out_base = File( desc='basename for output (warped) image', argstr='--out=%s' )
264-
method = traits.Enum( ('jac','lsr'), argstr='--method=%s', desc='use jacobian modulation (jac) or least-squares resampling (lsr)' )
265-
interp = traits.Enum( ('trilinear','spline'), argstr='--interp=%s', desc='interpolation method' )
266-
datatype = traits.Enum( ('char', 'short', 'int', 'float', 'double' ), argstr='-d=%s', desc='force output data type' )
261+
262+
class ApplyTOPUPInputSpec(FSLCommandInputSpec):
263+
in_files = InputMultiPath(File(exists=True), mandatory=True,
264+
desc='name of 4D file with images', argstr='%s')
265+
encoding_file = File(exists=True, mandatory=True,
266+
desc='name of text file with PE directions/times',
267+
argstr='--datain=%s')
268+
in_index = traits.List(argstr='%s', mandatory=True,
269+
desc=('comma separated list of indicies into '
270+
'--datain of the input image (to be '
271+
'corrected)'))
272+
in_topup_fieldcoef = File(exists=True, argstr="--topup=%s", copyfile=False,
273+
requires=['in_topup_movpar'],
274+
desc=('topup file containing the field '
275+
'coefficients'))
276+
in_topup_movpar = File(exists=True, requires=['in_topup_fieldcoef'],
277+
copyfile=False, desc='topup movpar.txt file')
278+
out_corrected = File(desc='output (warped) image',
279+
name_source=['in_files'], name_template='%s_corrected',
280+
argstr='--out=%s' )
281+
method = traits.Enum(('jac','lsr'), argstr='--method=%s',
282+
desc=('use jacobian modulation (jac) or least-squares '
283+
'resampling (lsr)'))
284+
interp = traits.Enum(('trilinear','spline'), argstr='--interp=%s',
285+
desc='interpolation method')
286+
datatype = traits.Enum(('char', 'short', 'int', 'float', 'double'),
287+
argstr='-d=%s', desc='force output data type')
267288

268289

269290
class ApplyTOPUPOutputSpec( TraitedSpec ):

nipype/workflows/dmri/fsl/epi.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -370,7 +370,7 @@ def topup_correction( name='topup_correction' ):
370370
>>> nipype_epicorrect = topup_correction('nipype_topup')
371371
>>> nipype_epicorrect.inputs.inputnode.in_file_dir = 'epi.nii'
372372
>>> nipype_epicorrect.inputs.inputnode.in_file_rev = 'epi_rev.nii'
373-
>>> nipype_epicorrect.inputs.inputnode.encoding_direction = 'y'
373+
>>> nipype_epicorrect.inputs.inputnode.encoding_direction = ['y', 'y-']
374374
>>> nipype_epicorrect.inputs.inputnode.ref_num = 0
375375
>>> nipype_epicorrect.run() # doctest: +SKIP
376376
@@ -400,7 +400,6 @@ def topup_correction( name='topup_correction' ):
400400
outputnode = pe.Node( niu.IdentityInterface(
401401
fields=['out_fieldcoef',
402402
'out_movpar',
403-
'out_topup',
404403
'out_enc_file',
405404
'epi_corrected'
406405
]), name='outputnode'

0 commit comments

Comments
 (0)