[GRASS-SVN] r66289 - in grass-addons/grass7/raster/r.green/r.green.hydro: . r.green.hydro.discharge

svn_grass at osgeo.org svn_grass at osgeo.org
Tue Sep 22 05:19:53 PDT 2015


Author: Giulia
Date: 2015-09-22 05:19:53 -0700 (Tue, 22 Sep 2015)
New Revision: 66289

Added:
   grass-addons/grass7/raster/r.green/r.green.hydro/r.green.hydro.discharge/
   grass-addons/grass7/raster/r.green/r.green.hydro/r.green.hydro.discharge/Makefile
   grass-addons/grass7/raster/r.green/r.green.hydro/r.green.hydro.discharge/r.green.hydro.discharge.html
   grass-addons/grass7/raster/r.green/r.green.hydro/r.green.hydro.discharge/r.green.hydro.discharge.py
   grass-addons/grass7/raster/r.green/r.green.hydro/r.green.hydro.discharge/r.green.hydro.discharge_input.png
   grass-addons/grass7/raster/r.green/r.green.hydro/r.green.hydro.discharge/r.green.hydro.discharge_output.png
   grass-addons/grass7/raster/r.green/r.green.hydro/r.green.hydro.discharge/r.green.hydro.discharge_output_table.png
Log:
r.green: add the module to compute the discharge according regional law for piedmont and veneto region

Added: grass-addons/grass7/raster/r.green/r.green.hydro/r.green.hydro.discharge/Makefile
===================================================================
--- grass-addons/grass7/raster/r.green/r.green.hydro/r.green.hydro.discharge/Makefile	                        (rev 0)
+++ grass-addons/grass7/raster/r.green/r.green.hydro/r.green.hydro.discharge/Makefile	2015-09-22 12:19:53 UTC (rev 66289)
@@ -0,0 +1,7 @@
+MODULE_TOPDIR = ../../../..
+
+PGM = r.green.hydro.discharge
+
+include $(MODULE_TOPDIR)/include/Make/Script.make
+
+default: script

