<jupyter_start><jupyter_text>Setup geometry & measurement area<jupyter_code>geometry = pygeos.polygons([(-9, 0), (-9, 5), (9, 5), (9, 0), (-9, 0)])
geometry_pita = Geometry(geometry)

ma = pygeos.polygons([(-1.5, 0), (-1.5, 5), (1.5, 5), (1.5, 0), (-1.5, 0)])
ml = pygeos.linestrings([(0, 0), (0, 5)])
ml = pygeos.linestrings([(-2.25, 0), (4, 0)])

direction = np.array([-1, 0])

# traj = parse_trajectory("demos/uni-directional/traj_UNI_CORR_500_01.txt")
traj = parse_trajectory("demos/bottleneck/traj.txt")<jupyter_output><empty_output><jupyter_text>Density  Classic density<jupyter_code>from analyzer.methods.density_calculator import compute_classic_density

classic_density = compute_classic_density(traj.data, ma)
classic_density
classic_density.reset_index().plot.line(x="frame", y="classic density")<jupyter_output><empty_output><jupyter_text>Voronoi density<jupyter_code>from analyzer.methods.density_calculator import compute_voronoi_density

density_voronoi, individual = compute_voronoi_density(traj.data, ma, geometry_pita)
density_voronoi
individual
density_voronoi.reset_index().plot.line(x="frame", y="voronoi density")
density_voronoi_cutoff, individual_cutoff = compute_voronoi_density(
    traj.data, ma, geometry_pita, 1.0, 12
)
density_voronoi_cutoff.reset_index().plot.line(x="frame", y="voronoi density")<jupyter_output><empty_output><jupyter_text>Comparision<jupyter_code>fig = plt.figure(figsize=(10, 6))
plt.plot(
    classic_density.reset_index().frame,
    classic_density["classic density"].values,
    label="classic",
    lw=3,
)
plt.plot(
    density_voronoi.reset_index().frame, density_voronoi["voronoi density"], label="voronoi", lw=3
)
plt.plot(
    density_voronoi_cutoff.reset_index().frame,
    density_voronoi_cutoff["voronoi density"],
    label="voronoi cutoff",
    lw=3,
)
plt.xlabel("frame")
plt.ylabel("rho / 1/m^2")
plt.legend()
plt.grid()
plt.show()<jupyter_output><empty_output><jupyter_text>Plot voronoi cells<jupyter_code>frame_start = 1200

for frame in range(frame_start, frame_start + 100, 20):
    fig = plt.figure(figsize=(15, 20))
    ax1 = fig.add_subplot(121, aspect="equal")

    ax1.plot(*pygeos.to_shapely(geometry).exterior.xy, color="k")
    ax1.plot(*pygeos.to_shapely(ma).exterior.xy, color="k")

    df_frame = individual[individual.frame == frame]
    df_frame = pd.merge(traj.data, df_frame, on=["ID", "frame"])
    for _, row in df_frame.iterrows():
        p = ax1.plot(*pygeos.to_shapely(row[6]).exterior.xy)
        ax1.scatter(row[2], row[3])
        ax1.add_patch(
            PolygonPatch(
                pygeos.to_shapely(row[6]), alpha=0.1, zorder=2, fc=p[-1].get_color(), ec="none"
            )
        )
    ax1.set_xlabel("x")
    ax1.set_ylabel("y")

    ax2 = fig.add_subplot(122, aspect="equal")

    ax2.plot(*pygeos.to_shapely(geometry).exterior.xy, color="k")
    ax2.plot(*pygeos.to_shapely(ma).exterior.xy, color="k")

    df_frame_cutoff = individual_cutoff[individual_cutoff.frame == frame]
    df_frame_cutoff = pd.merge(traj.data, df_frame_cutoff, on=["ID", "frame"])
    for _, row in df_frame_cutoff.iterrows():
        p = ax2.plot(*pygeos.to_shapely(row[6]).exterior.xy)
        ax2.scatter(row[2], row[3])
        ax2.add_patch(
            PolygonPatch(
                pygeos.to_shapely(row[6]), alpha=0.1, zorder=2, fc=p[-1].get_color(), ec="none"
            )
        )
    ax2.set_xlabel("x")
    ax2.set_ylabel("y")
    fig.tight_layout()
    plt.show()<jupyter_output><empty_output><jupyter_text>Velocity<jupyter_code>from analyzer.methods.velocity_calculator import compute_individual_velocity

