@@ -379,6 +379,8 @@ class RegistrationInputSpec(ANTSCommandInputSpec):
379
379
low = 0.0 , high = 1.0 , value = 0.0 , argstr = '%s' , usedefault = True , desc = "The Lower quantile to clip image ranges" )
380
380
381
381
verbose = traits .Bool (argstr = '-v' , default = False )
382
+ profiling = traits .Bool (True , usedefault = True ,
383
+ desc = 'generate profiling output fields' )
382
384
383
385
384
386
class RegistrationOutputSpec (TraitedSpec ):
@@ -395,6 +397,8 @@ class RegistrationOutputSpec(TraitedSpec):
395
397
warped_image = File (desc = "Outputs warped image" )
396
398
inverse_warped_image = File (desc = "Outputs the inverse of the warped image" )
397
399
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' )
398
402
399
403
400
404
class Registration (ANTSCommand ):
@@ -648,6 +652,24 @@ class Registration(ANTSCommand):
648
652
_quantilesDone = False
649
653
_linear_transform_names = ['Rigid' , 'Affine' , 'Translation' , 'CompositeAffine' , 'Similarity' ]
650
654
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
+
651
673
def _format_metric (self , index ):
652
674
"""
653
675
Format the antsRegistration -m metric argument(s).
@@ -981,4 +1003,7 @@ def _list_outputs(self):
981
1003
outputs ['inverse_warped_image' ] = os .path .abspath (inv_out_filename )
982
1004
if len (self .inputs .save_state ):
983
1005
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' )
984
1009
return outputs
0 commit comments