[GRASS-SVN] r59282 - grass-addons/grass7/raster/r.skyview

svn_grass at osgeo.org svn_grass at osgeo.org
Tue Mar 18 09:10:45 PDT 2014


Author: zarch
Date: 2014-03-18 09:10:45 -0700 (Tue, 18 Mar 2014)
New Revision: 59282

Modified:
   grass-addons/grass7/raster/r.skyview/r.skyview.py
Log:
Add an optional parameter: 'prefix' to keep intermediate maps.

Modified: grass-addons/grass7/raster/r.skyview/r.skyview.py
===================================================================
--- grass-addons/grass7/raster/r.skyview/r.skyview.py	2014-03-18 10:42:12 UTC (rev 59281)
+++ grass-addons/grass7/raster/r.skyview/r.skyview.py	2014-03-18 16:10:45 UTC (rev 59282)
@@ -31,7 +31,7 @@
 #% type: integer
 #% required: yes
 #% answer: 16
-#% options: 2-64
+#% options: 2-360
 #%end
 #%option
 #% key: maxdistance
@@ -39,6 +39,12 @@
 #% type: double
 #% required: no
 #%end
+#%option
+#%  key: prefix
+#%  type: string
+#%  multiple: no
+#%  description: Set the prefix of the created maps
+#%end
 
 
 import sys
@@ -47,10 +53,13 @@
 
 import grass.script.core as gcore
 import grass.script.raster as grast
+from grass.pygrass.messages import get_msgr
 
-TMP_NAME = 'tmp_horizon_'+ str(os.getpid())
+
+TMP_NAME = 'tmp_horizon_' + str(os.getpid())
 CLEANUP = True
 
+
 def cleanup():
     if CLEANUP:
         gcore.run_command('g.mremove', rast=TMP_NAME + "*", flags='f')
@@ -60,26 +69,30 @@
     elev = options['input']
     output = options['output']
     n_dir = int(options['ndir'])
+    global TMP_NAME, CLEANUP
+    if options['prefix']:
+        TMP_NAME = options['prefix']
+        CLEANUP = False
     horizon_step = 360. / n_dir
+    msgr = get_msgr()
 
     # checks if there are already some maps
     old_maps = _get_horizon_maps()
     if old_maps:
         if not gcore.overwrite():
-            global CLEANUP
             CLEANUP = False
-            gcore.fatal(_("You have to first check overwrite flag or remove the following maps:\n"
-                          "{names}").format(names=','.join(old_maps)))
+            msgr.fatal(_("You have to first check overwrite flag or remove the following maps:\n"
+                         "{names}").format(names=','.join(old_maps)))
         else:
-            gcore.warning(_("The following maps will be overwritten: {names}").format(names=','.join(old_maps)))
+            msgr.warning(_("The following maps will be overwritten: {names}").format(names=','.join(old_maps)))
 
     ret = gcore.run_command('r.horizon', elevin=elev, direction=0, horizonstep=horizon_step,
                             horizon=TMP_NAME, flags='d')
     if ret != 0:
-        gcore.fatal(_("r.horizon failed to compute horizon elevation angle maps. "
-                      "Please report this problem to developers."))
+        msgr.fatal(_("r.horizon failed to compute horizon elevation angle maps. "
+                     "Please report this problem to developers."))
 
-    gcore.info(_("Computing sky view factor ..."))
+    msgr.message(_("Computing sky view factor ..."))
     new_maps = _get_horizon_maps()
     expr = "{out} = 1 - (sin({first}) ".format(first=new_maps[0], out=output)
     for horizon in new_maps[1:]:



More information about the grass-commit mailing list