[GRASS-SVN] r61388 - grass/trunk/lib/python/script
svn_grass at osgeo.org
svn_grass at osgeo.org
Thu Jul 24 07:19:04 PDT 2014
Author: glynn
Date: 2014-07-24 07:19:04 -0700 (Thu, 24 Jul 2014)
New Revision: 61388
Modified:
grass/trunk/lib/python/script/raster.py
Log:
Add seed= parameter to grass.script.mapcalc()
Modified: grass/trunk/lib/python/script/raster.py
===================================================================
--- grass/trunk/lib/python/script/raster.py 2014-07-24 03:25:18 UTC (rev 61387)
+++ grass/trunk/lib/python/script/raster.py 2014-07-24 14:19:04 UTC (rev 61388)
@@ -25,6 +25,7 @@
import os
import string
import types
+import time
from core import *
@@ -86,26 +87,33 @@
# interface to r.mapcalc
-def mapcalc(exp, quiet = False, verbose = False, overwrite = False, **kwargs):
+def mapcalc(exp, quiet = False, verbose = False, overwrite = False, seed = None, **kwargs):
"""!Interface to r.mapcalc.
@param exp expression
@param quiet True to run quietly (<tt>--q</tt>)
@param verbose True to run verbosely (<tt>--v</tt>)
@param overwrite True to enable overwriting the output (<tt>--o</tt>)
+ @param seed an integer used to seed the random-number generator for the rand() function,
+ or 'auto' to generate a random seed
@param kwargs
"""
+
+ if seed == 'auto':
+ seed = hash((os.getpid(), time.time())) % (2**32)
+
t = string.Template(exp)
e = t.substitute(**kwargs)
if write_command('r.mapcalc', file = '-', stdin = e,
+ seed = seed,
quiet = quiet,
verbose = verbose,
overwrite = overwrite) != 0:
fatal(_("An error occurred while running r.mapcalc"))
-def mapcalc_start(exp, quiet = False, verbose = False, overwrite = False, **kwargs):
+def mapcalc_start(exp, quiet = False, verbose = False, overwrite = False, seed = None, **kwargs):
"""!Interface to r.mapcalc, doesn't wait for it to finish, returns Popen object.
\code
@@ -124,14 +132,21 @@
@param quiet True to run quietly (<tt>--q</tt>)
@param verbose True to run verbosely (<tt>--v</tt>)
@param overwrite True to enable overwriting the output (<tt>--o</tt>)
+ @param seed an integer used to seed the random-number generator for the rand() function,
+ or 'auto' to generate a random seed
@param kwargs
@return Popen object
"""
+
+ if seed == 'auto':
+ seed = hash((os.getpid(), time.time())) % (2**32)
+
t = string.Template(exp)
e = t.substitute(**kwargs)
p = feed_command('r.mapcalc', file = '-',
+ seed = seed,
quiet = quiet,
verbose = verbose,
overwrite = overwrite)
More information about the grass-commit
mailing list