Mercurial > hg > nsaunier > traffic-intelligence
comparison 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 |
comparison
equal
deleted
inserted
replaced
| 114:680d4c82886d | 115:550556378466 |
|---|---|
| 561 indicatorMap[(i,j)] = [indicatorValues[k]] | 561 indicatorMap[(i,j)] = [indicatorValues[k]] |
| 562 for k in indicatorMap.keys(): | 562 for k in indicatorMap.keys(): |
| 563 indicatorMap[k] = mean(indicatorMap[k]) | 563 indicatorMap[k] = mean(indicatorMap[k]) |
| 564 return indicatorMap | 564 return indicatorMap |
| 565 | 565 |
| 566 def indicatorMapFromPolygon(value, polygon, squareSize): | |
| 567 '''Fills an indicator map with the value within the polygon | |
| 568 (array of Nx2 coordinates of the polygon vertices)''' | |
| 569 import matplotlib.nxutils as nx | |
| 570 from numpy.core.multiarray import array, arange | |
| 571 from numpy import floor | |
| 572 | |
| 573 points = [] | |
| 574 for x in arange(min(polygon[:,0])+squareSize/2, max(polygon[:,0]), squareSize): | |
| 575 for y in arange(min(polygon[:,1])+squareSize/2, max(polygon[:,1]), squareSize): | |
| 576 points.append([x,y]) | |
| 577 inside = nx.points_inside_poly(array(points), polygon) | |
| 578 indicatorMap = {} | |
| 579 for i in xrange(len(inside)): | |
| 580 if inside[i]: | |
| 581 indicatorMap[(floor(points[i][0]/squareSize), floor(points[i][1]/squareSize))] = 0 | |
| 582 return indicatorMap | |
| 583 | |
| 584 def indicatorMapFromAxis(value, limits, squareSize): | |
| 585 '''axis = [xmin, xmax, ymin, ymax] ''' | |
| 586 from numpy.core.multiarray import arange | |
| 587 from numpy import floor | |
| 588 indicatorMap = {} | |
| 589 for x in arange(limits[0], limits[1], squareSize): | |
| 590 for y in arange(limits[2], limits[3], squareSize): | |
| 591 indicatorMap[(floor(x/squareSize), floor(y/squareSize))] = value | |
| 592 return indicatorMap | |
| 593 | |
| 566 def combineIndicatorMaps(maps, squareSize, combinationFunction): | 594 def combineIndicatorMaps(maps, squareSize, combinationFunction): |
| 567 '''Puts many indicator maps together | 595 '''Puts many indicator maps together |
| 568 (averaging the values in each cell | 596 (averaging the values in each cell |
| 569 if more than one maps has a value)''' | 597 if more than one maps has a value)''' |
| 570 #from numpy import mean | 598 #from numpy import mean |