individual_speed = compute_individual_velocity(traj.data, traj.frame_rate, 5)
individual_speed
individual_speed.reset_index().plot.scatter(x="frame", y="speed")
individual_speed_direction = compute_individual_velocity(traj.data, traj.frame_rate, 5, direction)
individual_speed_direction
individual_speed.reset_index().plot.scatter(x="frame", y="speed")<jupyter_output><empty_output><jupyter_text>Mean speed (all)<jupyter_code>from analyzer.methods.velocity_calculator import compute_mean_velocity_per_frame

mean_speed, individual_speed = compute_mean_velocity_per_frame(traj.data, traj.frame_rate, 10)
mean_speed
mean_speed.reset_index().plot.scatter(x="frame", y="speed")
mean_speed_direction, individual_speed_direction = compute_mean_velocity_per_frame(
    traj.data, traj.frame_rate, 5, direction
)
mean_speed_direction<jupyter_output><empty_output><jupyter_text>Mean speed (in measurement area)<jupyter_code>from analyzer.methods.method_utils import get_peds_in_area
from analyzer.methods.velocity_calculator import compute_mean_velocity_per_frame

peds_in_area = get_peds_in_area(traj.data, ma)
mean_speed_area, individual_speed_area = compute_mean_velocity_per_frame(
    peds_in_area, traj.frame_rate, 5
)
mean_speed_area.reset_index().plot.scatter(x="frame", y="speed")
mean_speed_area_direction, individual_speed_area_direction = compute_mean_velocity_per_frame(
    peds_in_area, traj.frame_rate, 5, direction
)
mean_speed_area_direction.reset_index().plot.scatter(x="frame", y="speed")<jupyter_output><empty_output><jupyter_text>Voronoi speed<jupyter_code>from analyzer.methods.density_calculator import (
    _compute_individual_voronoi_polygons,
    _compute_intersecting_polygons,
)
from analyzer.methods.velocity_calculator import (
    compute_individual_velocity,
    compute_voronoi_velocity,
)
individual_voronoi = _compute_individual_voronoi_polygons(traj.data, geometry_pita)
intersecting_voronoi = _compute_intersecting_polygons(individual_voronoi, ma)
voronoi_velocity, individual_velocity = compute_voronoi_velocity(
    traj.data, intersecting_voronoi, traj.frame_rate, 5, ma
)
voronoi_velocity
voronoi_velocity.reset_index().plot.scatter(x="frame", y="voronoi speed")
voronoi_velocity_direction = compute_voronoi_velocity(
    traj.data, intersecting_voronoi, traj.frame_rate, 5, ma, direction
)
voronoi_velocity_direction<jupyter_output><empty_output><jupyter_text>Comparison mean velocity vs voronoi velocity<jupyter_code>fig = plt.figure(figsize=(8, 6))
plt.scatter(voronoi_velocity.reset_index().frame, voronoi_velocity, label="voronoi")
plt.scatter(
    voronoi_velocity_direction.reset_index().frame,
    voronoi_velocity_direction,
    label="voronoi direction",
)
plt.scatter(mean_speed_area.reset_index().frame, mean_speed_area, label="classic")
plt.scatter(
    mean_speed_area_direction.reset_index().frame,
    mean_speed_area_direction,
    label="classic direction",
)
plt.xlabel("frame")
plt.ylabel("v / m/s")
plt.legend()
plt.grid()
plt.show()<jupyter_output><empty_output><jupyter_text>Flow  N-t diagram<jupyter_code>from analyzer.methods.flow_calculator import compute_n_t

nt, crossing = compute_n_t(traj.data, ml, traj.frame_rate)
nt.plot(x="Time [s]")<jupyter_output><empty_output><jupyter_text>Flow<jupyter_code>from analyzer.methods.flow_calculator import compute_flow

delta_t = 100
flow = compute_flow(nt, crossing, individual_speed, delta_t, traj.frame_rate)
flow<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.13116846284741918, 'fraction_numerical': 0.016874645490640952, 'mean_word_length': 6.5111821086261985, 'pattern_counts': {'":': 0, '<': 49, '<?xml version=': 0, '>': 49, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 1, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '12', 'dir': 'jupyter-structured-clean-dedup', 'id': '430011', 'license': 'MIT', 'n_tokens_mistral': 2779, 'n_tokens_neox': 2612, 'n_words': 347, 'path': 'usage.ipynb', 'repo_name': 'schroedtert/jpsreport-python', 'size': '7052'}