[GRASS-SVN] r58017 - in grass-addons/grass7/raster: . r.lake.series

svn_grass at osgeo.org svn_grass at osgeo.org
Wed Oct 16 09:35:31 PDT 2013


Author: wenzeslaus
Date: 2013-10-16 09:35:31 -0700 (Wed, 16 Oct 2013)
New Revision: 58017

Added:
   grass-addons/grass7/raster/r.lake.series/
   grass-addons/grass7/raster/r.lake.series/Makefile
   grass-addons/grass7/raster/r.lake.series/r.lake.series.html
   grass-addons/grass7/raster/r.lake.series/r.lake.series.jpg
   grass-addons/grass7/raster/r.lake.series/r.lake.series.py
   grass-addons/grass7/raster/r.lake.series/rural_flooding_105.jpg
   grass-addons/grass7/raster/r.lake.series/rural_flooding_108.jpg
Log:
r.lake.series: initial version, supports output of strds

Added: grass-addons/grass7/raster/r.lake.series/Makefile
===================================================================
--- grass-addons/grass7/raster/r.lake.series/Makefile	                        (rev 0)
+++ grass-addons/grass7/raster/r.lake.series/Makefile	2013-10-16 16:35:31 UTC (rev 58017)
@@ -0,0 +1,7 @@
+MODULE_TOPDIR = ../..
+
+PGM=r.lake.series
+
+include $(MODULE_TOPDIR)/include/Make/Script.make
+
+default: script


Property changes on: grass-addons/grass7/raster/r.lake.series/Makefile
___________________________________________________________________
Added: svn:mime-type
   + text/x-makefile
Added: svn:eol-style
   + native

Added: grass-addons/grass7/raster/r.lake.series/r.lake.series.html
===================================================================
--- grass-addons/grass7/raster/r.lake.series/r.lake.series.html	                        (rev 0)
+++ grass-addons/grass7/raster/r.lake.series/r.lake.series.html	2013-10-16 16:35:31 UTC (rev 58017)
@@ -0,0 +1,89 @@
+<h2>DESCRIPTION</h2>
+
+<em><b>r.lake.series</b></em> fills a lake or any area from a given start
+point or areas specified by raster map (<tt>seed_raster</tt> option).
+The module generates one map containing filled areas for each water level
+specified by water level options (<tt>start_water_level</tt>,
+<tt>end_water_level</tt>, <tt>water_level_step</tt>). This module uses
+<em><a href="r.lake.html">r.lake</a></em> module to generate individual
+maps for the map series. See <em><a href="r.lake.html">r.lake</a></em>
+manual for further discussion.
+
+Note that water level is absolute height, so it should be in same range
+as you digital elevation model. On the other hand, water depth in output
+maps is relative to the water level.
+
+<p>
+This module outputs:
+<ul>
+<li>a space-time raster dataset containing a map series</li>
+<li>a map series containing maps of areas with water for each water level</li>
+</ul>
+
+<h2>EXAMPLE</h2>
+The following example presents a bigger flooding in rural area of North
+Carolina sample dataset and included also visualization examples.
+<div class="code"><pre>
+# set computational region
+g.region rast=elev_lid792_1m
+# prepare input data
+v.to.rast -d input=streams output=rural_streams use=val val=1 
+
+# compute a flooding scenario
+r.lake.series elevation=elev_lid792_1m seed=rural_streams \
+              start_wl=104.0 end_wl=115.0 wl_step=0.2 output=flooding
+
+# visualize the flooding space-time raster dataset
+g.gui.animation strds=flooding
+
+# alternatively explore maps from dataset
+# prepare shaded relief map
+r.shaded.relief in=elev_lid792_1m out=elev_lid792_1m_shade
+# set color table for streams
+r.colors map=rural_streams rules=- <<EOF
+1 blue
+EOF
+
+# open d.mon or map display
+d.mon wx1
+
+# show base maps
+d.rast elev_lid792_1m_shade
+d.rast rural_streams
+
+# show particular flooding maps
+d.rast flooding_105.0
+d.rast flooding_108.0
+d.rast flooding_114.0
+</pre></div>
+<!--
+Pictures here were generated using this example.
+Trimmed (cropped) using `mogrify -trim *.jpg`.
+Resized to 320x321 approximately using Nautilus resize image in Ubuntu.
+The size may be changed.
+Modification should be using PNG because trim JPG is not perfect.
+PNG might be used also directly here if compressed enough.
+-->
+
+<center>
+<img src="rural_flooding_105.jpg">
+<img src="rural_flooding_108.jpg">
+<img src="r.lake.series.jpg">
+<p>
+Figure: A bigger flooding in rural area of North Carolina sample dataset
+with water level at 105, 108 and 114 meters (water depth differs in
+different areas).
+</center>
+
+<h2>SEE ALSO</h2>
+
+<em>
+<a href="r.lake.html">r.lake</a>
+</em>
+
+<h2>AUTHORS</h2>
+
+Vaclav Petras, <a href="http://gis.ncsu.edu/osgeorel/">NCSU OSGeoREL</a>,<br>
+Maris Nartiss (author of <em><a href="r.lake.html">r.lake</a></em>)
+
+<p><i>Last changed: $Date$</i>


