@@ -386,9 +386,13 @@ class N4BiasFieldCorrection(ANTSCommand):
386
386
input_spec = N4BiasFieldCorrectionInputSpec
387
387
output_spec = N4BiasFieldCorrectionOutputSpec
388
388
389
+ def __init__ (self , * args , ** kwargs ):
390
+ self ._out_bias_file = None
391
+ super (N4BiasFieldCorrection , self ).__init__ (* args , ** kwargs )
392
+
389
393
def _format_arg (self , name , trait_spec , value ):
390
- if name == 'output_image' and getattr ( self , ' _out_bias_file' , None ) :
391
- newval = '[ %s, %s ]' % (value , getattr ( self , ' _out_bias_file' ) )
394
+ if name == 'output_image' and self . _out_bias_file :
395
+ newval = '[ %s, %s ]' % (value , self . _out_bias_file )
392
396
return trait_spec .argstr % newval
393
397
394
398
if name == 'bspline_fitting_distance' :
@@ -413,24 +417,19 @@ def _format_arg(self, name, trait_spec, value):
413
417
414
418
def _parse_inputs (self , skip = None ):
415
419
skip = (skip or []) + ['save_bias' , 'bias_image' ]
420
+ self ._out_bias_file = None
416
421
if self .inputs .save_bias or isdefined (self .inputs .bias_image ):
417
422
bias_image = self .inputs .bias_image
418
423
if not isdefined (bias_image ):
419
424
bias_image = fname_presuffix (os .path .basename (self .inputs .input_image ),
420
425
suffix = '_bias' )
421
- setattr (self , '_out_bias_file' , bias_image )
422
- else :
423
- try :
424
- delattr (self , '_out_bias_file' )
425
- except AttributeError :
426
- pass
426
+ self ._out_bias_file = bias_image
427
427
return super (N4BiasFieldCorrection , self )._parse_inputs (skip = skip )
428
428
429
429
def _list_outputs (self ):
430
430
outputs = super (N4BiasFieldCorrection , self )._list_outputs ()
431
- bias_image = getattr (self , '_out_bias_file' , None )
432
- if bias_image :
433
- outputs ['bias_image' ] = bias_image
431
+ if self ._out_bias_file :
432
+ outputs ['bias_image' ] = self ._out_bias_file
434
433
return outputs
435
434
436
435
def _run_interface (self , runtime , correct_return_codes = (0 , )):
@@ -439,8 +438,8 @@ def _run_interface(self, runtime, correct_return_codes=(0, )):
439
438
440
439
if self .inputs .copy_header and runtime .returncode in correct_return_codes :
441
440
self ._copy_header (self .inputs .output_image )
442
- if getattr ( self , ' _out_bias_file' , None ) :
443
- self ._copy_header (getattr ( self , ' _out_bias_file' ) )
441
+ if self . _out_bias_file :
442
+ self ._copy_header (self . _out_bias_file )
444
443
445
444
return runtime
446
445
0 commit comments