|
| 1 | +#!/usr/bin/env python3 |
| 2 | +"""Demonstrates basic usage of the dataframe APIs.""" |
| 3 | + |
| 4 | +from __future__ import annotations |
| 5 | + |
| 6 | +import argparse |
| 7 | + |
| 8 | +import pyarrow as pa |
| 9 | +import rerun as rr |
| 10 | + |
| 11 | +DESCRIPTION = """ |
| 12 | +Usage: python dataframe_query.py <path_to_rrd> [entity_path_filter] |
| 13 | +
|
| 14 | +This example will query for the first 10 rows of data in your recording of choice, |
| 15 | +and display the results as a table in your terminal. |
| 16 | +
|
| 17 | +You can use one of your recordings, or grab one from our hosted examples, e.g.: |
| 18 | + curl 'https://app.rerun.io/version/latest/examples/dna.rrd' -o - > /tmp/dna.rrd |
| 19 | +
|
| 20 | +The results can be filtered further by specifying an entity filter expression: |
| 21 | + {bin_name} my_recording.rrd /skeleton/left_shoulder/** |
| 22 | +""".strip() |
| 23 | + |
| 24 | + |
| 25 | +def query(path_to_rrd: str, entity_path_filter: str) -> None: |
| 26 | + recording = rr.dataframe.load_recording(path_to_rrd) |
| 27 | + view = recording.view(index="log_time", contents=entity_path_filter) |
| 28 | + batches = view.select() |
| 29 | + |
| 30 | + table = pa.Table.from_batches(batches, batches.schema) |
| 31 | + table = table.slice(0, 10) |
| 32 | + print(table.to_pandas()) |
| 33 | + |
| 34 | + |
| 35 | +def main() -> None: |
| 36 | + parser = argparse.ArgumentParser(description=DESCRIPTION) |
| 37 | + parser.add_argument("path_to_rrd", type=str, help="Path to the .rrd file") |
| 38 | + parser.add_argument( |
| 39 | + "entity_path_filter", type=str, nargs="?", default="/**", help="Optional entity path filter expression" |
| 40 | + ) |
| 41 | + args = parser.parse_args() |
| 42 | + |
| 43 | + query(args.path_to_rrd, args.entity_path_filter) |
| 44 | + |
| 45 | + |
| 46 | +if __name__ == "__main__": |
| 47 | + main() |
0 commit comments