[GRASS-SVN] r65558 - in grass-addons/grass7/raster: . r.subdayprecip.series

svn_grass at osgeo.org svn_grass at osgeo.org
Fri Jul 10 00:50:08 PDT 2015


Author: martinl
Date: 2015-07-10 00:50:08 -0700 (Fri, 10 Jul 2015)
New Revision: 65558

Added:
   grass-addons/grass7/raster/r.subdayprecip.series/
   grass-addons/grass7/raster/r.subdayprecip.series/Makefile
   grass-addons/grass7/raster/r.subdayprecip.series/r.subdayprecip.series.html
   grass-addons/grass7/raster/r.subdayprecip.series/r.subdayprecip.series.py
Log:
new addon module r.subdayprecip.series

Added: grass-addons/grass7/raster/r.subdayprecip.series/Makefile
===================================================================
--- grass-addons/grass7/raster/r.subdayprecip.series/Makefile	                        (rev 0)
+++ grass-addons/grass7/raster/r.subdayprecip.series/Makefile	2015-07-10 07:50:08 UTC (rev 65558)
@@ -0,0 +1,7 @@
+MODULE_TOPDIR = ../..
+
+PGM = r.subdayprecip.series
+
+include $(MODULE_TOPDIR)/include/Make/Script.make
+
+default: script


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

Added: grass-addons/grass7/raster/r.subdayprecip.series/r.subdayprecip.series.html
===================================================================
--- grass-addons/grass7/raster/r.subdayprecip.series/r.subdayprecip.series.html	                        (rev 0)
+++ grass-addons/grass7/raster/r.subdayprecip.series/r.subdayprecip.series.html	2015-07-10 07:50:08 UTC (rev 65558)
@@ -0,0 +1,22 @@
+<h2>DESCRIPTION</h2>
+
+<em>r.in.proj</em> computes subday design precipitation series.
+
+TODO
+
+<h2>EXAMPLE</h2>
+
+TODO
+
+<h2>SEE ALSO</h2>
+
+<em>
+<a href="v.rast.stats.html">v.rast.stats</a>
+</em>
+
+<h2>AUTHORS</h2>
+
+Martin Landa, OSGeoREL, Czech Technical University in Prague<br>
+
+<p>
+<i>Last changed: $Date $</i>


Property changes on: grass-addons/grass7/raster/r.subdayprecip.series/r.subdayprecip.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.subdayprecip.series/r.subdayprecip.series.py
===================================================================
--- grass-addons/grass7/raster/r.subdayprecip.series/r.subdayprecip.series.py	                        (rev 0)
+++ grass-addons/grass7/raster/r.subdayprecip.series/r.subdayprecip.series.py	2015-07-10 07:50:08 UTC (rev 65558)
@@ -0,0 +1,159 @@
+#!/usr/bin/env python
+
+############################################################################
+#
+# MODULE:       r.subdayprecip.series
+#
+# AUTHOR(S):    Martin Landa
+#
+# PURPOSE:      Computes subday design precipitation series.
+#
+# COPYRIGHT:    (C) 2015 Martin Landa and 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: Computes subday design precipitation series.
+#%end
+
+#%option G_OPT_V_MAP
+#% description: Name of basin vector map
+#%end
+
+#%option G_OPT_R_INPUTS
+#% key: raster
+#% description: Name of input raster map(s) (H_002,H_005,H_010,H_020,H_050,H_100)
+#%end
+
+#%option
+#% key: rainlength
+#% description: Rain length value in minutes
+#% type: integer
+#% options: 0-1439
+#% required: yes
+#%end
+
+import os
+import sys
+
+import grass.script as grass 
+from grass.pygrass.modules import Module
+from grass.exceptions import CalledModuleError
+
+def main():
+    # get list of existing columns
+    try:
+        columns = grass.vector_columns(opt['map']).keys()
+    except CalledModuleError as e:
+        return 1
+
+    allowed_rasters = ('H_002', 'H_005', 'H_010', 'H_020', 'H_050', 'H_100')
+    
+    # extract multi values to points
+    for rast in opt['raster'].split(','):
+        # check valid rasters
+        name = grass.find_file(rast, element='raster')['name']
+        if not name:
+            grass.warning('Raster map <{}> not found. '
+                          'Skipped.'.format(rast))
+            continue
+        if name not in allowed_rasters:
+            grass.warning('Raster map <{}> skipped. '
+                          'Allowed: {}'.format(rast, allowed_rasters))
+            continue
+        
+        grass.message('Processing <{}>...'.format(rast))
+        table = '{}_table'.format(name)
+        # TODO: handle null values
+        Module('v.rast.stats', flags='c', map=opt['map'], raster=rast,
+               column_prefix=name, method='average', quiet=True)
+        
+        rl = float(opt['rainlength'])
+        field_name='{}_{}'.format(name, opt['rainlength'])
+        if field_name not in columns:
+            Module('v.db.addcolumn', map=opt['map'],
+                   columns='{} double precision'.format(field_name))
+            
+        a = c = None
+        if name == 'H_002':
+            if rl < 40: 
+                a = 0.166
+                c = 0.701
+            elif rl < 120:
+                a = 0.237
+                c = 0.803
+            elif rl < 1440:
+                a = 0.235
+                c = 0.801
+        elif name == 'H_005':
+            if rl < 40:
+                a = 0.171
+                c = 0.688
+            elif rl <120:
+                a = 0.265
+                c = 0.803
+            elif rl < 1440:
+                a = 0.324
+                c = 0.845
+        elif name == 'H_010':
+            if rl < 40:
+                a = 0.163
+                c = 0.656
+            elif rl <120:
+                a = 0.280
+                c = 0.803
+            elif rl < 1440:
+                a = 0.380
+                c = 0.867
+        elif name == 'H_020':
+            if rl < 40:
+                a = 0.169
+                c = 0.648
+            elif rl > 40 and rl < 120:
+                a = 0.300
+                c = 0.803
+            elif rl < 1440:
+                a = 0.463
+                c = 0.894
+        elif name == 'H_050':
+            if rl < 40:
+                a = 0.174
+                c = 0.638
+            elif rl < 120:
+                a = 0.323
+                c = 0.803
+            elif rl < 1440:
+                a = 0.580
+                c = 0.925
+        elif name == 'H_100':
+            if rl < 40:
+                a = 0.173
+                c = 0.625
+            elif rl < 120:
+                a = 0.335
+                c = 0.803
+            elif rl < 1440:
+                a = 0.642
+                c = 0.939
+
+        if a is None or c is None:
+            grass.fatal("Unable to calculate coefficients")
+        
+        coef = a * rl ** (1 - c)
+        expression = '{}_average * {}'.format(name, coef)
+        Module('v.db.update', map=opt['map'],
+               column=field_name, query_column=expression)
+        
+        # remove not used column
+        Module('v.db.dropcolumn', map=opt['map'],
+               columns='{}_average'.format(name))
+        
+    return 0
+
+if __name__ == "__main__":
+    opt, flg = grass.parser()
+    sys.exit(main())


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



More information about the grass-commit mailing list