Skip to content

Commit 8111eba

Browse files
author
Enrique Fernandez
committed
Add arg to specify plot format
png might failed on large plots with Overflow, so svg or pdf should be used instead
1 parent d3024b5 commit 8111eba

File tree

1 file changed

+31
-27
lines changed

1 file changed

+31
-27
lines changed

bag_tools/scripts/check_drop.py

Lines changed: 31 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737

3838
import matplotlib.pyplot as plt
3939

40-
def check_drop(inbags):
40+
def check_drop(inbags, plot_format='png'):
4141
# Retrieve msg time, bag time and sequence number for all topics and messages:
4242
msg_time = {}
4343
bag_time = {}
@@ -119,31 +119,34 @@ def check_drop(inbags):
119119
N = len(msg_time_diff_topic)
120120
x = numpy.array([0, N - 1])
121121

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)
147150

148151
if __name__ == "__main__":
149152
rospy.init_node('check_drop', anonymous=True)
@@ -153,9 +156,10 @@ def check_drop(inbags):
153156
'message dropping in a bagfile. Prints out min, max and mean '
154157
'differences and all values are shown on a plot.')
155158
parser.add_argument('inbag', help='input bagfile(s)', nargs='+')
159+
parser.add_argument('--plot_format', help='output plot format', default='png')
156160
args = parser.parse_args()
157161
try:
158-
check_drop(args.inbag)
162+
check_drop(args.inbag, args.plot_format)
159163
except Exception, e:
160164
import traceback
161165
traceback.print_exc()

0 commit comments

Comments
 (0)