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

Bag factory metaclass. More...

Inheritance diagram for Bag:
Inheritance graph

Public Member Functions

 __new__ (cls, f, mode="r", reindex=False, progress=False, **kwargs)
 Returns an object for reading or writing ROS bags.
 
 __subclasshook__ (cls, C)
 
 autodetect (cls, f)
 Returns registered bag class auto-detected from file, or None.
 
- Public Member Functions inherited from BaseBag
 __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

 READER_CLASSES = set()
 Bag reader classes, as {Cls, }.
 
 WRITER_CLASSES = set()
 Bag writer classes, as {Cls, }.
 
- Static Public Attributes inherited from BaseBag
 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}).
 

Additional Inherited Members

- Properties inherited from BaseBag
 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

Bag factory metaclass.

Result is a format-specific class instance, auto-detected from file extension or content: an extended rosbag.Bag for ROS1 bags, otherwise an object with a conforming interface.

E.g. McapBag if mcap plugin loaded and file recognized as MCAP format.

User plugins can add their own format support to READER_CLASSES and WRITER_CLASSES. Classes can have a static/class method autodetect(filename) returning whether given file is in recognizable format for the plugin class.

Definition at line 381 of file api.py.

Member Function Documentation

◆ __new__()

__new__ (   cls,
  f,
  mode = "r",
  reindex = False,
  progress = False,
**  kwargs 
)

Returns an object for reading or writing ROS bags.

Suitable Bag class is auto-detected by file extension or content.

Parameters
fbag file path, or a stream object (streams not supported for ROS2 .db3 SQLite bags)
modereturn reader if "r" else writer
reindexreindex unindexed bag (ROS1 only), making a backup if indexed format
progressshow progress bar with reindexing status
kwargsadditional keyword arguments for format-specific Bag constructor, like compression for ROS1 bag

Definition at line 401 of file api.py.

◆ __subclasshook__()

__subclasshook__ (   cls,
  C 
)

Definition at line 429 of file api.py.

◆ autodetect()

autodetect (   cls,
  f 
)

Returns registered bag class auto-detected from file, or None.

Definition at line 420 of file api.py.

Member Data Documentation

◆ READER_CLASSES

READER_CLASSES = set()
static

Bag reader classes, as {Cls, }.

Definition at line 384 of file api.py.

◆ WRITER_CLASSES

WRITER_CLASSES = set()
static

Bag writer classes, as {Cls, }.

Definition at line 387 of file api.py.


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