-
Notifications
You must be signed in to change notification settings - Fork 0
/
car_plots.py
executable file
·83 lines (72 loc) · 2.35 KB
/
car_plots.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
#! /usr/bin/python
# -*- coding: utf-8 -*-
"""
Created on Mon Jul 22 00:18:38 2013
@author: Damian
"""
import numpy as np
import matplotlib
#matplotlib.use("Agg")
import matplotlib.lines as lines
import matplotlib.pyplot as plt
import glob
import re
import os
from subprocess import call
import h5py
REAL_LANES = 4
ROADLENGTH = 50
TRIALS = 50
AREA = 1*(REAL_LANES)*ROADLENGTH
SPEED = 0
SIZE = -1
LAST = -1
def throughput(dist_trial):
"""Computes the throughput of one trial of the simulation."""
return np.sum([vehicles[SPEED]/ROADLENGTH for vehicles in dist_trial[LAST]])
#def load(_ratio, _density):
# '''Loads data from the hdf5 dataset.'''
# vehicledata = np.array([], dtype=np.int8)
# filename = "CarRatio.%.2f_Density.%.2f.h5" % (_ratio, _density)
# call(['bunzip2', filename+'.bz2'])
# fid = h5py.File(filename, 'r')
# n = 1
# group = "CarRatio::%.2f/Density::%.2f/" % (_ratio, _density)
# _trial = "Trial::%04d" % (n)
# dset = fid[group+_trial]
# vehicledata = np.append(vehicledata, dset)
# vehicledata = np.reshape(vehicledata, (dset.shape[0],
# dset.shape[1],
# dset.shape[2]))
# fid.close()
# call(["bzip2", "-6", filename])
# return vehicledata
def load(_ratio, _density):
"""Loads data from the hdf5 dataset."""
vehicledata = np.array([], dtype=np.int8)
filename = "CarRatio.%.2f_Density.%.2f.h5" % (_ratio, _density)
call(['bunzip2', filename + '.bz2'])
fid = h5py.File(filename, 'r')
for n in xrange(1):
group = "CarRatio::%.2f/Density::%.2f/" % (_ratio, _density)
_trial = "Trial::%04d" % (n + 1)
dset = fid[group + _trial]
vehicledata = np.append(vehicledata, dset)
vehicledata = np.reshape(vehicledata, (dset.shape[0],
dset.shape[1],
dset.shape[2]))
fid.close()
call(["bzip2", "-6", filename])
return vehicledata
ratio = 0
density = 0.05
vehicledata = load(ratio, density)
carchoices = np.random.randint(vehicledata.shape[1], size=4)
fig = plt.figure()
timesteps = range(vehicledata.shape[0])
for i, vehicle in enumerate(carchoices):
vel = vehicledata[:, vehicle, 0]
ax = fig.add_subplot(carchoices.size, 1, i)
ax.plot(range(1000), vel)
ax.set_ylim(0, 5)
plt.show()