[GRASS-SVN] r55789 - grass/branches/releasebranch_6_4/lib/python
svn_grass at osgeo.org
svn_grass at osgeo.org
Sun Apr 14 03:04:08 PDT 2013
Author: hamish
Date: 2013-04-14 03:04:08 -0700 (Sun, 14 Apr 2013)
New Revision: 55789
Modified:
grass/branches/releasebranch_6_4/lib/python/raster.py
Log:
backport raster.mapcalc_start() from devbr6, allows parallelizing mapcalc calls.
Modified: grass/branches/releasebranch_6_4/lib/python/raster.py
===================================================================
--- grass/branches/releasebranch_6_4/lib/python/raster.py 2013-04-14 09:48:27 UTC (rev 55788)
+++ grass/branches/releasebranch_6_4/lib/python/raster.py 2013-04-14 10:04:08 UTC (rev 55789)
@@ -108,3 +108,42 @@
if write_command('r.mapcalc', stdin = e, env = env) != 0:
fatal(_("An error occurred while running r.mapcalc"))
+
+
+def mapcalc_start(exp, quiet = False, verbose = False, overwrite = False, **kwargs):
+ """!Interface to r.mapcalc, doesn't wait for it to finish, returns Popen object.
+
+ \code
+ >>> expr1 = '"%s" = "%s" * 10' % (output, input)
+ >>> expr2 = '...' # etc.
+ >>> # launch the jobs:
+ >>> p1 = grass.mapcalc_start(expr1)
+ >>> p2 = grass.mapcalc_start(expr2) # etc.
+ ...
+ >>> # wait for them to finish:
+ >>> p1.wait()
+ >>> p2.wait() # etc.
+ \endcode
+
+ @param exp expression
+ @param kwargs
+
+ @return Popen object
+ """
+ t = string.Template(exp)
+ e = t.substitute(**kwargs)
+
+ env = os.environ.copy()
+ if quiet:
+ env['GRASS_VERBOSE'] = '0'
+ if verbose:
+ env['GRASS_VERBOSE'] = '3'
+ if overwrite:
+ env['GRASS_OVERWRITE'] = '1'
+
+ stdin = e
+ p = feed_command('r.mapcalc', env = env, **kwargs)
+ p.stdin.write(stdin)
+ p.stdin.close()
+
+ return p
More information about the grass-commit
mailing list