Added: grass-addons/grass7/raster/r.green/r.green.hydro/r.green.hydro.discharge/r.green.hydro.discharge.html
===================================================================
--- grass-addons/grass7/raster/r.green/r.green.hydro/r.green.hydro.discharge/r.green.hydro.discharge.html	                        (rev 0)
+++ grass-addons/grass7/raster/r.green/r.green.hydro/r.green.hydro.discharge/r.green.hydro.discharge.html	2015-09-22 12:19:53 UTC (rev 66289)
@@ -0,0 +1,82 @@
+<h2>DESCRIPTION</h2>
+<em>r.green.hydro.discharge</em> calculates the average natural discharge and the minimum flow discharge according to regional laws.
+
+<h2>NOTES</h2>
+
+The natural discharge is the discharge of the streams which doesn't consider the existing power plants and the other structures exploiting the water of the river. <br>
+The Minimal Flow Discharge (MFD) is the amount of water which has to remain in the river to preserve the ecosystems. The legislation differs in each region. The MFD can be considered as a percentage of the current discharge, which is the discharge of the river considering the structures exploiting the water. The current discharge is often considered as the mean annual discharge.<br><br>
+
+However, a percentage of the current discharge cannot define precisely the MFD and each region has a different method to define it. For the moment, this module only considers the legislation applied on Piave basin in the Veneto region. New tabs with the legislation of other regions could be added.<br><br>
+
+The module computes two raster maps : the natural discharge and the MFD. On Piave basin, the natural discharge can be computed thanks to the input raster map with the values of specific discharge, and the MFD is calculated thanks to this formula :<br><br>
+
+<center>Q<SUB>MFD</SUB> = ( K<SUB>b</SUB> + K<SUB>n</SUB> ) * 177 * S<SUP>0.85</SUP> * Q<SUB>spec</SUB> * 10<SUP>-6</SUP><br></center>
+
+<blockquote>where K<SUB>b</SUB> is the biological criticality index,<br>
+K<SUB>n</SUB> is the naturalistic criticality index,<br>
+S is the catchment area, in km<SUP>2</SUP>,<br>
+Q<SUB>spec</SUB> is the specific flow-rate per unit area of the catchment, in l/(s.km<SUP>2</SUP>) <br></blockquote>
+
+K<SUB>b</SUB> is typically within the range of 1-1.6; higher values are chosen for a river whose aquatic ecosystem is considered to be of a particular environmental value. <br>
+K<SUB>n</SUB> is typically within the range of 0-0.6; higher values of such index are used for basins having a particular naturalistic value, for instance national parks. <br>
+The values of K<SUB>b</SUB> and K<SUB>n</SUB> are imposed by the Piave River Catchment Authority (PRCA). They have different values depending on homogeneous segments which can be found in a table made by the PRCA. Also the values of Q<SUB>spec</SUB> depend on the area and are available in such a table.<br><br>
+
+Thanks to three raster maps respectively  with the values of K<SUB>b</SUB>, K<SUB>n</SUB> and Q<SUB>spec</SUB>, and also the elevation raster map and the streams vector map, the module creates the two raster maps with the values of MFD and average natural discharge.
+
+<h2>EXAMPLE</h2>
+This example is based on the case-study of Mis valley in Belluno province, Veneto, Italy.<br><br>
+
+Here is the map of the Mis valley with colored areas to define the K<SUB>n</SUB>, K<SUB>b</SUB> and Q<SUB>spec</SUB> values.
+
+<center>
+<img src="r.green.hydro.discharge_input.png" alt="input"><br>
+Picture which gathers the input raster maps with K<SUB>n</SUB>, K<SUB>b</SUB> and Q<SUB>spec</SUB> values
+</center><br><br>
+
+According to the legislation for the Piave basin explained above, the legal values for the Mis valley are :<br>
+K<SUB>n</SUB> = 0.4 in the whole region (yellow and red zones)<br>
+K<SUB>b</SUB> = 1.4 in the yellow zone and 1.6 in the red zone<br>
+Q<SUB>spec</SUB> = 44 l/(s.km<SUP>2</SUP>) in the yellow zone and 43 l/(s.km<SUP>2</SUP>) elsewhere (red and white zones)<br><br>
+
+These values are put in three different raster maps : q_spec, k_b and k_n.<br>
+Here is the code used to create the raster maps with the MFD and the natural discharge. The basins are considered with a threshold of 10000 m.<br><br>
+
+<div class="code"><pre>r.green.hydro.discharge q_spec=q_spec output_q_river=discharge k_b=k_b k_n=k_n output_mfd=mfd elevation=elevation output_streams=streams threshold=100000</pre></div><br><br>
+
+The following picture gathers the two output raster maps mfd and discharge which look like each other (yellow background with colored points following the river and containing the values of discharge). For a better understanding, the following picture also shows the border of the Mis valley and the streams.<br><br>
+
+<center>
+<img src="r.green.hydro.discharge_output.png" alt="output"><br>
+Picture which gathers the output raster maps with valued of MFD and natural discharge, also showing the vector maps with the borders and streams of Mis valley
+</center><br><br>
+
+The white point is queried in GRASS to know the values of MFD and natural discharge. The following picture shows these values in m<SUP>3</SUP>/s. <br><br>
+
+<center>
+<img src="r.green.hydro.discharge_output_table.png" alt="table"><br>
+Values of MFD and natural discharge (in m<SUP>3</SUP>/s) at the white point
+</center><br><br>
+
+
+<h2>SEE ALSO</h2>
+<em>
+<a href="r.green.hydro.delplants.html">r.green.hydro.delplants</a><br>
+<a href="r.green.hydro.theoretical.html">r.green.hydro.theoretical</a><br>
+<a href="r.green.hydro.optimal.html">r.green.hydro.optimal</a><br>
+<a href="r.green.hydro.recommended.html">r.green.hydro.recommended</a><br>
+<a href="r.green.hydro.structure.html">r.green.hydro.structure</a><br>
+<a href="r.green.hydro.technical.html">r.green.hydro.technical</a><br>
+<a href="r.green.hydro.financial.html">r.green.hydro.financial</a><br>
+</em>
+
+<h2>REFERENCE</h2>
+<i>Allegato alla delibera n. 4/2004 del Comitato Istituzionale del 3 marzo 2004<br>
+Piano stralcio per la gestione delle risorse idriche del bacino del Piave - Misure di Salvaguardia</i><br>
+from Autorità di bacino dei fiumi Isonzo, Tagliamento, Livenza, Piave, Brenta-Bacchiglione
+
+
+<h2>AUTHORS</h2>
+Giulia Garegnani (Eurac Research, Bolzano, Italy), Sara Biscaini (University of Trento, Italy), Manual written by Julie Gros.<br>
+Last changed: $Date : 2015-07-07 15:17 GMT+1$
+
+

