Mercurial Hosting > traffic-intelligence
diff python/moving.py @ 643:bfaa6b95dae2
added function to plot curvilinear position as a function of time
author | Nicolas Saunier <nicolas.saunier@polymtl.ca> |
---|---|
date | Fri, 10 Apr 2015 15:40:27 +0200 |
parents | 3058e00887bc |
children | 107f1ad02b69 |
line wrap: on
line diff
--- a/python/moving.py Fri Apr 10 14:54:05 2015 +0200 +++ b/python/moving.py Fri Apr 10 15:40:27 2015 +0200 @@ -1073,6 +1073,28 @@ else: return None + def plotCurvilinearPositions(self, lane = None, options = '', withOrigin = False, **kwargs): + if hasattr(self, 'curvilinearPositions'): + from matplotlib.pylab import plot + from numpy import NaN + if lane is None: + plot(list(self.getTimeInterval()), self.curvilinearPositions.positions[0], options, **kwargs) + else: + instants = [] + coords = [] + for t, p in zip(self.getTimeInterval(), self.curvilinearPositions): + if p[2] == lane: + instants.append(t) + coords.append(p[0]) + else: + instants.append(NaN) + coords.append(NaN) + plot(instants, coords, options, **kwargs) + if withOrigin: + plot([self.getFirstInstant()], [self.curvilinearPositions.positions[0][0]], 'ro', **kwargs) + else: + print('Object {} has no curvilinear positions'.format(self.getNum())) + def setUserType(self, userType): self.userType = userType