Package rosbag :: Module bag :: Class Bag
[frames] | no frames]

Class Bag

source code

object --+
         |
        Bag

Bag serialize messages to and from a single file on disk using the bag format.

Instance Methods
 
__init__(self, f, mode='r', compression='none', chunk_threshold=786432, allow_unindexed=False, options=None, skip_index=False)
Open a bag file.
source code
 
__iter__(self) source code
 
__enter__(self) source code
 
__exit__(self, exc_type, exc_value, traceback) source code
generator of tuples of (str, genpy.Message, genpy.Time) [not raw] or (str, (str, str, str, tuple, class), genpy.Time) [raw]
read_messages(self, topics=None, start_time=None, end_time=None, connection_filter=None, raw=False)
Read messages from the bag, optionally filtered by topic, timestamp and connection details.
source code
 
flush(self)
Write the open chunk to disk so subsequent reads will read all messages.
source code
 
write(self, topic, msg, t=None, raw=False)
Write a message to the bag.
source code
 
reindex(self)
Reindexes the bag file.
source code
 
close(self)
Close the bag file.
source code
 
__str__(self)
str(x)
source code

Inherited from object: __delattr__, __format__, __getattribute__, __hash__, __new__, __reduce__, __reduce_ex__, __repr__, __setattr__, __sizeof__, __subclasshook__

Properties
  options
Get the options.
  filename
Get the filename.
  version
Get the version.
  mode
Get the mode.
  size
Get the size in bytes.
  compression
Get the compression method to use for writing.
  chunk_threshold
Get the chunk threshold to use for writing.

Inherited from object: __class__

Method Details

__init__(self, f, mode='r', compression='none', chunk_threshold=786432, allow_unindexed=False, options=None, skip_index=False)
(Constructor)

source code 

Open a bag file. The mode can be 'r', 'w', or 'a' for reading (default), writing or appending. The file will be created if it doesn't exist when opened for writing or appending; it will be truncated when opened for writing. Simultaneous reading and writing is allowed when in writing or appending mode.

Parameters:
  • f (str or file) - filename of bag to open or a stream to read from
  • mode (str) - mode, either 'r', 'w', or 'a'
  • compression (str) - compression mode, see rosbag.Compression for valid modes
  • chunk_threshold (int) - minimum number of uncompressed bytes per chunk
  • allow_unindexed (bool) - if True, allow opening unindexed bags
  • options (dict) - the bag options (currently: compression and chunk_threshold)
  • skip_index (bool) - if True, don't read the connection index records on open [2.0+]
Raises:
Overrides: object.__init__

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

source code 

Read messages from the bag, optionally filtered by topic, timestamp and connection details.

Parameters:
  • topics (list(str) or str) - list of topics or a single topic [optional]
  • start_time (genpy.Time) - earliest timestamp of message to return [optional]
  • end_time (genpy.Time) - latest timestamp of message to return [optional]
  • connection_filter (function taking (topic, datatype, md5sum, msg_def, header) and returning bool) - function to filter connections to include [optional]
  • raw (bool) - if True, then generate tuples of (datatype, (data, md5sum, position), pytype)
Returns: generator of tuples of (str, genpy.Message, genpy.Time) [not raw] or (str, (str, str, str, tuple, class), genpy.Time) [raw]
generator of (topic, message, timestamp) tuples for each message in the bag file

flush(self)

source code 

Write the open chunk to disk so subsequent reads will read all messages.

Raises:
  • ValueError - if bag is closed

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

source code 

Write a message to the bag.

Parameters:
  • topic (str) - name of topic
  • msg (Message or tuple of raw message data) - message to add to bag, or tuple (if raw)
  • t (genpy.Time) - ROS time of message publication, if None specifed, use current time [optional]
  • raw (bool) - if True, msg is in raw format, i.e. (msg_type, serialized_bytes, md5sum, pytype)
Raises:
  • ValueError - if arguments are invalid or bag is closed

reindex(self)

source code 

Reindexes the bag file. Yields position of each chunk for progress.

close(self)

source code 

Close the bag file. Closing an already closed bag does nothing.

__str__(self)
(Informal representation operator)

source code 

str(x)

Overrides: object.__str__
(inherited documentation)

Property Details

options

Get the options.

Get Method:
unreachable.options(self) - Get the options.

filename

Get the filename.

Get Method:
unreachable.filename(self) - Get the filename.

version

Get the version.

Get Method:
unreachable.version(self) - Get the version.

mode

Get the mode.

Get Method:
unreachable.mode(self) - Get the mode.

size

Get the size in bytes.

Get Method:
unreachable.size(self) - Get the size in bytes.

compression

Get the compression method to use for writing.

Get Method:
_get_compression(self) - Get the compression method to use for writing.
Set Method:
_set_compression(self, compression) - Set the compression method to use for writing.

chunk_threshold

Get the chunk threshold to use for writing.

Get Method:
_get_chunk_threshold(self) - Get the chunk threshold to use for writing.
Set Method:
_set_chunk_threshold(self, chunk_threshold) - Set the chunk threshold to use for writing.