[GRASS-SVN] r55076 - in grass-addons/grass7/raster/r.agent: libagent tests
svn_grass at osgeo.org
svn_grass at osgeo.org
Sat Feb 16 05:50:02 PST 2013
Author: mic
Date: 2013-02-16 05:50:02 -0800 (Sat, 16 Feb 2013)
New Revision: 55076
Modified:
grass-addons/grass7/raster/r.agent/libagent/playground.py
grass-addons/grass7/raster/r.agent/tests/test_playground.py
Log:
adding halflife functionality for cell values
Modified: grass-addons/grass7/raster/r.agent/libagent/playground.py
===================================================================
--- grass-addons/grass7/raster/r.agent/libagent/playground.py 2013-02-16 07:59:19 UTC (rev 55075)
+++ grass-addons/grass7/raster/r.agent/libagent/playground.py 2013-02-16 13:50:02 UTC (rev 55076)
@@ -175,3 +175,21 @@
position[1]+1]))
return positions
+ def decaycellvalues(self, layername, halflife, minimum=0):
+ """
+ Let the values in each cell decay, volatilize or evaporate over time
+ @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
+ """
+ if halflife > 0:
+ 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)))
+ if v > minimum:
+ self.layers[layername][i][j] = v
+ else:
+ self.layers[layername][i][j] = minimum
+
Modified: grass-addons/grass7/raster/r.agent/tests/test_playground.py
===================================================================
--- grass-addons/grass7/raster/r.agent/tests/test_playground.py 2013-02-16 07:59:19 UTC (rev 55075)
+++ grass-addons/grass7/raster/r.agent/tests/test_playground.py 2013-02-16 13:50:02 UTC (rev 55076)
@@ -111,5 +111,16 @@
self.assertTrue(ps[2])
self.assertFalse(ps[3])
+ def test_decaycellvalues(self):
+ l = "bar"
+ self.pg.createlayer(l)
+ self.pg.layers[l][0][0] = 100
+ self.pg.decaycellvalues(l, 3)
+ self.assertEqual(self.pg.layers[l][0][0], 79)
+ self.pg.decaycellvalues(l, 3)
+ self.assertEqual(self.pg.layers[l][0][0], 63)
+ self.pg.decaycellvalues(l, 3)
+ self.assertEqual(self.pg.layers[l][0][0], 50)
+
# def tearDown(self):
More information about the grass-commit
mailing list