comparison python/storage.py @ 541:048b43654870

added condition on warmup time to load trajectories from vissim files and corrected condition on number of objects
author Nicolas Saunier <nicolas.saunier@polymtl.ca>
date Mon, 07 Jul 2014 12:30:46 -0400
parents 6c264b914846
children a3add9f751ef
comparison
equal deleted inserted replaced
540:4fdce0f09ece 541:048b43654870
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): 422 def loadTrajectoriesFromVissimFile(filename, simulationStepsPerTimeUnit, nObjects = -1, warmUpLastInstant = None):
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 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, 425 for example, there seems to be 5 simulation steps per simulated second in VISSIM,
426 so simulationStepsPerTimeUnit should be 5, 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) 427 so that all times correspond to the number of the simulation step (and can be stored as integers)
428 428
429 Assumed to be sorted over time''' 429 Assumed to be sorted over time'''
430 objects = {} # dictionary of objects index by their id 430 objects = {} # dictionary of objects index by their id
431 firstInstants = {}
431 432
432 infile = openCheck(filename, quitting = True) 433 infile = openCheck(filename, quitting = True)
433 434
434 # data = pd.read_csv(filename, skiprows=15, delimiter=';') 435 # data = pd.read_csv(filename, skiprows=15, delimiter=';')
435 # skip header: 15 lines + 1 436 # skip header: 15 lines + 1
441 objNum = int(data[1]) 442 objNum = int(data[1])
442 instant = int(float(data[0])*simulationStepsPerTimeUnit) 443 instant = int(float(data[0])*simulationStepsPerTimeUnit)
443 s = float(data[4]) 444 s = float(data[4])
444 y = float(data[5]) 445 y = float(data[5])
445 lane = data[2]+'_'+data[3] 446 lane = data[2]+'_'+data[3]
446 if objNum not in objects: 447 if objNum not in firstInstants:
447 objects[objNum] = moving.MovingObject(num = objNum, timeInterval = moving.TimeInterval(instant, instant)) 448 firstInstants[objNum] = instant
448 objects[objNum].curvilinearPositions = moving.CurvilinearTrajectory() 449 if warmUpLastInstant == None or firstInstants[objNum] >= warmUpLastInstant:
449 objects[objNum].timeInterval.last = instant 450 if nObjects < 0 or len(objects) < nObjects:
450 objects[objNum].curvilinearPositions.addPosition(s, y, lane) 451 objects[objNum] = moving.MovingObject(num = objNum, timeInterval = moving.TimeInterval(instant, instant))
451 if nObjects > 0 and len(objects) > nObjects: 452 objects[objNum].curvilinearPositions = moving.CurvilinearTrajectory()
452 return objects.values()[:nObjects] 453 if (warmUpLastInstant == None or firstInstants[objNum] >= warmUpLastInstant) and objNum in objects:
454 objects[objNum].timeInterval.last = instant
455 objects[objNum].curvilinearPositions.addPosition(s, y, lane)
453 456
454 return objects.values() 457 return objects.values()
455 458
456 def loadTrajectoriesFromNgsimFile(filename, nObjects = -1, sequenceNum = -1): 459 def loadTrajectoriesFromNgsimFile(filename, nObjects = -1, sequenceNum = -1):
457 '''Reads data from the trajectory data provided by NGSIM project 460 '''Reads data from the trajectory data provided by NGSIM project