@@ -379,6 +379,8 @@ class RegistrationInputSpec(ANTSCommandInputSpec):
379379 low = 0.0 , high = 1.0 , value = 0.0 , argstr = '%s' , usedefault = True , desc = "The Lower quantile to clip image ranges" )
380380
381381 verbose = traits .Bool (argstr = '-v' , default = False )
382+ profiling = traits .Bool (True , usedefault = True ,
383+ desc = 'generate profiling output fields' )
382384
383385
384386class RegistrationOutputSpec (TraitedSpec ):
@@ -395,6 +397,8 @@ class RegistrationOutputSpec(TraitedSpec):
395397 warped_image = File (desc = "Outputs warped image" )
396398 inverse_warped_image = File (desc = "Outputs the inverse of the warped image" )
397399 save_state = File (desc = "The saved registration state to be restored" )
400+ metric_value = traits .Float (desc = 'the final value of metric' )
401+ elapsed_time = traits .Float (desc = 'the total elapsed time as reported by ANTs' )
398402
399403
400404class Registration (ANTSCommand ):
@@ -648,6 +652,24 @@ class Registration(ANTSCommand):
648652 _quantilesDone = False
649653 _linear_transform_names = ['Rigid' , 'Affine' , 'Translation' , 'CompositeAffine' , 'Similarity' ]
650654
655+ def _run_interface (self , runtime , correct_return_codes = (0 ,)):
656+ runtime = super (Registration , self )._run_interface (runtime )
657+
658+ # Parse some profiling info
659+ if self .inputs .profiling :
660+ lines = runtime .stdout .split ('\n ' )
661+ for l in lines [::- 1 ]:
662+ # This should be the last line
663+ if l .strip ().startswith ('Total elapsed time:' ):
664+ setattr (self , '_elapsed_time' , float (
665+ l .strip ().replace ('Total elapsed time: ' , '' )))
666+ elif 'DIAGNOSTIC' in l :
667+ setattr (self , '_metric_value' , float (
668+ l .split (',' )[2 ]))
669+ break
670+
671+ return runtime
672+
651673 def _format_metric (self , index ):
652674 """
653675 Format the antsRegistration -m metric argument(s).
@@ -981,4 +1003,7 @@ def _list_outputs(self):
9811003 outputs ['inverse_warped_image' ] = os .path .abspath (inv_out_filename )
9821004 if len (self .inputs .save_state ):
9831005 outputs ['save_state' ] = os .path .abspath (self .inputs .save_state )
1006+ if self .inputs .profiling :
1007+ outputs ['metric_value' ] = getattr (self , '_metric_value' )
1008+ outputs ['elapsed_time' ] = getattr (self , '_elapsed_time' )
9841009 return outputs
0 commit comments