Skip to content

Commit

Permalink
add 210 edgestarts for backwards compatibility (#985)
Browse files Browse the repository at this point in the history
* 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 <[email protected]>
  • Loading branch information
liljonnystyle and AboudyKreidieh authored Jul 8, 2020
1 parent c319a6c commit d36da2e
Showing 1 changed file with 51 additions and 15 deletions.
66 changes: 51 additions & 15 deletions flow/visualize/time_space_diagram.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@
import matplotlib
matplotlib.use('TkAgg')
from matplotlib import pyplot as plt
from matplotlib.collections import LineCollection
from matplotlib.collections import LineCollection, PatchCollection
from matplotlib.patches import Rectangle
import matplotlib.colors as colors
import numpy as np
import pandas as pd
Expand Down Expand Up @@ -186,8 +187,6 @@ def _highway(data):
pd.DataFrame
modified trajectory dataframe
"""
data.loc[:, :] = data[(data['distance'] > 500)]
data.loc[:, :] = data[(data['distance'] < 2300)]
segs = data[['time_step', 'distance', 'next_time', 'next_pos']].values.reshape((len(data), 2, 2))

return segs, data
Expand Down Expand Up @@ -240,10 +239,6 @@ def _i210_subnetwork(data):
pd.DataFrame
modified trajectory dataframe
"""
# Omit ghost edges
omit_edges = {'ghost0', '119257908#3'}
data.loc[:, :] = data[~data['edge_id'].isin(omit_edges)]

# Reset lane numbers that are offset by ramp lanes
offset_edges = set(data[data['lane_id'] == 5]['edge_id'].unique())
data.loc[data['edge_id'].isin(offset_edges), 'lane_id'] -= 1
Expand Down Expand Up @@ -357,6 +352,22 @@ def _get_abs_pos(df, params):
}
elif params['network'] == HighwayNetwork:
return df['x']
elif params['network'] == I210SubNetwork:
edgestarts = {
'119257914': -5.0999999999995795,
'119257908#0': 56.49000000018306,
':300944379_0': 56.18000000000016,
':300944436_0': 753.4599999999871,
'119257908#1-AddedOnRampEdge': 756.3299999991157,
':119257908#1-AddedOnRampNode_0': 853.530000000022,
'119257908#1': 856.7699999997207,
':119257908#1-AddedOffRampNode_0': 1096.4499999999707,
'119257908#1-AddedOffRampEdge': 1099.6899999995558,
':1686591010_1': 1198.1899999999541,
'119257908#2': 1203.6499999994803,
':1842086610_1': 1780.2599999999056,
'119257908#3': 1784.7899999996537,
}
else:
edgestarts = defaultdict(float)

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


def plot_tsd(ax, df, segs, args, lane=None):
def plot_tsd(ax, df, segs, args, lane=None, ghost_edges=None, ghost_bounds=None):
"""Plot the time-space diagram.
Take the pre-processed segments and other meta-data, then plot all the line segments.
Expand All @@ -391,15 +402,18 @@ def plot_tsd(ax, df, segs, args, lane=None):
parsed arguments
lane : int, optional
lane number to be shown in plot title
ghost_edges : list or set of str
ghost edge names to be greyed out, default None
ghost_bounds : tuple
lower and upper bounds of domain, excluding ghost edges, default None
Returns
-------
None
"""
norm = plt.Normalize(args.min_speed, args.max_speed)

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

rects = []
if ghost_edges:
y_domain_min = df[~df['edge_id'].isin(ghost_edges)]['distance'].min()
y_domain_max = df[~df['edge_id'].isin(ghost_edges)]['distance'].max()
rects.append(Rectangle((xmin, y_domain_min), args.start - xmin, y_domain_max - y_domain_min))
rects.append(Rectangle((xmin, ymin), xmax - xmin, y_domain_min - ymin))
rects.append(Rectangle((xmin, y_domain_max), xmax - xmin, ymax - y_domain_max))
elif ghost_bounds:
rects.append(Rectangle((xmin, ghost_bounds[0]), args.start - xmin, ghost_bounds[1] - ghost_bounds[0]))
rects.append(Rectangle((xmin, ymin), xmax - xmin, ghost_bounds[0] - ymin))
rects.append(Rectangle((xmin, ghost_bounds[1]), xmax - xmin, ymax - ghost_bounds[1]))
else:
rects.append(Rectangle((xmin, ymin), args.start - xmin, ymax - ymin))

if rects:
pc = PatchCollection(rects, facecolor='grey', alpha=0.5, edgecolor=None)
pc.set_zorder(20)
ax.add_collection(pc)

if lane:
ax.set_title('Time-Space Diagram: Lane {}'.format(lane), fontsize=25)
else:
Expand Down Expand Up @@ -452,8 +485,6 @@ def plot_tsd(ax, df, segs, args, lane=None):
help='The minimum speed in the color range.')
parser.add_argument('--start', type=float, default=0,
help='initial time (in sec) in the plot.')
parser.add_argument('--stop', type=float, default=float('inf'),
help='final time (in sec) in the plot.')

args = parser.parse_args()

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

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

plot_tsd(ax, traj_df, segs, args)
if flow_params['network'] == HighwayNetwork:
plot_tsd(ax, traj_df, segs, args, ghost_bounds=(500, 2300))
else:
plot_tsd(ax, traj_df, segs, args)

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

plt.show()
outfile = args.trajectory_path.replace('csv', 'png')
plt.savefig(outfile)

0 comments on commit d36da2e

Please sign in to comment.