Commit fd7953ae authored by Benedikt Zoennchen's avatar Benedikt Zoennchen
Browse files

Merge branch 'issue#242' into 'master'

fix issue #242.

Closes #242

See merge request !66
parents a303cac0 ea3b983c
Pipeline #122557 passed with stages
in 114 minutes and 28 seconds
%% Cell type:markdown id: tags:
### Note
You can find the required data on the Nextcloud data/Paperdaten/2019/TGF2019-vadere
%% Cell type:code id: tags:
``` python
# expand the cell of the notebook
import json
......@@ -9,11 +14,15 @@
import math
import matplotlib as mpl
import matplotlib.pyplot as plt
from matplotlib.lines import Line2D
import seaborn as sns
sns.set(style="ticks")
import functools
import operator
sns.set_context("poster")
sns.set(style="whitegrid", font_scale=1.8)
from IPython.core.display import display, HTML
display(HTML('<style>.container { width:100% !important; }</style>'))
```
......@@ -42,23 +51,20 @@
```
%% Cell type:code id: tags:
``` python
file = "./data/TrajectoryMetric/trajectories_simulation.txt"
f = open(file, "r")
header = f.readline();
trajectories = dict({});
for row in f:
s = row.split(" ");
pedId = int(s[0]);
footsteps = json.loads(s[1]);
trajectories[pedId] = footsteps[0]['footSteps'];
ptrajectories = trajectories_to_dataframe(trajectories)
ptrajectories.head()
def load_simulation_data(file):
f = open(file, "r")
header = f.readline();
trajectories = dict({});
for row in f:
s = row.split(" ");
pedId = int(s[0]);
footsteps = json.loads(s[1]);
trajectories[pedId] = footsteps[0]['footSteps'];
return trajectories_to_dataframe(trajectories)
```
%% Cell type:markdown id: tags:
# Convert experiment data into a DataFrame
......@@ -80,29 +86,29 @@
#print(trajectories)
last_ped_id = None
lastX = None
lastY = None
for row in data.itertuples():
endX = row.x / 100 + 18.7
endY = row.y / 100 + 4.2
endX = row.x / 100.0 + 18.7
endY = row.y / 100.0 + 4.2
startTime = row.timeStep / fps - 1/fps
endTime = row.timeStep / fps
if last_ped_id is None or last_ped_id != row.pedestrianId:
startX = np.nan
startY = np.nan
distance = np.nan
velocity = np.nan
else:
startX = lastX / 100 + 18.7
startY = lastY / 100 + 4.2
startX = lastX / 100.0 + 18.7
startY = lastY / 100.0 + 4.2
distance = np.sqrt(np.square(endX - startX) + np.square(endY - startY))
velocity = distance / (endTime - startTime)
rows.append([row.pedestrianId, startX, startY, endX, endY, startTime, endTime, distance, velocity])
last_ped_id = row.pedestrianId
lastX = row.x
lastY = row.y
rows.append([row.pedestrianId, startX, startY, endX, endY, startTime, endTime, distance, velocity])
dataframe = pd.DataFrame(rows, columns=['pedestrianId', 'startX', 'startY', 'endX', 'endY','startTime','endTime','distance','velocity'])
return dataframe
def to_trajectories(data):
trajectories = dict({})
......@@ -124,92 +130,134 @@
trajectory = []
pedId = data['pedestrianId'][i]
return trajectories
```
%% Cell type:markdown id: tags:
# Load all data
The following code loads the experiment data as well as the simulated data and transforms everything into the same format (data frame). The simulated trajectories are cut with respect to the camera bounds of the experiment.
%% Cell type:code id: tags:
``` python
#times = np.linspace(4,10,10)
#euclid_d(get_trajectory(1), get_trajectory(1), times)
#to_trajectories(load_experiment(real_file))[1]
real_file = "./data/TrajectoryMetric/KO/ko-240-120-240/ko-240-120-240_combined_MB.txt"
trajectoriesReal = load_experiment(real_file)
#trajectoriesReal = to_trajectories(data)
trajectoriesReal.query('pedestrianId == 1').head()
```
trajectories240o050o240 = load_experiment("./T-junction-experiment-trajectories-files/KO/ko-240-050-240/ko-240-050-240_combined_MB.txt")
trajectories240o060o240 = load_experiment("./T-junction-experiment-trajectories-files/KO/ko-240-060-240/ko-240-060-240_combined_MB.txt")
trajectories240o080o240 = load_experiment("./T-junction-experiment-trajectories-files/KO/ko-240-080-240/ko-240-080-240_combined_MB.txt")
trajectories240o100o240 = load_experiment("./T-junction-experiment-trajectories-files/KO/ko-240-100-240/ko-240-100-240_combined_MB.txt")
trajectories240o120o240 = load_experiment("./T-junction-experiment-trajectories-files/KO/ko-240-120-240/ko-240-120-240_combined_MB.txt")
trajectories240o150o240 = load_experiment("./T-junction-experiment-trajectories-files/KO/ko-240-150-240/ko-240-150-240_combined_MB.txt")
trajectories240o240o240 = load_experiment("./T-junction-experiment-trajectories-files/KO/ko-240-240-240/ko-240-240-240_combined_MB.txt")
trajectoriesReal = pd.concat([trajectories240o050o240, trajectories240o060o240, trajectories240o080o240,
trajectories240o100o240, trajectories240o120o240, trajectories240o150o240,
trajectories240o240o240], ignore_index=True)
%% Cell type:markdown id: tags:
# trajectories starting from left
cut_minX = trajectoriesReal[trajectoriesReal["endX"] < 15].groupby(["pedestrianId"])["startX"].min().max() + 0.12
# Convert DataFrame to postvis DataFrame
# trajectories starting from right
cut_maxX = trajectoriesReal[trajectoriesReal["endX"] > 21].groupby(["pedestrianId"])["startX"].max().min() - 0.2
%% Cell type:code id: tags:
# trajectories ending at top
cut_maxY = trajectoriesReal.groupby(["pedestrianId"])["endY"].max().min() - 0.168
``` python
def to_postVis(df):
simTimeStep = 0.4
fps = 16
df['timeStep'] = np.ceil(df['endTime'] / (1/fps)).astype(np.int)
df['x'] = df['endX']
df['y'] = df['endY']
df['simTime'] = df['endTime']
df = df.drop(columns=['startX','startY','endX','endY','startTime', 'endTime'])
return df
```
trajectories240o050o240 = cut(trajectories240o050o240, cut_minX, cut_maxX, cut_maxY)
trajectories240o060o240 = cut(trajectories240o060o240, cut_minX, cut_maxX, cut_maxY)
trajectories240o080o240 = cut(trajectories240o080o240, cut_minX, cut_maxX, cut_maxY)
trajectories240o100o240 = cut(trajectories240o100o240, cut_minX, cut_maxX, cut_maxY)
trajectories240o120o240 = cut(trajectories240o120o240, cut_minX, cut_maxX, cut_maxY)
trajectories240o150o240 = cut(trajectories240o150o240, cut_minX, cut_maxX, cut_maxY)
trajectories240o240o240 = cut(trajectories240o240o240, cut_minX, cut_maxX, cut_maxY)
%% Cell type:code id: tags:
osm_trajectories240o050o240 = load_simulation_data("./T-junction-sim-trajectory-files/trajectories-OSM-240-050-240.txt")
osm_trajectories240o050o240 = cut(osm_trajectories240o050o240, cut_minX, cut_maxX, cut_maxY)
``` python
to_postVis(trajectoriesReal).to_csv('expteriment_2.trajectories',index=False,sep=' ')
to_postVis(trajectoriesReal).head(10)
```
osm_trajectories240o060o240 = load_simulation_data("./T-junction-sim-trajectory-files/trajectories-OSM-240-060-240.txt")
osm_trajectories240o060o240 = cut(osm_trajectories240o060o240, cut_minX, cut_maxX, cut_maxY)
%% Cell type:markdown id: tags:
osm_trajectories240o080o240 = load_simulation_data("./T-junction-sim-trajectory-files/trajectories-OSM-240-080-240.txt")
osm_trajectories240o080o240 = cut(osm_trajectories240o080o240, cut_minX, cut_maxX, cut_maxY)
# Calculate evacution time
osm_trajectories240o100o240 = load_simulation_data("./T-junction-sim-trajectory-files/trajectories-OSM-240-100-240.txt")
osm_trajectories240o100o240 = cut(osm_trajectories240o100o240, cut_minX, cut_maxX, cut_maxY)
%% Cell type:markdown id: tags:
osm_trajectories240o120o240 = load_simulation_data("./T-junction-sim-trajectory-files/trajectories-OSM-240-120-240.txt")
osm_trajectories240o120o240 = cut(osm_trajectories240o120o240, cut_minX, cut_maxX, cut_maxY)
Evacuation time = endTime - startTime
osm_trajectories240o150o240 = load_simulation_data("./T-junction-sim-trajectory-files/trajectories-OSM-240-150-240.txt")
osm_trajectories240o150o240 = cut(osm_trajectories240o150o240, cut_minX, cut_maxX, cut_maxY)
%% Cell type:markdown id: tags:
osm_trajectories240o240o240 = load_simulation_data("./T-junction-sim-trajectory-files/trajectories-OSM-240-240-240.txt")
osm_trajectories240o240o240 = cut(osm_trajectories240o240o240, cut_minX, cut_maxX, cut_maxY)
trajectoriesOSM = pd.concat([osm_trajectories240o050o240, osm_trajectories240o060o240, osm_trajectories240o080o240, osm_trajectories240o100o240, osm_trajectories240o120o240, osm_trajectories240o150o240, osm_trajectories240o240o240], ignore_index=True)
bhm_trajectories240o050o240 = load_simulation_data("./T-junction-sim-trajectory-files/trajectories-BHM-240-050-240.txt")
bhm_trajectories240o050o240 = cut(bhm_trajectories240o050o240, cut_minX, cut_maxX, cut_maxY)
bhm_trajectories240o060o240 = load_simulation_data("./T-junction-sim-trajectory-files/trajectories-BHM-240-060-240.txt")
bhm_trajectories240o060o240 = cut(bhm_trajectories240o060o240, cut_minX, cut_maxX, cut_maxY)
bhm_trajectories240o080o240 = load_simulation_data("./T-junction-sim-trajectory-files/trajectories-BHM-240-080-240.txt")
bhm_trajectories240o080o240 = cut(bhm_trajectories240o080o240, cut_minX, cut_maxX, cut_maxY)
bhm_trajectories240o100o240 = load_simulation_data("./T-junction-sim-trajectory-files/trajectories-BHM-240-100-240.txt")
bhm_trajectories240o100o240 = cut(bhm_trajectories240o100o240, cut_minX, cut_maxX, cut_maxY)
bhm_trajectories240o120o240 = load_simulation_data("./T-junction-sim-trajectory-files/trajectories-BHM-240-120-240.txt")
bhm_trajectories240o120o240 = cut(bhm_trajectories240o120o240, cut_minX, cut_maxX, cut_maxY)
bhm_trajectories240o150o240 = load_simulation_data("./T-junction-sim-trajectory-files/trajectories-BHM-240-150-240.txt")
bhm_trajectories240o150o240 = cut(bhm_trajectories240o150o240, cut_minX, cut_maxX, cut_maxY)
## Real data
bhm_trajectories240o240o240 = load_simulation_data("./T-junction-sim-trajectory-files/trajectories-BHM-240-240-240.txt")
bhm_trajectories240o240o240 = cut(bhm_trajectories240o240o240, cut_minX, cut_maxX, cut_maxY)
trajectoriesBHM = pd.concat([bhm_trajectories240o050o240, bhm_trajectories240o060o240, bhm_trajectories240o080o240,
bhm_trajectories240o100o240, bhm_trajectories240o120o240, bhm_trajectories240o150o240,
bhm_trajectories240o240o240], ignore_index=True)
```
%% Cell type:code id: tags:
``` python
# Sum up all measured time deltas of a pedestrian to get the final evacuation time
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
cut_maxX = trajectoriesReal[trajectoriesReal["endX"] > 21].groupby(["pedestrianId"])["endX"].max().min()
cut_maxY = trajectoriesReal.groupby(["pedestrianId"])["endY"].max().min()
et = copy.groupby(["pedestrianId"])["timeDelta"].sum()
print("Evacuation time (real data)")
print("- mean: {:.2f} [s]".format(evacuation_time.mean()))
print("- std: {:.2f} [s]".format(evacuation_time.std()))
print("- min: {:.2f} [s]".format(evacuation_time.min()))
print("- max: {:.2f} [s]".format(evacuation_time.max()))
print("- mean: {:.2f} [s]".format(et.mean()))
print("- std: {:.2f} [s]".format(et.std()))
print("- min: {:.2f} [s]".format(et.min()))
print("- max: {:.2f} [s]".format(et.max()))
print("- minX: {:.2f} [m]".format(cut_minX))
print("- maxX: {:.2f} [m]".format(cut_maxX))
print("- maxY: {:.2f} [m]".format(cut_maxY))
```
%% Cell type:markdown id: tags:
# Convert DataFrame to postvis DataFrame
%% Cell type:code id: tags:
``` python
rightX = trajectoriesReal[trajectoriesReal.endX < 16].groupby(["pedestrianId"])["endX"].min().max()
leftX = trajectoriesReal[trajectoriesReal.endX > 16].groupby(["pedestrianId"])["endX"].max().min()
topY = trajectoriesReal.groupby(["pedestrianId"])["endY"].max().min()
topY
def to_postVis(df):
simTimeStep = 0.4
fps = 16
df['timeStep'] = np.ceil(df['endTime'] / (1/fps)).astype(np.int)
df['x'] = df['endX']
df['y'] = df['endY']
df['simTime'] = df['endTime']
df = df.drop(columns=['startX','startY','endX','endY','startTime', 'endTime'])
return df
```
%% Cell type:markdown id: tags:
## Simulation data
......@@ -229,11 +277,11 @@
"""returns a data frame containing the trajectory of one specific agent."""
query = 'pedestrianId == ' + str(pedId)
return trajectories.query(query)
def get_trajectories(t, trajectories):
return trajectories[np.logical_and(trajectories.startTime <= t, trajectories.endTime >= t)]
return trajectories[np.logical_and(trajectories.startTime <= t, trajectories.endTime > t)]
def get_pedestrianIds(trajectories):
return trajectories['pedestrianId'].unique()
#def get_velocity(trajectories, t, dt):
......@@ -285,10 +333,15 @@
i1 = trajectory[trajectory.endY >= ymax].index.min()
i2 = trajectory[trajectory.endY <= ymin].index.min()
#assert (i1 is np.nan and i2 is not np.nan) or (i1 is not np.nan and i2 is np.nan)
y = ymax if i2 is np.nan or (i1 is not np.nan and i1 < i2) else ymin
i = i1 if y == ymax else i2
if i is np.nan:
print("i1:"+str(i1))
print("i2:"+str(i2))
assert i is not np.nan
#print(i)
# cut the footstep at the tail to exactly fit xmin or xmax
fs = trajectory.loc[i]
start = np.array([fs["startX"], fs["startY"]])
end = np.array([fs["endX"], fs["endY"]])
......@@ -311,41 +364,36 @@
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[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()
i1 = trajectory[trajectory.startX >= xmax].index.max()
i2 = trajectory[trajectory.startX <= xmin].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
assert i is not np.nan
# cut the footstep at the tail to exactly fit xmin or xmax
fs = trajectory.loc[i]
start = np.array([fs["startX"], fs["startY"]])
end = np.array([fs["endX"], fs["endY"]])
startTime = fs["startTime"]
endTime = fs["endTime"]
distance = fs["distance"]
velocity = fs["velocity"]
d = end - start
if abs(fs["endX"] - fs["startX"]) > 0.00001:
r = (x - fs["startX"]) / (fs["endX"] - fs["startX"])
end = start + (d * r)
r = (fs["endX"] - x) / (fs["endX"] - fs["startX"])
start = end - (d * r)
time = fs["endTime"] - fs["startTime"]
endTime = fs["startTime"] + (time * r)
startTime = fs["endTime"] - (time * r)
distance = np.linalg.norm(end - start)
if abs(endTime - startTime) < 0.00001:
if distance < 0.00001:
velocity = 0
else:
raise exception
else:
velocity = distance / (endTime - startTime)
velocity = distance / (endTime - startTime)
assert startTime <= endTime
df = trajectory.loc[i+1:]
llist = [[fs["pedestrianId"],fs["startX"],fs["startY"],fs["startTime"],end[0],end[1],endTime,distance,velocity]]
llist = [[fs["pedestrianId"],start[0],start[1],startTime,fs["endX"],fs["endY"],fs["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)
return df_tail
def cuthead_by(trajectories, ymin, ymax):
......@@ -360,24 +408,14 @@
pedIds = get_pedestrianIds(trajectories)
for pedId in pedIds:
df = df.append(cuttail_trajectory_by(get_trajectory(pedId, trajectories), xmin, xmax), ignore_index=True)
return df
def cut(trajectories):
def cut(trajectories, cut_minX, cut_maxX, cut_maxY):
df = cuttail_by(trajectories, cut_minX, cut_maxX)
df = cuthead_by(df, -1000, cut_maxY)
return df
traj = get_trajectory(2, trajectoriesReal)
ts = traj[traj.endX > 22].index.max()
ts
#cut(trajectoriesReal)
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
......@@ -396,10 +434,24 @@
return np.sqrt(dx*dx + dy*dy);
def mean_velocity_at(t, trajectories):
return get_trajectories(t, trajectories)['velocity'].mean()
def evacuation_times(trajectories):
pedIds = get_pedestrianIds(trajectories)
rows = []
for pedId in pedIds:
evacTime = evacuation_time(pedId, trajectories)
rows.append([pedId, evacTime])
return pd.DataFrame(rows, columns=['pedestrianId', 'evacuationTime'])
def evacuation_time(pedId, trajectories):
traj = get_trajectory(pedId, trajectories)
start = traj.iloc[0]['endTime']
end = traj.iloc[len(traj)-1]['endTime']
return end - start
def trajectory_length(trajectory):
"""Euclidean length of a trajectory."""
dx = trajectory['startX']-trajectory['endX']
dy = trajectory['startY']-trajectory['endY']
return np.sqrt(dx*dx + dy*dy).sum();
......@@ -533,30 +585,20 @@
```
%% Cell type:code id: tags:
``` python
#start_time(get_trajectory(1, ptrajectories))
#max_start_time(ptrajectories)
#end_time(get_trajectory(1, ptrajectories))
#foot_step_length(get_footstep(get_trajectory(1, ptrajectories), 0))
#trajectory_length(get_trajectory(1, ptrajectories))
#trajectory_speed(get_trajectory(1, ptrajectories))
#cutTraj.mask(cutTraj['startTime'] <= 4 and 4 > cutTraj['endTime'])
#start_time(get_trajectory(1, ptrajectories))
#trajectories_position(ptrajectories, [1,2,3,4]).head()
trajPos1 = trajectories_position(get_trajectory(2, ptrajectories), [1,2,3,4,5,6,8,9,10,11,12,13])
trajPos2 = trajectories_position(get_trajectory(7, ptrajectories), [1,2,3,4,5,6,8,9,10,11,12,13])
trajPos1 = trajectories_position(get_trajectory(2, osm_trajectories240o120o240), [1,2,3,4,5,6,8,9,10,11,12,13])
trajPos2 = trajectories_position(get_trajectory(7, osm_trajectories240o120o240), [1,2,3,4,5,6,8,9,10,11,12,13])
trajPos1 = trajPos1[~np.isnan(trajPos1.x)]
trajPos2 = trajPos2[~np.isnan(trajPos2.x)]
euclid_path_length(trajPos1, trajPos2)
euclid_len(ptrajectories,0,10000)
#print(total_inter_agent(ptrajectories, ptrajectories, [1,2]))
euclid_len(osm_trajectories240o120o240,0,10000)
t = 0.5
ttraj = ptrajectories[np.logical_and(ptrajectories.startTime <= t, ptrajectories.endTime >= t)]
#ptrajectories["velocity"] = numpy.linalg.norm(
get_trajectories(0.5, ptrajectories).head()
ttraj = osm_trajectories240o120o240[np.logical_and(osm_trajectories240o120o240.startTime <= t, osm_trajectories240o120o240.endTime >= t)]
get_trajectories(0.5, osm_trajectories240o120o240).head()
#osm_trajectories240o120o240
```
%% Cell type:code id: tags:
``` python
......@@ -583,21 +625,10 @@
return match
```
%% Cell type:markdown id: tags:
Here we cut all trajectory data such each left trajectory starts at the same $x$-coordinate and each right trajectory starts at the same $x$-coordinate. In addition each trajectory ends a the same $y$-coordinate.
%% Cell type:code id: tags:
``` python
c_real_trajectories = cut(trajectoriesReal)
c_sim_trajecotories = cut(ptrajectories)
```
%% Cell type:markdown id: tags:
# Plot trajectories
Now we plot the cut trajectories.
%% Cell type:code id: tags:
......@@ -610,40 +641,373 @@
y = trajectory['endY'].values
if x[0] < xleft:
c = current_palette[2]
else:
c = current_palette[0]
return x, y, Line2D(x, y, color=c, linewidth=0.3)
return x, y, Line2D(x, y, color=c, linewidth=0.4)
def add_lines(trajectories, xleft, ax):
grouped = trajectories.groupby(['pedestrianId'])
for name, group in grouped:
x, y, line = to_line(group, xleft)
ax.add_line(line)
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)
#TODO: this is very very memory expensive!
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.loc[:,'x'] = traj.loc[:,'startX']
#traj.loc[:,'y'] = traj.loc[:,'startY']
traj = traj[traj.apply(lambda x: contains(x['x'], x['y'],rect), axis=1)]
return traj
def density_velocity(t, rect, trajectories):
area = rect.get_width() * rect.get_height()
traj = filter_by_time_and_place(t, rect, trajectories)
meanVelocity = traj.loc[:,'velocity'].mean();
number_of_peds = len(traj)
traj = None
#gc.collect()
if number_of_peds == 0:
return np.nan, np.nan
else:
return number_of_peds / area, meanVelocity
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 np.nan
else:
return number_of_peds / area
```
%% Cell type:code id: tags:
``` python
x_vcenter = 17.5
y_vcenter = 5.2
fig_trajectories = plt.figure(figsize=(10,10))
ax1_trajectories = fig_trajectories.add_subplot(121)
add_lines(c_real_trajectories, 16, ax1_trajectories)
ax1_trajectories.set_xlim(x_vcenter-5, x_vcenter+6)
ax1_trajectories.set_ylim(y_vcenter-4, y_vcenter+4)
xmin = x_vcenter-4
xmax = x_vcenter+5
ymin = y_vcenter-3.2
ymax = y_vcenter+3
alp = 0.549020
measurementArea_front = mpl.patches.Rectangle((16.3,6.0), 2.4, 2.0, color='r', alpha = alp)
measurementArea_left = mpl.patches.Rectangle((14.2,1.8), 2.0, 2.4, color='r', alpha = alp)
measurementArea_right = mpl.patches.Rectangle((19.7,1.8), 2.0, 2.4, color='r', alpha = alp)
fig_trajectories = plt.figure(figsize=(20,20))
ax1_trajectories = fig_trajectories.add_subplot(131)
ax1_trajectories.add_patch(measurementArea_left)
ax1_trajectories.add_patch(measurementArea_right)
ax1_trajectories.add_patch(measurementArea_front)
add_lines(trajectories240o150o240, 16, ax1_trajectories)
ax1_trajectories.set_title("Experiment")
ax1_trajectories.set_xlim(xmin, xmax)
ax1_trajectories.set_ylim(ymin, ymax)
ax1_trajectories.set_aspect(1)
ax2_trajectories = fig_trajectories.add_subplot(122, sharey=ax1)
add_lines(c_sim_trajecotories, 16, ax2_trajectories)
ax2_trajectories = fig_trajectories.add_subplot(132, sharey=ax1_trajectories)
ax2_trajectories.add_patch(mpl.patches.Rectangle((16.3,6.0), 2.4, 2.0, color='r', alpha = alp))
ax2_trajectories.add_patch(mpl.patches.Rectangle((14.2,1.8), 2.0, 2.4, color='r', alpha = alp))
ax2_trajectories.add_patch(mpl.patches.Rectangle((19.7,1.8), 2.0, 2.4, color='r', alpha = alp))
add_lines(osm_trajectories240o150o240, 16, ax2_trajectories)
plt.setp(ax2_trajectories.get_yticklabels(), visible=False)
ax2_trajectories.set_xlim(x_vcenter-5, x_vcenter+6)
ax2_trajectories.set_ylim(y_vcenter-4, y_vcenter+4)
ax2_trajectories.set_title("OSM")
ax2_trajectories.set_xlim(xmin, xmax)
ax2_trajectories.set_ylim(ymin, ymax)
ax2_trajectories.set_aspect(1)
plt.show()
ax3_trajectories = fig_trajectories.add_subplot(133, sharey=ax2_trajectories)
ax3_trajectories.add_patch(mpl.patches.Rectangle((16.3,6.0), 2.4, 2.0, color='r', alpha = alp))
ax3_trajectories.add_patch(mpl.patches.Rectangle((14.2,1.8), 2.0, 2.4, color='r', alpha = alp))
ax3_trajectories.add_patch(mpl.patches.Rectangle((19.7,1.8), 2.0, 2.4, color='r', alpha = alp))
add_lines(bhm_trajectories240o150o240, 16, ax3_trajectories)
plt.setp(ax3_trajectories.get_yticklabels(), visible=False)
ax3_trajectories.set_title("BHM")
ax3_trajectories.set_xlim(xmin, xmax)
ax3_trajectories.set_ylim(ymin, ymax)
ax3_trajectories.set_aspect(1)