Mercurial Hosting > traffic-intelligence
changeset 642:932f96c89212
added pandas to read vissim fzp (more robust with respect to column names
author | Nicolas Saunier <nicolas.saunier@polymtl.ca> |
---|---|
date | Fri, 10 Apr 2015 14:54:05 +0200 |
parents | 9fe254f11743 |
children | bfaa6b95dae2 |
files | python/storage.py |
diffstat | 1 files changed, 15 insertions(+), 4 deletions(-) [+] |
line wrap: on
line diff
--- a/python/storage.py Thu Apr 09 16:55:24 2015 +0200 +++ b/python/storage.py Fri Apr 10 14:54:05 2015 +0200 @@ -652,7 +652,7 @@ finally: self.sechead = None else: return self.fp.readline() -def loadTrajectoriesFromVissimFile(filename, simulationStepsPerTimeUnit, nObjects = -1, warmUpLastInstant = None, usePandas = False): +def loadTrajectoriesFromVissimFile(filename, simulationStepsPerTimeUnit, nObjects = -1, warmUpLastInstant = None, usePandas = False, nDecimals = 2): '''Reads data from VISSIM .fzp trajectory file simulationStepsPerTimeUnit is the number of simulation steps per unit of time used by VISSIM for example, there seems to be 5 simulation steps per simulated second in VISSIM, @@ -665,12 +665,23 @@ if usePandas: from pandas import read_csv + from numpy import min, max, round data = read_csv(filename, delimiter=';', skiprows=16) - print('Work in progress') - return [] + data['LANE'] = data['LANE\LINK\NO'].astype(str)+'_'+data['LANE\INDEX'].astype(str) + data['TIME'] = data['$VEHICLE:SIMSEC']*simulationStepsPerTimeUnit + grouped = data.loc[:,['NO','TIME']].groupby(['NO'], as_index = False) + instants = grouped['TIME'].agg({'first': min, 'last': max}) + if warmUpLastInstant is not None: + instants = instants[instants['first'] >= warmUpLastInstant] + for row_index, row in instants.iterrows(): + objNum = int(row['NO']) + tmp = data[data['NO'] == objNum] + objects[objNum] = moving.MovingObject(num = objNum, timeInterval = moving.TimeInterval(row['first'], row['last'])) + # positions should be rounded to nDecimals decimals only + objects[objNum].curvilinearPositions = moving.CurvilinearTrajectory(S = round(tmp['POS'].tolist(), nDecimals), Y = round(tmp['POSLAT'].tolist(), nDecimals), lanes = tmp['LANE'].tolist()) + return objects.values() else: inputfile = openCheck(filename, quitting = True) - # data = pd.read_csv(filename, skiprows=15, delimiter=';') # skip header: 15 lines + 1 line = readline(inputfile, '*$')