@@ -47,8 +47,7 @@ class FramewiseDisplacementInputSpec(BaseInterfaceInputSpec):
47
47
out_figure = File ('fd_power_2012.pdf' , usedefault = True , desc = 'output figure name' )
48
48
series_tr = traits .Float (desc = 'repetition time in sec.' )
49
49
save_plot = traits .Bool (False , usedefault = True , desc = 'write FD plot' )
50
- normalize = traits .Bool (False , usedefault = True , desc = 'calculate FD in mm/s' ,
51
- requires = ['series_tr' ])
50
+ normalize = traits .Bool (False , usedefault = True , desc = 'calculate FD in mm/s' )
52
51
figdpi = traits .Int (100 , usedefault = True , desc = 'output dpi for the FD plot' )
53
52
figsize = traits .Tuple (traits .Float (11.7 ), traits .Float (2.3 ), usedefault = True ,
54
53
desc = 'output figure size' )
@@ -86,12 +85,18 @@ def _run_interface(self, runtime):
86
85
}
87
86
np .savetxt (self .inputs .out_file , fd_res )
88
87
88
+
89
89
if self .inputs .save_plot :
90
- self ._results ['out_figure' ] = op .abspath (self .inputs .out_figure )
91
90
tr = None
92
- if self .inputs .normalize :
91
+ if isdefined ( self .inputs .series_tr ) :
93
92
tr = self .inputs .series_tr
94
- fig = plot_fd (fd_res , self .inputs .figsize , series_tr = tr )
93
+
94
+ if self .inputs .normalize and tr is None :
95
+ iflogger .warn ('FD plot cannot be normalized if TR is not set' )
96
+
97
+ self ._results ['out_figure' ] = op .abspath (self .inputs .out_figure )
98
+ fig = plot_fd (fd_res , self .inputs .figsize , series_tr = tr ,
99
+ normalize = self .inputs .normalize )
95
100
fig .savefig (self ._results ['out_figure' ], dpi = float (self .inputs .figdpi ),
96
101
format = self .inputs .out_figure [- 3 :],
97
102
bbox_inches = 'tight' )
@@ -1523,7 +1528,7 @@ def merge_rois(in_files, in_idxs, in_ref,
1523
1528
return out_file
1524
1529
1525
1530
1526
- def plot_fd (fd_values , figsize , series_tr = None ):
1531
+ def plot_fd (fd_values , figsize , series_tr = None , normalize = False ):
1527
1532
"""
1528
1533
A helper function to plot the framewise displacement
1529
1534
"""
@@ -1540,9 +1545,12 @@ def plot_fd(fd_values, figsize, series_tr=None):
1540
1545
grid .update (hspace = 1.0 , right = 0.95 , left = 0.1 , bottom = 0.2 )
1541
1546
1542
1547
ax = fig .add_subplot (grid [0 , :- 1 ])
1548
+ if normalize and series_tr is not None :
1549
+ fd_values /= series_tr
1550
+
1543
1551
ax .plot (fd_values )
1544
1552
ax .set_xlim ((0 , len (fd_values )))
1545
- ax .set_ylabel ('FD [{}] ' .format ('mm/s' if series_tr is not None else 'mm ' ))
1553
+ ax .set_ylabel ('FD {} ' .format ('speed [ mm/s] ' if normalize else '[mm] ' ))
1546
1554
1547
1555
xlabel = 'Frame #'
1548
1556
if series_tr is not None :
0 commit comments