@@ -617,16 +617,20 @@ class AvScaleInputSpec(FSLCommandInputSpec):
617
617
618
618
619
619
class AvScaleOutputSpec (TraitedSpec ):
620
- rotation_translation_matrix = traits .Any (
621
- desc = 'Rotation and Translation Matrix' )
622
- scales = traits .Any (desc = 'Scales (x,y,z)' )
623
- skews = traits .Any (desc = 'Skews' )
624
- average_scaling = traits .Any (desc = 'Average Scaling' )
625
- determinant = traits .Any (desc = 'Determinant' )
626
- forward_half_transform = traits .Any (desc = 'Forward Half Transform' )
627
- backward_half_transform = traits .Any (desc = 'Backwards Half Transform' )
620
+ rotation_translation_matrix = traits .List (
621
+ traits .List (traits .Float ), desc = 'Rotation and Translation Matrix' )
622
+ scales = traits .List (traits .Float , desc = 'Scales (x,y,z)' )
623
+ skews = traits .List (traits .Float , desc = 'Skews' )
624
+ average_scaling = traits .Float (desc = 'Average Scaling' )
625
+ determinant = traits .Float (desc = 'Determinant' )
626
+ forward_half_transform = traits .List (
627
+ traits .List (traits .Float ), desc = 'Forward Half Transform' )
628
+ backward_half_transform = traits .List (
629
+ traits .List (traits .Float ), desc = 'Backwards Half Transform' )
628
630
left_right_orientation_preserved = traits .Bool (
629
631
desc = 'True if LR orientation preserved' )
632
+ rot_angles = traits .List (traits .Float , desc = 'rotation angles' )
633
+ translations = traits .List (traits .Float , desc = 'translations' )
630
634
631
635
632
636
class AvScale (FSLCommand ):
@@ -652,26 +656,37 @@ def _format_arg(self, name, trait_spec, value):
652
656
def aggregate_outputs (self , runtime = None , needed_outputs = None ):
653
657
outputs = self ._outputs ()
654
658
655
- def lines_to_float (lines ):
656
- out = []
657
- for line in lines :
658
- values = line .split ()
659
- out .append ([float (val ) for val in values ])
660
- return out
661
-
662
- out = runtime .stdout .split ('\n ' )
663
-
664
- outputs .rotation_translation_matrix = lines_to_float (out [1 :5 ])
665
- outputs .scales = lines_to_float ([out [6 ].split (" = " )[1 ]])
666
- outputs .skews = lines_to_float ([out [8 ].split (" = " )[1 ]])
667
- outputs .average_scaling = lines_to_float ([out [10 ].split (" = " )[1 ]])
668
- outputs .determinant = lines_to_float ([out [12 ].split (" = " )[1 ]])
669
- if out [13 ].split (": " )[1 ] == 'preserved' :
670
- outputs .left_right_orientation_preserved = True
671
- else :
672
- outputs .left_right_orientation_preserved = False
673
- outputs .forward_half_transform = lines_to_float (out [16 :20 ])
674
- outputs .backward_half_transform = lines_to_float (out [22 :- 1 ])
659
+ expr = re .compile (
660
+ 'Rotation\ &\ Translation\ Matrix:\n (?P<rot_tran_mat>[0-9\.\ \n -]+)[\s\n ]*'
661
+ '(Rotation\ Angles\ \(x,y,z\)\ \[rads\]\ =\ (?P<rot_angles>[0-9\.\ -]+))?[\s\n ]*'
662
+ '(Translations\ \(x,y,z\)\ \[mm\]\ =\ (?P<translations>[0-9\.\ -]+))?[\s\n ]*'
663
+ 'Scales\ \(x,y,z\)\ =\ (?P<scales>[0-9\.\ -]+)[\s\n ]*'
664
+ 'Skews\ \(xy,xz,yz\)\ =\ (?P<skews>[0-9\.\ -]+)[\s\n ]*'
665
+ 'Average\ scaling\ =\ (?P<avg_scaling>[0-9\.-]+)[\s\n ]*'
666
+ 'Determinant\ =\ (?P<determinant>[0-9\.-]+)[\s\n ]*'
667
+ 'Left-Right\ orientation:\ (?P<lr_orientation>[A-Za-z]+)[\s\n ]*'
668
+ 'Forward\ half\ transform\ =[\s]*\n '
669
+ '(?P<fwd_half_xfm>[0-9\.\ \n -]+)[\s\n ]*'
670
+ 'Backward\ half\ transform\ =[\s]*\n '
671
+ '(?P<bwd_half_xfm>[0-9\.\ \n -]+)[\s\n ]*' )
672
+
673
+ out = expr .search (runtime .stdout ).groupdict ()
674
+
675
+ outputs ['rotation_translation_matrix' ] = [
676
+ float (v ) for v in r .split (' ' ) for r in out ['rot_tran_mat' ].strip ().split ('\n ' )]
677
+ outputs ['scales' ] = [float (s ) for s in out ['scales' ].strip ()]
678
+ outputs ['skews' ] = [float (s ) for s in out ['skews' ].strip ()]
679
+ outputs ['average_scaling' ] = float (out ['avg_scaling' ].strip ())
680
+ outputs ['determinant' ] = float (out ['determinant' ].strip ())
681
+ outputs ['left_right_orientation_preserved' ] = out ['lr_orientation' ].strip () == 'preserved'
682
+ outputs ['forward_half_transform' ] = [
683
+ float (v ) for v in r .split (' ' ) for r in out ['fwd_half_xfm' ].strip ().split ('\n ' )]
684
+ outputs ['backward_half_transform' ] = [
685
+ float (v ) for v in r .split (' ' ) for r in out ['bwd_half_xfm' ].strip ().split ('\n ' )]
686
+
687
+ if self .inputs .all_param :
688
+ outputs ['rot_angles' ] = [float (r ) for r in out ['rot_angles' ].strip ().split (' ' )]
689
+ outputs ['translations' ] = [float (r ) for r in out ['translations' ].strip ().split (' ' )]
675
690
676
691
return outputs
677
692
0 commit comments