Mercurial Hosting > traffic-intelligence
diff python/moving.py @ 115:550556378466
added functionalities to indicator maps
author | Nicolas Saunier <nicolas.saunier@polymtl.ca> |
---|---|
date | Sat, 23 Jul 2011 02:18:16 -0400 |
parents | 680d4c82886d |
children | ad21db62b785 |
line wrap: on
line diff
--- a/python/moving.py Mon Jul 18 19:24:06 2011 -0400 +++ b/python/moving.py Sat Jul 23 02:18:16 2011 -0400 @@ -563,6 +563,34 @@ 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 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): + indicatorMap[(floor(x/squareSize), floor(y/squareSize))] = value + return indicatorMap + def combineIndicatorMaps(maps, squareSize, combinationFunction): '''Puts many indicator maps together (averaging the values in each cell