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

grepros library interface. More...

Functions

 grep (args=None, **kwargs)
 Yields matching messages from specified source.
 
 init (args=None, **kwargs)
 Initializes ROS version bindings, loads all built-in plugins if dependencies available.
 
 sink (args=None, **kwargs)
 Convenience for creating a Sink instance from arguments, MultiSink if several outputs.
 
 source (args=None, **kwargs)
 Convenience for creating a Source instance from arguments.
 

Detailed Description

grepros library interface.

Source classes:

  • AppSource: produces messages from iterable or pushed data
  • BagSource: produces messages from ROS bagfiles
  • LiveSource: produces messages from live ROS topics

Sink classes:

  • AppSink: provides messages to callback function
  • BagSink: writes messages to bagfile
  • ConsoleSink: prints messages to console
  • CsvSink: writes messages to CSV files, each topic to a separate file
  • HtmlSink: writes messages to an HTML file
  • LiveSink: publishes messages to ROS topics
  • McapSink: writes messages to MCAP file
  • MultiSink: combines any number of sinks
  • ParquetSink: writes messages to Apache Parquet files
  • PostgresSink: writes messages to a Postgres database
  • SqliteSink: writes messages to an SQLite database
  • SqlSink: writes SQL schema file for message type tables and topic views

Bag: generic bag interface. Scanner: ROS message grepper.

Format-specific bag classes:

  • ROS1Bag: ROS1 bag reader and writer in .bag format
  • ROS2Bag: ROS2 bag reader and writer in .db3 SQLite format
  • EmbagReader: ROS1 bag reader using the embag library
  • McapBag: ROS1/ROS2 bag reader and writer in MCAP format

Output sink write_options arguments can be given with underscores instead of dashes, e.g. "rollover_size" instead of "rollover-size".

Function Documentation

◆ grep()

grep (   args = None,
**  kwargs 
)

Yields matching messages from specified source.

Initializes grepros if not already initialized.

Read from bagfiles: grep(file="2022-10-*.bag", pattern="cpu").

Read from live topics: grep(live=True, pattern="cpu").

Parameters
argsarguments as namespace or dictionary, case-insensitive; or a single path as the ROS bagfile to read, or one or more Bag instances, or a Source instance
kwargsany and all arguments as keyword overrides, case-insensitive

Bag source:

Parameters
args.filenames of ROS bagfiles to read if not all in directory
args.pathpaths to scan if not current directory
args.recurserecurse into subdirectories when looking for bagfiles
args.decompressdecompress archived bags to file directory
args.reindexmake a copy of unindexed bags and reindex them (ROS1 only)
args.orderby"topic" or "type" if any to group results by
args.timescaleemit messages on original timeline from first message at given rate, 0 disables
args.timescale_emissionstart timeline from first matched message not first in bag
args.bagone or more Bag instances

Live source:

Parameters
args.livewhether reading messages from live ROS topics
args.queue_size_insubscriber queue size (default 10)
args.ros_time_instamp messages with ROS time instead of wall time

App source:

Parameters
args.appwhether reading messages from iterable or pushed data; may contain the iterable itself
args.iterableiterable yielding (topic, msg, stamp) or (topic, msg); yielding None signals end of content Any source:
args.topicROS topics to read if not all
args.typeROS message types to read if not all
args.skip_topicROS topics to skip
args.skip_typeROS message types to skip
args.start_timeearliest timestamp of messages to read
args.end_timelatest timestamp of messages to read
args.start_indexmessage index within topic to start from
args.end_indexmessage index within topic to stop at
args.nth_messageread every Nth message in topic, starting from first
args.nth_intervalminimum time interval between messages in topic, as seconds or ROS duration
args.select_fieldmessage fields to use in matching if not all
args.noselect_fieldmessage fields to skip in matching
args.uniqueemit messages that are unique in topic (select_field and noselect_field apply if specified)
args.conditionPython expressions that must evaluate as true for message to be processable, see ConditionMixin

Search‍:

Parameters
args.patternpattern(s) to find in message field values
args.fixed_stringpattern contains ordinary strings, not regular expressions
args.caseuse case-sensitive matching in pattern
args.invertselect messages not matching pattern
args.expressionpattern(s) are a logical expression like 'this AND (this2 OR NOT "skip this")', with elements as patterns to find in message fields
args.nth_matchemit every Nth match in topic, starting from first
args.max_countnumber of matched messages to emit (per file if bag input)
args.max_per_topicnumber of matched messages to emit from each topic
args.max_topicsnumber of topics to print matches from
args.beforenumber of messages of leading context to emit before match
args.afternumber of messages of trailing context to emit after match
args.contextnumber of messages of leading and trailing context to emit around match
args.highlighthighlight matched values
args.match_wrapperstring to wrap around matched values, both sides if one value, start and end if more than one, or no wrapping if zero values
Returns
GrepMessage namedtuples
of (topic, message, timestamp, match, index)

Definition at line 159 of file library.py.

