Mercurial Hosting > traffic-intelligence
changeset 161:41a5853ec495
added utility to offset the time intervales of complete trajectory files
author | Nicolas Saunier <nicolas.saunier@polymtl.ca> |
---|---|
date | Tue, 20 Sep 2011 13:49:01 -0400 |
parents | b0719b3ad3db |
children | 61fd5aff418c |
files | python/offset-trajectories.py python/ubc_utils.py |
diffstat | 2 files changed, 24 insertions(+), 2 deletions(-) [+] |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/python/offset-trajectories.py Tue Sep 20 13:49:01 2011 -0400 @@ -0,0 +1,23 @@ +#! /usr/bin/env python +import sys + +import ubc_utils +import utils + +if len(sys.argv) < 3: + print("Usage: %s filename offsetframes") + sys.exit() + +nFrames = int(sys.argv[2]) + +def modifyLines(objectNum, lines): + result = lines + tmp = lines[0].split(" ") + firstInstant = int(tmp[1])+nFrames + lastInstant = int(tmp[2])+nFrames + tmp[1] = str(firstInstant) + tmp[2] = str(lastInstant) + result[0] = " ".join(tmp) + return result + +ubc_utils.modifyTrajectoryFile(modifyLines, sys.argv[1], sys.argv[1]+".new")
--- a/python/ubc_utils.py Mon Sep 19 16:43:28 2011 -0400 +++ b/python/ubc_utils.py Tue Sep 20 13:49:01 2011 -0400 @@ -80,8 +80,7 @@ print('read {0} objects'.format(objNum)) def modifyTrajectoryFile(modifyLines, filenameIn, filenameOut): - '''Reads filenameIn, replaces the first line with the result of modifyLines and writes the result in filenameOut''' - #sortByNum(objects) + '''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)