Commit 387a0b00 authored by BZoennchen's avatar BZoennchen

small changes to the trajectory notebook.

parent 1d700175
......@@ -8,6 +8,7 @@
"source": [
"# expand the cell of the notebook\n",
"import json\n",
"import gc\n",
"import numpy as np\n",
"import pandas as pd\n",
"import math\n",
......@@ -223,8 +224,9 @@
"outputs": [],
"source": [
"# Sum up all measured time deltas of a pedestrian to get the final evacuation time\n",
"trajectoriesReal[\"timeDelta\"] = trajectoriesReal[\"endTime\"] - trajectoriesReal[\"startTime\"]\n",
"evacuation_time = trajectoriesReal.groupby([\"pedestrianId\"])[\"timeDelta\"].sum()\n",
"copy = trajectoriesReal.copy(deep=True)\n",
"copy[\"timeDelta\"] = copy[\"endTime\"] - copy[\"startTime\"]\n",
"evacuation_time = copy.groupby([\"pedestrianId\"])[\"timeDelta\"].sum()\n",
"\n",
"# trajectories starting from left\n",
"cut_minX = trajectoriesReal[trajectoriesReal[\"endX\"] < 15].groupby([\"pedestrianId\"])[\"endX\"].min().max()\n",
......@@ -370,8 +372,8 @@
"\n",
"def cuttail_trajectory_by(trajectory, xmin, xmax):\n",
" #i1 = trajectory[np.logical_and(trajectory.endX >= xmax, trajectory.startX < xmax)].index.max()\n",
" i1 = trajectory[trajectory.endX >= xmax].index.max()\n",
" i2 = trajectory[trajectory.endX <= xmin].index.max()\n",
" i1 = trajectory[np.logical_or(trajectory.endX >= xmax, trajectory.startX is np.nan)].index.max()\n",
" i2 = trajectory[np.logical_or(trajectory.endX <= xmin, trajectory.startX is np.nan)].index.max()\n",
" #assert (i1 is np.nan and i2 is not np.nan) or (i1 is not np.nan and i2 is np.nan)\n",
" x = xmax if i2 is np.nan or (i1 is not np.nan and i1 > i2) else xmin\n",
" i = i1 if x == xmax else i2\n",
......@@ -391,7 +393,13 @@
" time = fs[\"endTime\"] - fs[\"startTime\"]\n",
" endTime = fs[\"startTime\"] + (time * r)\n",
" distance = np.linalg.norm(end - start)\n",
" velocity = distance / (endTime - startTime)\n",
" if abs(endTime - startTime) < 0.00001:\n",
" if distance < 0.00001:\n",
" velocity = 0\n",
" else:\n",
" raise exception\n",
" else:\n",
" velocity = distance / (endTime - startTime)\n",
" \n",
" df = trajectory.loc[i+1:]\n",
" llist = [[fs[\"pedestrianId\"],fs[\"startX\"],fs[\"startY\"],fs[\"startTime\"],end[0],end[1],endTime,distance,velocity]]\n",
......@@ -422,10 +430,11 @@
"ts = traj[traj.endX > 22].index.max()\n",
"ts\n",
"#cut(trajectoriesReal)\n",
"#cuttail_by(trajectoriesReal, 13, 22).head()\n",
"cuttail_by(trajectoriesReal, cut_minX, cut_maxX).head()\n",
"#cuthead_by(trajectoriesReal, 0, 4).tail()\n",
"#traj.loc[100]\n",
"#trajectoriesReal.tail()"
"#trajectoriesReal.tail()\n",
"trajectoriesReal.head()"
]
},
{
......@@ -739,7 +748,7 @@
},
"outputs": [],
"source": [
"times = np.arange(0, 70, 0.2)\n",
"times = np.arange(0, 70, 5)\n",
"velocity1 = list(map(lambda t: mean_velocity_at(t, c_real_trajectories), times))\n",
"std1 = list(map(lambda t: get_trajectories(t, c_real_trajectories)['velocity'].std(),times))\n",
"\n",
......@@ -787,6 +796,10 @@
"metadata": {},
"outputs": [],
"source": [
"%%prun\n",
"#gc.disable()\n",
"print(len(times))\n",
"gc.disable()\n",
"def contains(x,y,rect):\n",
" #ma = mpl.patches.Rectangle((16.3,6.0), 2.4, 2.0)\n",
" 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()\n",
......@@ -795,8 +808,8 @@
" \"\"\"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\n",
" agent at the time t contained in the rectanlge rect. Two new colums will be added for x and y.\"\"\"\n",
" traj = get_trajectories(t, trajectories)\n",
" traj.loc[:,'x'] = traj['startX'] + (traj['endX'] - traj['startX']) * (t - traj['startTime']) / (traj['endTime'] - traj['startTime'])\n",
" traj.loc[:,'y'] = traj['startY'] + (traj['endY'] - traj['startY']) * (t - traj['startTime']) / (traj['endTime'] - traj['startTime'])\n",
" traj.loc[:,'x'] = traj.loc[:,'startX'] + (traj.loc[:,'endX'] - traj.loc[:,'startX']) * (t - traj.loc[:,'startTime']) / (traj.loc[:,'endTime'] - traj.loc[:,'startTime'])\n",
" traj.loc[:,'y'] = traj.loc[:,'startY'] + (traj.loc[:,'endY'] - traj.loc[:,'startY']) * (t - traj.loc[:,'startTime']) / (traj.loc[:,'endTime'] - traj.loc[:,'startTime'])\n",
" traj = traj[traj.apply(lambda x: contains(x['x'], x['y'],rect), axis=1)]\n",
" return traj\n",
"\n",
......@@ -804,14 +817,17 @@
" area = rect.get_width() * rect.get_height()\n",
" traj = filter_by_time_and_place(t, rect, trajectories)\n",
" number_of_peds = len(traj)\n",
" traj = None\n",
" #gc.collect()\n",
" if number_of_peds == 0:\n",
" return 0\n",
" else:\n",
" return number_of_peds / area\n",
" \n",
"\n",
"measurementArea = mpl.patches.Rectangle((16.3,6.0), 2.4, 2.0)\n",
"density1 = list(map(lambda t: density(t, measurementArea, c_real_trajectories), times))\n",
"density2 = list(map(lambda t: density(t, measurementArea, c_sim_trajecotories), times))\n",
"#gc.enable()\n",
"\n",
"fig_density = plt.figure(figsize=(10,5))\n",
"ax1_density = fig_density.add_subplot(121)\n",
......@@ -853,6 +869,20 @@
"plt.plot(velocity2, density2, '*')\n",
"plt.show()"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
......
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