From fc590051453c187cbaeddb9bfb043071a1650df8 Mon Sep 17 00:00:00 2001 From: Mathis Hocke <mathis.hocke@fu-berlin.de> Date: Thu, 1 Sep 2022 16:21:00 +0200 Subject: [PATCH] Show optional debug info in terminal --- src/robofish/io/file.py | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/src/robofish/io/file.py b/src/robofish/io/file.py index 6029cfb..bdef232 100644 --- a/src/robofish/io/file.py +++ b/src/robofish/io/file.py @@ -1046,12 +1046,18 @@ class File(h5py.File): border = patches.Polygon(border_vertices.T, facecolor="w", zorder=-1) - def title(file_frame: int) -> str: - """Search for datasets containing text for displaying it in the video""" + if options["show_text"] and not video_path: + print(self) + + def get_text(file_frame: int) -> str: + """Search for datasets containing text for displaying it in the terminal""" output = [] + keys = ["target_fish_ids"] for e in self.entities: for key, val in e.items(): - if val.dtype == object and type(val[0]) == bytes: + if key in keys: + output.append(f"{e.name}.{key}='{val[file_frame]}'") + elif val.dtype == object and type(val[0]) == bytes: output.append(f"{e.name}.{key}='{val[file_frame].decode()}'") return ", ".join(output) @@ -1154,8 +1160,12 @@ class File(h5py.File): self.middle_of_swarm[1] - self.view_size / 2, self.middle_of_swarm[1] + self.view_size / 2, ) - if options["show_text"]: - ax.set_title(title(file_frame)) + if options["show_text"] and not video_path: + terminal_width = shutil.get_terminal_size((80, 20)).columns + print( + f"{get_text(file_frame)[:terminal_width]:<{terminal_width}}", + end="\r", + ) if options["render_goals"]: goal = get_goal(file_frame) -- GitLab