37
37
38
38
import matplotlib .pyplot as plt
39
39
40
- def check_drop (inbags ):
40
+ def check_drop (inbags , plot_format = 'png' ):
41
41
# Retrieve msg time, bag time and sequence number for all topics and messages:
42
42
msg_time = {}
43
43
bag_time = {}
@@ -119,31 +119,34 @@ def check_drop(inbags):
119
119
N = len (msg_time_diff_topic )
120
120
x = numpy .array ([0 , N - 1 ])
121
121
122
- fig = plt .figure ()
123
- fig .set_size_inches (20 , 15 )
124
-
125
- plt .subplot (311 )
126
- plt .title (topic + ' - Message time difference [s]' )
127
- plt .plot (msg_time_diff_topic , 'b' )
128
- plt .plot (x , numpy .array ([msg_time_diff_min , msg_time_diff_min ]), 'r--' )
129
- plt .plot (x , numpy .array ([msg_time_diff_max , msg_time_diff_max ]), 'r--' )
130
- plt .plot (x , numpy .array ([msg_time_diff_mean , msg_time_diff_mean ]), 'g' )
131
-
132
- plt .subplot (312 )
133
- plt .title (topic + ' - Bag time difference [s]' )
134
- plt .plot (bag_time_diff_topic , 'b' )
135
- plt .plot (x , numpy .array ([bag_time_diff_min , bag_time_diff_min ]), 'r--' )
136
- plt .plot (x , numpy .array ([bag_time_diff_max , bag_time_diff_max ]), 'r--' )
137
- plt .plot (x , numpy .array ([bag_time_diff_mean , bag_time_diff_mean ]), 'g' )
138
-
139
- plt .subplot (313 )
140
- plt .title (topic + ' - Sequence number difference' )
141
- plt .plot (seq_diff_topic , 'b' )
142
- plt .plot (x , numpy .array ([seq_diff_min , seq_diff_min ]), 'r--' )
143
- plt .plot (x , numpy .array ([seq_diff_max , seq_diff_max ]), 'r--' )
144
- plt .plot (x , numpy .array ([seq_diff_mean , seq_diff_mean ]), 'g' )
145
-
146
- plt .savefig (basename + topic .replace ('/' , '_' ).replace (' ' , '_' ).replace (':' , '_' ) + '.png' )
122
+ try :
123
+ fig = plt .figure ()
124
+ fig .set_size_inches (20 , 15 )
125
+
126
+ plt .subplot (311 )
127
+ plt .title (topic + ' - Message time difference [s]' )
128
+ plt .plot (msg_time_diff_topic , 'b' )
129
+ plt .plot (x , numpy .array ([msg_time_diff_min , msg_time_diff_min ]), 'r--' )
130
+ plt .plot (x , numpy .array ([msg_time_diff_max , msg_time_diff_max ]), 'r--' )
131
+ plt .plot (x , numpy .array ([msg_time_diff_mean , msg_time_diff_mean ]), 'g' )
132
+
133
+ plt .subplot (312 )
134
+ plt .title (topic + ' - Bag time difference [s]' )
135
+ plt .plot (bag_time_diff_topic , 'b' )
136
+ plt .plot (x , numpy .array ([bag_time_diff_min , bag_time_diff_min ]), 'r--' )
137
+ plt .plot (x , numpy .array ([bag_time_diff_max , bag_time_diff_max ]), 'r--' )
138
+ plt .plot (x , numpy .array ([bag_time_diff_mean , bag_time_diff_mean ]), 'g' )
139
+
140
+ plt .subplot (313 )
141
+ plt .title (topic + ' - Sequence number difference' )
142
+ plt .plot (seq_diff_topic , 'b' )
143
+ plt .plot (x , numpy .array ([seq_diff_min , seq_diff_min ]), 'r--' )
144
+ plt .plot (x , numpy .array ([seq_diff_max , seq_diff_max ]), 'r--' )
145
+ plt .plot (x , numpy .array ([seq_diff_mean , seq_diff_mean ]), 'g' )
146
+
147
+ plt .savefig (basename + topic .replace ('/' , '_' ).replace (' ' , '_' ).replace (':' , '_' ) + '.' + plot_format )
148
+ except OverflowError as e :
149
+ rospy .logerr ('%s: Failed to save plots as %s image files (try other format, e.g. svg): %s' , topic .ljust (max_len + 2 ), plot_format , e .message )
147
150
148
151
if __name__ == "__main__" :
149
152
rospy .init_node ('check_drop' , anonymous = True )
@@ -153,9 +156,10 @@ def check_drop(inbags):
153
156
'message dropping in a bagfile. Prints out min, max and mean '
154
157
'differences and all values are shown on a plot.' )
155
158
parser .add_argument ('inbag' , help = 'input bagfile(s)' , nargs = '+' )
159
+ parser .add_argument ('--plot_format' , help = 'output plot format' , default = 'png' )
156
160
args = parser .parse_args ()
157
161
try :
158
- check_drop (args .inbag )
162
+ check_drop (args .inbag , args . plot_format )
159
163
except Exception , e :
160
164
import traceback
161
165
traceback .print_exc ()
0 commit comments