[GRASS-SVN] r68744 - grass-addons/grass7/raster/r.forestfrag
svn_grass at osgeo.org
svn_grass at osgeo.org
Wed Jun 22 18:37:04 PDT 2016
Author: wenzeslaus
Date: 2016-06-22 18:37:04 -0700 (Wed, 22 Jun 2016)
New Revision: 68744
Modified:
grass-addons/grass7/raster/r.forestfrag/r.forestfrag.py
Log:
r.forestfrag: run clip mapcalc only when needed, handle tmp reg correctly
Old code also tried to delete raster and causef warning.
use_temp_region just does everything automatically.
Using better name for flag name.
Modified: grass-addons/grass7/raster/r.forestfrag/r.forestfrag.py
===================================================================
--- grass-addons/grass7/raster/r.forestfrag/r.forestfrag.py 2016-06-23 01:32:17 UTC (rev 68743)
+++ grass-addons/grass7/raster/r.forestfrag/r.forestfrag.py 2016-06-23 01:37:04 UTC (rev 68744)
@@ -182,7 +182,7 @@
" is ignored"))
flag_r = flags['r']
flag_s = flags['s']
- flag_a = flags['a']
+ clip_output = flags['a']
# set to current input map region (user option, default=current region)
@@ -325,14 +325,16 @@
Index = tmpname('tmpA15_')
gs.run_command("r.series", input=[f1,f2,f3,f4,f5,f6], output=Index,
method="sum", quiet=True)
- indexfin2 = tmpname('tmpA16_')
+ if clip_output:
+ indexfin2 = tmpname('tmpA16_')
+ else:
+ indexfin2 = opl
gs.mapcalc("$if2 = int($ipl * $Index)",
if2=indexfin2, ipl=ipl, Index=Index)
# Shrink the region
- if flag_a:
- regionoriginal = tmpname('tmpA18_')
- gs.run_command("g.region", save=regionoriginal, quiet=True, overwrite=True)
+ if clip_output:
+ gs.use_temp_region()
reginfo = gs.parse_command("g.region", flags="gp")
NSCOR = SWn * float(reginfo['nsres'])
EWCOR = SWn * float(reginfo['ewres'])
@@ -342,7 +344,7 @@
e=float(reginfo['e'])-EWCOR,
w=float(reginfo['w'])+EWCOR,
quiet=True)
- gs.mapcalc("$opl = $if3", opl=opl, if3=indexfin2, quiet=True)
+ gs.mapcalc("$opl = $if3", opl=opl, if3=indexfin2, quiet=True)
# create categories
# TODO: parametrize classes (also in r.mapcalc, r.colors and desc)?
@@ -402,11 +404,7 @@
if user_pff:
gs.info(_("The proportion forested pixel pairs (pff): %s") % pff)
- # Clean up
- if flag_a:
- gs.run_command("g.region", region=regionoriginal, quiet=True, overwrite=True)
-
if __name__ == "__main__":
options, flags = gs.parser()
atexit.register(cleanup)
More information about the grass-commit
mailing list