Mercurial Hosting > traffic-intelligence
comparison trafficintelligence/storage.py @ 1095:e53c6e87bb3f
update pems loader
author | Nicolas Saunier <nicolas.saunier@polymtl.ca> |
---|---|
date | Wed, 06 Feb 2019 12:55:10 -0500 |
parents | 3939ae415be0 |
children | 3972d85e3b6c |
comparison
equal
deleted
inserted
replaced
1094:c96388c696ac | 1095:e53c6e87bb3f |
---|---|
975 yield line | 975 yield line |
976 | 976 |
977 def loadPemsTraffic(filename): | 977 def loadPemsTraffic(filename): |
978 '''Loads traffic data downloaded from the http://pems.dot.ca.gov clearinghouse | 978 '''Loads traffic data downloaded from the http://pems.dot.ca.gov clearinghouse |
979 into pandas dataframe''' | 979 into pandas dataframe''' |
980 f = utils.openCheck(filename) | 980 data=read_csv(filename, nrows = 3) |
981 l = f.readline().strip() | 981 headerNames = ['time', 'station', 'district', 'freeway', 'direction', 'lanetype', 'length', 'nsamples', 'pctobserved', 'totalflow', 'occupancy', 'speed'] # default for 5 min |
982 items = l.split(',') | 982 nLanes = int((len(data.columns)-len(headerNames))/5) |
983 headers = ['time', 'station', 'district', 'route', 'direction', 'lanetype', 'length', 'nsamples', 'pctobserved', 'flow', 'occupancy', 'speed', 'delay35', 'delay40', 'delay45', 'delay50', 'delay55', 'delay60'] | 983 for i in range(1, nLanes+1): |
984 nLanes = (len(items)-len(headers))/3 | 984 headerNames += ['nsamples{}'.format(i), 'flow{}'.format(i), 'occupancy{}'.format(i), 'speed{}'.format(i), 'pctobserved{}'.format(i)] |
985 for i in range(nLanes): | 985 return read_csv(filename, names = headerNames) |
986 headers += ['flow{}'.format(i+1), 'occupancy{}'.format(i+1), 'speed{}'.format(i+1)] | 986 |
987 f.close() | |
988 return read_csv(filename, delimiter = ',', names = headers) | |
989 | |
990 def generatePDLaneColumn(data): | 987 def generatePDLaneColumn(data): |
991 data['LANE'] = data['LANE\\LINK\\NO'].astype(str)+'_'+data['LANE\\INDEX'].astype(str) | 988 data['LANE'] = data['LANE\\LINK\\NO'].astype(str)+'_'+data['LANE\\INDEX'].astype(str) |
992 | 989 |
993 def convertTrajectoriesVissimToSqlite(filename): | 990 def convertTrajectoriesVissimToSqlite(filename): |
994 '''Relies on a system call to sqlite3 | 991 '''Relies on a system call to sqlite3 |