Skip to content

Commit d36da2e

Browse files
add 210 edgestarts for backwards compatibility (#985)
* fixed h-baselines bug * potential bug fix * add 210 edgestarts for backwards compatibility * add 210 edgestarts for backwards compatibility * add 210 edgestarts for backwards compatibility * add 210 edgestarts for backwards compatibility * fastforward PR 989 * fix typo Co-authored-by: AboudyKreidieh <akreidieh@gmail.com>
1 parent c319a6c commit d36da2e

File tree

1 file changed

+51
-15
lines changed

1 file changed

+51
-15
lines changed

flow/visualize/time_space_diagram.py

Lines changed: 51 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,8 @@
2727
import matplotlib
2828
matplotlib.use('TkAgg')
2929
from matplotlib import pyplot as plt
30-
from matplotlib.collections import LineCollection
30+
from matplotlib.collections import LineCollection, PatchCollection
31+
from matplotlib.patches import Rectangle
3132
import matplotlib.colors as colors
3233
import numpy as np
3334
import pandas as pd
@@ -186,8 +187,6 @@ def _highway(data):
186187
pd.DataFrame
187188
modified trajectory dataframe
188189
"""
189-
data.loc[:, :] = data[(data['distance'] > 500)]
190-
data.loc[:, :] = data[(data['distance'] < 2300)]
191190
segs = data[['time_step', 'distance', 'next_time', 'next_pos']].values.reshape((len(data), 2, 2))
192191

193192
return segs, data
@@ -240,10 +239,6 @@ def _i210_subnetwork(data):
240239
pd.DataFrame
241240
modified trajectory dataframe
242241
"""
243-
# Omit ghost edges
244-
omit_edges = {'ghost0', '119257908#3'}
245-
data.loc[:, :] = data[~data['edge_id'].isin(omit_edges)]
246-
247242
# Reset lane numbers that are offset by ramp lanes
248243
offset_edges = set(data[data['lane_id'] == 5]['edge_id'].unique())
249244
data.loc[data['edge_id'].isin(offset_edges), 'lane_id'] -= 1
@@ -357,6 +352,22 @@ def _get_abs_pos(df, params):
357352
}
358353
elif params['network'] == HighwayNetwork:
359354
return df['x']
355+
elif params['network'] == I210SubNetwork:
356+
edgestarts = {
357+
'119257914': -5.0999999999995795,
358+
'119257908#0': 56.49000000018306,
359+
':300944379_0': 56.18000000000016,
360+
':300944436_0': 753.4599999999871,
361+
'119257908#1-AddedOnRampEdge': 756.3299999991157,
362+
':119257908#1-AddedOnRampNode_0': 853.530000000022,
363+
'119257908#1': 856.7699999997207,
364+
':119257908#1-AddedOffRampNode_0': 1096.4499999999707,
365+
'119257908#1-AddedOffRampEdge': 1099.6899999995558,
366+
':1686591010_1': 1198.1899999999541,
367+
'119257908#2': 1203.6499999994803,
368+
':1842086610_1': 1780.2599999999056,
369+
'119257908#3': 1784.7899999996537,
370+
}
360371
else:
361372
edgestarts = defaultdict(float)
362373

@@ -374,7 +385,7 @@ def _get_abs_pos(df, params):
374385
return ret
375386

376387

377-
def plot_tsd(ax, df, segs, args, lane=None):
388+
def plot_tsd(ax, df, segs, args, lane=None, ghost_edges=None, ghost_bounds=None):
378389
"""Plot the time-space diagram.
379390
380391
Take the pre-processed segments and other meta-data, then plot all the line segments.
@@ -391,15 +402,18 @@ def plot_tsd(ax, df, segs, args, lane=None):
391402
parsed arguments
392403
lane : int, optional
393404
lane number to be shown in plot title
405+
ghost_edges : list or set of str
406+
ghost edge names to be greyed out, default None
407+
ghost_bounds : tuple
408+
lower and upper bounds of domain, excluding ghost edges, default None
394409
395410
Returns
396411
-------
397412
None
398413
"""
399414
norm = plt.Normalize(args.min_speed, args.max_speed)
400415

