Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Provide an utility to compute partitions from a list of possibly-repeating timestamp #7333

Open
abey79 opened this issue Sep 2, 2024 · 1 comment
Labels
🐍 Python API Python logging API

Comments

@abey79
Copy link
Member

abey79 commented Sep 2, 2024

A possibly recurrent user scenario is to have data as two arrays of the same length:

  • possibly-repeating timestamps
  • matching data (e.g. points, etc.)

For the rr.send_columns API, one must prepare a list of non-repeating timestamp, and the matching "partitions", i.e. the size of the groups in the data that corresponds to each non-repeating timestamp. It's sufficiently annoying to do with numpy that this would warrant an helper, such as to make the following code more compact:

points = ... # numpy array of points
times = ... # numpy array of possibly-repeating timestamps

# indices at which `times` changes, excluding 0, including `n`
change_indices = (np.argwhere(times != np.concatenate((times[1:], [np.nan]))).T + 1).reshape(-1)

# non-repeating timestamps
non_repeating_times = times[change_indices - 1]

# partitions (e.g. size of groups corresponding to each 
partitions = np.concatenate(([change_indices[0]], np.diff(change_indices)))
assert np.sum(partitions) == len(times)

# logging

rr.send_columns(
    "/entity/path",
    [rr.TimeSecondsColumn("time", non_repeating_times)],
    [rr.components.Position3DBatch(positions).partition(partitions)]
)
@abey79 abey79 added the 🐍 Python API Python logging API label Sep 2, 2024
@abey79
Copy link
Member Author

abey79 commented Sep 3, 2024

This example includes an implementation of such a helper:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🐍 Python API Python logging API
Projects
None yet
Development

No branches or pull requests

1 participant