Skip to content

Instantly share code, notes, and snippets.

@jbohren
Created September 12, 2016 21:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jbohren/ea206fb67d8b73d7390d951f3d97eb2b to your computer and use it in GitHub Desktop.
Save jbohren/ea206fb67d8b73d7390d951f3d97eb2b to your computer and use it in GitHub Desktop.
#!/usr/bin/env python
from __future__ import print_function
import sys
import os
from multiprocessing import Pool
import rosbag
from tf.msg import tfMessage
def fix_bag_tf(args):
(lambda bag_name, fixed_bag_name:
((lambda bag, fixed_bag:
[(fixed_bag.write(topic, tfMessage(msg.transforms), stamp)
if topic.find('/tf') >= 0
else (fixed_bag.write(topic, msg, stamp)))
for topic, msg, stamp in bag.read_messages()]
)(rosbag.Bag(bag_name, mode='r'),
rosbag.Bag(fixed_bag_name, mode='w', compression='bz2'))
if not os.path.exists(fixed_bag_name) else None)
or print('Converted {}'.format(bag_name))
)(*args)
((print('usage: {} THREADS BAG [BAG ...]'.format(sys.argv[0])) and sys.exit(1))
if len(sys.argv) < 3
else
Pool(int(sys.argv[1])).map(
fix_bag_tf,
[(bag_name, '{}_fixed{}'.format(*os.path.splitext(bag_name)))
for bag_name in sys.argv[2:]
if not bag_name.endswith('_fixed.bag')]))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment