Beispiel #1
0
def myplot(sim, auxinfo, roadinfo, platoon=[]):
    #note to self: platoon keyword is messed up becauase plotformat is hacky - when vehicles wrap around they get put in new keys
    meas, platooninfo = plotformat(sim,
                                   auxinfo,
                                   roadinfo,
                                   starttimeind=0,
                                   endtimeind=math.inf,
                                   density=1)
    platoonplot(meas,
                None,
                platooninfo,
                platoon=platoon,
                lane=1,
                colorcode=True,
                speed_limit=[0, 25])
    plt.ylim(0, roadinfo[0])
Beispiel #2
0
        curtime += 1

        # check if we need to remove vehicles
        # if len(cur_vehicles)>0:
        veh = cur_vehicles[0]
        if abs(veh.acc*dt) < acc_tolerance*10 and abs(veh.speed-eql_speed) < speed_tolerance:
            all_vehicles.append(veh)
            veh.end = curtime
            leadveh.pos = veh.pos
            leadveh.speed = veh.speed
            cur_vehicles.pop(0)
            if len(cur_vehicles) > 0:
                cur_vehicles[0].lead = leadveh

    return all_vehicles, cur_vehicles, curtime

#%%  simulation and plotting
start = time.time()
all_vehicles, cur_vehicles, timesteps = make_waves()
end = time.time()
print('simulation time is '+str(end-start)+' over '+str(sum([timesteps - veh.start+1 if veh.end is None else veh.end - veh.start+1
                                                         for veh in all_vehicles]))+' timesteps')
all_vehicles.extend(cur_vehicles)

laneinds = {mainroad[0]:0}
sim, siminfo = hp.plot_format(all_vehicles, laneinds)

hp.platoonplot(sim,None, siminfo, lane=0, opacity=0)


start = time.time()
simulation.simulate(timesteps)
end = time.time()

all_vehicles = simulation.prev_vehicles.copy()
all_vehicles.extend(simulation.vehicles)

print('simulation time is ' + str(end - start) + ' over ' + str(
    sum([
        timesteps - veh.start + 1 if veh.end is None else veh.end - veh.start +
        1 for veh in all_vehicles
    ])) + ' timesteps')

#%%
laneinds = {main_road[0]: 0, main_road[1]: 1, onramp_road[0]: 2}
sim, siminfo = plot_format(all_vehicles, laneinds)

mylane2list = []
for veh in sim.keys():
    if 2 in sim[veh][:, 7]:
        mylane2list.append(veh)
#%%
platoonplot(sim, None, siminfo, lane=2, opacity=0)
platoonplot(sim, None, siminfo, lane=1, opacity=0)
# platoonplot(sim, None, siminfo, lane = 0, opacity = 0)
# platoonplot(sim, None, siminfo, lane = 2, colorcode = False)
# platoonplot(sim, None, siminfo, lane = 1, colorcode = False)
# %%
# plotspacetime(sim, siminfo, lane = 2)
# plotspacetime(sim, siminfo, lane = 1)
# plotspacetime(sim, siminfo, lane = 0)
Beispiel #4
0
print('simulation time is ' + str(end - start) + ' over ' + str(
    sum([
        timesteps - veh.starttime + 1 if veh.endtime is None else veh.endtime -
        veh.starttime + 1 for veh in all_vehicles
    ])) + ' timesteps')
print('inflow buffers are: ' +
      str([i.inflow_buffer for i in simulation.inflow_lanes]))

#%%
laneinds = {lane0: 0, lane1: 1, lane2: 2}
sim, siminfo = plot_format(all_vehicles, laneinds)

#%%
# platoonplot(sim, None, siminfo, lane = 2, opacity = 0, speed_limit=[0,30])
platoonplot(sim, None, siminfo, lane=1, opacity=0, speed_limit=[0, 35])
plt.ylabel('distance (m)')
plt.xlabel('time index (.25s)')
# platoonplot(sim, None, siminfo, lane = 0, opacity = 0, speed_limit=[0,33.5])
# platoonplot(sim, None, siminfo, lane = 1, colorcode = False, opacity=0)
# platoonplot(sim, None, siminfo, lane = 1, colorcode = False)

# %%
# plotflows(sim, [[0,100],[1300,1400], [1900,2000]], [0, 28800], 480, lane=1, h=.25, MFD=True, Flows=False, method='area')
# plt.plot(density*1000, flows*3600, '--k',alpha=.1)  # from 'boundary conditions.py'
plotflows(sim, [[1900, 2000]], [480 * 7, 480 * 30],
          480,
          lane=1,
          h=.25,
          MFD=False,
          Flows=True,
Beispiel #5
0
        endtime = counter #get end time and update platooninfo
        platooninfo[idcount][2:] = [endtime,endtime]
        #update meas
        meas[idcount] = np.zeros((endtime-curtime+1,8))
        meas[idcount][:,1] = tlist
        meas[idcount][:,2] = xlist
        meas[idcount][:,3] = vlist
        #lane just set always to 1
        meas[idcount][:,7] = 1
        
        idcount += 1
            

    return meas, platooninfo

bestind = np.arange(1,40,2)
bestind = np.arange(0,41,1)
meas, platooninfo = plotformat(sim,auxinfo,roadinfo, endtimeind = math.inf, indlist = bestind, specialind = 21)

#meas2 = {}
#platooninfo2 = {}
#count = 0
#for i in meas.keys():
#    meas2[i] = meas[i].copy()
#    platooninfo2[i] = platooninfo[i].copy()
#    count +=1
#    if count > 20: 
#        break

platoonplot(meas,None,platooninfo,platoon=[], lane=1, colorcode= True, speed_limit = [0,25]) 
plt.ylim(0,roadinfo[0]) #dunno why ylimit is messed up 
Beispiel #6
0
        1001)  #equivalent to list(range(1001+100*i))[100*i:]
    testmeas2[i][:, 2] = np.linspace(0, 1000, 1001)

q, k = calculateflows(testmeas2, [[200, 400], [800, 1000]], [0, 1000], 300)
print(q, k)
#q = [.00166, .08333, 0, 0] for first region, [0, 0, .00166, .01]
#k is the same as q in this example

#%%
#another toy example I want you to test on to verify on
meas[898][100:200, 7] = 3
meas[905][150:250, 7] = 3
platoonplot(meas,
            None,
            platooninfo,
            platoon=[898, 905, 909, 916, 920],
            lane=None,
            opacity=.1,
            colorCode=True,
            speed_limit=[10, 35])
plt.plot([2600, 2600, 2800, 2800, 2600], [400, 800, 800, 400, 400], 'k-')
plt.plot([2800, 2800, 3000, 3000, 2800], [400, 800, 800, 400, 400], 'k-')
testmeas3 = {}
for i in [898, 905, 909, 916, 920]:
    testmeas3[i] = meas[i].copy()

q, k = calculateflows(testmeas3, [[400, 800]], [2600, 3000], 200, lane=2)
print(q, k)
#measurements taken by hand (if lane = 2):
#q - [.0128125, .0082125] #q[1] has incorrect value in both cases for lane == none and lane is 2
#k - [.0068875, .0051]
Beispiel #7
0
    L=None,
    v=15,
    perturb=2)  #create initial state on road
sim2, curstate, auxinfo = simulate_cir(initstate,
                                       auxinfo,
                                       roadinfo,
                                       update_cir,
                                       timesteps=25000,
                                       dt=.25)

#%%
#platoonplot is basically the main plotting api - it has different use cases
platoonplot(meas,
            None,
            platooninfo,
            platoon=testplatoon[0],
            colorcode=True,
            speed_limit=[20,
                         35])  #single platoon, can specify colorcoding speeds
platoonplot(meas,
            None,
            platooninfo,
            platoon=platoonlist[48:60],
            colorcode=True)  #list of platoons
platoonplot(
    meas,
    None,
    platooninfo,
    platoon=platoonlist[48:60],
    colorcode=True,
    lane=2,
Beispiel #8
0
def myplot(sim, auxinfo, roadinfo, platoon=[]):
    # note to self: very hacky
    meas, platooninfo = plotformat(sim, auxinfo, roadinfo, starttimeind=0, endtimeind=math.inf, density=1)
    platoonplot(meas, None, platooninfo, platoon=platoon, lane=1, colorcode=True, speed_limit=[0, 25])
    plt.ylim(0, roadinfo[0])
    plt.show()
Beispiel #9
0
#%%
import pickle
import numpy as np 
import matplotlib.pyplot as plt 
from matplotlib import cm


# with open('/Users/qiwuzou/Documents/assignment/M.Eng/follow_up/hav-sim-master/visualization/plottingtesting.pkl','rb') as f:
#     meas, platooninfo, platoonlist, sim = pickle.load(f)
#
# vehlist = []
# [vehlist.extend(i[1:]) for i in platoonlist]

from havsim.plotting import platoonplot, calculateflows, plotflows

"""
TO DO 
color code the trajectories in platoonplot based on the current speed of vehicles
add new keyword argument to control whether or not to color code the trajectories. There should also be a keyword that can set the maximum/minimum 
speeds, and if this keyword is None, the function should find the minimum/maximum speeds 
You should also add a colorbar which shows what speeds the color correspond to. You can use plt.colobar() to do this. 

Matplotlib has some default colormaps (from matplotlib import cm), you should use 
cm.RdYlBu 
as the colormap the function uses.

I also want you to add the feature where you can click on a trajectory to display the vehicle ID. the function optplot already has this feature added. 
To do this, when you plot things pass in keyword 'picker = 5'. e.g. plt.plot([1,2,3],[1,2,3],picker=5)
You will also need to keep reference to the figure you are using (fig = plt.figure()). Then add in an extra line 
fig.canvas.callbacks.connect('pick_event', on_pick) 
What happens is when you click within 5 pixels of an artist in fig, it triggers a 'pick_event' which then calls the function you define called on_pick
Beispiel #10
0
from havsim import calibration
from havsim.calibration import calibration_models
import tensorflow as tf
import pickle
#%%  # plot a platoon of vehicles
vehs = [
    1145, 1152, 1155, 1163, 1173, 1174, 1183, 1177, 1184, 1193, 1200, 1214,
    1215, 1219, 1226, 1232, 1241, 1240, 1243, 1252, 1260, 1266, 1267, 1275,
    1278, 1282, 1283, 1293, 1290, 1298, 1302, 1313, 1320, 1323, 1330, 1336,
    1340, 1347, 1352, 1361, 1368, 1374, 1375, 1379, 1384, 1396, 1391
]

hp.platoonplot(meas,
               None,
               platooninfo,
               platoon=vehs,
               lane=6,
               opacity=0,
               colorcode=False)
plt.xlabel('time (.1 s)')
plt.savefig('relaxspacetime.png', dpi=200)

#%%  Just for looking at different vehicles to find some pretty ones
inds = [66, 67, 68, 78, 79, 85]
for ind in inds:
    veh = [lc_list[ind]]
    hp.plotvhd(meas,
               None,
               platooninfo,
               veh,
               plot_color_line=True,