comparison python/storage.py @ 514:1ba618fb0f70

corrected bug from merging and argument issue in display-trajectories
author Nicolas Saunier <nicolas.saunier@polymtl.ca>
date Thu, 05 Jun 2014 17:50:42 -0400
parents 935430b1d408
children 1dced8932b08
comparison
equal deleted inserted replaced
513:dbf4b83afbb9 514:1ba618fb0f70
383 dataStrings += [s.strip()] 383 dataStrings += [s.strip()]
384 s = readline(f, commentChar) 384 s = readline(f, commentChar)
385 return dataStrings 385 return dataStrings
386 386
387 def writeList(filename, l): 387 def writeList(filename, l):
388 f = utils.openCheck(filename, 'w') 388 f = openCheck(filename, 'w')
389 for x in l: 389 for x in l:
390 f.write('{}\n'.format(x)) 390 f.write('{}\n'.format(x))
391 f.close() 391 f.close()
392 392
393 def loadListStrings(filename, commentChar = commentChar): 393 def loadListStrings(filename, commentChar = commentChar):
394 f = utils.openCheck(filename, 'r') 394 f = openCheck(filename, 'r')
395 result = getLines(f, commentChar) 395 result = getLines(f, commentChar)
396 f.close() 396 f.close()
397 return result 397 return result
398 398
399 def getValuesFromINIFile(filename, option, delimiterChar = '=', commentChar = commentChar): 399 def getValuesFromINIFile(filename, option, delimiterChar = '=', commentChar = commentChar):
422 def loadTrajectoriesFromNgsimFile(filename, nObjects = -1, sequenceNum = -1): 422 def loadTrajectoriesFromNgsimFile(filename, nObjects = -1, sequenceNum = -1):
423 '''Reads data from the trajectory data provided by NGSIM project 423 '''Reads data from the trajectory data provided by NGSIM project
424 and returns the list of Feature objects''' 424 and returns the list of Feature objects'''
425 objects = [] 425 objects = []
426 426
427 input = utils.openCheck(filename) 427 input = openCheck(filename)
428 if not input: 428 if not input:
429 import sys 429 import sys
430 sys.exit() 430 sys.exit()
431 431
432 def createObject(numbers): 432 def createObject(numbers):
487 487
488 def convertNgsimFile(inFile, outFile, append = False, nObjects = -1, sequenceNum = 0): 488 def convertNgsimFile(inFile, outFile, append = False, nObjects = -1, sequenceNum = 0):
489 '''Reads data from the trajectory data provided by NGSIM project 489 '''Reads data from the trajectory data provided by NGSIM project
490 and converts to our current format.''' 490 and converts to our current format.'''
491 if append: 491 if append:
492 out = utils.openCheck(outFile,'a') 492 out = openCheck(outFile,'a')
493 else: 493 else:
494 out = utils.openCheck(outFile,'w') 494 out = openCheck(outFile,'w')
495 nObjectsPerType = [0,0,0] 495 nObjectsPerType = [0,0,0]
496 496
497 features = loadNgsimFile(inFile, sequenceNum) 497 features = loadNgsimFile(inFile, sequenceNum)
498 for f in features: 498 for f in features:
499 nObjectsPerType[f.userType-1] += 1 499 nObjectsPerType[f.userType-1] += 1
514 p2 = curvilinearPositions[i] 514 p2 = curvilinearPositions[i]
515 s += ',{},{}'.format(p2[0],p2[1]) 515 s += ',{},{}'.format(p2[0],p2[1])
516 f.write(s+'\n') 516 f.write(s+'\n')
517 517
518 def writeTrajectoriesToCsv(filename, objects): 518 def writeTrajectoriesToCsv(filename, objects):
519 f = utils.openCheck(filename, 'w') 519 f = openCheck(filename, 'w')
520 for i,obj in enumerate(objects): 520 for i,obj in enumerate(objects):
521 writePositionsToCsv(f, obj) 521 writePositionsToCsv(f, obj)
522 f.close() 522 f.close()
523 523
524 524