# HG changeset patch # User Nicolas Saunier # Date 1438747972 14400 # Node ID 49e99ca34a7d2a418f6e165ed023546ab1d3d00b # Parent 52272f6bf62a4bd776491948b54704e8e07584e5 corrected bugs in old ubc code diff -r 52272f6bf62a -r 49e99ca34a7d python/storage.py --- a/python/storage.py Mon Aug 03 14:48:41 2015 -0400 +++ b/python/storage.py Wed Aug 05 00:12:52 2015 -0400 @@ -654,11 +654,11 @@ s = f.readline() return s.strip() -def getLines(f, commentCharacters = commentChar): +def getLines(f, delimiterChar = delimiterChar, commentCharacters = commentChar): '''Gets a complete entry (all the lines) in between delimiterChar.''' dataStrings = [] s = readline(f, commentCharacters) - while len(s) > 0: + while len(s) > 0 and s[0] != delimiterChar: dataStrings += [s.strip()] s = readline(f, commentCharacters) return dataStrings diff -r 52272f6bf62a -r 49e99ca34a7d python/ubc_utils.py --- a/python/ubc_utils.py Mon Aug 03 14:48:41 2015 -0400 +++ b/python/ubc_utils.py Wed Aug 05 00:12:52 2015 -0400 @@ -1,7 +1,7 @@ #! /usr/bin/env python '''Various utilities to load data saved by the UBC tool(s)''' -import utils, events +import utils, events, storage from moving import MovingObject, TimeInterval, Trajectory @@ -57,13 +57,13 @@ by just copying the corresponding trajectory and velocity data from the inFilename, and saving the characteristics in objects (first line) into outFilename''' - infile = utils.openCheck(inFilename) - outfile = utils.openCheck(outFilename,'w') + infile = storage.openCheck(inFilename) + outfile = storage.openCheck(outFilename,'w') if (inFilename.find('features') >= 0) or (not infile) or (not outfile): return - lines = utils.getLines(infile) + lines = storage.getLines(infile) objNum = 0 # in inFilename while lines != []: # find object in objects (index i) @@ -80,16 +80,16 @@ outfile.write(utils.delimiterChar+'\n') # next object objNum += 1 - lines = utils.getLines(infile) + lines = storage.getLines(infile) print('read {0} objects'.format(objNum)) def modifyTrajectoryFile(modifyLines, filenameIn, filenameOut): '''Reads filenameIn, replaces the lines with the result of modifyLines and writes the result in filenameOut''' - fileIn = utils.openCheck(filenameIn, 'r', True) - fileOut = utils.openCheck(filenameOut, "w", True) + fileIn = storage.openCheck(filenameIn, 'r', True) + fileOut = storage.openCheck(filenameOut, "w", True) - lines = utils.getLines(fileIn) + lines = storage.getLines(fileIn) trajNum = 0 while (lines != []): modifiedLines = modifyLines(trajNum, lines) @@ -97,7 +97,7 @@ for l in modifiedLines: fileOut.write(l+"\n") fileOut.write(utils.delimiterChar+"\n") - lines = utils.getLines(fileIn) + lines = storage.getLines(fileIn) trajNum += 1 fileIn.close() @@ -106,17 +106,17 @@ def copyTrajectoryFile(keepTrajectory, filenameIn, filenameOut): '''Reads filenameIn, keeps the trajectories for which the function keepTrajectory(trajNum, lines) is True and writes the result in filenameOut''' - fileIn = utils.openCheck(filenameIn, 'r', True) - fileOut = utils.openCheck(filenameOut, "w", True) + fileIn = storage.openCheck(filenameIn, 'r', True) + fileOut = storage.openCheck(filenameOut, "w", True) - lines = utils.getLines(fileIn) + lines = storage.getLines(fileIn) trajNum = 0 while (lines != []): if keepTrajectory(trajNum, lines): for l in lines: fileOut.write(l+"\n") fileOut.write(utils.delimiterChar+"\n") - lines = utils.getLines(fileIn) + lines = storage.getLines(fileIn) trajNum += 1 fileIn.close() @@ -125,14 +125,14 @@ def loadTrajectories(filename, nObjects = -1): '''Loads trajectories''' - file = utils.openCheck(filename) + file = storage.openCheck(filename) if (not file): return [] objects = [] objNum = 0 objectType = getFileType(filename) - lines = utils.getLines(file) + lines = storage.getLines(file) while (lines != []) and ((nObjects<0) or (objNum