Property changes on: grass-addons/grass7/raster/r.lake.series/r.lake.series.html
___________________________________________________________________
Added: svn:mime-type
   + text/html
Added: svn:keywords
   + Author Date Id
Added: svn:eol-style
   + native

Added: grass-addons/grass7/raster/r.lake.series/r.lake.series.jpg
===================================================================
(Binary files differ)


Property changes on: grass-addons/grass7/raster/r.lake.series/r.lake.series.jpg
___________________________________________________________________
Added: svn:mime-type
   + image/jpeg

Added: grass-addons/grass7/raster/r.lake.series/r.lake.series.py
===================================================================
--- grass-addons/grass7/raster/r.lake.series/r.lake.series.py	                        (rev 0)
+++ grass-addons/grass7/raster/r.lake.series/r.lake.series.py	2013-10-16 16:35:31 UTC (rev 58017)
@@ -0,0 +1,212 @@
+#!/usr/bin/env python
+# -*- coding: utf-8 -*-
+#
+############################################################################
+#
+# MODULE:       r.lake.series
+# AUTHOR(S):    Vaclav Petras
+# PURPOSE:      Fills lake at given point(s) to given levels.
+#
+# COPYRIGHT:    (C) 2013 by the GRASS Development Team
+#
+#               This program is free software under the GNU General Public
+#               License (>=v2). Read the file COPYING that comes with GRASS
+#               for details.
+#
+#############################################################################
+
+
+#%module
+#% description: Fills lake at given point(s) to given levels.
+#% keywords: raster
+#% keywords: hydrology
+#% keywords: hazard
+#% keywords: flood
+#%end
+#%option G_OPT_R_ELEV
+#%end
+#%option G_OPT_STRDS_OUTPUT
+#% label: Name of the output space time raster dataset
+#% description: The name of the dataset is used as a base name for created output maps. Map names will consist of a base name, underscore and water level value or number depending on -c flag.
+#%end
+#%option
+#% key: start_water_level
+#% type: double
+#% label: Start water level
+#% description: Units should be meters?
+#% required: yes
+#% guisection: Water
+#%end
+#%option
+#% key: end_water_level
+#% type: double
+#% label: Final (maximal) water level
+#% description: Units should be meters?
+#% required: yes
+#% guisection: Water
+#%end
+#%option
+#% key: water_level_step
+#% type: double
+#% label: Water level step
+#% description: Units should be meters?
+#% guisection: Water
+#% required: yes
+#%end
+#%option G_OPT_M_COORDS
+#% label: Seed point coordinates
+#% description: Either this coordinates pair or a seed map name have to be specified.
+#% required: no
+#% guisection: Water
+#%end
+#%option G_OPT_R_INPUT
+#% key: seed_raster
+#% label: Name of input raster map with given starting point(s) (at least 1 cell > 0)
+#% description: Either this parameter or a coordinates pair have to be specified.
+#% required: no
+#% guisection: Water
+#%end
+#%option
+#% key: time_step
+#% type: double
+#% label: Time increment
+#% description: Time increment between two states (maps) used to register output maps in space-time raster dataset. Used together with time_units parameter.
+#% required: no
+#% answer: 30
+#% options: 0-
+#% guisection: Time
+#%end
+#%option
+#% key: time_unit
+#% type: string
+#% label: Time units
+#% description: Time units used to register output maps in space-time raster dataset. Used together with time_step parameter.
+#% required: no
+#% options: years,months,days,hours,minutes,seconds
+#% answer: minutes
+#% guisection: Time
+#%end
+#%option
+#% key: nproc
+#% type: integer
+#% label: Number of processes to run in parallel (currently ignored)
+#% required: no
+#% answer: 1
+#% options: 1-
+#%end
+#%flag
+#% key: n
+#% label: Use negative depth values for lake raster map
+#% description: This flag is passed to r.lake module.
+#%end
+#%flag
+#% key: c
+#% label: Use map number instead of the water level in map name (currently ignored)
+#% description: This names are always in the right alphabetical order and are also valid vector map names.
+#%end
+
+"""
+Created on Tue Oct 15 21:18:00 2013
+
+ at author: Vaclav Petras <wenzeslaus gmail.com>
+"""
+
+# TODO: support parallel
+# TODO: generate SQL valid map names (replace decimal dot by underscore)
+# TODO: use numbers instead of water levels flag
+# TODO: remove unused functions
+
+import sys
+
+from grass.script import core as gcore
+import grass.temporal as tgis
+
+
+def format_time(time):
+    return '%05.2f' % time
+
+
+def format_order(number, zeros):
+    return str(number).zfill(zeros)
+
+
+def frange(x, y, step):
+    while x <= y:
+        yield x
+        x += step
+
+
+def check_maps_exist(maps, mapset):
+    for map_ in maps:
+        if gcore.find_file(map_, element='cell', mapset=mapset)['file']:
+            gcore.fatal(_("Raster map <%s> already exists. Change the base name or allow overwrite.") % map_)
+
+
+def main():
+    options, flags = gcore.parser()
+
+    elevation = options['elevation']
+    strds = options['output']
+    basename = strds
+    start_water_level = float(options['start_water_level'])
+    end_water_level = float(options['end_water_level'])
+    water_level_step = float(options['water_level_step'])
+    #if options['coordinates']:
+    #    options['coordinates'].split(',')
+    # passing coordinates parameter as is
+    coordinates = options['coordinates']
+    seed_raster = options['seed_raster']
+    if seed_raster and coordinates:
+        gcore.fatal(_("Both seed raster and coordinates cannot be specified"
+                      " together, please specify only one of them."))
+
+    time_unit = options['time_unit']
+    time_step = options['time_step']
+    if time_step <= 0:
+        gcore.fatal(_("Time step must be greater than zero."
+                      " Please specify number > 0."))
+
+    mapset = gcore.gisenv()['MAPSET']
+    title = _("r.lake series")
+    desctiption = _("r.lake series")
+
+    water_levels = [step for step in frange(start_water_level,
+                                            end_water_level, water_level_step)]
+    outputs = ['%s%s%s' % (basename, '_', water_level)
+               for water_level in water_levels]
+
+    if not gcore.overwrite():
+        check_maps_exist(outputs, mapset)
+
+    kwargs = {}
+    flags = ''
+    if seed_raster:
+        kwargs['seed'] = seed_raster
+    elif coordinates:
+        kwargs['xy'] = coordinates
+    if 'n' in flags:
+        flags += 'n'
+
+    for i, water_level in enumerate(water_levels):
+        print outputs[i]
+        gcore.run_command('r.lake', elevation=elevation, lake=outputs[i],
+                          wl=water_level,
+                          overwrite=gcore.overwrite(),  # TODO: really works? Its seems that hardcoding here False does not prevent overwriting.
+                          **kwargs)
+
+    gcore.info(_("Registering created maps into temporal dataset..."))
+
+    # Make sure the temporal database exists
+    tgis.init()
+
+    tgis.open_new_space_time_dataset(strds, type='strds',
+                                     temporaltype='relative',
+                                     title=title, descr=desctiption,
+                                     semantic='sum', dbif=None,
+                                     overwrite=gcore.overwrite())
+    # we must start from 1 because there is a bug in register_maps_in_space_time_dataset
+    tgis.register_maps_in_space_time_dataset(
+        type='rast', name=basename, maps=','.join(outputs), start=1, end=None,
+        unit=time_unit, increment=time_step, dbif=None, interval=False)
+if __name__ == '__main__':
+    sys.exit(main())


Property changes on: grass-addons/grass7/raster/r.lake.series/r.lake.series.py
___________________________________________________________________
Added: svn:mime-type
   + text/x-python
Added: svn:eol-style
   + native

Added: grass-addons/grass7/raster/r.lake.series/rural_flooding_105.jpg
===================================================================
(Binary files differ)


Property changes on: grass-addons/grass7/raster/r.lake.series/rural_flooding_105.jpg
___________________________________________________________________
Added: svn:mime-type
   + image/jpeg

Added: grass-addons/grass7/raster/r.lake.series/rural_flooding_108.jpg
===================================================================
(Binary files differ)


Property changes on: grass-addons/grass7/raster/r.lake.series/rural_flooding_108.jpg
___________________________________________________________________
Added: svn:mime-type
   + image/jpeg



More information about the grass-commit mailing list