Skip to content

Commit def5d6b

Browse files
committed
made interfaces more user friendly
1 parent 1deaad8 commit def5d6b

File tree

2 files changed

+64
-42
lines changed

2 files changed

+64
-42
lines changed

nipype/interfaces/dtitk/registration.py

Lines changed: 45 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -163,9 +163,9 @@ class ComposeXfmInputSpec(CommandLineInputSpec):
163163
argstr="-df %s", copyfile=False, mandatory=True)
164164
in_aff = File(desc='affine transform file', exists=True,
165165
argstr="-aff %s", mandatory=True)
166-
out_file = traits.File(desc='output path',
167-
argstr="-out %s", name_source="in_df",
168-
name_template="%s_aff.df", keep_extension=True)
166+
out_file = File(desc='output path',
167+
argstr="-out %s", name_source="in_df",
168+
name_template="%s_aff.df", keep_extension=True)
169169

170170

171171
class ComposeXfmOutputSpec(TraitedSpec):
@@ -196,9 +196,9 @@ class ComposeXfm(CommandLineDtitk):
196196
class affSymTensor3DVolInputSpec(CommandLineInputSpec):
197197
in_file = File(desc='moving tensor volume', exists=True,
198198
argstr="-in %s", mandatory=True)
199-
out_file = traits.File(desc='output filename',
200-
argstr="-out %s", name_source="in_file",
201-
name_template="%s_affxfmd", keep_extension=True)
199+
out_file = File(desc='output filename',
200+
argstr="-out %s", name_source="in_file",
201+
name_template="%s_affxfmd", keep_extension=True)
202202
transform = File(exists=True, argstr="-trans %s",
203203
xor=['target', 'translation', 'euler', 'deformation'],
204204
desc='transform to apply: specify an input transformation\
@@ -254,16 +254,17 @@ class affSymTensor3DVol(CommandLineDtitk):
254254
class affScalarVolInputSpec(CommandLineInputSpec):
255255
in_file = File(desc='moving scalar volume', exists=True,
256256
argstr="-in %s", mandatory=True)
257-
out_file = traits.File(desc='output filename',
258-
argstr="-out %s", name_source="in_file",
259-
name_template="%s_affxfmd", keep_extension=True)
257+
out_file = File(desc='output filename',
258+
argstr="-out %s", name_source="in_file",
259+
name_template="%s_affxfmd", keep_extension=True)
260260
transform = File(exists=True, argstr="-trans %s",
261261
xor=['target', 'translation', 'euler', 'deformation'],
262262
desc='transform to apply: specify an input transformation\
263263
file; parameters input will be ignored',)
264-
interpolation = traits.Enum(0, 1, usedefault=True,
265-
argstr="-interp %s",
266-
desc='0=trilinear (def); 1=nearest neighbor')
264+
interpolation = traits.Enum('trilinear', 'NN',
265+
usedefault=True, argstr="-interp %s",
266+
desc='trilinear or nearest neighbor\
267+
interpolation')
267268
target = File(exists=True, argstr="-target %s", xor=['transform'],
268269
desc='output volume specification read from the target volume\
269270
if specified')
@@ -301,13 +302,18 @@ class affScalarVol(CommandLineDtitk):
301302
output_spec = affScalarVolOutputSpec
302303
_cmd = 'affineScalarVolume'
303304

305+
def _format_arg(self, name, spec, value):
306+
if name == 'interpolation':
307+
value = {'trilinear': 0, 'NN': 1}[value]
308+
super(affScalarVol, self)._format_arg(name, spec, value)
309+
304310

305311
class diffeoSymTensor3DVolInputSpec(CommandLineInputSpec):
306312
in_file = File(desc='moving tensor volume', exists=True,
307313
argstr="-in %s", mandatory=True)
308-
out_file = traits.File(desc='output filename',
309-
argstr="-out %s", name_source="in_file",
310-
name_template="%s_diffeoxfmd", keep_extension=True)
314+
out_file = File(desc='output filename',
315+
argstr="-out %s", name_source="in_file",
316+
name_template="%s_diffeoxfmd", keep_extension=True)
311317
transform = File(exists=True, argstr="-trans %s",
312318
mandatory=True, desc='transform to apply')
313319
df = traits.Str('FD', argstr="-df %s", usedefault=True)
@@ -326,7 +332,8 @@ class diffeoSymTensor3DVolInputSpec(CommandLineInputSpec):
326332
argstr="-vsize %g %g %g", xor=['target'])
327333
flip = traits.Tuple((traits.Int(), traits.Int(), traits.Int()),
328334
exists=True, argstr="-flip %d %d %d")
329-
resampling_type = traits.Enum(1, 0, desc='1=backward(def), 0=forward',
335+
resampling_type = traits.Enum('backward', 'forward',
336+
desc='use backward or forward resampling',
330337
exists=True, argstr="-type %d")
331338

332339

@@ -355,13 +362,18 @@ class diffeoSymTensor3DVol(CommandLineDtitk):
355362
output_spec = diffeoSymTensor3DVolOutputSpec
356363
_cmd = 'deformationSymTensor3DVolume'
357364

365+
def _format_arg(self, name, spec, value):
366+
if name == 'resampling_type':
367+
value = {'forward': 0, 'backward': 1}[value]
368+
super(diffeoSymTensor3DVol, self)._format_arg(name, spec, value)
369+
358370

359371
class diffeoScalarVolInputSpec(CommandLineInputSpec):
360372
in_file = File(desc='moving scalar volume', exists=True,
361373
argstr="-in %s", mandatory=True)
362-
out_file = traits.File(desc='output filename',
363-
argstr="-out %s", name_source="in_file",
364-
name_template="%s_diffeoxfmd", keep_extension=True)
374+
out_file = File(desc='output filename',
375+
argstr="-out %s", name_source="in_file",
376+
name_template="%s_diffeoxfmd", keep_extension=True)
365377
transform = transform = File(exists=True, argstr="-trans %s",
366378
mandatory=True, desc='transform to apply')
367379
target = File(exists=True, argstr="-target %s", xor=['voxel_size'],
@@ -372,10 +384,13 @@ class diffeoScalarVolInputSpec(CommandLineInputSpec):
372384
argstr="-vsize %g %g %g", xor=['target'])
373385
flip = traits.Tuple((traits.Int(), traits.Int(), traits.Int()),
374386
exists=True, argstr="-flip %d %d %d")
375-
resampling_type = traits.Enum(1, 0, desc='1=backward(def), 0=forward',
387+
resampling_type = traits.Enum('backward', 'forward',
388+
desc='use backward or forward resampling',
376389
exists=True, argstr="-type %d")
377-
interp = traits.Enum(0, 1, desc='0=trilinear(def), 1=nearest neighbor',
378-
exists=True, argstr="-interp %d", usedefault=True)
390+
interpolation = traits.Enum('trilinear', 'NN',
391+
desc='trilinear, or nearest neighbor',
392+
exists=True, argstr="-interp %d",
393+
usedefault=True)
379394

380395

381396
class diffeoScalarVolOutputSpec(TraitedSpec):
@@ -402,3 +417,11 @@ class diffeoScalarVol(CommandLineDtitk):
402417
input_spec = diffeoScalarVolInputSpec
403418
output_spec = diffeoScalarVolOutputSpec
404419
_cmd = 'deformationScalarVolume'
420+
421+
def _format_arg(self, name, spec, value):
422+
if name == 'resampling_type':
423+
value = {'forward': 0, 'backward': 1}[value]
424+
super(diffeoScalarVol, self)._format_arg(name, spec, value)
425+
if name == 'interpolation':
426+
value = {'trilinear': 0, 'NN': 1}[value]
427+
super(diffeoScalarVol, self)._format_arg(name, spec, value)

nipype/interfaces/dtitk/utils.py

Lines changed: 19 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -35,12 +35,12 @@
3535
class TVAdjustVoxSpInputSpec(CommandLineInputSpec):
3636
in_file = File(desc="tensor volume to modify", exists=True,
3737
mandatory=True, argstr="-in %s")
38-
out_file = traits.File(genfile=True, desc='output path',
39-
argstr="-out %s", name_source='in_file',
40-
name_template='%s_avs', keep_extension=True)
41-
target_file = traits.File(desc='target volume to match',
42-
argstr="-target %s",
43-
xor=['voxel_size', 'origin'])
38+
out_file = File(genfile=True, desc='output path',
39+
argstr="-out %s", name_source='in_file',
40+
name_template='%s_avs', keep_extension=True)
41+
target_file = File(desc='target volume to match',
42+
argstr="-target %s",
43+
xor=['voxel_size', 'origin'])
4444
voxel_size = traits.Tuple((traits.Float(), traits.Float(), traits.Float()),
4545
desc='xyz voxel size (superseded by target)',
4646
argstr="-vsize %g %g %g", xor=['target_file'])
@@ -77,9 +77,9 @@ class TVAdjustVoxSp(CommandLineDtitk):
7777
class SVAdjustVoxSpInputSpec(CommandLineInputSpec):
7878
in_file = File(desc="scalar volume to modify", exists=True,
7979
mandatory=True, argstr="-in %s")
80-
out_file = traits.File(desc='output path', argstr="-out %s",
81-
name_source="in_file", name_template='%s_avs',
82-
keep_extension=True)
80+
out_file = File(desc='output path', argstr="-out %s",
81+
name_source="in_file", name_template='%s_avs',
82+
keep_extension=True)
8383
target_file = File(desc='target volume to match',
8484
argstr="-target %s", xor=['voxel_size', 'origin'])
8585
voxel_size = traits.Tuple((traits.Float(), traits.Float(), traits.Float()),
@@ -118,9 +118,9 @@ class SVAdjustVoxSp(CommandLineDtitk):
118118
class TVResampleInputSpec(CommandLineInputSpec):
119119
in_file = File(desc="tensor volume to resample", exists=True,
120120
mandatory=True, argstr="-in %s")
121-
out_file = traits.File(desc='output path',
122-
name_source="in_file", name_template="%s_resampled",
123-
keep_extension=True, argstr="-out %s")
121+
out_file = File(desc='output path',
122+
name_source="in_file", name_template="%s_resampled",
123+
keep_extension=True, argstr="-out %s")
124124
target_file = File(desc='specs read from the target volume',
125125
argstr="-target %s",
126126
xor=['array_size', 'voxel_size', 'origin'])
@@ -166,9 +166,9 @@ class TVResample(CommandLineDtitk):
166166
class SVResampleInputSpec(CommandLineInputSpec):
167167
in_file = File(desc="image to resample", exists=True,
168168
mandatory=True, argstr="-in %s")
169-
out_file = traits.File(desc='output path',
170-
name_source="in_file", name_template="%s_resampled",
171-
keep_extension=True, argstr="-out %s")
169+
out_file = File(desc='output path',
170+
name_source="in_file", name_template="%s_resampled",
171+
keep_extension=True, argstr="-out %s")
172172
target_file = File(desc='specs read from the target volume',
173173
argstr="-target %s",
174174
xor=['array_size', 'voxel_size', 'origin'])
@@ -215,8 +215,7 @@ class TVtoolInputSpec(CommandLineInputSpec):
215215
'''NOTE: there are a lot more options here; not implementing all of them'''
216216
in_flag = traits.Enum('fa', 'tr', 'ad', 'rd', 'pd', 'rgb', exists=True,
217217
argstr="-%s", desc='')
218-
out_file = traits.File(exists=True,
219-
argstr="-out %s", genfile=True)
218+
out_file = File(exists=True, argstr="-out %s", genfile=True)
220219

221220

222221
class TVtoolOutputSpec(TraitedSpec):
@@ -263,9 +262,9 @@ def _gen_filename(self, name):
263262
class BinThreshInputSpec(CommandLineInputSpec):
264263
in_file = File(desc='Image to threshold/binarize', exists=True,
265264
position=0, argstr="%s", mandatory=True)
266-
out_file = traits.File(desc='', position=1, argstr="%s",
267-
keep_extension=True, name_source='in_file',
268-
name_template='%s_thrbin')
265+
out_file = File(desc='', position=1, argstr="%s",
266+
keep_extension=True, name_source='in_file',
267+
name_template='%s_thrbin')
269268
lower_bound = traits.Float(0.01, position=2, argstr="%g", mandatory=True)
270269
upper_bound = traits.Float(100, position=3, argstr="%g", mandatory=True)
271270
inside_value = traits.Float(1, position=4, argstr="%g", usedefault=True,

0 commit comments

Comments
 (0)