Mercurial Hosting > traffic-intelligence
changeset 660:994dd644f6ab
corrected impact of warmUpLastInstant
author | Nicolas Saunier <nicolas.saunier@polymtl.ca> |
---|---|
date | Fri, 15 May 2015 23:09:49 +0200 |
parents | 784298512b60 |
children | dc70d9e711f5 |
files | python/moving.py python/storage.py |
diffstat | 2 files changed, 12 insertions(+), 9 deletions(-) [+] |
line wrap: on
line diff
--- a/python/moving.py Thu May 14 23:18:44 2015 +0200 +++ b/python/moving.py Fri May 15 23:09:49 2015 +0200 @@ -1081,6 +1081,8 @@ from numpy import NaN if lane is None: plot(list(self.getTimeInterval()), self.curvilinearPositions.positions[0], options, **kwargs) + if withOrigin: + plot([self.getFirstInstant()], [self.curvilinearPositions.positions[0][0]], 'ro', **kwargs) else: instants = [] coords = [] @@ -1092,8 +1094,8 @@ instants.append(NaN) coords.append(NaN) plot(instants, coords, options, **kwargs) - if withOrigin: - plot([self.getFirstInstant()], [self.curvilinearPositions.positions[0][0]], 'ro', **kwargs) + if withOrigin and len(instants)>0: + plot([instants[0]], [coords[0]], 'ro', **kwargs) else: print('Object {} has no curvilinear positions'.format(self.getNum()))
--- a/python/storage.py Thu May 14 23:18:44 2015 +0200 +++ b/python/storage.py Fri May 15 23:09:49 2015 +0200 @@ -648,6 +648,9 @@ for example, there seems to be 5 simulation steps per simulated second in VISSIM, so simulationStepsPerTimeUnit should be 5, so that all times correspond to the number of the simulation step (and can be stored as integers) + + Objects positions will be considered only after warmUpLastInstant + (if the object has no such position, it won't be loaded) Assumed to be sorted over time''' objects = {} # dictionary of objects index by their id @@ -658,10 +661,10 @@ data = read_csv(filename, delimiter=';', comment='*', header=0, skiprows = 1) generatePDLaneColumn(data) data['TIME'] = data['$VEHICLE:SIMSEC']*simulationStepsPerTimeUnit + if warmUpLastInstant is not None: + data = data[data['TIME']>=warmUpLastInstant] grouped = data.loc[:,['NO','TIME']].groupby(['NO'], as_index = False) instants = grouped['TIME'].agg({'first': min, 'last': max}) - if warmUpLastInstant is not None: - instants = instants[instants['first'] >= warmUpLastInstant] for row_index, row in instants.iterrows(): objNum = int(row['NO']) tmp = data[data['NO'] == objNum] @@ -670,7 +673,6 @@ 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 @@ -682,13 +684,12 @@ s = float(data[4]) y = float(data[5]) lane = data[2]+'_'+data[3] - if objNum not in firstInstants: - firstInstants[objNum] = instant - if warmUpLastInstant is None or firstInstants[objNum] >= warmUpLastInstant: + if objNum not in objects: + if warmUpLastInstant is None or instant >= warmUpLastInstant: if nObjects < 0 or len(objects) < nObjects: objects[objNum] = moving.MovingObject(num = objNum, timeInterval = moving.TimeInterval(instant, instant)) objects[objNum].curvilinearPositions = moving.CurvilinearTrajectory() - if (warmUpLastInstant is None or firstInstants[objNum] >= warmUpLastInstant) and objNum in objects: + if (warmUpLastInstant is None or instant >= warmUpLastInstant) and objNum in objects: objects[objNum].timeInterval.last = instant objects[objNum].curvilinearPositions.addPositionSYL(s, y, lane) line = readline(inputfile, '*$')