[GRASS-SVN] r74196 - grass-addons/grass7/raster/r.landscape.evol

svn_grass at osgeo.org svn_grass at osgeo.org
Sat Mar 9 03:47:57 PST 2019


Author: cmbarton
Date: 2019-03-09 03:47:57 -0800 (Sat, 09 Mar 2019)
New Revision: 74196

Modified:
   grass-addons/grass7/raster/r.landscape.evol/r.landscape.evol.py
Log:
fixed Windows bug for color rules file

Modified: grass-addons/grass7/raster/r.landscape.evol/r.landscape.evol.py
===================================================================
--- grass-addons/grass7/raster/r.landscape.evol/r.landscape.evol.py	2019-03-08 20:46:46 UTC (rev 74195)
+++ grass-addons/grass7/raster/r.landscape.evol/r.landscape.evol.py	2019-03-09 11:47:57 UTC (rev 74196)
@@ -349,13 +349,15 @@
         tmperosion = '%sTEMPORARY_erosion%04d' % (pid, o)
         tmpdep = '%sTEMPORARY_deposition%04d' % (pid, o)
     # Make color rules for netchange maps
-    nccolors = tempfile.NamedTemporaryFile()
-    nccolors.write('100% 0 0 100\n1 blue\n0.5 indigo\n0.01 green\n0 white\n-0.01 yellow\n-0.5 orange\n-1 red\n0% 150 0 50')
-    nccolors.flush()
+    nccolors = grass.tempfile()
+    colors = open(nccolors, 'w')
+    colors.write('100% 0 0 100\n1 blue\n0.5 indigo\n0.01 green\n0 white\n-0.01 yellow\n-0.5 orange\n-1 red\n0% 150 0 50\n')
+    colors.close()
     # Make color rules for soil depth maps
-    sdcolors = tempfile.NamedTemporaryFile()
-    sdcolors.write('100% 0:249:47\n20% 78:151:211\n6% 194:84:171\n0% 227:174:217')
-    sdcolors.flush()
+    sdcolors = grass.tempfile()
+    colors = open(sdcolors, 'w')
+    colors.write('100% 0:249:47\n20% 78:151:211\n6% 194:84:171\n0% 227:174:217\n')
+    colors.close()
     # If first iteration, use input maps. Otherwise, use maps generated from previous iterations
     if ( o == 1 ):
         old_dem = '%s' % options["elev"]
@@ -408,6 +410,7 @@
         grass.run_command('v.db.renamecolumn', quiet = "True", map = vout, column = 'covervalue,Princ_curv')
         grass.run_command('v.db.addcolumn', quiet = "True", map = vout, columns = 'Tang_curv double precision, Slope double precision')
         grass.run_command('v.what.rast', quiet = "True", map = vout, raster = tc, column = "Tang_curv")
+        grass.run_command('v.what.rast', quiet = "True", map = vout, raster = slope, column = "Slope")
         if ( flags["k"] is True ):
             grass.message('--Keeping the created maps (Flow Accumulation, Slope, Principle Curvature, Tangential Curvature)')
         else:
@@ -505,7 +508,7 @@
         grass.message('There was a problem reading the median-smoothing variable, so maps will not be median-smoothed.')
         grass.run_command('g.rename',  quiet = "True", rast = tempnetchange2 + ',' + netchange)
     #Set the netchange map colors to the rules we've provided above
-    grass.run_command('r.colors', quiet = "True", map = netchange, rules = nccolors.name)
+    grass.run_command('r.colors', quiet = "True", map = netchange, rules = nccolors)
     #Grab the stats from these new smoothed netchange maps and save them to dictionaries (Note that the temporary erosion and deposition maps made in this step are overwriting the two temporary maps made for gathering the stats for the soft-knee limiting filter)
     grass.mapcalc('${tmperosion}=if(${netchange} < -0, ${netchange}, null())', quiet = "True", overwrite = "True", tmperosion = tmperosion, netchange = netchange)
     grass.mapcalc('${tmpdep}=if(${netchange} > 0, ${netchange}, null())', quiet = "True", overwrite = "True", tmpdep = tmpdep, netchange = netchange)
@@ -518,7 +521,7 @@
     #Set colors for elevation map to match other dems
     grass.run_command('r.colors',  quiet = "True", map = new_dem, rast = options["elev"])
     grass.mapcalc('${new_soil}=if ((${new_dem} - ${initbdrk}) < 0, 0, (${new_dem} - ${initbdrk}))', quiet = "True", new_soil = new_soil, new_dem = new_dem, initbdrk = initbdrk)
-    grass.run_command('r.colors', quiet = "True", map = new_soil, rules = sdcolors.name)
+    grass.run_command('r.colors', quiet = "True", map = new_soil, rules = sdcolors)
     grass.message('\n*************************\n Iteration %s -- ' % o + 'step 6: writing stats to output file\n *************************\n\n')
     #Finish gathering stats (just need the soil depth stats now)
     soilstats = grass.parse_command('r.univar', flags = 'ge', map = new_soil, percentile = '99')
@@ -569,8 +572,8 @@
             pass
         else:
             grass.run_command('g.remove', quiet = "True", flags = 'f', type = "rast", name = ','.join(mapstoremove))
-    sdcolors.close()
-    nccolors.close()
+    #sdcolors.close()
+    #nccolors.close()
     grass.message('\n*************************\nDone with Iteration %s ' % o + '\n*************************\n')
     return(0)
 



More information about the grass-commit mailing list