Overwriting data of bag file in append mode

asked 2020-03-12 03:59:43 -0600

srinivast6 gravatar image

updated 2020-03-12 05:11:17 -0600

I am trying to overwrite a data point in a bag file which is already recorded at time T. For this I am opening that bag file in append mode and writing new data point at that time T . But this is not overwriting the existing data point. but just creating two data points at the same time?

How can I overwrite it without creating a new bag file?

I am attaching the code below.

 import rosbag,rospy
 from std_msgs.msg import String

 bag = rosbag.Bag('/home/kpit/Desktop/merge.bag','a')

 with bag as outbag:
     T = rospy.Time(1581070456,834536791)
     label_msg = String(data='fg')
     outbag.write('/Labels/wl', label_msg, T)
edit retag flag offensive close merge delete

Comments

Please provide more information. How are you opening it, how do you add the new data point? I guess you are using some kind of the rosbag API. So I guess you only have to search the respective data point and delete / change it...

mgruhler gravatar image mgruhler  ( 2020-03-12 04:11:09 -0600 )edit

@mgruhler, yes I am using rosbag API. How can i delete a msg from a bag file?? I have attached the code

srinivast6 gravatar image srinivast6  ( 2020-03-12 05:12:26 -0600 )edit

Checking the API, it seems there is no direct way to delete a message. I guess you have to work around that by reading all messages from the bag, writing them in a new one and replace the specific entry you want gone. Then move the new one over the old one...

mgruhler gravatar image mgruhler  ( 2020-03-12 05:21:40 -0600 )edit

Thank you for the help. But that is an expensive task for a small change when file size is more than 30GB.

srinivast6 gravatar image srinivast6  ( 2020-03-12 05:28:57 -0600 )edit

Agreed. Maybe you can do the writing directly into the opened file (open as 'w' only). So you would at least get rid of the copy step. But please test this beforehand.

I'm not familiar with the implementation details. but it might be worth opening an issue at the ros_comm repo with that feature request.

mgruhler gravatar image mgruhler  ( 2020-03-12 05:45:58 -0600 )edit