# HG changeset patch # User Nicolas Saunier # Date 1428673227 -7200 # Node ID bfaa6b95dae26018288fc5599b8ec48d73e76c0f # Parent 932f96c89212cad6ee3188ce88748dedd9bcd8e0 added function to plot curvilinear position as a function of time diff -r 932f96c89212 -r bfaa6b95dae2 python/moving.py --- 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 diff -r 932f96c89212 -r bfaa6b95dae2 python/storage.py --- a/python/storage.py Fri Apr 10 14:54:05 2015 +0200 +++ b/python/storage.py Fri Apr 10 15:40:27 2015 +0200 @@ -661,7 +661,6 @@ Assumed to be sorted over time''' objects = {} # dictionary of objects index by their id - firstInstants = {} if usePandas: from pandas import read_csv @@ -681,6 +680,7 @@ objects[objNum].curvilinearPositions = moving.CurvilinearTrajectory(S = round(tmp['POS'].tolist(), nDecimals), Y = round(tmp['POSLAT'].tolist(), nDecimals), lanes = tmp['LANE'].tolist()) return objects.values() else: + firstInstants = {} inputfile = openCheck(filename, quitting = True) # data = pd.read_csv(filename, skiprows=15, delimiter=';') # skip header: 15 lines + 1