[GRASS-SVN] r58542 - grass-addons/grass7/raster/r.sun.hourly

svn_grass at osgeo.org svn_grass at osgeo.org
Sat Dec 28 08:33:58 PST 2013


Author: annakrat
Date: 2013-12-28 08:33:57 -0800 (Sat, 28 Dec 2013)
New Revision: 58542

Modified:
   grass-addons/grass7/raster/r.sun.hourly/r.sun.hourly.html
   grass-addons/grass7/raster/r.sun.hourly/r.sun.hourly.py
Log:
r.sun.hourly: new flag b for binary output

Modified: grass-addons/grass7/raster/r.sun.hourly/r.sun.hourly.html
===================================================================
--- grass-addons/grass7/raster/r.sun.hourly/r.sun.hourly.html	2013-12-28 15:16:23 UTC (rev 58541)
+++ grass-addons/grass7/raster/r.sun.hourly/r.sun.hourly.html	2013-12-28 16:33:57 UTC (rev 58542)
@@ -5,15 +5,20 @@
 (instant mode, see r.sun <a href="r.sun.html">manual page</a>).
 
 <h3>Output parameters explanation</h3>
-Output is one or more series of raster maps.
-
-Series of maps are (if flag <i>t</i> is checked) registered
+<p>
+Output is one or more series of irradiance raster maps.
+If flag <b>b</b> is checked the output is a series of binary maps.
+Using this flag in combination with <n>beam_rad_basename</b>
+is a convenient way to determine if there is direct sunlight or not at a certain place and time.
+</p>
+<p>
+Series of maps are (if flag <b>t</b> is checked) registered
 to space time raster dataset with absolute time and point time (not interval time).
-Option <i>year</i> has to be specified so that the raster maps can be registered
+Option <b>year</b> has to be specified so that the raster maps can be registered
 to space time dataset or assigned a timestamp. The reason is that it is not possible
 to assign time without date.
-
 For GRASS 6, only timestamp is assigned.
+</p>
 
 <h2>EXAMPLE</h2>
 
@@ -26,6 +31,9 @@
 t.rast.list beam
 </pre></div>
 
+<h2>NOTE</h2>
+Beam irradiance binary raster maps can be displayed as semitransparent over other map layers
+or module <a href="r.null.html"><em>r.null</em></a> can be used to set one of the values (either shade or sunlight) as NULL.
 
 <h2>SEE ALSO</h2>
 

Modified: grass-addons/grass7/raster/r.sun.hourly/r.sun.hourly.py
===================================================================
--- grass-addons/grass7/raster/r.sun.hourly/r.sun.hourly.py	2013-12-28 15:16:23 UTC (rev 58541)
+++ grass-addons/grass7/raster/r.sun.hourly/r.sun.hourly.py	2013-12-28 16:33:57 UTC (rev 58542)
@@ -125,6 +125,10 @@
 #% label: Register created series of output maps into temporal dataset
 #%end
 #%flag
+#% key: b
+#% description: Create binary rasters instead of irradiation rasters
+#%end
+#%flag
 #% key: overwrite
 #% description: Allow output files to overwrite existing files
 #%end
@@ -162,7 +166,7 @@
 
 # add latitude map
 def run_r_sun(elevation, aspect, slope, day, time, beam_rad, diff_rad,
-              refl_rad, glob_rad, incidout, suffix):
+              refl_rad, glob_rad, incidout, suffix, binary, binaryTmpName):
     params = {}
     if beam_rad:
         params.update({'beam_rad': beam_rad + suffix})
@@ -187,14 +191,27 @@
                           day=day, time=time,
                           overwrite=core.overwrite(), quiet=True,
                           **params)
+    if binary:
+        for output in (beam_rad, diff_rad, refl_rad, glob_rad):
+            if not output:
+                continue
+            exp='{out} = if({inp} > 0, 1, 0)'.format(out=output + suffix + binaryTmpName,
+                                                    inp=output + suffix)
+            grass.mapcalc(exp=exp, overwrite=core.overwrite())
+            grass.run_command('g.rename', rast=[output + suffix + binaryTmpName,
+                                                output + suffix],
+                              overwrite=True)
 
 
-def set_color_table(rasters):
+def set_color_table(rasters, binary=False):
+    table = 'gyr'
+    if binary:
+        table='grey'
     if is_grass_7():
