Mercurial Hosting > traffic-intelligence
comparison python/storage.py @ 524:1dced8932b08
corrected bugs
author | Nicolas Saunier <nicolas.saunier@polymtl.ca> |
---|---|
date | Thu, 19 Jun 2014 13:31:00 -0400 |
parents | 1ba618fb0f70 |
children | 7124c7d2a663 |
comparison
equal
deleted
inserted
replaced
523:ce4eaabacc26 | 524:1dced8932b08 |
---|---|
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, nObjects = -1, sequenceNum = -1): | |
423 '''Reads data from VISSIM .fzp trajectory file''' | |
424 objects = [] | |
425 | |
426 infile = openCheck(filename) | |
427 if not infile: | |
428 import sys | |
429 sys.exit() | |
430 | |
431 | |
432 return objects | |
433 | |
422 def loadTrajectoriesFromNgsimFile(filename, nObjects = -1, sequenceNum = -1): | 434 def loadTrajectoriesFromNgsimFile(filename, nObjects = -1, sequenceNum = -1): |
423 '''Reads data from the trajectory data provided by NGSIM project | 435 '''Reads data from the trajectory data provided by NGSIM project |
424 and returns the list of Feature objects''' | 436 and returns the list of Feature objects''' |
425 objects = [] | 437 objects = [] |
426 | 438 |
427 input = openCheck(filename) | 439 infile = openCheck(filename) |
428 if not input: | 440 if not infile: |
429 import sys | 441 import sys |
430 sys.exit() | 442 sys.exit() |
431 | 443 |
432 def createObject(numbers): | 444 def createObject(numbers): |
433 firstFrameNum = int(numbers[1]) | 445 firstFrameNum = int(numbers[1]) |
449 obj.curvilinearPositions = moving.CurvilinearTrajectory([float(numbers[5])],[float(numbers[4])], obj.laneNums) # X is the longitudinal coordinate | 461 obj.curvilinearPositions = moving.CurvilinearTrajectory([float(numbers[5])],[float(numbers[4])], obj.laneNums) # X is the longitudinal coordinate |
450 obj.speeds = [float(numbers[11])] | 462 obj.speeds = [float(numbers[11])] |
451 obj.size = [float(numbers[8]), float(numbers[9])] # 8 lengh, 9 width # TODO: temporary, should use a geometry object | 463 obj.size = [float(numbers[8]), float(numbers[9])] # 8 lengh, 9 width # TODO: temporary, should use a geometry object |
452 return obj | 464 return obj |
453 | 465 |
454 numbers = input.readline().strip().split() | 466 numbers = infile.readline().strip().split() |
455 if (len(numbers) > 0): | 467 if (len(numbers) > 0): |
456 obj = createObject(numbers) | 468 obj = createObject(numbers) |
457 | 469 |
458 for line in input: | 470 for line in infile: |
459 numbers = line.strip().split() | 471 numbers = line.strip().split() |
460 if obj.getNum() != int(numbers[0]): | 472 if obj.getNum() != int(numbers[0]): |
461 # check and adapt the length to deal with issues in NGSIM data | 473 # check and adapt the length to deal with issues in NGSIM data |
462 if (obj.length() != obj.positions.length()): | 474 if (obj.length() != obj.positions.length()): |
463 print 'length pb with object %s (%d,%d)' % (obj.getNum(),obj.length(),obj.positions.length()) | 475 print 'length pb with object %s (%d,%d)' % (obj.getNum(),obj.length(),obj.positions.length()) |
480 if (obj.size[0] != float(numbers[8])): | 492 if (obj.size[0] != float(numbers[8])): |
481 print 'changed length obj %d' % (obj.getNum()) | 493 print 'changed length obj %d' % (obj.getNum()) |
482 if (obj.size[1] != float(numbers[9])): | 494 if (obj.size[1] != float(numbers[9])): |
483 print 'changed width obj %d' % (obj.getNum()) | 495 print 'changed width obj %d' % (obj.getNum()) |
484 | 496 |
485 input.close() | 497 infile.close() |
486 return objects | 498 return objects |
487 | 499 |
488 def convertNgsimFile(inFile, outFile, append = False, nObjects = -1, sequenceNum = 0): | 500 def convertNgsimFile(inFile, outFile, append = False, nObjects = -1, sequenceNum = 0): |
489 '''Reads data from the trajectory data provided by NGSIM project | 501 '''Reads data from the trajectory data provided by NGSIM project |
490 and converts to our current format.''' | 502 and converts to our current format.''' |