Mercurial Hosting > traffic-intelligence
changeset 377:2aed569f39e7
added utils
author | Nicolas Saunier <nicolas.saunier@polymtl.ca> |
---|---|
date | Thu, 18 Jul 2013 02:08:51 -0400 |
parents | 2e6b8610bcaa |
children | 3805b9639647 |
files | python/moving.py python/storage.py |
diffstat | 2 files changed, 21 insertions(+), 3 deletions(-) [+] |
line wrap: on
line diff
--- a/python/moving.py Wed Jul 17 18:19:08 2013 -0400 +++ b/python/moving.py Thu Jul 18 02:08:51 2013 -0400 @@ -687,6 +687,18 @@ def play(self, videoFilename, homography = None): cvutils.displayTrajectories(videoFilename, [self], homography, self.getFirstInstant(), self.getLastInstant()) + def speedDiagnostics(self, display = False): + from numpy import std + speeds = self.getSpeeds() + coef = utils.linearRegression(range(len(speeds)), speeds) + print(speeds[-2]-speeds[1], std(speeds), coef[0]) + if display: + from matplotlib.pyplot import figure, plot + figure(1) + self.draw() + figure(2) + plot(list(self.getTimeInterval()), speeds) + def getInstantsCrossingLane(self, p1, p2): '''Returns the instant(s) at which the object passes from one side of the segment to the other
--- a/python/storage.py Wed Jul 17 18:19:08 2013 -0400 +++ b/python/storage.py Thu Jul 18 02:08:51 2013 -0400 @@ -364,9 +364,9 @@ '''Reads data from the trajectory data provided by NGSIM project and converts to our current format.''' if append: - out = open(outFile,'a') + out = utils.openCheck(outFile,'a') else: - out = open(outFile,'w') + out = utils.openCheck(outFile,'w') nObjectsPerType = [0,0,0] features = loadNgsimFile(inFile, sequenceNum) @@ -391,11 +391,17 @@ f.write(s+'\n') def writeTrajectoriesToCsv(filename, objects): - f = open(filename, 'w') + f = utils.openCheck(filename, 'w') for i,obj in enumerate(objects): writePositionsToCsv(f, obj) f.close() +def writeList(filename, l): + f = utils.openCheck(filename, 'w') + for x in l: + f.write('{}\n'.format(x)) + f.close() + if __name__ == "__main__": import doctest import unittest