Added: grass-addons/grass7/raster/r.green/r.green.hydro/r.green.hydro.discharge/r.green.hydro.discharge.py
===================================================================
--- grass-addons/grass7/raster/r.green/r.green.hydro/r.green.hydro.discharge/r.green.hydro.discharge.py	                        (rev 0)
+++ grass-addons/grass7/raster/r.green/r.green.hydro/r.green.hydro.discharge/r.green.hydro.discharge.py	2015-09-22 12:19:53 UTC (rev 66289)
@@ -0,0 +1,325 @@
+#!/usr/bin/env python
+# -- coding: utf-8 --
+#
+############################################################################
+#
+# MODULE:      r.green.hydro.discharge
+# AUTHOR(S):   Giulia Garegnani
+# PURPOSE:     ?
+# COPYRIGHT:   (C) 2014 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: Calculate average natural discharge and minimum flow following regional law an
+#% keywords: raster
+#% overwrite: yes
+#%end
+#%option G_OPT_R_INPUT
+#% key: q_spec
+#% type: string
+#% gisprompt: old,cell,raster
+#% key_desc: name
+#% description: Name of the specific discharge [l/s/km2]
+#% required: no
+#%end
+#%option G_OPT_R_OUTPUT
+#% key: q_river
+#% type: string
+#% key_desc: name
+#% description: Name of raster map with the discharge along river [m3/s]
+#% required: yes
+#%end
+#%option G_OPT_R_INPUT
+#% key: k_b
+#% type: string
+#% gisprompt: old,cell,raster
+#% key_desc: name
+#% description: Name of raster map with kb parameter
+#% required: no
+#% guisection: Regione Veneto
+#%end
+#%option G_OPT_R_INPUT
+#% key: k_n
+#% type: string
+#% gisprompt: old,cell,raster
+#% key_desc: name
+#% description: Name of raster map with kn parameter
+#% required: no
+#% guisection: Regione Veneto
+#%end
+#%option
+#% key: rain
+#% type: string
+#% gisprompt: old,cell,raster
+#% key_desc: name
+#% description: Name of the specific with rain [mm]
+#% required: no
+#%end
+#%option
+#% key: k_matrix
+#% type: string
+#% gisprompt: old,cell,raster
+#% key_desc: name
+#% description: Name of k area map with k parameter
+#% required: no
+#% guisection: Regione Piemonte
+#%end
+#%option
+#% key: m_matrix
+#% type: string
+#% gisprompt: old,cell,raster
+#% key_desc: name
+#% description: Name of M area map with M parameter
+#% required: no
+#% guisection: Regione Piemonte
+#%end
+#%option
+#% key: a_matrix
+#% type: string
+#% gisprompt: old,cell,raster
+#% key_desc: name
+#% description: Name of A area map with A parameter
+#% required: no
+#% guisection: Regione Piemonte
+#%end
+
+#%option G_OPT_R_OUTPUT
+#% key: mfd
+#% type: string
+#% key_desc: name
+#% description: Name of raster map with minimum flow along the river [m3/s]
+#% required: yes
+#%end
+#%option G_OPT_R_OUTPUT
+#% key: a_river
+#% type: string
+#% key_desc: name
+#% description: Name of raster map with area of the basin along the river [m2]
+#% required: no
+#%end
+#%flag
+#% key: d
+#% description: Debug with intermediate maps
+#%end
+#%flag
+#% key: f
+#% description: compute the discharge in the river with q_spec=flow map
+#%end
+#%flag
+#% key: p
+#% description: compute the discharge in the river with q_spec computed as see manual
+#%end
+#%option G_OPT_R_ELEV
+#%  required: yes
+#%end
+#%option G_OPT_V_INPUT
+#% key: river
+#% label: Name of river network
+#% required: no
+#%end
+#%option G_OPT_V_INPUT
+#% key: lakes
+#% label: Name of lakes network
+#% required: no
+#%end
+#%option G_OPT_V_OUTPUT
+#% key: streams
+#% type: string
+#% key_desc: name
+#% description: Name of the new stream network
+#% required: yes
+#%end
+#%option
+#% key: corr_fact
+#% type: string
+#% gisprompt: old,cell,raster
+#% key_desc: name
+#% description: Name of corrective factors area map for environmental flow
+#TODO: list of maps
+#% required: no
+#%end
+#%option
+#% key: env_area
+#% type: string
+#% gisprompt: old,cell,raster
+#% key_desc: name
+#% description: Name of area with environmental restriction
+#% required: no
+#%end
+#%option
+#% key: threshold
+#% type: double
+#% description: Minimum size of exterior watershed basin
+#% required: yes
+#% answer: 100000
+#%END
+
+# import system libraries
+import os
+import sys
+import atexit
+#import pdb
+
+# import grass libraries
+from grass.script import core as gcore
+from grass.pygrass.messages import get_msgr
+from grass.pygrass.utils import set_path
+from grass.script import mapcalc
+
+set_path('r.green', 'libhydro', '..')
+set_path('r.green', 'libgreen', os.path.join('..', '..'))
+# finally import the module in the library
+from libgreen.utils import cleanup
+from libhydro.basin import dtm_corr
+
+
+if "GISBASE" not in os.environ:
+    print("You must be in GRASS GIS to run this program.")
+    sys.exit(1)
+
+
+def compute_a(threshold, dtm, stream, a_river, acc):
+    """ Compute the area of the basin for each pixel of stream
+        the accumulation map and the new streams
+    """
+    pid = os.getpid()
+    info = gcore.parse_command('g.region', flags='pg')
+    area_px = float(info['nsres'])*float(info['ewres'])
+    tmp_stream = 'tmprgreen_%i_stream' % pid
+    tmp_tmp_stream = 'tmprgreen_%i_tmpstream' % pid
+    gcore.run_command('r.watershed',
+                      elevation=dtm,
+                      threshold=threshold,
+                      accumulation=acc,
+                      stream=tmp_stream,
+                      memory=3000)
+    gcore.run_command('r.thin', input=tmp_stream,
+                      output=tmp_tmp_stream)
+    gcore.run_command('r.to.vect', flags='v', overwrite=True,
+                      input=tmp_tmp_stream, output=stream,
+                      type='line')
+
+    command = "%s = abs(%s)/1000000.0 * %f" % (a_river, acc, area_px)
+    mapcalc(command, overwrite=True)
+
+
+def compute_q(threshold, q_spec, q_river, dtm):
+    """ Compute the discharge along the river given the specific discharge
+    """
+    pid = os.getpid()
+    info = gcore.parse_command('g.region', flags='pg')
+    area_px = float(info['nsres'])*float(info['ewres'])
+    q_cum = "tmprgreen_%i_q_cum" % pid
+    gcore.run_command('r.watershed',
+                      elevation=dtm,
+                      flow=q_spec,
+                      threshold=threshold,
+                      accumulation=q_cum,
+                      memory=3000)
+    command = "%s=abs(%s/1000.0* %f/1000000.0)" % (q_river, q_cum, area_px)
+    mapcalc(command)
+
+
+def regione_veneto(q_spec, a_river, k_b, k_n, min_flow):
+    # minimum flow m3/s
+    command = ('%s=(%s+%s)*177.0*exp(%s,0.85)*%s*exp(10.0,-6)'
+               % (min_flow, k_b, k_n, a_river, q_spec))
+    mapcalc(command, overwrite=True)
+
+
+def main(options, flags):
+    pid = os.getpid()
+    pat = "tmprgreen_%i_*" % pid
+    DEBUG = False
+    atexit.register(cleanup,
+                    pattern=pat,
+                    debug=DEBUG)
+    rain = options['rain']
+    q_spec = options['q_spec']
+    a_river = options['a_river']
+    q_river = options['q_river']
+    dtm = options['elevation']
+    river = options['river']
+    lakes = options['lakes']
+    threshold = options['threshold']
+    DEBUG = flags['d']
+    rf = flags['f']  # ra flow map
+    rp = flags['p']  # rain map, piedmont formula
+    k_mat = options['k_matrix']  # raster
+    m_mat = options['m_matrix']  # raster
+    a_mat = options['a_matrix']
+    new_stream = options['streams']
+    env_area = options['env_area']
+    corr_fact = options['corr_fact']
+
+    if not a_river:
+        a_river = "tmprgreen_%i_a_river" % pid
+    msgr = get_msgr()
+
+    msgr.warning("set region to elevation raster")
+    gcore.run_command('g.region', raster=dtm)
+
+    # compute temporary DTM
+    if river:
+        tmp_dtm_corr = "tmprgreen_%i_dtm_corr" % pid
+        dtm_corr(dtm, river, tmp_dtm_corr, lakes)
+        dtm_old = dtm
+        dtm = tmp_dtm_corr
+    # compute the area for each cell
+    tmp_acc = 'tmprgreen_%i_acc' % pid
+    compute_a(threshold, dtm, new_stream, a_river, tmp_acc)
+    # compute q_river
+    if rf:
+        compute_q(threshold, q_spec, q_river, dtm)
+        q_spec = "tmpgreen_%i_q_spec" % pid
+        command = "%s=if(%s,%s/%s)" % (q_spec, a_river, q_river, a_river)
+        mapcalc(command, overwrite=True)
+    elif rp:
+        if not(q_spec):
+            # compute the mean elevation of the basin
+            h_cum = 'tmprgreen_%i_h_cum' % pid
+            h_mean = 'tmprgreen_%i_h_mean' % pid
+            gcore.run_command('r.watershed',
+                              elevation=dtm,
+                              flow=dtm_old,
+                              threshold=threshold,
+                              accumulation=h_cum,
+                              memory=3000)
+            command = '%s = %s/%s' % (h_mean, h_cum, tmp_acc)
+            mapcalc(command)
+            #TODO: compute the mean rain
+            command = 'q_spec =0.0086*%s+0.03416*%s-24.5694' % (rain, h_mean)
+            q_spec = 'q_spec'
+            mapcalc(command)
+    else:
+        command = '%s = %s * %s/1000.0' % (q_river, q_spec, a_river)
+        mapcalc(command)
+    # compute MVF with Regione Veneto Formula
+    if options['k_b']:
+        msgr.warning("Regione Veneto plan")
+        k_b = options['k_b']  # raster
+        k_n = options['k_n']  # raster
+        min_flow = options['mfd']
+        regione_veneto(a_river, q_spec, k_b, k_n,
+                       min_flow)
+    elif k_mat:
+        msgr.warning("Piedmont Plan")
+        command = '%s=%s*%s*%s*%s*%s/1000.0' % (min_flow, k_mat, a_river,
+                                                     q_spec, m_mat, a_mat)
+        mapcalc(command, overwrite=True)
+    else:
+        msgr.warning("No formula fot the MVF")
+    if corr_fact:
+    # if corr_fact coumpute the environemtal flow else the minimum flow"
+        command = '%s=if(not(%s), %s, %s*%s)' % (env_area, min_flow,
+                                                 corr_fact*min_flow)
+
+if __name__ == "__main__":
+    options, flags = gcore.parser()
+    sys.exit(main(options, flags))

Added: grass-addons/grass7/raster/r.green/r.green.hydro/r.green.hydro.discharge/r.green.hydro.discharge_input.png
===================================================================
(Binary files differ)


Property changes on: grass-addons/grass7/raster/r.green/r.green.hydro/r.green.hydro.discharge/r.green.hydro.discharge_input.png
___________________________________________________________________
Added: svn:mime-type
   + application/octet-stream

Added: grass-addons/grass7/raster/r.green/r.green.hydro/r.green.hydro.discharge/r.green.hydro.discharge_output.png
===================================================================
(Binary files differ)


Property changes on: grass-addons/grass7/raster/r.green/r.green.hydro/r.green.hydro.discharge/r.green.hydro.discharge_output.png
___________________________________________________________________
Added: svn:mime-type
   + application/octet-stream

Added: grass-addons/grass7/raster/r.green/r.green.hydro/r.green.hydro.discharge/r.green.hydro.discharge_output_table.png
===================================================================
(Binary files differ)


Property changes on: grass-addons/grass7/raster/r.green/r.green.hydro/r.green.hydro.discharge/r.green.hydro.discharge_output_table.png
___________________________________________________________________
Added: svn:mime-type
   + application/octet-stream



More information about the grass-commit mailing list