Mercurial > hg > nsaunier > traffic-intelligence
comparison 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 |
comparison
equal
deleted
inserted
replaced
| 642:932f96c89212 | 643:bfaa6b95dae2 |
|---|---|
| 1070 def getCurvilinearPositions(self): | 1070 def getCurvilinearPositions(self): |
| 1071 if hasattr(self, 'curvilinearPositions'): | 1071 if hasattr(self, 'curvilinearPositions'): |
| 1072 return self.curvilinearPositions | 1072 return self.curvilinearPositions |
| 1073 else: | 1073 else: |
| 1074 return None | 1074 return None |
| 1075 | |
| 1076 def plotCurvilinearPositions(self, lane = None, options = '', withOrigin = False, **kwargs): | |
| 1077 if hasattr(self, 'curvilinearPositions'): | |
| 1078 from matplotlib.pylab import plot | |
| 1079 from numpy import NaN | |
| 1080 if lane is None: | |
| 1081 plot(list(self.getTimeInterval()), self.curvilinearPositions.positions[0], options, **kwargs) | |
| 1082 else: | |
| 1083 instants = [] | |
| 1084 coords = [] | |
| 1085 for t, p in zip(self.getTimeInterval(), self.curvilinearPositions): | |
| 1086 if p[2] == lane: | |
| 1087 instants.append(t) | |
| 1088 coords.append(p[0]) | |
| 1089 else: | |
| 1090 instants.append(NaN) | |
| 1091 coords.append(NaN) | |
| 1092 plot(instants, coords, options, **kwargs) | |
| 1093 if withOrigin: | |
| 1094 plot([self.getFirstInstant()], [self.curvilinearPositions.positions[0][0]], 'ro', **kwargs) | |
| 1095 else: | |
| 1096 print('Object {} has no curvilinear positions'.format(self.getNum())) | |
| 1075 | 1097 |
| 1076 def setUserType(self, userType): | 1098 def setUserType(self, userType): |
| 1077 self.userType = userType | 1099 self.userType = userType |
| 1078 | 1100 |
| 1079 def setFeatures(self, features): | 1101 def setFeatures(self, features): |
