comparison python/storage.py @ 646:6680a69d5bf3

added fast function to detect VISSIM simulations with errors
author Nicolas Saunier <nicolas.saunier@polymtl.ca>
date Tue, 14 Apr 2015 16:30:27 +0200
parents 5ed2118c959d
children 458890c0437c
comparison
equal deleted inserted replaced
645:5ed2118c959d 646:6680a69d5bf3
703 objects[objNum].curvilinearPositions.addPositionSYL(s, y, lane) 703 objects[objNum].curvilinearPositions.addPositionSYL(s, y, lane)
704 line = readline(inputfile, '*$') 704 line = readline(inputfile, '*$')
705 705
706 return objects.values() 706 return objects.values()
707 707
708 def countStoppedVehiclesVissim(filename, proportionStationaryTime = 0.7):
709 '''Counts the number of vehicles stopped for a long time in a VISSIM trajectory file
710 and the total number of vehicles
711
712 Vehicles are considered finally stationary
713 if more than proportionStationaryTime of their total time'''
714 from pandas import read_csv
715 from numpy import array, sum as npsum
716 data = read_csv(filename, delimiter=';', comment='*', header=0, skiprows = 1, usecols = ['NO', '$VEHICLE:SIMSEC', 'POS']) # 'LANE\LINK\NO', 'LANE\INDEX',
717 data.sort(['$VEHICLE:SIMSEC'], inplace = True)
718 #merged = merge(data, data, how='inner', left_on=['LANE\LINK\NO', 'LANE\INDEX', '$VEHICLE:SIMSEC'], right_on=['LANE\LINK\NO', 'LANE\INDEX', '$VEHICLE:SIMSEC'], sort = False)
719 #merged = merged[merged['NO_x']>merged['NO_y']]
720
721 nStationary = 0
722 from matplotlib.pyplot import plot, figure
723 nVehicles = 0
724 for name, group in data.groupby(['NO'], sort = False):
725 nVehicles += 1
726 positions = array(group['POS'])
727 diff = positions[1:]-positions[:-1]
728 if npsum(diff == 0.) >= proportionStationaryTime*len(positions):
729 nStationary += 1
730
731 return nStationary, nVehicles
732
708 def countCollisionsVissim(filename, collisionTimeDifference = 0.2): 733 def countCollisionsVissim(filename, collisionTimeDifference = 0.2):
709 '''Counts the number of collisions per lane in a VISSIM trajectory file 734 '''Counts the number of collisions per lane in a VISSIM trajectory file
710 735
711 To distinguish between cars passing and collision, 736 To distinguish between cars passing and collision,
712 one checks when the sign of the position difference inverts 737 one checks when the sign of the position difference inverts