grepros 1.2.2
grep for ROS bag files and live topics
Loading...
Searching...
No Matches
BaseBag Class Reference

ROS bag interface. More...

Inheritance diagram for BaseBag:
Inheritance graph

Public Member Functions

 __bool__ (self)
 
 __contains__ (self, key)
 Returns whether bag contains given topic.
 
 __copy__ (self)
 
 __deepcopy__ (self, memo=None)
 
 __enter__ (self)
 Context manager entry, opens bag if not open.
 
 __exit__ (self, exc_type, exc_value, traceback)
 Context manager exit, closes bag.
 
 __getitem__ (self, key)
 Returns an iterator yielding messages from the bag in given topic, supporting len().
 
 __iter__ (self)
 Iterates over all messages in the bag.
 
 __len__ (self)
 Returns the number of messages in the bag.
 
 __next__ (self)
 Retrieves next message from bag as (topic, message, timestamp).
 
 __nonzero__ (self)
 
 __str__ (self)
 Returns informative text for bag, with a full overview of topics and types.
 
 close (self)
 Closes the bag file.
 
 flush (self)
 Ensures all changes are written to bag file.
 
 get_end_time (self)
 Returns the end time of the bag, as UNIX timestamp, or None if bag empty.
 
 get_message_class (self, typename, typehash=None)
 Returns ROS message type class, or None if unknown message type for bag.
 
 get_message_count (self, topic_filters=None)
 Returns the number of messages in the bag.
 
 get_message_definition (self, msg_or_type)
 Returns ROS message type definition full text, including subtype definitions.
 
 get_message_type_hash (self, msg_or_type)
 Returns ROS message type MD5 hash, or None if unknown message type for bag.
 
 get_qoses (self, topic, typename)
 Returns topic Quality-of-Service profiles as a list of dicts, or None if not available.
 
 get_start_time (self)
 Returns the start time of the bag, as UNIX timestamp, or None if bag empty.
 
 get_topic_info (self, counts=True)
 Returns topic and message type metainfo as {(topic, typename, typehash): count}.
 
 get_type_and_topic_info (self, topic_filters=None)
 Returns thorough metainfo on topic and message types.
 
 open (self)
 Opens the bag file if not already open.
 
 read_messages (self, topics=None, start_time=None, end_time=None, raw=False, **__)
 Yields messages from the bag, optionally filtered by topic and timestamp.
 
 write (self, topic, msg, t=None, raw=False, **kwargs)
 Writes a message to the bag.
 

Static Public Attributes

 BagMessage = collections.namedtuple("BagMessage", "topic message timestamp")
 Returned from read_messages() as (topic name, ROS message, ROS timestamp object).
 
tuple MODES = ("r", "w", "a")
 Supported opening modes, overridden in subclasses.
 
 next
 
bool STREAMABLE = True
 Whether bag supports reading or writing stream objects, overridden in subclasses.
 
 TopicTuple
 Returned from get_type_and_topic_info() as (typename, message count, connection count, median frequency).
 
 TypesAndTopicsTuple = collections.namedtuple("TypesAndTopicsTuple", ["msg_types", "topics"])
 Returned from get_type_and_topic_info() as ({typename: typehash}, {topic name: TopicTuple}).
 

Properties

 closed = property
 Returns whether file is closed.
 
 filename = property
 Returns bag file path.
 
 mode = property
 Returns file open mode.
 
 size = property
 Returns current file size in bytes.
 
 stop_on_error = property
 Whether raising read error on unknown message type (ROS2 SQLite .db3 specific).
 
 topics = property
 Returns the list of topics in bag, in alphabetic order.
 

Detailed Description

ROS bag interface.

Bag can be used a context manager, is an iterable providing (topic, message, timestamp) tuples and supporting len(bag); and supports topic-based membership (if mytopic in bag, for t, m, s in bag[mytopic], len(bag[mytopic])).

Extra methods and properties compared with rosbag.Bag: Bag.get_message_class(),

Bag.get_message_definition(), Bag.get_message_type_hash(), Bag.get_topic_info();

Bag.closed and Bag.topics.

Definition at line 98 of file api.py.

Member Function Documentation

◆ __bool__()

