[GRASS-SVN] r56043 - grass-addons/grass7/raster/r.agent/libagent
svn_grass at osgeo.org
svn_grass at osgeo.org
Tue Apr 30 02:18:36 PDT 2013
Author: mic
Date: 2013-04-30 02:18:36 -0700 (Tue, 30 Apr 2013)
New Revision: 56043
Modified:
grass-addons/grass7/raster/r.agent/libagent/grassland.py
grass-addons/grass7/raster/r.agent/libagent/playground.py
Log:
optimize decay for numpy and remove rounding alltogether
Modified: grass-addons/grass7/raster/r.agent/libagent/grassland.py
===================================================================
--- grass-addons/grass7/raster/r.agent/libagent/grassland.py 2013-04-30 09:16:06 UTC (rev 56042)
+++ grass-addons/grass7/raster/r.agent/libagent/grassland.py 2013-04-30 09:18:36 UTC (rev 56043)
@@ -116,3 +116,20 @@
self.layers[layername][p[0]][p[1]] = value
return vectors
+ def decaycellvalues(self, layername, halflife, minimum=0):
+ """
+ Let the values in each cell decay, volatilize or evaporate over time.
+ This method is optimized for numpy arrays, see playground for plain
+ arrays.
+ @param string layername name of the layer to work on
+ @param long halflife or number of years when to reach half of the value
+ @param long minimum value to keep on cell
+ """
+ layer = self.layers[layername]
+ if halflife > 0:
+ layer = layer*0.5**(1.0/halflife)
+ #TODO think about moving 'minimum' to a predifined matrix in anthill
+ if minimum > 0:
+ mask = garray.numpy.ones_like(layer) + minimum
+ garray.numpy.maximum(layer, mask)
+
Modified: grass-addons/grass7/raster/r.agent/libagent/playground.py
===================================================================
--- grass-addons/grass7/raster/r.agent/libagent/playground.py 2013-04-30 09:16:06 UTC (rev 56042)
+++ grass-addons/grass7/raster/r.agent/libagent/playground.py 2013-04-30 09:18:36 UTC (rev 56043)
@@ -196,7 +196,9 @@
def decaycellvalues(self, layername, halflife, minimum=0):
"""
- Let the values in each cell decay, volatilize or evaporate over time
+ Let the values in each cell decay, volatilize or evaporate over time.
+ This method is intendet for relativly small 2D python arrays, see
+ grassland.Grassland.decaycellvalues for numpy arrays.
@param string layername name of the layer to work on
@param long halflife or number of years when to reach half of the value
@param long minimum value to keep on cell
@@ -205,8 +207,7 @@
for i in range(self.region["rows"]):
for j in range(self.region["cols"]):
if self.layers[layername][i][j] > minimum:
- v = int(round(
- self.layers[layername][i][j]*0.5**(1.0/halflife)))
+ v = self.layers[layername][i][j]*0.5**(1.0/halflife)
if v > minimum:
self.layers[layername][i][j] = v
else:
More information about the grass-commit
mailing list