-        grass.run_command('r.colors', map=rasters, col='gyr', quiet=True)
+        grass.run_command('r.colors', map=rasters, col=table, quiet=True)
     else:
         for rast in rasters:
-            grass.run_command('r.colors', map=rast, col='gyr', quiet=True)
+            grass.run_command('r.colors', map=rast, col=table, quiet=True)
 
 
 def set_time_stamp(raster, time):
@@ -205,13 +222,23 @@
     return '%05.2f' % time
 
 
-def check_time_map_names(basename, mapset, start_time, end_time, time_step):
+def check_time_map_names(basename, mapset, start_time, end_time, time_step,
+                         binary, binaryTmpName):
     if not basename:
         return
     for time in frange(start_time, end_time, time_step):
-        map_ = '%s%s%s' % (basename, '_', format_time(time))
-        if grass.find_file(map_, element='cell', mapset=mapset)['file']:
-            grass.fatal(_("Raster map <%s> already exists. Change the base name or allow overwrite.") % map_)
+        maps = []
+        maps.append('{name}{delim}{time}'.format(name=basename,
+                                                    delim='_',
+                                                    time=format_time(time)))
+        if binary:
+            maps.append('{name}{delim}{time}{binary}'.format(name=basename,
+                                                             delim='_',
+                                                             time=format_time(time),
+                                                             binary=binaryTmpName))
+        for map_ in maps:
+            if grass.find_file(map_, element='cell', mapset=mapset)['file']:
+                grass.fatal(_("Raster map <%s> already exists. Change the base name or allow overwrite.") % map_)
 
 
 def frange(x, y, step):
@@ -255,6 +282,8 @@
     nprocs = int(options['nprocs'])
     day = int(options['day'])
     temporal = flags['t']
+    binary = flags['b']
+    binaryTmpName = 'binary'
     year = int(options['year'])
 
     if not is_grass_7() and temporal:
@@ -269,13 +298,13 @@
     # here we check all the days
     if not grass.overwrite():
         check_time_map_names(beam_rad_basename, grass.gisenv()['MAPSET'],
-                              start_time, end_time, time_step)
+                              start_time, end_time, time_step, binary, binaryTmpName)
         check_time_map_names(diff_rad_basename, grass.gisenv()['MAPSET'],
-                              start_time, end_time, time_step)
+                              start_time, end_time, time_step, binary, binaryTmpName)
         check_time_map_names(refl_rad_basename, grass.gisenv()['MAPSET'],
-                              start_time, end_time, time_step)
+                              start_time, end_time, time_step, binary, binaryTmpName)
         check_time_map_names(glob_rad_basename, grass.gisenv()['MAPSET'],
-                              start_time, end_time, time_step)
+                              start_time, end_time, time_step, binary, binaryTmpName)
 
     # check for slope/aspect
     if not aspect_input or not slope_input:
@@ -315,7 +344,8 @@
                                        refl_rad_basename,
                                        glob_rad_basename,
                                        incidout_basename,
-                                       suffix)))
+                                       suffix,
+                                       binary, binaryTmpName)))
 
         proc_list[proc_count].start()
         proc_count += 1
@@ -401,16 +431,16 @@
 
     if beam_rad_basename:
         maps = [beam_rad_basename + suf for suf in suffixes_all]
-        set_color_table(maps)
+        set_color_table(maps, binary)
     if diff_rad_basename:
         maps = [diff_rad_basename + suf for suf in suffixes_all]
-        set_color_table(maps)
+        set_color_table(maps, binary)
     if refl_rad_basename:
         maps = [refl_rad_basename + suf for suf in suffixes_all]
-        set_color_table(maps)
+        set_color_table(maps, binary)
     if glob_rad_basename:
         maps = [glob_rad_basename + suf for suf in suffixes_all]
-        set_color_table(maps)
+        set_color_table(maps, binary)
     if incidout_basename:
         maps = [incidout_basename + suf for suf in suffixes_all]
         set_color_table(maps)



More information about the grass-commit mailing list