Currently job artifacts in CI/CD pipelines on LRZ GitLab never expire. Starting from Wed 26.1.2022 the default expiration time will be 30 days (GitLab default). Currently existing artifacts in already completed jobs will not be affected by the change. The latest artifacts for all jobs in the latest successful pipelines will be kept. More information: https://gitlab.lrz.de/help/user/admin_area/settings/continuous_integration.html#default-artifacts-expiration

Commit 387a0b00 authored by Benedikt Zoennchen's avatar Benedikt Zoennchen
Browse files

small changes to the trajectory notebook.

parent 1d700175
%% Cell type:code id: tags:
``` python
# expand the cell of the notebook
import json
import gc
import numpy as np
import pandas as pd
import math
import matplotlib as mpl
import matplotlib.pyplot as plt
......@@ -177,12 +178,13 @@
%% Cell type:code id: tags:
``` python
# Sum up all measured time deltas of a pedestrian to get the final evacuation time
trajectoriesReal["timeDelta"] = trajectoriesReal["endTime"] - trajectoriesReal["startTime"]
evacuation_time = trajectoriesReal.groupby(["pedestrianId"])["timeDelta"].sum()
copy = trajectoriesReal.copy(deep=True)
copy["timeDelta"] = copy["endTime"] - copy["startTime"]
evacuation_time = copy.groupby(["pedestrianId"])["timeDelta"].sum()
# trajectories starting from left
cut_minX = trajectoriesReal[trajectoriesReal["endX"] < 15].groupby(["pedestrianId"])["endX"].min().max()
# trajectories starting from right
......@@ -309,12 +311,12 @@
df = df.append(df_head, ignore_index=True)
return df
def cuttail_trajectory_by(trajectory, xmin, xmax):
#i1 = trajectory[np.logical_and(trajectory.endX >= xmax, trajectory.startX < xmax)].index.max()
i1 = trajectory[trajectory.endX >= xmax].index.max()
i2 = trajectory[trajectory.endX <= xmin].index.max()
i1 = trajectory[np.logical_or(trajectory.endX >= xmax, trajectory.startX is np.nan)].index.max()
i2 = trajectory[np.logical_or(trajectory.endX <= xmin, trajectory.startX is np.nan)].index.max()
#assert (i1 is np.nan and i2 is not np.nan) or (i1 is not np.nan and i2 is np.nan)
x = xmax if i2 is np.nan or (i1 is not np.nan and i1 > i2) else xmin
i = i1 if x == xmax else i2
i = i+1
# cut the footstep at the tail to exactly fit xmin or xmax
......@@ -330,11 +332,17 @@
r = (x - fs["startX"]) / (fs["endX"] - fs["startX"])
end = start + (d * r)
time = fs["endTime"] - fs["startTime"]
endTime = fs["startTime"] + (time * r)
distance = np.linalg.norm(end - start)
velocity = distance / (endTime - startTime)
if abs(endTime - startTime) < 0.00001:
if distance < 0.00001:
velocity = 0
else:
raise exception
else:
velocity = distance / (endTime - startTime)
df = trajectory.loc[i+1:]
llist = [[fs["pedestrianId"],fs["startX"],fs["startY"],fs["startTime"],end[0],end[1],endTime,distance,velocity]]
df_tail = pd.DataFrame(llist, columns=['pedestrianId','startX','startY','startTime','endX','endY','endTime','distance','velocity'])
df_tail = df_tail.append(df, ignore_index=True)
......@@ -361,14 +369,15 @@
traj = get_trajectory(2, trajectoriesReal)
ts = traj[traj.endX > 22].index.max()
ts
#cut(trajectoriesReal)
#cuttail_by(trajectoriesReal, 13, 22).head()
cuttail_by(trajectoriesReal, cut_minX, cut_maxX).head()
#cuthead_by(trajectoriesReal, 0, 4).tail()
#traj.loc[100]
#trajectoriesReal.tail()
trajectoriesReal.head()
```
%% Cell type:markdown id: tags:
# Helper methods to compute different metrices
......@@ -642,11 +651,11 @@
The following code plots the mean (over all agents / pedestrians) velocity at $t = 0, 0.5, \ldots 70$ and the corresponding standard deviation.
%% Cell type:code id: tags:
``` python
times = np.arange(0, 70, 0.2)
times = np.arange(0, 70, 5)
velocity1 = list(map(lambda t: mean_velocity_at(t, c_real_trajectories), times))
std1 = list(map(lambda t: get_trajectories(t, c_real_trajectories)['velocity'].std(),times))
velocity2 = list(map(lambda t: mean_velocity_at(t, c_sim_trajecotories), times))
std2 = list(map(lambda t: get_trajectories(t, c_sim_trajecotories)['velocity'].std(),times))
......@@ -684,35 +693,42 @@
The following code plots the density inside the measurement area at $t = 0, 0.5, \ldots 70$ and the corresponding standard deviation.
%% Cell type:code id: tags:
``` python
%%prun
#gc.disable()
print(len(times))
gc.disable()
def contains(x,y,rect):
#ma = mpl.patches.Rectangle((16.3,6.0), 2.4, 2.0)
return x >= rect.get_x() and y >= rect.get_y() and x <= rect.get_x() + rect.get_width() and y <= rect.get_y() + rect.get_height()
def filter_by_time_and_place(t, rect, trajectories):
"""returns a subset of trajectories i.e. at most one footstep for each pedestrian / agent such that the footstep the position (x,y) is the position of the
agent at the time t contained in the rectanlge rect. Two new colums will be added for x and y."""
traj = get_trajectories(t, trajectories)
traj.loc[:,'x'] = traj['startX'] + (traj['endX'] - traj['startX']) * (t - traj['startTime']) / (traj['endTime'] - traj['startTime'])
traj.loc[:,'y'] = traj['startY'] + (traj['endY'] - traj['startY']) * (t - traj['startTime']) / (traj['endTime'] - traj['startTime'])
traj.loc[:,'x'] = traj.loc[:,'startX'] + (traj.loc[:,'endX'] - traj.loc[:,'startX']) * (t - traj.loc[:,'startTime']) / (traj.loc[:,'endTime'] - traj.loc[:,'startTime'])
traj.loc[:,'y'] = traj.loc[:,'startY'] + (traj.loc[:,'endY'] - traj.loc[:,'startY']) * (t - traj.loc[:,'startTime']) / (traj.loc[:,'endTime'] - traj.loc[:,'startTime'])
traj = traj[traj.apply(lambda x: contains(x['x'], x['y'],rect), axis=1)]
return traj
def density(t, rect, trajectories):
area = rect.get_width() * rect.get_height()
traj = filter_by_time_and_place(t, rect, trajectories)
number_of_peds = len(traj)
traj = None
#gc.collect()
if number_of_peds == 0:
return 0
else:
return number_of_peds / area
measurementArea = mpl.patches.Rectangle((16.3,6.0), 2.4, 2.0)
density1 = list(map(lambda t: density(t, measurementArea, c_real_trajectories), times))
density2 = list(map(lambda t: density(t, measurementArea, c_sim_trajecotories), times))
#gc.enable()
fig_density = plt.figure(figsize=(10,5))
ax1_density = fig_density.add_subplot(121)
ax1_density.set_xlim(min(times),max(times))
ax1_density.set_ylim(0,6)
......@@ -744,5 +760,17 @@
ax1_fundamental.set_ylabel("density")
plt.plot(velocity1, density1, '*')
plt.plot(velocity2, density2, '*')
plt.show()
```
%% Cell type:code id: tags:
``` python
```
%% Cell type:code id: tags:
``` python
```
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment