changeset 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 932f96c89212
children e54751e71d61
files python/moving.py python/storage.py
diffstat 2 files changed, 23 insertions(+), 1 deletions(-) [+]
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
 
--- 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