updated parameters and updated visualization function to better display the flow

This commit is contained in:
lbaumberger
2026-04-28 00:42:22 +02:00
parent adb1b492df
commit 6b8d5bc94c
3 changed files with 57 additions and 17 deletions
+18 -3
View File
@@ -1,4 +1,5 @@
import sys
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
from matplotlib.animation import FuncAnimation
@@ -9,6 +10,20 @@ if len(sys.argv) < 2:
df = pd.read_csv(sys.argv[1])
frames = sorted(df["time"].unique())
# Replace p.e with direction-of-next-hop: where the ped actually moves to next frame.
# Falls back to p.e for the last frame and for teleport jumps.
df = df.sort_values(["id", "time"]).reset_index(drop=True)
df["dx"] = df.groupby("id")["x"].shift(-1) - df["x"]
df["dy"] = df.groupby("id")["y"].shift(-1) - df["y"]
mag = np.sqrt(df["dx"]**2 + df["dy"]**2)
TELEPORT_THRESHOLD = 5.0 # any per-step jump larger than this is the teleport, not motion
fallback = (mag > TELEPORT_THRESHOLD) | mag.isna() | (mag < 1e-9)
df.loc[fallback, "dx"] = df.loc[fallback, "p.e.x"]
df.loc[fallback, "dy"] = df.loc[fallback, "p.e.y"]
mag = np.sqrt(df["dx"]**2 + df["dy"]**2).replace(0, 1.0)
df["dx"] = df["dx"] / mag
df["dy"] = df["dy"] / mag
fig, ax = plt.subplots(figsize=(10, 2.2))
ax.set_xlim(0, 50); ax.set_ylim(0, 10)
ax.set_aspect("equal"); ax.set_facecolor("white")
@@ -39,13 +54,13 @@ def update(t):
# Draw fresh arrows each frame
arrow_scale = 1.5 # Tune this to change arrow length visually
if len(w):
q_white = ax.quiver(w["x"], w["y"], w["p.e.x"], w["p.e.y"],
q_white = ax.quiver(w["x"], w["y"], w["dx"], w["dy"],
color="black", angles="xy", scale_units="xy",
scale=1/arrow_scale, width=0.003,
headwidth=4, headlength=5, zorder=3)
quivers.append(q_white)
if len(b):
q_black = ax.quiver(b["x"], b["y"], b["p.e.x"], b["p.e.y"],
q_black = ax.quiver(b["x"], b["y"], b["dx"], b["dy"],
color="gray", angles="xy", scale_units="xy",
scale=1/arrow_scale, width=0.003,
headwidth=4, headlength=5, zorder=3)
@@ -57,7 +72,7 @@ def update(t):
anim = FuncAnimation(fig, update, frames=frames, interval=50, blit=False)
if len(sys.argv) >= 3:
anim.save(sys.argv[2], writer="ffmpeg", fps=20)
anim.save(sys.argv[2], writer="ffmpeg", fps=5)
print(f"Saved {sys.argv[2]}")
else:
plt.show()