Skip to content
Open
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
43 changes: 24 additions & 19 deletions tribev2/plotting/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -376,13 +376,16 @@ def plot_stimuli(

TEXT_KEY, SOUND_KEY, VIDEO_KEY = "Text", "Audio", "Video"

# Audio is optional (e.g., silent screen recordings produce no audio).
audio = get_audio(
segments[0], stop_offset=(len(segments) - 1) * segments[0].duration
)
soundarray = audio.to_soundarray().mean(axis=1)
axes[SOUND_KEY].plot(soundarray, color="k")
axes[SOUND_KEY].set_xlim(0, len(soundarray))
axes[SOUND_KEY].axis("off")
if audio is not None:
soundarray = audio.to_soundarray().mean(axis=1)
axes[SOUND_KEY].plot(soundarray, color="k")
axes[SOUND_KEY].set_xlim(0, len(soundarray))
if SOUND_KEY in axes:
axes[SOUND_KEY].axis("off")
axes[TEXT_KEY].axis("off")
full_start, full_duration = (
segments[0].start,
Expand Down Expand Up @@ -411,22 +414,24 @@ def plot_stimuli(
ax.set_xlim(-margin, img.shape[1] + margin)
ax.set_ylim(img.shape[0] + margin, -margin)
ax.axis("off")
# Text/words are optional (silent or non-speech clips have no word events).
events = segment.events
words = events[events.type == "Word"]
for word in words.itertuples():
if word.start < full_start:
continue
axes[TEXT_KEY].text(
(word.start - full_start) / full_duration,
0.5,
word.text,
color="k",
transform=axes[TEXT_KEY].transAxes,
ha="center",
va="center",
rotation=45,
fontsize=10,
)
if events is not None and "type" in events.columns:
words = events[events.type == "Word"]
for word in words.itertuples():
if word.start < full_start:
continue
axes[TEXT_KEY].text(
(word.start - full_start) / full_duration,
0.5,
word.text,
color="k",
transform=axes[TEXT_KEY].transAxes,
ha="center",
va="center",
rotation=45,
fontsize=10,
)

def plot_timesteps_mp4(
self,
Expand Down