◆ init()

init (   args = None,
**  kwargs 
)

Initializes ROS version bindings, loads all built-in plugins if dependencies available.

Parameters
args
args.pluginone or more extra plugins to load, as full names or instances of Python module/class
kwargsany and all arguments as keyword overrides, case-insensitive

Definition at line 353 of file library.py.

◆ sink()

sink (   args = None,
**  kwargs 
)

Convenience for creating a Sink instance from arguments, MultiSink if several outputs.

Initializes grepros if not already initialized.

Parameters
argsarguments as namespace or dictionary, case-insensitive; or a single item as sink target like bag filename
kwargsany and all arguments as keyword overrides, case-insensitive
args.appprovide messages to given callback function
args.consoleprint matches to console
args.publishpublish matches to live topics
args.writefile or other target like Postgres database to write, as "target", or ["target", dict(format="format", ..)] or [[..target1..], [..target2..], ..]
args.write_optionsformat-specific options like {"overwrite": whether to overwrite existing file (default false)}

Console sink:

Parameters
args.line_prefixprint source prefix like bag filename on each message line
args.max_field_linesmaximum number of lines to print per field
args.start_linemessage line number to start output from
args.end_linemessage line number to stop output at
args.max_message_linesmaximum number of lines to output per message
args.lines_around_matchnumber of message lines around matched fields to output
args.matched_fields_onlyoutput only the fields where match was found
args.wrap_widthcharacter width to wrap message YAML output at
args.match_wrapperstring to wrap around matched values, both sides if one value, start and end if more than one, or no wrapping if zero values

Console / HTML sink:

Parameters
args.colorFalse or "never" for not using colors in replacements
args.highlighthighlight matched values (default true)
args.emit_fieldmessage fields to emit if not all
args.noemit_fieldmessage fields to skip in output
args.max_field_linesmaximum number of lines to output per field
args.start_linemessage line number to start output from
args.end_linemessage line number to stop output at
args.max_message_linesmaximum number of lines to output per message
args.lines_around_matchnumber of message lines around matched fields to output
args.matched_fields_onlyoutput only the fields where match was found
args.wrap_widthcharacter width to wrap message YAML output at
args.match_wrapperstring to wrap around matched values, both sides if one value, start and end if more than one, or no wrapping if zero values

Topic sink:

Parameters
args.queue_size_outpublisher queue size (default 10)
args.publish_prefixoutput topic prefix, prepended to input topic
args.publish_suffixoutput topic suffix, appended to output topic
args.publish_fixnamesingle output topic name to publish to, overrides prefix and suffix if given

App sink:

Parameters
args.emitcallback(topic, msg, stamp, highlighted msg, index in topic) if any
args.metaemitcallback(metadata dict) if any, invoked before first emit from source batch

Any sink:

Parameters
args.metawhether to print metainfo
args.verbosewhether to print debug information

Definition at line 324 of file library.py.

◆ source()

source (   args = None,
**  kwargs 
)

Convenience for creating a Source instance from arguments.

Initializes grepros if not already initialized.

Parameters
argsarguments as namespace or dictionary, case-insensitive; or a single path as the ROS bagfile to read
kwargsany and all arguments as keyword overrides, case-insensitive
args.fileone or more names of ROS bagfiles to read from
args.liveread messages from live ROS topics instead
args.appread messages from iterable or pushed data instead; may contain the iterable itself

Bag source:

Parameters
args.filenames of ROS bagfiles to read if not all in directory
args.pathpaths to scan if not current directory
args.recurserecurse into subdirectories when looking for bagfiles
args.orderby"topic" or "type" if any to group results by
args.decompressdecompress archived bags to file directory
args.reindexmake a copy of unindexed bags and reindex them (ROS1 only)
args.timescaleemit messages on original timeline from first message at given rate, 0 disables
args.timescale_emissionstart timeline from first matched message not first in bag
args.progresswhether to print progress bar

Live source:

Parameters
args.queue_size_insubscriber queue size (default 10)
args.ros_time_instamp messages with ROS time instead of wall time
args.progresswhether to print progress bar

App source:

Parameters
args.iterableiterable yielding (topic, msg, stamp) or (topic, msg); yielding None signals end of content

Any source:

Parameters
args.topicROS topics to read if not all
args.typeROS message types to read if not all
args.skip_topicROS topics to skip
args.skip_typeROS message types to skip
args.start_timeearliest timestamp of messages to read
args.end_timelatest timestamp of messages to read
args.start_indexmessage index within topic to start from
args.end_indexmessage index within topic to stop at
args.uniqueemit messages that are unique in topic
args.select_fieldmessage fields to use for uniqueness if not all
args.noselect_fieldmessage fields to skip for uniqueness
args.nth_messageread every Nth message in topic, starting from first
args.nth_intervalminimum time interval between messages in topic, as seconds or ROS duration
args.conditionPython expressions that must evaluate as true for message to be processable, see ConditionMixin

Definition at line 241 of file library.py.