__bool__ (   self)

Definition at line 141 of file api.py.

◆ __contains__()

__contains__ (   self,
  key 
)

Returns whether bag contains given topic.

Reimplemented in EmbagReader, McapBag, ROS1Bag, and ROS2Bag.

Definition at line 143 of file api.py.

◆ __copy__()

__copy__ (   self)

Definition at line 147 of file api.py.

◆ __deepcopy__()

__deepcopy__ (   self,
  memo = None 
)

Definition at line 149 of file api.py.

◆ __enter__()

__enter__ (   self)

Context manager entry, opens bag if not open.

Definition at line 121 of file api.py.

◆ __exit__()

__exit__ (   self,
  exc_type,
  exc_value,
  traceback 
)

Context manager exit, closes bag.

Definition at line 126 of file api.py.

◆ __getitem__()

__getitem__ (   self,
  key 
)

Returns an iterator yielding messages from the bag in given topic, supporting len().

Definition at line 151 of file api.py.

◆ __iter__()

__iter__ (   self)

Iterates over all messages in the bag.

Definition at line 117 of file api.py.

◆ __len__()

__len__ (   self)

Returns the number of messages in the bag.

Definition at line 130 of file api.py.

◆ __next__()

__next__ (   self)

Retrieves next message from bag as (topic, message, timestamp).

Reimplemented in EmbagReader, McapBag, ROS1Bag, and ROS2Bag.

Definition at line 134 of file api.py.

◆ __nonzero__()

__nonzero__ (   self)

Definition at line 139 of file api.py.

◆ __str__()

__str__ (   self)

Returns informative text for bag, with a full overview of topics and types.

Definition at line 157 of file api.py.

◆ close()

close (   self)

Closes the bag file.

Reimplemented in EmbagReader, McapBag, ROS1Bag, and ROS2Bag.

Definition at line 311 of file api.py.

◆ flush()

flush (   self)

Ensures all changes are written to bag file.

Definition at line 315 of file api.py.

◆ get_end_time()

get_end_time (   self)

Returns the end time of the bag, as UNIX timestamp, or None if bag empty.

Reimplemented in EmbagReader, McapBag, ROS1Bag, and ROS2Bag.

Definition at line 225 of file api.py.

◆ get_message_class()

get_message_class (   self,
  typename,
  typehash = None 
)

Returns ROS message type class, or None if unknown message type for bag.

Reimplemented in EmbagReader, McapBag, ROS1Bag, and ROS2Bag.

Definition at line 256 of file api.py.

◆ get_message_count()

get_message_count (   self,
  topic_filters = None 
)

Returns the number of messages in the bag.

Parameters
topic_filterslist of topics or a single topic to filter by, if any

Reimplemented in EmbagReader, McapBag, and ROS2Bag.

Definition at line 218 of file api.py.

◆ get_message_definition()

get_message_definition (   self,
  msg_or_type 
)

Returns ROS message type definition full text, including subtype definitions.

Returns None if unknown message type for bag.

Reimplemented in EmbagReader, McapBag, ROS1Bag, and ROS2Bag.

Definition at line 265 of file api.py.

◆ get_message_type_hash()

get_message_type_hash (   self,
  msg_or_type 
)

Returns ROS message type MD5 hash, or None if unknown message type for bag.

Reimplemented in EmbagReader, McapBag, ROS1Bag, and ROS2Bag.

Definition at line 268 of file api.py.

◆ get_qoses()

get_qoses (   self,
  topic,
  typename 
)

Returns topic Quality-of-Service profiles as a list of dicts, or None if not available.

Functional only in ROS2.

Reimplemented in McapBag, and ROS2Bag.

Definition at line 253 of file api.py.

◆ get_start_time()

get_start_time (   self)

Returns the start time of the bag, as UNIX timestamp, or None if bag empty.

Reimplemented in EmbagReader, McapBag, ROS1Bag, and ROS2Bag.

Definition at line 221 of file api.py.

◆ get_topic_info()

get_topic_info (   self,
  counts = True 
)

Returns topic and message type metainfo as {(topic, typename, typehash): count}.

Parameters
countsif false, counts may be returned as None if lookup is costly

