Skip to content

Getting Started

Prerequisites

  • Python 3.10+
  • ROS2 environment (Humble / Jazzy)

Installation

From PyPI

pip install baglab

From source

git clone https://github.com/Kotakku/baglab.git
cd baglab
pip install -e ".[dev]"

Basic usage

Load a rosbag

import baglab

bag = baglab.load("path/to/rosbag")
print(bag.topics)
# {"/motor/angle": "sensor_msgs/msg/JointState", ...}

Access topic data

Topic data is loaded lazily — only when you access it:

twist_df = bag["/cmd_vel"]

Dot-access for message fields

twist_df.msg.twist.linear.x         # pandas Series
twist_df.msg.twist.linear.df        # DataFrame with columns [x, y, z]

Timestamps

t = baglab.stamp_to_sec(twist_df)                  # absolute time [s]
t = baglab.stamp_to_sec(twist_df, relative=True)   # relative time (starts at 0)

Reindex by stamp

twist_df = baglab.reindex_by_stamp(twist_df)

Time slicing

sliced = baglab.time_slice(twist_df, t_start=1.0, t_end=5.0)

Plot example

import baglab
import matplotlib.pyplot as plt

bag = baglab.load("path/to/rosbag")
twist_df = bag["/cmd_vel"]

t = baglab.stamp_to_sec(twist_df, relative=True)
vel = twist_df.msg.twist.linear.df

fig, axes = plt.subplots(3, 1, sharex=True)
for ax, axis_name in zip(axes, ["x", "y", "z"]):
    ax.plot(t, vel[axis_name])
    ax.set_ylabel(axis_name)
axes[-1].set_xlabel("time [s]")
plt.show()