# HG changeset patch # User Nicolas Saunier # Date 1289110190 18000 # Node ID 75cf537b8d88daf6b233f4d30ee0a0d3f62ba21c # Parent c75bcdaed00f76fffb382d5ad4c6e5a955d11d4f moved and generalized map making functions to the library diff -r c75bcdaed00f -r 75cf537b8d88 .hgignore --- a/.hgignore Fri Nov 05 11:07:44 2010 -0400 +++ b/.hgignore Sun Nov 07 01:09:50 2010 -0500 @@ -6,6 +6,7 @@ *.o *.exe *.pyc +*.pyo *~ *.rej *.orig diff -r c75bcdaed00f -r 75cf537b8d88 python/moving.py --- a/python/moving.py Fri Nov 05 11:07:44 2010 -0400 +++ b/python/moving.py Sun Nov 07 01:09:50 2010 -0500 @@ -387,6 +387,42 @@ else: return None +def indicatorMap(indicatorValues, trajectory, squareSize): + '''Returns a dictionary + with keys for the indices of the cells (squares) + in which the trajectory positions are located + at which the indicator values are attached''' + from numpy import floor, mean + assert len(indicatorValues) == trajectory.length() + indicatorMap = {} + for k in xrange(trajectory.length()): + p = trajectory[k] + i = floor(p.x/squareSize) + j = floor(p.y/squareSize) + if indicatorMap.has_key((i,j)): + indicatorMap[(i,j)].append(indicatorValues[k]) + else: + indicatorMap[(i,j)] = [indicatorValues[k]] + for k in indicatorMap.keys(): + indicatorMap[k] = mean(indicatorMap[k]) + return indicatorMap + +def combineIndicatorMaps(maps, squareSize): + '''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(): + if indicatorMap.has_key(k): + indicatorMap[k].append(v) + else: + indicatorMap[k] = [v] + for k in indicatorMap.keys(): + indicatorMap[k] = mean(indicatorMap[k]) + return indicatorMap + if __name__ == "__main__": import doctest import unittest diff -r c75bcdaed00f -r 75cf537b8d88 python/utils.py --- a/python/utils.py Fri Nov 05 11:07:44 2010 -0400 +++ b/python/utils.py Sun Nov 07 01:09:50 2010 -0500 @@ -132,6 +132,20 @@ colors = PlottingPropertyValues('brgmyck') # 'w' +def plotIndicatorMap(indicatorMap, squareSize): + from numpy import array, arange, ones, ma + from matplotlib.pyplot import pcolor + coords = array(indicatorMap.keys()) + minX = min(coords[:,0]) + minY = min(coords[:,1]) + X = arange(minX, max(coords[:,0])+1.1)*squareSize + Y = arange(minY, max(coords[:,1])+1.1)*squareSize + C = -ones((len(Y), len(X))) + for k,v in indicatorMap.iteritems(): + C[k[1]-minY,k[0]-minX] = v + masked = ma.masked_where(C<0,C) + pcolor(X, Y, masked) + ######################### # file I/O section #########################