401-
xmin = max(df['time_step'].min(), args.start)
402-
xmax = min(df['time_step'].max(), args.stop)
416+
xmin, xmax = df['time_step'].min(), df['time_step'].max()
403417
xbuffer = (xmax - xmin) * 0.025 # 2.5% of range
404418
ymin, ymax = df['distance'].min(), df['distance'].max()
405419
ybuffer = (ymax - ymin) * 0.025 # 2.5% of range
@@ -413,6 +427,25 @@ def plot_tsd(ax, df, segs, args, lane=None):
413427
ax.add_collection(lc)
414428
ax.autoscale()
415429

430+
rects = []
431+
if ghost_edges:
432+
y_domain_min = df[~df['edge_id'].isin(ghost_edges)]['distance'].min()
433+
y_domain_max = df[~df['edge_id'].isin(ghost_edges)]['distance'].max()
434+
rects.append(Rectangle((xmin, y_domain_min), args.start - xmin, y_domain_max - y_domain_min))
435+
rects.append(Rectangle((xmin, ymin), xmax - xmin, y_domain_min - ymin))
436+
rects.append(Rectangle((xmin, y_domain_max), xmax - xmin, ymax - y_domain_max))
437+
elif ghost_bounds:
438+
rects.append(Rectangle((xmin, ghost_bounds[0]), args.start - xmin, ghost_bounds[1] - ghost_bounds[0]))
439+
rects.append(Rectangle((xmin, ymin), xmax - xmin, ghost_bounds[0] - ymin))
440+
rects.append(Rectangle((xmin, ghost_bounds[1]), xmax - xmin, ymax - ghost_bounds[1]))
441+
else:
442+
rects.append(Rectangle((xmin, ymin), args.start - xmin, ymax - ymin))
443+
444+
if rects:
445+
pc = PatchCollection(rects, facecolor='grey', alpha=0.5, edgecolor=None)
446+
pc.set_zorder(20)
447+
ax.add_collection(pc)
448+
416449
if lane:
417450
ax.set_title('Time-Space Diagram: Lane {}'.format(lane), fontsize=25)
418451
else:
@@ -452,8 +485,6 @@ def plot_tsd(ax, df, segs, args, lane=None):
452485
help='The minimum speed in the color range.')
453486
parser.add_argument('--start', type=float, default=0,
454487
help='initial time (in sec) in the plot.')
455-
parser.add_argument('--stop', type=float, default=float('inf'),
456-
help='final time (in sec) in the plot.')
457488

458489
args = parser.parse_args()
459490

@@ -485,13 +516,17 @@ def plot_tsd(ax, df, segs, args, lane=None):
485516
for lane, df in traj_df.groupby('lane_id'):
486517
ax = plt.subplot(nlanes, 1, lane+1)
487518

488-
plot_tsd(ax, df, segs[lane], args, lane)
519+
plot_tsd(ax, df, segs[lane], args, int(lane+1), ghost_edges={'ghost0', '119257908#3'})
520+
plt.tight_layout()
489521
else:
490522
# perform plotting operation
491523
fig = plt.figure(figsize=(16, 9))
492524
ax = plt.axes()
493525

494-
plot_tsd(ax, traj_df, segs, args)
526+
if flow_params['network'] == HighwayNetwork:
527+
plot_tsd(ax, traj_df, segs, args, ghost_bounds=(500, 2300))
528+
else:
529+
plot_tsd(ax, traj_df, segs, args)
495530

496531
###########################################################################
497532
# Note: For MergeNetwork only #
@@ -502,4 +537,5 @@ def plot_tsd(ax, df, segs, args, lane=None):
502537
[-0.1, -0.1], linewidth=3, color="white") #
503538
###########################################################################
504539

505-
plt.show()
540+
outfile = args.trajectory_path.replace('csv', 'png')
541+
plt.savefig(outfile)

0 commit comments

Comments
 (0)