Mercurial Hosting > traffic-intelligence
comparison python/storage.py @ 744:ed6ff2ec0aeb dev
bug correction from Laurent Gauthier
author | Nicolas Saunier <nicolas.saunier@polymtl.ca> |
---|---|
date | Thu, 10 Sep 2015 15:48:01 -0400 |
parents | 867bab9f317a |
children | 6049e9b6902c |
comparison
equal
deleted
inserted
replaced
741:5b91b8d97cf3 | 744:ed6ff2ec0aeb |
---|---|
827 if npsum(diff == 0.) >= proportionStationaryTime*len(positions): | 827 if npsum(diff == 0.) >= proportionStationaryTime*len(positions): |
828 nStationary += 1 | 828 nStationary += 1 |
829 | 829 |
830 return nStationary, nVehicles | 830 return nStationary, nVehicles |
831 | 831 |
832 def countCollisionsVissim(filename, lanes = None, collisionTimeDifference = 0.2): | 832 def countCollisionsVissim(filename, lanes = None, collisionTimeDifference = 0.2, lowMemory = True): |
833 '''Counts the number of collisions per lane in a VISSIM trajectory file | 833 '''Counts the number of collisions per lane in a VISSIM trajectory file |
834 | 834 |
835 To distinguish between cars passing and collision, | 835 To distinguish between cars passing and collision, |
836 one checks when the sign of the position difference inverts | 836 one checks when the sign of the position difference inverts |
837 (if the time are closer than collisionTimeDifference) | 837 (if the time are closer than collisionTimeDifference) |
838 If lanes is not None, only the data for the selected lanes will be provided | 838 If lanes is not None, only the data for the selected lanes will be provided |
839 (format as string x_y where x is link index and y is lane index)''' | 839 (format as string x_y where x is link index and y is lane index)''' |
840 from pandas import read_csv, merge | 840 from pandas import read_csv, merge |
841 data = read_csv(filename, delimiter=';', comment='*', header=0, skiprows = 1, usecols = ['LANE\LINK\NO', 'LANE\INDEX', '$VEHICLE:SIMSEC', 'NO', 'POS'], low_memory = lowMemory) | 841 data = read_csv(filename, delimiter=';', comment='*', header=0, skiprows = 1, usecols = ['LANE\LINK\NO', 'LANE\INDEX', '$VEHICLE:SIMSEC', 'NO', 'POS'], low_memory = lowMemory) |
842 data = selectPDLanes(data, lanes) | 842 data = selectPDLanes(data, lanes) |
843 data = data.convert_objects(convert_numeric=True) | |
844 | |
843 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) | 845 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) |
844 merged = merged[merged['NO_x']>merged['NO_y']] | 846 merged = merged[merged['NO_x']>merged['NO_y']] |
845 | 847 |
846 nCollisions = 0 | 848 nCollisions = 0 |
847 for name, group in merged.groupby(['LANE\LINK\NO', 'LANE\INDEX', 'NO_x', 'NO_y']): | 849 for name, group in merged.groupby(['LANE\LINK\NO', 'LANE\INDEX', 'NO_x', 'NO_y']): |
848 diff = group['POS_x'].convert_objects(convert_numeric=True)-group['POS_y'].convert_objects(convert_numeric=True) | 850 diff = group['POS_x']-group['POS_y'] |
849 # diff = group['POS_x']-group['POS_y'] # to check the impact of convert_objects and the possibility of using type conversion in read_csv or function to convert strings if any | 851 # diff = group['POS_x']-group['POS_y'] # to check the impact of convert_objects and the possibility of using type conversion in read_csv or function to convert strings if any |
850 if len(diff) >= 2 and npmin(diff) < 0 and npmax(diff) > 0: | 852 if len(diff) >= 2 and npmin(diff) < 0 and npmax(diff) > 0: |
851 xidx = diff[diff < 0].argmax() | 853 xidx = diff[diff < 0].argmax() |
852 yidx = diff[diff > 0].argmin() | 854 yidx = diff[diff > 0].argmin() |
853 if abs(group.loc[xidx, '$VEHICLE:SIMSEC'] - group.loc[yidx, '$VEHICLE:SIMSEC']) <= collisionTimeDifference: | 855 if abs(group.loc[xidx, '$VEHICLE:SIMSEC'] - group.loc[yidx, '$VEHICLE:SIMSEC']) <= collisionTimeDifference: |