Reimplemented in EmbagReader, McapBag, ROS1Bag, and ROS2Bag.

Definition at line 234 of file api.py.

◆ get_type_and_topic_info()

get_type_and_topic_info (   self,
  topic_filters = None 
)

Returns thorough metainfo on topic and message types.

Parameters
topic_filterslist of topics or a single topic to filter returned topics-dict by, if any
Returns
TypesAndTopicsTuple(msg_types, topics) namedtuple, msg_types as dict of {typename: typehash}, topics as a dict of {topic: TopicTuple() namedtuple}.

Reimplemented in EmbagReader, McapBag, and ROS2Bag.

Definition at line 245 of file api.py.

◆ open()

open (   self)

Opens the bag file if not already open.

Reimplemented in EmbagReader, McapBag, ROS1Bag, and ROS2Bag.

Definition at line 307 of file api.py.

◆ read_messages()

read_messages (   self,
  topics = None,
  start_time = None,
  end_time = None,
  raw = False,
**  __ 
)

Yields messages from the bag, optionally filtered by topic and timestamp.

Parameters
topicslist of topics or a single topic to filter by, if any
start_timeearliest timestamp of message to return, as ROS time or convertible
(int/float/duration/datetime/decimal)
end_timelatest timestamp of message to return, as ROS time
(int/float/duration/datetime/decimal)
rawif true, then returned messages are tuples of
(typename, bytes, typehash, typeclass)
or (typename, bytes, typehash, position, typeclass), depending on file format
Returns
BagMessage namedtuples of (topic, message, timestamp as ROS time)

Reimplemented in EmbagReader, McapBag, ROS2Bag, and ROS1Bag.

Definition at line 291 of file api.py.

◆ write()

write (   self,
  topic,
  msg,
  t = None,
  raw = False,
**  kwargs 
)

Writes a message to the bag.

Parameters
topicname of topic
msgROS message
tmessage timestamp if not using current wall time, as ROS time or convertible (int/float/duration/datetime/decimal)
rawif true, msg is in raw format, (typename, bytes, typehash, typeclass)
kwargsROS version-specific arguments, like connection_header for ROS1 or qoses for ROS2

Reimplemented in McapBag, ROS1Bag, and ROS2Bag.

Definition at line 304 of file api.py.

Member Data Documentation

◆ BagMessage

BagMessage = collections.namedtuple("BagMessage", "topic message timestamp")
static

Returned from read_messages() as (topic name, ROS message, ROS timestamp object).

Definition at line 101 of file api.py.

◆ MODES

tuple MODES = ("r", "w", "a")
static

Supported opening modes, overridden in subclasses.

Definition at line 112 of file api.py.

◆ next

next
static

Definition at line 137 of file api.py.

◆ STREAMABLE

bool STREAMABLE = True
static

Whether bag supports reading or writing stream objects, overridden in subclasses.

Definition at line 115 of file api.py.

◆ TopicTuple

TopicTuple
static
Initial value:
= collections.namedtuple("TopicTuple", ["msg_type", "message_count",
"connections", "frequency"])

Returned from get_type_and_topic_info() as (typename, message count, connection count, median frequency).

Definition at line 105 of file api.py.

◆ TypesAndTopicsTuple

TypesAndTopicsTuple = collections.namedtuple("TypesAndTopicsTuple", ["msg_types", "topics"])
static

Returned from get_type_and_topic_info() as ({typename: typehash}, {topic name: TopicTuple}).

Definition at line 109 of file api.py.

Property Documentation

◆ closed

closed = property
static

Returns whether file is closed.

Definition at line 348 of file api.py.

◆ filename

filename = property
static

Returns bag file path.

Definition at line 327 of file api.py.

◆ mode

mode = property
static

Returns file open mode.

Definition at line 341 of file api.py.

◆ size

size = property
static

Returns current file size in bytes.

Definition at line 334 of file api.py.

◆ stop_on_error

stop_on_error = property
static

Whether raising read error on unknown message type (ROS2 SQLite .db3 specific).

Definition at line 355 of file api.py.

◆ topics

topics = property
static

Returns the list of topics in bag, in alphabetic order.

Definition at line 320 of file api.py.


The documentation for this class was generated from the following file: