-
Notifications
You must be signed in to change notification settings - Fork 0
/
mcap_to_csv.py
39 lines (30 loc) · 1.01 KB
/
mcap_to_csv.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# This file is part of holohover-sysid.
#
# Copyright (c) 2024 EPFL
#
# This source code is licensed under the BSD 2-Clause License found in the
# LICENSE file in the root directory of this source tree.
# pip3 install pandas mcap-ros2-support
import os
import sys
import pandas as pd
from src.utils import read_mcap_file
def main():
# maps topic to csv file
topic_mapping = None
# topic_mapping = {
# '/car/state': 'state',
# '/car/set/control': 'control',
# }
topic_msgs = read_mcap_file(sys.argv[1], topic_mapping.keys() if topic_mapping is not None else None)
if topic_mapping is None:
class TopicToFile:
def __getitem__(self, topic):
return topic.strip('/').replace('/', '_')
topic_mapping = TopicToFile()
dir = os.path.dirname(sys.argv[1])
for topic, msgs in topic_msgs.items():
df = pd.DataFrame(msgs)
df.to_csv(os.path.join(dir, f'{topic_mapping[topic]}.csv'), index=False)
if __name__ == '__main__':
main()