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 = {}
@@ -96,6 +96,10 @@ def check_drop(inbags):
96
96
bag_time_diff_topic = bag_time_diff [topic ]
97
97
seq_diff_topic = seq_diff [topic ]
98
98
99
+ if len (msg_time_diff_topic ) == 0 :
100
+ rospy .logwarn ('%s has no messages' , topic .ljust (max_len + 2 ))
101
+ continue
102
+
99
103
msg_time_diff_min = numpy .min (msg_time_diff_topic )
100
104
msg_time_diff_max = numpy .max (msg_time_diff_topic )
101
105
msg_time_diff_mean = numpy .mean (msg_time_diff_topic )
@@ -119,31 +123,35 @@ def check_drop(inbags):
119
123
N = len (msg_time_diff_topic )
120
124
x = numpy .array ([0 , N - 1 ])
121
125
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' )
126
+ try :
127
+ fig = plt .figure ()
128
+ fig .set_size_inches (20 , 15 )
129
+
130
+ plt .subplot (311 )
131
+ plt .title (topic + ' - Message time difference [s]' )
132
+ plt .plot (msg_time_diff_topic , 'b' )
133
+ plt .plot (x , numpy .array ([msg_time_diff_min , msg_time_diff_min ]), 'r--' )
134
+ plt .plot (x , numpy .array ([msg_time_diff_max , msg_time_diff_max ]), 'r--' )
135
+ plt .plot (x , numpy .array ([msg_time_diff_mean , msg_time_diff_mean ]), 'g' )
136
+
137
+ plt .subplot (312 )
138
+ plt .title (topic + ' - Bag time difference [s]' )
139
+ plt .plot (bag_time_diff_topic , 'b' )
140
+ plt .plot (x , numpy .array ([bag_time_diff_min , bag_time_diff_min ]), 'r--' )
141
+ plt .plot (x , numpy .array ([bag_time_diff_max , bag_time_diff_max ]), 'r--' )
142
+ plt .plot (x , numpy .array ([bag_time_diff_mean , bag_time_diff_mean ]), 'g' )
143
+
144
+ plt .subplot (313 )
145
+ plt .title (topic + ' - Sequence number difference' )
146
+ plt .plot (seq_diff_topic , 'b' )
147
+ plt .plot (x , numpy .array ([seq_diff_min , seq_diff_min ]), 'r--' )
148
+ plt .plot (x , numpy .array ([seq_diff_max , seq_diff_max ]), 'r--' )
149
+ plt .plot (x , numpy .array ([seq_diff_mean , seq_diff_mean ]), 'g' )
150
+
151
+ plt .savefig (basename + topic .replace ('/' , '_' ).replace (' ' , '_' ).replace (':' , '_' ) + '.' + plot_format )
152
+ plt .close (fig )
153
+ except OverflowError as e :
154
+ 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
155
148
156
if __name__ == "__main__" :
149
157
rospy .init_node ('check_drop' , anonymous = True )
@@ -153,9 +161,10 @@ def check_drop(inbags):
153
161
'message dropping in a bagfile. Prints out min, max and mean '
154
162
'differences and all values are shown on a plot.' )
155
163
parser .add_argument ('inbag' , help = 'input bagfile(s)' , nargs = '+' )
164
+ parser .add_argument ('--plot_format' , help = 'output plot format' , default = 'png' )
156
165
args = parser .parse_args ()
157
166
try :
158
- check_drop (args .inbag )
167
+ check_drop (args .inbag , args . plot_format )
159
168
except Exception , e :
160
169
import traceback
161
170
traceback .print_exc ()
0 commit comments