Skip to content

Commit e72cfbb

Browse files
committed
Updated _format_arg to produce a n_iterations only output if convergence threshold is not specified in N4BiasField Correction. Tests updated to match (with updates for image_dimension changes).
1 parent 8e46eb8 commit e72cfbb

File tree

1 file changed

+23
-14
lines changed

1 file changed

+23
-14
lines changed

nipype/interfaces/ants/segmentation.py

Lines changed: 23 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -276,26 +276,33 @@ class N4BiasFieldCorrection(ANTSCommand):
276276
>>> n4.inputs.bspline_fitting_distance = 300
277277
>>> n4.inputs.shrink_factor = 3
278278
>>> n4.inputs.n_iterations = [50,50,30,20]
279-
>>> n4.inputs.convergence_threshold = 1e-6
280279
>>> n4.cmdline
281280
'N4BiasFieldCorrection --bspline-fitting [ 300 ] \
282-
--image-dimension 3 --input-image structural.nii \
283-
--convergence [ 50x50x30x20, 1e-06 ] --output structural_corrected.nii \
281+
-d 3 --input-image structural.nii \
282+
--convergence [ 50x50x30x20 ] --output structural_corrected.nii \
284283
--shrink-factor 3'
285284
286285
>>> n4_2 = copy.deepcopy(n4)
287-
>>> n4_2.inputs.bspline_order = 5
286+
>>> n4.inputs.convergence_threshold = 1e-6
288287
>>> n4_2.cmdline
289-
'N4BiasFieldCorrection --bspline-fitting [ 300, 5 ] \
290-
--image-dimension 3 --input-image structural.nii \
288+
'N4BiasFieldCorrection --bspline-fitting [ 300 ] \
289+
-d 3 --input-image structural.nii \
291290
--convergence [ 50x50x30x20, 1e-06 ] --output structural_corrected.nii \
292291
--shrink-factor 3'
293292
294-
>>> n4_3 = N4BiasFieldCorrection()
295-
>>> n4_3.inputs.input_image = 'structural.nii'
296-
>>> n4_3.inputs.save_bias = True
293+
>>> n4_3 = copy.deepcopy(n4)
294+
>>> n4_3.inputs.bspline_order = 5
297295
>>> n4_3.cmdline
298-
'N4BiasFieldCorrection --image-dimension 3 --input-image structural.nii \
296+
'N4BiasFieldCorrection --bspline-fitting [ 300, 5 ] \
297+
-d 3 --input-image structural.nii \
298+
--convergence [ 50x50x30x20, 1e-06 ] --output structural_corrected.nii \
299+
--shrink-factor 3'
300+
301+
>>> n4_4 = N4BiasFieldCorrection()
302+
>>> n4_4.inputs.input_image = 'structural.nii'
303+
>>> n4_4.inputs.save_bias = True
304+
>>> n4_4.cmdline
305+
'N4BiasFieldCorrection -d 3 --input-image structural.nii \
299306
--output [ structural_corrected.nii, structural_bias.nii ]'
300307
"""
301308

@@ -334,10 +341,12 @@ def _format_arg(self, name, trait_spec, value):
334341
newval = '[ %g ]' % value
335342
return trait_spec.argstr % newval
336343

337-
if ((name == 'n_iterations') and
338-
(isdefined(self.inputs.convergence_threshold))):
339-
newval = '[ %s, %g ]' % ('x'.join([str(elt) for elt in value]),
340-
self.inputs.convergence_threshold)
344+
if name == 'n_iterations':
345+
if isdefined(self.inputs.convergence_threshold):
346+
newval = '[ %s, %g ]' % ('x'.join([str(elt) for elt in value]),
347+
self.inputs.convergence_threshold)
348+
else:
349+
newval = '[ %s ]' % 'x'.join([str(elt) for elt in value])
341350
return trait_spec.argstr % newval
342351

343352
return super(N4BiasFieldCorrection,

0 commit comments

Comments
 (0)