[GRASS-SVN] r61419 - grass-addons/grass7/raster/r.random.weight

svn_grass at osgeo.org svn_grass at osgeo.org
Sun Jul 27 02:28:27 PDT 2014


Author: pvanbosgeo
Date: 2014-07-27 02:28:27 -0700 (Sun, 27 Jul 2014)
New Revision: 61419

Modified:
   grass-addons/grass7/raster/r.random.weight/r.random.weight.html
   grass-addons/grass7/raster/r.random.weight/r.random.weight.py
Log:
some small improvements / corrections

Modified: grass-addons/grass7/raster/r.random.weight/r.random.weight.html
===================================================================
--- grass-addons/grass7/raster/r.random.weight/r.random.weight.html	2014-07-27 04:02:34 UTC (rev 61418)
+++ grass-addons/grass7/raster/r.random.weight/r.random.weight.html	2014-07-27 09:28:27 UTC (rev 61419)
@@ -5,7 +5,7 @@
 
 <p>By default the script is run setting a random seed every time. To ensure that your results are reproducible you can set the seed value under the 'Sample options' tab. See the 'Random number generator initialization' in the r.mapcalc helpfile for more details.
  
-<p>By default the minimum and maximum weight are set to be equal to the minimum and maximum values of the weight raster layer. Note that this means that the raster cells with the maximum values will all be selected. You have the option however to set define different minimum and maximum weights under the 'Sample options' tab. This effectively changes the probability of cells to be selected. For example if you have a weight raster layer with values between 0 and 100 and you want to ensure all cells with a value of 50 or more are selected, you set the maximum weight at 50.
+<p>You can play with the probability for a cell to be selected by changing the minimum and/or maximum weights. The script will give a warning if the user defined minimum > minimum raster value or if the user defined maximum < maximum raster value. The script will still run as the user may have set this values intentionally.
 
 <p>You can also set the total number of sample points to be selected using the under the 'Sample options' tab. This can be done using an absolute number or as percentage (see the help file of the r.random function for more details). 
  

Modified: grass-addons/grass7/raster/r.random.weight/r.random.weight.py
===================================================================
--- grass-addons/grass7/raster/r.random.weight/r.random.weight.py	2014-07-27 04:02:34 UTC (rev 61418)
+++ grass-addons/grass7/raster/r.random.weight/r.random.weight.py	2014-07-27 09:28:27 UTC (rev 61419)
@@ -44,14 +44,14 @@
 #% key: start
 #% type: double
 #% description: minimum weight
-#% guisection: Sample options
+#% required: yes
 #%end
 
 #%option
 #% key: end
 #% type: double
 #% description: maximum weight
-#% guisection: Sample options
+#% required: yes
 #%end
 
 #%option
@@ -79,7 +79,7 @@
 import grass.script as grass
 
 # Runs modules silently
-# os.environ['GRASS_VERBOSE']='-1' 
+#os.environ['GRASS_VERBOSE']='-1' 
 
 def cleanup():
 	grass.run_command('g.remove', 
@@ -101,18 +101,15 @@
     outmap = options['output']
     subsample = options['subsample']
     seed = options['seed']
-    
-    if (minval == '' or maxval == '') :
-        minmax = grass.parse_command('r.univar', 
-            map = weight,
-            flags='g',
-            sep = ':')
-        minval = minmax['min']
-        maxval = minmax['max']
-    
+       
     # setup temporary files and seed
     tmp_map = 'r_w_rand_987654321'
     tmp_map2 = 'r_w_rand_987654321a'
+    
+    # Compute minimum and maximum value raster
+    minmax = grass.parse_command('r.univar', 
+        map = weight,
+        flags='g')
    
     if seed == "auto":  
         grass.mapcalc("$tmp_map = rand(${minval},${maxval})", 
@@ -146,9 +143,15 @@
             tmp_map2 = tmp_map2)
         grass.run_command('g.remove', rast=tmp_map2)
 
-    print("Ready, name of raster created is " + outmap)
-    print("computed over value range " + minval + " - " + maxval)
-    
+    print("------------------")
+    print("Ready!")
+    print("The name of raster created is " + outmap)
+    if minval > minmax['min'] or maxval < minmax['max']:
+        print("Warning!")
+        print("You defined the minimum and maximum weights as: " + minval + " & " + maxval)
+        print("Value range of weight raster is: " + minmax['min'] + " - " + minmax['max'])
+    print("------------------")    
+
 if __name__ == "__main__":
     options, flags = grass.parser()
     atexit.register(cleanup)



More information about the grass-commit mailing list