Mercurial Hosting > traffic-intelligence
changeset 691:fa9aa5f08210 dev
cleaned imports in indicators.py
author | Nicolas Saunier <nicolas.saunier@polymtl.ca> |
---|---|
date | Mon, 29 Jun 2015 16:15:04 -0400 |
parents | 463150a8e129 |
children | 9a258687af4c |
files | python/events.py python/indicators.py |
diffstat | 2 files changed, 21 insertions(+), 29 deletions(-) [+] |
line wrap: on
line diff
--- a/python/events.py Mon Jun 29 15:47:30 2015 -0400 +++ b/python/events.py Mon Jun 29 16:15:04 2015 -0400 @@ -192,16 +192,16 @@ self.interactionInterval = moving.TimeInterval() self.addIndicator(indicators.SeverityIndicator(Interaction.indicatorNames[0], collisionCourseDotProducts)) self.addIndicator(indicators.SeverityIndicator(Interaction.indicatorNames[1], collisionCourseAngles)) - self.addIndicator(indicators.SeverityIndicator(Interaction.indicatorNames[2], distances)) + self.addIndicator(indicators.SeverityIndicator(Interaction.indicatorNames[2], distances, mostSevereIsMax = False)) self.addIndicator(indicators.SeverityIndicator(Interaction.indicatorNames[4], velocityAngles)) self.addIndicator(indicators.SeverityIndicator(Interaction.indicatorNames[5], speedDifferentials)) # if we have features, compute other indicators if self.roadUser1.hasFeatures() and self.roadUser2.hasFeatures(): - minDistance={} + minDistances={} for instant in self.timeInterval: - minDistance[instant] = moving.MovingObject.minDistance(self.roadUser1, self.roadUser2, instant) - self.addIndicator(indicators.SeverityIndicator(Interaction.indicatorNames[3], minDistance)) + minDistances[instant] = moving.MovingObject.minDistance(self.roadUser1, self.roadUser2, instant) + self.addIndicator(indicators.SeverityIndicator(Interaction.indicatorNames[3], minDistances, mostSevereIsMax = False)) def computeCrossingsCollisions(self, predictionParameters, collisionDistanceThreshold, timeHorizon, computeCZ = False, debug = False, timeInterval = None, nProcesses = 1, usePrototypes=False, route1= (-1,-1), route2=(-1,-1), prototypes={}, secondStepPrototypes={}, nMatching={}, objects=[], noiseEntryNums=[], noiseExitNums=[], minSimilarity=0.1, mostMatched=None, useDestination=True, useSpeedPrototype=True, acceptPartialLength=30, step=1): '''Computes all crossing and collision points at each common instant for two road users. '''
--- a/python/indicators.py Mon Jun 29 15:47:30 2015 -0400 +++ b/python/indicators.py Mon Jun 29 16:15:04 2015 -0400 @@ -2,6 +2,10 @@ '''Class for indicators, temporal indicators, and safety indicators''' import moving +#import matplotlib.nxutils as nx +from matplotlib.pyplot import plot, ylim +from matplotlib.pylab import find +from numpy import array, arange, mean, floor, mean # need for a class representing the indicators, their units, how to print them in graphs... @@ -74,7 +78,6 @@ return [self.__getitem__(t) for t in self.timeInterval] def plot(self, options = '', xfactor = 1., yfactor = 1., timeShift = 0, **kwargs): - from matplotlib.pylab import plot,ylim if self.getTimeInterval().length() == 1: marker = 'o' else: @@ -141,9 +144,6 @@ self.mostSevereIsMax = mostSevereIsMax def getMostSevereValue(self, minNInstants=1): # TODO use np.percentile - from matplotlib.mlab import find - from numpy.core.multiarray import array - from numpy.core.fromnumeric import mean values = array(self.values.values()) indices = range(len(values)) if len(indices) >= minNInstants: @@ -163,7 +163,6 @@ ex: speeds and trajectory''' - from numpy import floor, mean assert len(indicatorValues) == trajectory.length() indicatorMap = {} for k in xrange(trajectory.length()): @@ -178,28 +177,22 @@ indicatorMap[k] = mean(indicatorMap[k]) return indicatorMap -def indicatorMapFromPolygon(value, polygon, squareSize): - '''Fills an indicator map with the value within the polygon - (array of Nx2 coordinates of the polygon vertices)''' - import matplotlib.nxutils as nx - from numpy.core.multiarray import array, arange - from numpy import floor - - points = [] - for x in arange(min(polygon[:,0])+squareSize/2, max(polygon[:,0]), squareSize): - for y in arange(min(polygon[:,1])+squareSize/2, max(polygon[:,1]), squareSize): - points.append([x,y]) - inside = nx.points_inside_poly(array(points), polygon) - indicatorMap = {} - for i in xrange(len(inside)): - if inside[i]: - indicatorMap[(floor(points[i][0]/squareSize), floor(points[i][1]/squareSize))] = 0 - return indicatorMap +# def indicatorMapFromPolygon(value, polygon, squareSize): +# '''Fills an indicator map with the value within the polygon +# (array of Nx2 coordinates of the polygon vertices)''' +# points = [] +# for x in arange(min(polygon[:,0])+squareSize/2, max(polygon[:,0]), squareSize): +# for y in arange(min(polygon[:,1])+squareSize/2, max(polygon[:,1]), squareSize): +# points.append([x,y]) +# inside = nx.points_inside_poly(array(points), polygon) +# indicatorMap = {} +# for i in xrange(len(inside)): +# if inside[i]: +# indicatorMap[(floor(points[i][0]/squareSize), floor(points[i][1]/squareSize))] = 0 +# return indicatorMap def indicatorMapFromAxis(value, limits, squareSize): '''axis = [xmin, xmax, ymin, ymax] ''' - from numpy.core.multiarray import arange - from numpy import floor indicatorMap = {} for x in arange(limits[0], limits[1], squareSize): for y in arange(limits[2], limits[3], squareSize): @@ -210,7 +203,6 @@ '''Puts many indicator maps together (averaging the values in each cell if more than one maps has a value)''' - #from numpy import mean indicatorMap = {} for m in maps: for k,v in m.iteritems():