comparison python/storage.py @ 377:2aed569f39e7

added utils
author Nicolas Saunier <nicolas.saunier@polymtl.ca>
date Thu, 18 Jul 2013 02:08:51 -0400
parents 14a2405f54f8
children ba813f148ade
comparison
equal deleted inserted replaced
376:2e6b8610bcaa 377:2aed569f39e7
362 362
363 def convertNgsimFile(inFile, outFile, append = False, nObjects = -1, sequenceNum = 0): 363 def convertNgsimFile(inFile, outFile, append = False, nObjects = -1, sequenceNum = 0):
364 '''Reads data from the trajectory data provided by NGSIM project 364 '''Reads data from the trajectory data provided by NGSIM project
365 and converts to our current format.''' 365 and converts to our current format.'''
366 if append: 366 if append:
367 out = open(outFile,'a') 367 out = utils.openCheck(outFile,'a')
368 else: 368 else:
369 out = open(outFile,'w') 369 out = utils.openCheck(outFile,'w')
370 nObjectsPerType = [0,0,0] 370 nObjectsPerType = [0,0,0]
371 371
372 features = loadNgsimFile(inFile, sequenceNum) 372 features = loadNgsimFile(inFile, sequenceNum)
373 for f in features: 373 for f in features:
374 nObjectsPerType[f.userType-1] += 1 374 nObjectsPerType[f.userType-1] += 1
389 p2 = curvilinearPositions[i] 389 p2 = curvilinearPositions[i]
390 s += ',{},{}'.format(p2[0],p2[1]) 390 s += ',{},{}'.format(p2[0],p2[1])
391 f.write(s+'\n') 391 f.write(s+'\n')
392 392
393 def writeTrajectoriesToCsv(filename, objects): 393 def writeTrajectoriesToCsv(filename, objects):
394 f = open(filename, 'w') 394 f = utils.openCheck(filename, 'w')
395 for i,obj in enumerate(objects): 395 for i,obj in enumerate(objects):
396 writePositionsToCsv(f, obj) 396 writePositionsToCsv(f, obj)
397 f.close()
398
399 def writeList(filename, l):
400 f = utils.openCheck(filename, 'w')
401 for x in l:
402 f.write('{}\n'.format(x))
397 f.close() 403 f.close()
398 404
399 if __name__ == "__main__": 405 if __name__ == "__main__":
400 import doctest 406 import doctest
401 import unittest 407 import unittest