comparison python/storage.py @ 660:994dd644f6ab

corrected impact of warmUpLastInstant
author Nicolas Saunier <nicolas.saunier@polymtl.ca>
date Fri, 15 May 2015 23:09:49 +0200
parents df9ddeaee4a6
children 455f9b93819c
comparison
equal deleted inserted replaced
659:784298512b60 660:994dd644f6ab
646 '''Reads data from VISSIM .fzp trajectory file 646 '''Reads data from VISSIM .fzp trajectory file
647 simulationStepsPerTimeUnit is the number of simulation steps per unit of time used by VISSIM 647 simulationStepsPerTimeUnit is the number of simulation steps per unit of time used by VISSIM
648 for example, there seems to be 5 simulation steps per simulated second in VISSIM, 648 for example, there seems to be 5 simulation steps per simulated second in VISSIM,
649 so simulationStepsPerTimeUnit should be 5, 649 so simulationStepsPerTimeUnit should be 5,
650 so that all times correspond to the number of the simulation step (and can be stored as integers) 650 so that all times correspond to the number of the simulation step (and can be stored as integers)
651
652 Objects positions will be considered only after warmUpLastInstant
653 (if the object has no such position, it won't be loaded)
651 654
652 Assumed to be sorted over time''' 655 Assumed to be sorted over time'''
653 objects = {} # dictionary of objects index by their id 656 objects = {} # dictionary of objects index by their id
654 657
655 if usePandas: 658 if usePandas:
656 from pandas import read_csv 659 from pandas import read_csv
657 from numpy import min, max, round 660 from numpy import min, max, round
658 data = read_csv(filename, delimiter=';', comment='*', header=0, skiprows = 1) 661 data = read_csv(filename, delimiter=';', comment='*', header=0, skiprows = 1)
659 generatePDLaneColumn(data) 662 generatePDLaneColumn(data)
660 data['TIME'] = data['$VEHICLE:SIMSEC']*simulationStepsPerTimeUnit 663 data['TIME'] = data['$VEHICLE:SIMSEC']*simulationStepsPerTimeUnit
664 if warmUpLastInstant is not None:
665 data = data[data['TIME']>=warmUpLastInstant]
661 grouped = data.loc[:,['NO','TIME']].groupby(['NO'], as_index = False) 666 grouped = data.loc[:,['NO','TIME']].groupby(['NO'], as_index = False)
662 instants = grouped['TIME'].agg({'first': min, 'last': max}) 667 instants = grouped['TIME'].agg({'first': min, 'last': max})
663 if warmUpLastInstant is not None:
664 instants = instants[instants['first'] >= warmUpLastInstant]
665 for row_index, row in instants.iterrows(): 668 for row_index, row in instants.iterrows():
666 objNum = int(row['NO']) 669 objNum = int(row['NO'])
667 tmp = data[data['NO'] == objNum] 670 tmp = data[data['NO'] == objNum]
668 objects[objNum] = moving.MovingObject(num = objNum, timeInterval = moving.TimeInterval(row['first'], row['last'])) 671 objects[objNum] = moving.MovingObject(num = objNum, timeInterval = moving.TimeInterval(row['first'], row['last']))
669 # positions should be rounded to nDecimals decimals only 672 # positions should be rounded to nDecimals decimals only
670 objects[objNum].curvilinearPositions = moving.CurvilinearTrajectory(S = round(tmp['POS'].tolist(), nDecimals), Y = round(tmp['POSLAT'].tolist(), nDecimals), lanes = tmp['LANE'].tolist()) 673 objects[objNum].curvilinearPositions = moving.CurvilinearTrajectory(S = round(tmp['POS'].tolist(), nDecimals), Y = round(tmp['POSLAT'].tolist(), nDecimals), lanes = tmp['LANE'].tolist())
671 return objects.values() 674 return objects.values()
672 else: 675 else:
673 firstInstants = {}
674 inputfile = openCheck(filename, quitting = True) 676 inputfile = openCheck(filename, quitting = True)
675 # data = pd.read_csv(filename, skiprows=15, delimiter=';') 677 # data = pd.read_csv(filename, skiprows=15, delimiter=';')
676 # skip header: 15 lines + 1 678 # skip header: 15 lines + 1
677 line = readline(inputfile, '*$') 679 line = readline(inputfile, '*$')
678 while len(line) > 0:#for line in inputfile: 680 while len(line) > 0:#for line in inputfile:
680 objNum = int(data[1]) 682 objNum = int(data[1])
681 instant = int(float(data[0])*simulationStepsPerTimeUnit) 683 instant = int(float(data[0])*simulationStepsPerTimeUnit)
682 s = float(data[4]) 684 s = float(data[4])
683 y = float(data[5]) 685 y = float(data[5])
684 lane = data[2]+'_'+data[3] 686 lane = data[2]+'_'+data[3]
685 if objNum not in firstInstants: 687 if objNum not in objects:
686 firstInstants[objNum] = instant 688 if warmUpLastInstant is None or instant >= warmUpLastInstant:
687 if warmUpLastInstant is None or firstInstants[objNum] >= warmUpLastInstant:
688 if nObjects < 0 or len(objects) < nObjects: 689 if nObjects < 0 or len(objects) < nObjects:
689 objects[objNum] = moving.MovingObject(num = objNum, timeInterval = moving.TimeInterval(instant, instant)) 690 objects[objNum] = moving.MovingObject(num = objNum, timeInterval = moving.TimeInterval(instant, instant))
690 objects[objNum].curvilinearPositions = moving.CurvilinearTrajectory() 691 objects[objNum].curvilinearPositions = moving.CurvilinearTrajectory()
691 if (warmUpLastInstant is None or firstInstants[objNum] >= warmUpLastInstant) and objNum in objects: 692 if (warmUpLastInstant is None or instant >= warmUpLastInstant) and objNum in objects:
692 objects[objNum].timeInterval.last = instant 693 objects[objNum].timeInterval.last = instant
693 objects[objNum].curvilinearPositions.addPositionSYL(s, y, lane) 694 objects[objNum].curvilinearPositions.addPositionSYL(s, y, lane)
694 line = readline(inputfile, '*$') 695 line = readline(inputfile, '*$')
695 696
696 return objects.values() 697 return objects.values()