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

feat: show events #37

Merged
merged 2 commits into from
Jun 28, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions pyorerun/rrc3d.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ def rrc3d(
show_floor: bool = True,
show_force_plates: bool = True,
show_forces: bool = True,
show_events: bool = True,
down_sampled_forces: bool = False,
video: str | tuple[str, ...] = None,
video_crop_mode: str = "from_c3d",
Expand All @@ -35,6 +36,8 @@ def rrc3d(
If True, show the force plates.
show_forces: bool
If True, show the forces.
show_events: bool
If True, show the events, as log entries.
down_sampled_forces: bool
If True, down sample the force data to align with the marker data.
If False, the force data will be displayed at their original frame rate, It may get slower when loading the data.
Expand Down Expand Up @@ -113,13 +116,38 @@ def rrc3d(
multi_phase_rerun = MultiFrameRatePhaseRerun(phase_reruns)
multi_phase_rerun.rerun(filename, notebook=notebook)

if show_events:
try:
set_event_as_log(c3d_file)
except:
raise NotImplementedError(
"The events feature is still experimental and may not work properly. " "Set show_events=False."
)

if marker_trajectories:
# todo: find a better way to display curves but hacky way ok for now
for frame, t in enumerate(t_span):
rr.set_time_seconds("stable_time", t)
phase_rerun.xp_data.xp_data[0].to_rerun_curve(frame)


def set_event_as_log(c3d_file: str) -> None:
c3d_file = c3d_file_format(c3d_file)
times = c3d_file["parameters"]["EVENT"]["TIMES"]["value"][1, :]
labels = c3d_file["parameters"]["EVENT"]["LABELS"]["value"]
descriptions = c3d_file["parameters"]["EVENT"]["DESCRIPTIONS"]["value"]
context = c3d_file["parameters"]["EVENT"]["CONTEXTS"]["value"]

for i, (time, label, description, context) in enumerate(zip(times, labels, descriptions, context)):
rr.set_time_seconds("stable_time", time)
rr.log(
f"events",
rr.TextLog(
f"{label}_{context} - {description}",
),
)


def max_xy_coordinate_span_by_markers(pyomarkers: PyoMarkers) -> float:
"""Return the max span of the x and y coordinates of the markers."""
min_pyomarkers = np.nanmin(np.nanmin(pyomarkers.to_numpy(), axis=2), axis=1)
Expand Down
Loading