comparison python/storage.py @ 527:37830a831818

loading from VISSIM trajectory data works
author Nicolas Saunier <nicolas.saunier@polymtl.ca>
date Sat, 21 Jun 2014 14:46:20 -0400
parents 21bdeb29f855
children 95276d310972
comparison
equal deleted inserted replaced
526:21bdeb29f855 527:37830a831818
417 if self.sechead: 417 if self.sechead:
418 try: return self.sechead 418 try: return self.sechead
419 finally: self.sechead = None 419 finally: self.sechead = None
420 else: return self.fp.readline() 420 else: return self.fp.readline()
421 421
422 def loadTrajectoriesFromVissimFile(filename, simulationStepsPerTimeUnit, nObjects = -1, sequenceNum = -1): 422 def loadTrajectoriesFromVissimFile(filename, simulationStepsPerTimeUnit, nObjects = -1):
423 '''Reads data from VISSIM .fzp trajectory file 423 '''Reads data from VISSIM .fzp trajectory file
424 simulationStepsPerTimeUnit is the number of simulation steps per unit of time used by VISSIM
425 for example, there seems to be 5 simulation steps per simulated second in VISSIM,
426 so simulationStepsPerTimeUnit should be 5,
427 so that all times correspond to the number of the simulation step (and can be stored as integers)
424 428
425 Assumed to be sorted over time''' 429 Assumed to be sorted over time'''
426 objects = {} # dictionary of objects index by their id 430 objects = {} # dictionary of objects index by their id
427 431
428 infile = openCheck(filename, quitting = True) 432 infile = openCheck(filename, quitting = True)
436 data = line.strip().split(';') 440 data = line.strip().split(';')
437 objNum = int(data[1]) 441 objNum = int(data[1])
438 instant = int(float(data[0])*simulationStepsPerTimeUnit) 442 instant = int(float(data[0])*simulationStepsPerTimeUnit)
439 s = float(data[4]) 443 s = float(data[4])
440 y = float(data[5]) 444 y = float(data[5])
441 lane = int(data[3]) 445 lane = data[2]+'_'+data[3]
442 if objNum not in objects: 446 if objNum not in objects:
443 objects[objNum] = moving.MovingObject(num = objNum, timeInterval = moving.TimeInterval(instant, instant)) 447 objects[objNum] = moving.MovingObject(num = objNum, timeInterval = moving.TimeInterval(instant, instant))
444 objects[objNum].curvilinearPositions = moving.CurvilinearTrajectory() 448 objects[objNum].curvilinearPositions = moving.CurvilinearTrajectory()
445 objects[objNum].timeInterval.last = instant 449 objects[objNum].timeInterval.last = instant
446 objects[objNum].curvilinearPositions.addPosition(s, y, lane) 450 objects[objNum].curvilinearPositions.addPosition(s, y, lane)