[GRASS-SVN] r65581 - in grass-addons/grass7/raster/r.green: libgreen r.green.hydro r.green.hydro/libhydro r.green.hydro/r.green.hydro.delplants r.green.hydro/r.green.hydro.optimal r.green.hydro/r.green.hydro.recommended r.green.hydro/r.green.hydro.structure

svn_grass at osgeo.org svn_grass at osgeo.org
Mon Jul 13 02:37:12 PDT 2015


Author: Giulia
Date: 2015-07-13 02:37:12 -0700 (Mon, 13 Jul 2015)
New Revision: 65581

Added:
   grass-addons/grass7/raster/r.green/r.green.hydro/r.green.hydro.delplants/r_green_hydro_delplants_input.png
   grass-addons/grass7/raster/r.green/r.green.hydro/r.green.hydro.delplants/r_green_hydro_delplants_output.png
   grass-addons/grass7/raster/r.green/r.green.hydro/r.green.hydro.optimal/r_green_hydro_optimal_input.png
   grass-addons/grass7/raster/r.green/r.green.hydro/r.green.hydro.optimal/r_green_hydro_optimal_output.png
   grass-addons/grass7/raster/r.green/r.green.hydro/r.green.hydro.recommended/r_green_hydro_recommended_input.png
   grass-addons/grass7/raster/r.green/r.green.hydro/r.green.hydro.recommended/r_green_hydro_recommended_output_park.png
   grass-addons/grass7/raster/r.green/r.green.hydro/r.green.hydro.recommended/r_green_hydro_recommended_output_points.png
   grass-addons/grass7/raster/r.green/r.green.hydro/r.green.hydro.structure/r_green_hydro_structure_input.png
   grass-addons/grass7/raster/r.green/r.green.hydro/r.green.hydro.structure/r_green_hydro_structure_output.png
   grass-addons/grass7/raster/r.green/r.green.hydro/r.green.hydro.structure/r_green_hydro_structure_picstruct.png
Removed:
   grass-addons/grass7/raster/r.green/r.green.hydro/r.green.hydro.legal/
   grass-addons/grass7/raster/r.green/r.green.hydro/r.green.hydro.optimal/r_green_hydro_optimal_availablestreams.png
   grass-addons/grass7/raster/r.green/r.green.hydro/r.green.hydro.optimal/r_green_hydro_optimal_potentialplants.png
   grass-addons/grass7/raster/r.green/r.green.hydro/r.green.hydro.structure/r_green_hydro_structure_plantstructure.png
   grass-addons/grass7/raster/r.green/r.green.hydro/r.green.hydro.structure/r_green_hydro_structure_potentialplants.png
Modified:
   grass-addons/grass7/raster/r.green/libgreen/utils.py
   grass-addons/grass7/raster/r.green/r.green.hydro/libhydro/basin.py
   grass-addons/grass7/raster/r.green/r.green.hydro/libhydro/optimal.py
   grass-addons/grass7/raster/r.green/r.green.hydro/libhydro/plant.py
   grass-addons/grass7/raster/r.green/r.green.hydro/r.green.hydro.delplants/r.green.hydro.delplants.html
   grass-addons/grass7/raster/r.green/r.green.hydro/r.green.hydro.delplants/r.green.hydro.delplants.py
   grass-addons/grass7/raster/r.green/r.green.hydro/r.green.hydro.optimal/r.green.hydro.optimal.html
   grass-addons/grass7/raster/r.green/r.green.hydro/r.green.hydro.optimal/r.green.hydro.optimal.py
   grass-addons/grass7/raster/r.green/r.green.hydro/r.green.hydro.recommended/r.green.hydro.recommended.html
   grass-addons/grass7/raster/r.green/r.green.hydro/r.green.hydro.recommended/r.green.hydro.recommended.py
   grass-addons/grass7/raster/r.green/r.green.hydro/r.green.hydro.structure/r.green.hydro.structure.html
   grass-addons/grass7/raster/r.green/r.green.hydro/r.green.hydro.structure/r.green.hydro.structure.py
Log:
r.green.hydro: new version

Modified: grass-addons/grass7/raster/r.green/libgreen/utils.py
===================================================================
--- grass-addons/grass7/raster/r.green/libgreen/utils.py	2015-07-12 14:09:18 UTC (rev 65580)
+++ grass-addons/grass7/raster/r.green/libgreen/utils.py	2015-07-13 09:37:12 UTC (rev 65581)
@@ -1,5 +1,4 @@
 # -*- coding: utf-8 -*-
-from scipy.sparse import csr_matrix
 import numpy as np
 #import pdb
 
@@ -10,14 +9,20 @@
 from grass.pygrass.raster.buffer import Buffer
 from grass.pygrass.gis.region import Region
 
+try:
+    from scipy.sparse import csr_matrix
+except ImportError:
+    gcore.warning('You should install scipy to use this module: '
+                  'pip install scipy')
 
-def cleanup(rast=None, vect=None, debug=False):
+
+def cleanup(raster=None, vector=None, debug=False):
     """Delete temporary maps"""
     if not debug:
-        if rast:
-            gcore.run_command("g.remove", flags="f", type='rast', name=rast)
-        if vect:
-            gcore.run_command("g.remove", flags="f", type='vect', name=vect)
+        if raster:
+            gcore.run_command("g.remove", flags="f", type='raster', name=raster)
+        if vector:
+            gcore.run_command("g.remove", flags="f", type='vector', name=vector)
 
 
 def check_overlay_rv(raster, vector):

Modified: grass-addons/grass7/raster/r.green/r.green.hydro/libhydro/basin.py
===================================================================
--- grass-addons/grass7/raster/r.green/r.green.hydro/libhydro/basin.py	2015-07-12 14:09:18 UTC (rev 65580)
+++ grass-addons/grass7/raster/r.green/r.green.hydro/libhydro/basin.py	2015-07-13 09:37:12 UTC (rev 65581)
@@ -17,7 +17,6 @@
 # import system libraries
 import os
 
-from scipy import integrate
 import numpy as np
 import itertools
 #import pdb
@@ -29,6 +28,12 @@
 from grass.script import mapcalc
 from grass.pygrass.utils import set_path
 
+try:
+    from scipy import integrate
+except ImportError:
+    gcore.warning('You should install scipy to use this module: '
+                  'pip install scipy')
+
 set_path('r.green', 'libhydro', '..')
 set_path('r.green', 'libgreen', os.path.join('..', '..'))
 # finally import the module in the library
@@ -267,6 +272,7 @@
     def E_spec(self):
         """
         compute the specific energy for length unit of the basin
+        TOFIX
         """
         #pdb.set_trace()
         E_spec = self.E_own/self.area  # kW/km2
@@ -331,13 +337,14 @@
     # TODO: dissolve the areas with the same cat
     # adding columns
     gcore.run_command("v.db.addcolumn", map=E,
-                      columns="E_spec double precision,"
+                      columns=
                       "Qown double precision,"
                       "Qtot double precision, Hmean double precision,"
                       "H0 double precision, Eown_kW double precision,"
                       "IDup1 int, Eup1_kW double precision,"
                       "IDup2 int, Eup2_kW double precision,"
-                      "IDup3 int, Eup3_kW double precision")
+                      "IDup3 int, Eup3_kW double precision,"
+                      "Etot_kW double precision")
     gcore.run_command("db.dropcolumn", flags="f",
                       table=E, column="label")
     # Open database connection
@@ -357,24 +364,26 @@
         for l in vec.cat(ID, 'lines'):
             length += l.length()
         basins_tot[ID].length = length
-        db = [basins_tot[ID].E_spec(),
-              basins_tot[ID].discharge_own,
+        db = [basins_tot[ID].discharge_own,
               basins_tot[ID].discharge_tot,
               basins_tot[ID].h_mean,
               basins_tot[ID].h_closure,
               basins_tot[ID].E_own]
         if len(basins_tot[ID].E_up) == 0:
-            db = db + [0, 0.0, 0, 0.0, 0, 0.0]
+            db = db + [0, 0.0, 0, 0.0, 0, 0.0,
+                       basins_tot[ID].E_own]
         elif len(basins_tot[ID].E_up) == 1:
             db = (db + [basins_tot[ID].E_up.keys()[0],
                   basins_tot[ID].E_up.values()[0],
-                  0, 0.0, 0, 0.0])
+                  0, 0.0, 0, 0.0, basins_tot[ID].E_own
+                  + sum(basins_tot[ID].E_up.values())])
         elif len(basins_tot[ID].E_up) == 2:
             db = (db + [basins_tot[ID].E_up.keys()[0],
                   basins_tot[ID].E_up.values()[0],
                   basins_tot[ID].E_up.keys()[1],
                   basins_tot[ID].E_up.values()[1],
-                  0, 0])
+                  0, 0, basins_tot[ID].E_own
+                  + sum(basins_tot[ID].E_up.values())])
         elif len(basins_tot[ID].E_up) == 3:
             #pdb.set_trace()
             db = (db + [basins_tot[ID].E_up.keys()[0],
@@ -382,7 +391,8 @@
                   basins_tot[ID].E_up.keys()[1],
                   basins_tot[ID].E_up.values()[1],
                   basins_tot[ID].E_up.keys()[2],
-                  basins_tot[ID].E_up.values()[2]])
+                  basins_tot[ID].E_up.values()[2],basins_tot[ID].E_own
+                  + sum(basins_tot[ID].E_up.values())])
         else:
             db = db + [0, 0.0, 0, 0.0, 0, 0.0]
         #print db

Modified: grass-addons/grass7/raster/r.green/r.green.hydro/libhydro/optimal.py
===================================================================
--- grass-addons/grass7/raster/r.green/r.green.hydro/libhydro/optimal.py	2015-07-12 14:09:18 UTC (rev 65580)
+++ grass-addons/grass7/raster/r.green/r.green.hydro/libhydro/optimal.py	2015-07-13 09:37:12 UTC (rev 65581)
@@ -8,18 +8,23 @@
 from __future__ import print_function
 import os
 import sys
-from scipy import interpolate
-from scipy.optimize import fsolve
+
 import numpy as np
 
-# import scientific libraries
-from scipy import optimize
-
 #from grass.script import mapcalc
 from grass.script import core as gcore
 from grass.pygrass.messages import get_msgr
 from grass.pygrass.raster import RasterRow
 
+# import scientific libraries
+try:
+    from scipy import optimize
+    from scipy import interpolate
+    from scipy.optimize import fsolve
+except ImportError:
+    gcore.warning('You should install scipy to use this module: '
+                  'pip install scipy')
+
 #from grass.pygrass.raster.buffer import Buffer
 from grass.pygrass.gis.region import Region
 from grass.pygrass.vector import VectorTopo
@@ -305,7 +310,7 @@
     return plants
 
 
-def write_plants(plants, output, efficiency):
+def write_plants(plants, output, efficiency, min_power):
     # create vetor segment
     new_vec = VectorTopo(output)
     #TODO:  check if the vector already exists
@@ -313,37 +318,85 @@
     new_vec.open('w', tab_cols=COLS)
     reg = Region()
     for pla in plants:
-        new_vec.write(pla.line, (pla.id, pla.id_stream,
-                                 pla.potential_power(efficiency=efficiency)))
+        power = pla.potential_power(efficiency=efficiency)
+        if power > min_power:
 
+            for ink in pla.intakes:
+                new_vec.write(pla.line, (pla.id, pla.id_stream, power,
+                                     float(pla.restitution.discharge),
+                                     float(ink.elevation),
+                                     float(pla.restitution.elevation)))
+
     new_vec.table.conn.commit()
     new_vec.comment = (' '.join(sys.argv))
     #pdb.set_trace()
     new_vec.close()
 
 
-def write_points(plants, output, efficiency):
+def write_points(plants, output, efficiency, min_power):
     # create vetor segment
     new_vec = VectorTopo(output)
     #TODO:  check if the vector already exists
     new_vec.layer = 1
     new_vec.open('w', tab_cols=COLS_points)
     reg = Region()
+
     # import ipdb; ipdb.set_trace()
     for pla in plants:
-        new_vec.write(pla.line[-1], (pla.restitution.id,
-                      pla.id, 'restitution', pla.id_stream,
-                      float(pla.restitution.elevation),
-                      float(pla.restitution.discharge),
-                      pla.potential_power()))
-        for ink in pla.intakes:
-            new_vec.write(pla.line[0], (ink.id,
-                          pla.id, 'intake', pla.id_stream,
-                          float(ink.elevation), float(ink.discharge),
-                          pla.potential_power(efficiency=efficiency)))
+        power = pla.potential_power(efficiency=efficiency)
+        if power > min_power:
+            new_vec.write(pla.line[-1], (pla.restitution.id,
+                          pla.id, 'restitution', pla.id_stream,
+                          float(pla.restitution.elevation),
+                          float(pla.restitution.discharge),
+                          power))
+            for ink in pla.intakes:
+                new_vec.write(pla.line[0], (ink.id,
+                              pla.id, 'intake', pla.id_stream,
+                              float(ink.elevation), float(ink.discharge),
+                              power))
 
     new_vec.table.conn.commit()
     new_vec.comment = (' '.join(sys.argv))
     new_vec.write_header()
     #pdb.set_trace()
     new_vec.close()
+
+
+def conv_segpoints(seg, output):
+
+    segments, mset = (seg.split('@') if '@' in seg
+                else (seg, ''))
+    # convert the map with segments in a map with intakes and restitution
+    new_vec = VectorTopo(output)
+    #TODO:  check if the vector already exists
+    new_vec.layer = 1
+    new_vec.open('w', tab_cols=COLS_points)
+    reg = Region()
+
+    seg = VectorTopo(segments, mapset=mset)
+    seg.layer = 1
+    seg.open('r')
+
+
+    for pla in seg:
+            #import ipdb; ipdb.set_trace()
+            new_vec.write(pla[-1], (2,
+                          pla.attrs['plant_id'], 'restitution', pla.attrs['stream_id'],
+                          pla.attrs['elev_down'],
+                          pla.attrs['discharge'],
+                          pla.attrs['pot_power']))
+            #import ipdb; ipdb.set_trace()
+            new_vec.write(pla[0], (1,
+                          pla.attrs['plant_id'], 'intake', pla.attrs['stream_id'],
+                          pla.attrs['elev_up'],
+                          pla.attrs['discharge'],
+                          pla.attrs['pot_power']))
+
+    new_vec.table.conn.commit()
+    new_vec.comment = (' '.join(sys.argv))
+    new_vec.write_header()
+    #pdb.set_trace()
+    new_vec.close()
+
+    return new_vec

Modified: grass-addons/grass7/raster/r.green/r.green.hydro/libhydro/plant.py
===================================================================
--- grass-addons/grass7/raster/r.green/r.green.hydro/libhydro/plant.py	2015-07-12 14:09:18 UTC (rev 65580)
+++ grass-addons/grass7/raster/r.green/r.green.hydro/libhydro/plant.py	2015-07-13 09:37:12 UTC (rev 65581)
@@ -14,7 +14,10 @@
 COLS = [(u'cat',       'INTEGER PRIMARY KEY'),
         (u'plant_id',  'VARCHAR(10)'),
         (u'stream_id',  'INTEGER'),
-        (u'potential_power', 'DOUBLE')]
+        (u'pot_power', 'DOUBLE'),
+        (u'discharge', 'DOUBLE'),
+        (u'elev_up', 'DOUBLE'),
+        (u'elev_down', 'DOUBLE'),]
 
 
 COLS_points = [(u'cat',       'INTEGER PRIMARY KEY'),
@@ -24,7 +27,7 @@
                (u'stream_id',  'INTEGER'),
                (u'elevation', 'DOUBLE'),
                (u'discharge', 'DOUBLE'),
-               (u'potential_power', 'DOUBLE')]
+               (u'pot_power', 'DOUBLE')]
 
 HydroStruct = namedtuple('HydroStruct',
                          ['intake', 'conduct', 'penstock', 'side'])
@@ -81,7 +84,6 @@
     return l0, l1
 
 
-
 def read_plants(hydro, elev=None, restitution='restitution', intake='intake',
                 cid_plant='id_plant', cid_point='id_point', ckind_label='kind_label',
                 celevation='elevation', cdischarge='discharge'):

Modified: grass-addons/grass7/raster/r.green/r.green.hydro/r.green.hydro.delplants/r.green.hydro.delplants.html
===================================================================
--- grass-addons/grass7/raster/r.green/r.green.hydro/r.green.hydro.delplants/r.green.hydro.delplants.html	2015-07-12 14:09:18 UTC (rev 65580)
+++ grass-addons/grass7/raster/r.green/r.green.hydro/r.green.hydro.delplants/r.green.hydro.delplants.html	2015-07-13 09:37:12 UTC (rev 65581)
@@ -1,10 +1,40 @@
 <h2>DESCRIPTION</h2>
+<em>r.green.hydro.delplants</em> deletes segments of river where there is an existing plant.
 
+<h2>NOTES</h2>
+This command is used to select the segments of river which are not already exploited by a plant or another structure.<br>
+The required inputs are the elevation raster map, the map with the streams and the one with the intakes and restitution of the existing plants. In option, it is possible to add the map with the intakes and restitution of the other structures such aqueducts or irrigation in order to delete these segments too. <br>
+It is necessary to verify in "Optional" that the intakes and restitution are well reported in the table of the input maps (hydro and other).
+
+<h2>EXAMPLE</h2>
+This example is based on the case-study of Mis valley in Belluno province, Veneto, Italy.<br><br>
+
+<center>
+<img src="r_green_hydro_delplants_input.png" alt="input"><br>
+Input vector maps : streams of Mis Valley in black and intakes and restitution of existing plants in red
+</center><br><br>
+
+We use the following code to compute the available streams and obtain the next map :
+<div class="code"><pre>r.green.hydro.delplants hydro=existingplants river=streams output=availablestreams elevation=elevation<br>
+d.vect map=existingplants color=red<br></pre></div><br>
+
+<center>
+<img src="r_green_hydro_delplants_output.png" alt="output"><br>
+Output vector map in black : streams of Mis Valley without the existing plants (intakes and restitution of existing plants are added there in red)
+</center><br>
+
 <h2>SEE ALSO</h2>
+<em>
+<a href="r.green.hydro.discharge.html">r.green.hydro.discharge</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>AUTHORS</h2>
+Giulia Garegnani and Pietro Zambelli (Eurac Research, Bolzano, Italy), Manual written by Julie Gros.<br>
+Last changed: $Date : 2015-07-07 15:17 GMT+1$
 
-Pietro Zambelli,
-Giulia Garegnani
-
-<p><i>Last changed: $Date$</i>

Modified: grass-addons/grass7/raster/r.green/r.green.hydro/r.green.hydro.delplants/r.green.hydro.delplants.py
===================================================================
--- grass-addons/grass7/raster/r.green/r.green.hydro/r.green.hydro.delplants/r.green.hydro.delplants.py	2015-07-12 14:09:18 UTC (rev 65580)
+++ grass-addons/grass7/raster/r.green/r.green.hydro/r.green.hydro.delplants/r.green.hydro.delplants.py	2015-07-13 09:37:12 UTC (rev 65581)
@@ -3,9 +3,9 @@
 #
 ############################################################################
 #
-# MODULE:      r.green.hydro.del_plants
+# MODULE:      r.green.hydro.delplants
 # AUTHOR(S):   Pietro Zambelli & Giulia Garegnani
-# PURPOSE:     Delete segmets where there is an existing plant
+# PURPOSE:     Delete segments where there is an existing plant
 # COPYRIGHT:   (C) 2014 by the GRASS Development Team
 #
 #              This program is free software under the GNU General Public
@@ -15,83 +15,79 @@
 #############################################################################
 #
 #%Module
-#% description: Delete segmets where there is an existing plant
+#% description: Delete segments where there is an existing plant
 #% overwrite: yes
 #%End
 #%option G_OPT_V_INPUT
 #%  key: hydro
-#%  description: Name of the vector map point of hydro plants.
+#%  label: Name of the vector map with the points (intake and restitution) of hydropower plants
 #%  required: yes
 #%end
 #%option G_OPT_V_FIELD
 #%  key: hydro_layer
-#%  description: Name of the vector map layer of the hydro plant, with the following attributes: kind (water intake/turbine), discharge [l/s], working hours [hours], altitute[m], id point, id plant
+#%  label: Name of the vector map layer of the hydropower plants, with the following attributes: kind_label (intake/restitution), discharge [m3/s], id_point, id_plant
 #%  required: no
 #%  answer: 1
 #%end
 #%option G_OPT_V_INPUT
 #%  key: river
-#%  description: Name of the vector map with the streams.
+#%  label: Name of the vector map with the streams
 #%  required: yes
 #%end
-#%option G_OPT_V_OUTPUT
-#%  description: Name of the vector map with the stream segments without plants.
+#%option
+#%  key: output_streams
+#%  type: string
+#%  description: Name of the vector map with the stream segments without plants
 #%  required: yes
 #%end
-#%option G_OPT_V_OUTPUT
-#%  key: plants
-#%  description: Name of the vector map with the stream segments already with plants.
+#%option
+#%  key: output_plants
+#%  type: string
+#%  description: Name of the vector map with the stream segments of the existing plants
 #%  required: no
 #%end
 #%option
 #%  key: hydro_kind_intake
 #%  type: string
-#%  description: Value contained in the column: hydro_kind that indicate the plant is an intake.
+#%  description: Value contained in the column kind_label that indicates the plant is an intake
 #%  required: no
 #%  answer: intake
 #%end
 #%option
 #%  key: hydro_kind_turbine
 #%  type: string
-#%  description: Value contained in the column: hydro_kind that indicate the plant is an intake.
+#%  description: Value contained in the column kind_label that indicates the plant is a restitution
 #%  required: no
-#%  answer: turbine
+#%  answer: restitution
 #%end
 #%option G_OPT_R_ELEV
 #%  required: yes
 #%end
 #%option G_OPT_V_MAP
 #%  key: other
-#%  description: Name of the vector map point of other plants such as irrigation, acqueducts, etc.
+#%  label: Name of the vector map with points (intake and restitution) of other plants such as irrigation, acqueducts, etc.
 #%  required: no
 #%end
 #%option G_OPT_V_INPUT
 #%  key: other_layer
-#%  description: Name of the vector map layer of other plants, with the following attributes: kind (water intake/turbine), discharge [m3/year], id point, id plant
+#%  label: Name of the vector map layer of other plants, with the following attributes: kind_label (intake/restitution), discharge [m3/s], id_point, id_plant
 #%  required: no
 #%  answer: 1
 #%end
 #%option
 #%  key: other_kind_intake
 #%  type: string
-#%  description: Value contained in the column: other_kind that indicate the plant is an intake.
+#%  description: Value contained in the column kind_label that indicates the plant is an intake
 #%  required: no
 #%  answer: intake
 #%end
 #%option
 #%  key: other_kind_turbine
 #%  type: string
-#%  description: Value contained in the column: other_kind that indicate the plant is an intake.
+#%  description: Value contained in the column kind_label that indicates the plant is a restitution
 #%  required: no
-#%  answer: turbine
+#%  answer: restitution
 #%end
-#%option
-#%  key: efficiency
-#%  type: double
-#%  description: Plant efficiency.
-#%  required: no
-#%  answer: 0.8
-#%end
 #%flag
 #% key: d
 #% description: Debug with intermediate maps
@@ -126,11 +122,11 @@
     DEBUG = True if flgs['d'] else False
     atexit.register(cleanup, vect=TMPVECT, debug=DEBUG)
     # check input maps
-    rhydro = ['kind', 'discharge', 'id_point', 'id_plant']
-    rother = ['kind', 'discharge', 'id_point', 'id_plant']
+    rhydro = ['kind_label', 'discharge', 'id_point', 'id_plant']
+    rother = ['kind_label', 'discharge', 'id_point', 'id_plant']
     ovwr = overwrite()
 
-    try:
+    try:        
         hydro = check_required_columns(opts['hydro'], int(opts['hydro_layer']),
                                        rhydro, 'hydro')
         if opts['other']:
@@ -141,8 +137,6 @@
         #minflow = check_float_or_raster(opts['minflow'])
     except ParameterError as exc:
         exception2error(exc)
-    # TODO: do we really nead the efficiency of the plant here?
-    #efficiency = float(opts['efficiency'])
 
     # start working
     hydro.open('r')
@@ -150,6 +144,7 @@
                 else (opts['elevation'], ''))
     elev = RasterRow(name=el, mapset=mset)
     elev.open('r')
+    #import ipdb; ipdb.set_trace()
     plants, skipped = read_plants(hydro, elev=elev,
                                   restitution=opts['hydro_kind_turbine'],
                                   intake=opts['hydro_kind_intake'])
@@ -157,9 +152,9 @@
     rvname, rvmset = (opts['river'].split('@') if '@' in opts['river']
                       else (opts['river'], ''))
 
-    vplants = opts['plants'] if opts['plants'] else 'tmpplants'
+    vplants = opts['output_plants'] if opts['output_plants'] else 'tmpplants'
     #FIXME: I try with tmpplants in my mapset and it doesn'work
-    if opts['plants'] == '':
+    if opts['output_plants'] == '':
         TMPVECT.append(vplants)
     with VectorTopo(rvname, rvmset, mode='r') as river:
         write_plants(plants, vplants, river, elev, overwrite=ovwr)
@@ -176,7 +171,7 @@
     TMPVECT.append(buff)
     # return all the river segments that are not already with plants
     v.overlay(flags='t', ainput=opts['river'], atype='line', binput=buff,
-              operator='not', output=opts['output'], overwrite=ovwr)
+              operator='not', output=opts['output_streams'], overwrite=ovwr)
 
 
 if __name__ == "__main__":

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


Property changes on: grass-addons/grass7/raster/r.green/r.green.hydro/r.green.hydro.delplants/r_green_hydro_delplants_input.png
___________________________________________________________________
Added: svn:mime-type
   + image/png

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


Property changes on: grass-addons/grass7/raster/r.green/r.green.hydro/r.green.hydro.delplants/r_green_hydro_delplants_output.png
___________________________________________________________________
Added: svn:mime-type
   + image/png

Modified: grass-addons/grass7/raster/r.green/r.green.hydro/r.green.hydro.optimal/r.green.hydro.optimal.html
===================================================================
--- grass-addons/grass7/raster/r.green/r.green.hydro/r.green.hydro.optimal/r.green.hydro.optimal.html	2015-07-12 14:09:18 UTC (rev 65580)
+++ grass-addons/grass7/raster/r.green/r.green.hydro/r.green.hydro.optimal/r.green.hydro.optimal.html	2015-07-13 09:37:12 UTC (rev 65581)
@@ -1,53 +1,67 @@
 <h2>DESCRIPTION</h2>
-<em>r.green.hydro.optimal</em> calculates the hydropower energy potential for each basin. Deciding the range of plant length and the distance between plants, the module returns a vector file with the intakes and the restitution of the river which maximize the power that can be produced.
+<em>r.green.hydro.optimal</em> detects the position of the potential hydropower plants that can produce the highest possible power. Deciding the range of plant length and the distance between plants, the module returns two vector maps with the segments of rivers exploited by the potential plants and with the intakes and restitution of these plants. The module computes the potential plants in order to maximize the power that can be produced.
 
 <h2>NOTES</h2>
-The power is defined as P=ηρgQΔh where :<br>
-η is the efficiency of the plant <br>
+
+The three input files are the rivers considered (vector), the discharge for each point of this river (raster) and the elevation raster map to calculate the gross head.<br><br>
+
+The power is defined as :<br>
+
+<center>P=η * ρ * g * Q * Δh</center>
+
+<blockquote>where η is the efficiency of the plant <br>
 ρ the density of water (1000 kg/m<sup>3</sup>) <br>
 g the gravity term (9,81 m/s<sup>2</sup>) <br>
 Q the discharge of the river<br>
-Δh the gross head of the considered segment<br> <br>
+Δh the gross head of the considered segment</blockquote><br>
 
-The module maximizes the power over a given range by a brute-force search in order to examine all possible arrangements of Q and Δh. Thus, the potential segments can be shorter than the maximum length plant chosen because it depends on the maximization of the product  Q * Δh. <br>  <br>
-The three input files have to give : the river considered, the discharge for each point of this river and the dtm to calculate the gross head. <br> <br>
-For each potential segment, the potential power is given in kW in attribute. The categories are divided in range of segment lengths. Arms of river are distinguished by a number, as well as the plants on these arms.
+The module maximizes the power over a given range by a brute-force search in order to examine all possible arrangements of Q and Δh. Thus, the potential segments can be shorter than the maximum length plant chosen because it depends on the maximization of the product  Q * Δh. <br><br>
 
+For each potential segment, the potential power is given in kW in attribute.
 
+
 <h2>EXAMPLE</h2>
-These examples are based on the Pnam file which refers to the Gesso and Vermenagna Valley in Piedmont, Italy.<br><br>
+This example is based on the case-study of Gesso and Vermenagna valleys in the Natural Park of the Maritime Alps, Piedmont, Italy.<br><br>
 
-Here is the vector file availablestreams of the interested streams. The river segments already exploited by an existing plant do not appear in the file.<br>
+Here is the vector file availablestreams of the interested streams in which we want to compute the potential hydropower plants. The river segments already exploited by an existing plant do not appear in the file.<br>
 
 <center>
-<img src="r_green_hydro_optimal_availablestreams.jpg" alt="r_green_hydro_optimal_availablestreams"><br>
-Vector map availablestreams
+<img src="r_green_hydro_optimal_input.png" alt="availablestreams"><br>
+Input vector map availablestreams
 </center><br>
 
-<div class="code"><pre>r.green.hydro.optimal discharge=discharge river=availablestreams dtm=elevation len_plant=800 distance=200 output_plant=potentialsegments output_point=potentialplants efficiency=1<br>
-d.vect map= potentialplants color=red<br>
-d.vect map= potentialsegments color=blue<br></pre></div><br>
+The following command computes the potential plants for a plant length range from 10 to 800 m and a distance between plants of 800m :<br><br>
 
-This command calculates the energy potential for a plant length range from 10 to 800 m and a distance between plants of 200m.<br><br>
+<div class="code"><pre>r.green.hydro.optimal 
+discharge=discharge 
+river=availablestreams 
+elevation=elevation 
+len_plant=800 
+distance=800 
+output_plant=potentialsegments 
+output_point=potentialpoints<br>
+d.vect map= potentialpoints color=red<br>
+d.vect map= potentialplants color=blue<br></pre></div><br>
 
+The output vector maps are shown in the following picture which gathers the potential segments vector map (potentialplants, in blue) and the potential intakes and restitution vector map (potentialpoints, in red) 
 <center>
-<img src="r_green_hydro_optimal_potentialplants.jpg" alt="r_green_hydro_optimal_potentialplants"><br>
-Superposition of the potential segments vector file (potentialsegments, in blue) and the potential intakes and restitution vector file (potentialplants, in red)
+<img src="r_green_hydro_optimal_output.png" alt="potentialplants"><br>
+Output vector maps potentialplants (in blue) and potentialpoints (in red)
 </center>
 
 
 <h2>SEE ALSO</h2>
 <em>
-<a href="r.green.hydro.structure.html">r.green.hydro.structure</a>,
-<a href="r.green.hydro.technical.html">r.green.hydro.technical</a>
+<a href="r.green.hydro.discharge.html">r.green.hydro.discharge</a><br>
+<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.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>
-
-
 <h2>AUTHORS</h2>
+Giulia Garegnani (Eurac Research, Bolzano, Italy), Manual written by Julie Gros.<br>
+Last changed: $Date : 2015-07-08 10:57 GMT+1$
 
-Giulia Garegnani,
-Julie Gros
-
-<p><i>Last changed: $Date$</i>

Modified: grass-addons/grass7/raster/r.green/r.green.hydro/r.green.hydro.optimal/r.green.hydro.optimal.py
===================================================================
--- grass-addons/grass7/raster/r.green/r.green.hydro/r.green.hydro.optimal/r.green.hydro.optimal.py	2015-07-12 14:09:18 UTC (rev 65580)
+++ grass-addons/grass7/raster/r.green/r.green.hydro/r.green.hydro.optimal/r.green.hydro.optimal.py	2015-07-13 09:37:12 UTC (rev 65581)
@@ -15,33 +15,23 @@
 #############################################################################
 #
 #%module
-#% description: Calculate the hydropower energy potential for each basin
+#% description: Detect the position of the potential hydropower plants that can produce the highest possible power
 #% keyword: raster
+#% overwrite: yes
 #%end
-#%option
+#%option G_OPT_R_ELEV
+#%  required: yes
+#%end
+#%option G_OPT_R_INPUT
 #% key: discharge
-#% type: string
-#% gisprompt: old,cell,raster
-#% key_desc: name
-#% description: Name of river discharge [m^3/s]
+#% label: Name of river discharge [m^3/s]
 #% required: yes
 #%end
-#%option
+#%option G_OPT_V_INPUT
 #% key: river
-#% type: string
-#% gisprompt: old,vector,vector
-#% key_desc: name
-#% description: Name of vector map with interested segments of rivers
+#% label: Name of vector map with interested segments of rivers
 #% required: yes
 #%end
-#%option
-#% key: elevation
-#% type: string
-#% gisprompt: old,cell,raster
-#% key_desc: name
-#% description: Name of elevation raster map [m]
-#% required: yes
-#%end
 #%flag
 #% key: d
 #% description: Debug with intermediate maps
@@ -78,18 +68,21 @@
 #% required: no
 #%end
 #%option
+#% key: p_min
+#% type: double
+#% description: Minimum mean power [kW]
+#% answer: 10.0
+#% required: yes
+#%end
+#%option G_OPT_V_OUTPUT
 #% key: output_plant
-#% type: string
-#% key_desc: name
-#% description: Name of output vector with potential power segments [kW]
-#% required: no
+#% label: Name of output vector map with segments of potential power segments [kW]
+#% required: yes
 #%end
-#%option
+#%option G_OPT_V_OUTPUT
 #% key: output_point
-#% type: string
-#% key_desc: name
-#% description: Name of output vector with potential power intakes and restitution [kW]
-#% required: yes
+#% label: Name of output vector map with potential power intakes and restitution [kW]
+#% required: no
 #%end
 #%option
 #% key: efficiency
@@ -155,11 +148,12 @@
         p_max = float(options['p_max'])
     else:
         p_max = None
+    p_min = float(options['p_min'])
     DEBUG = flags['d']
     c = flags['c']
     msgr = get_msgr()
 
-    # pdb.set_trace()
+    #import ipdb; ipdb.set_trace()
 
     TMPVEC = ['river_clean']
     if not gcore.overwrite():
@@ -174,15 +168,16 @@
         # number of cell of the river
     # range for the solution
     msgr.message("\Loop on the category of segments\n")
-    #pdb.set_trace()
+
     range_plant = (len_min, len_plant)
     plants = find_segments(river, discharge, elevation, range_plant, distance,
                            p_max)
+                           
     if output_plant:
-        write_plants(plants, output_plant, efficiency)
-    write_points(plants, output_point, efficiency)
-#    else:
+        write_plants(plants, output_plant, efficiency, p_min)
+    write_points(plants, output_point, efficiency, p_min)
 
+
 if __name__ == "__main__":
     options, flags = gcore.parser()
     sys.exit(main(options, flags))

Deleted: grass-addons/grass7/raster/r.green/r.green.hydro/r.green.hydro.optimal/r_green_hydro_optimal_availablestreams.png
===================================================================
(Binary files differ)

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


Property changes on: grass-addons/grass7/raster/r.green/r.green.hydro/r.green.hydro.optimal/r_green_hydro_optimal_input.png
___________________________________________________________________
Added: svn:mime-type
   + image/png

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


Property changes on: grass-addons/grass7/raster/r.green/r.green.hydro/r.green.hydro.optimal/r_green_hydro_optimal_output.png
___________________________________________________________________
Added: svn:mime-type
   + image/png

Deleted: grass-addons/grass7/raster/r.green/r.green.hydro/r.green.hydro.optimal/r_green_hydro_optimal_potentialplants.png
===================================================================
(Binary files differ)

Modified: grass-addons/grass7/raster/r.green/r.green.hydro/r.green.hydro.recommended/r.green.hydro.recommended.html
===================================================================
--- grass-addons/grass7/raster/r.green/r.green.hydro/r.green.hydro.recommended/r.green.hydro.recommended.html	2015-07-12 14:09:18 UTC (rev 65580)
+++ grass-addons/grass7/raster/r.green/r.green.hydro/r.green.hydro.recommended/r.green.hydro.recommended.html	2015-07-13 09:37:12 UTC (rev 65581)
@@ -1,8 +1,124 @@
 <h2>DESCRIPTION</h2>
+<em>r.green.hydro.recommended</em> detects the position of the potential hydropower plants including the legal constrains and the user's recommendations. Deciding the range of plant length, the distance between plants, the legal discharge we can exploit and the areas we want to exclude from the calculation (ex. protected areas and the ones according to user's recommendations), the module returns a vector file with the potential plants.
 
+<h2>NOTES</h2>
+
+The difference between this module and r.green.hydro.optimal is that here we can consider a legal dicharge and add areas which will be deleted from the considered streams map used to compute the potential plants.<br> <br>
+
+The input files are : <br> <br>
+
+<blockquote>- the <b>rivers considered</b> (vector) on which the potential plants wille be computed<br><br>
+
+- the <b>current discharge</b> (raster) for each point of these rivers. <br>
+In the section Legal discharge, you can take into consideration the <b>Minimal Flow Discharge (MFD)</b>. It is the amount of water which has to remain in the river to preserve the ecosystems. There are three different ways to proceed which depend on the data you have :<br><br>
+
+<blockquote>or the MFD can be considered as a percentage of the natural discharge, which is the discharge of the river without considering the structures exploiting the water. In this case, you have to give in input the percentage you want to consider and the raster map of the natural discharge. The discharge considered in the calculation will be the current discharge minus the MFD thus calculated.<br><br>
+
+or you already have the raster map with the MFD. In this case, the discharge considered in the calculation will be the current discharge minus the MFD read in your input raster map. The module r.green.hydro.discharge can compute the raster map of the MFD according to the legislation of some regions.<br><br>
+
+or you already have the raster map with the legal discharge. In this case, you can add this map as current discharge input and not use the parameters MFD and natural discharge.<br><br>
+
+But for each case the raster map of the current discharge is a required input.</blockquote>
+
+- the <b>areas to exclude</b> (vector). You can exclude some areas adding in input a vector map of them with or without a buffer around them. Only the rivers outside these excluded areas will be considered to compute the potential plants. There's also the possibility to add an input vector map with points of interest. Then, an area corresponding to the fields of vision from these points is computed, the latter correspond to visibility zones. You can choose to exclude these areas or the areas where several visibility zones are superimposed. The number of points for the visibility corresponds to the number of visibility zones which are superimposed. For example, if this number is 3, the areas where two or less visibility zones are superimposed will be excluded.<br><br>
+
+- the <b>elevation</b> raster map, to calculate the gross head <br><br>
+
+- the <b>range of plant length, distance between plants, minimum power and efficiency</b> (optional parameters)<br><br></blockquote>
+
+The power is defined as :<br>
+
+<center>P=η * ρ * g * Q * Δh</center>
+
+<blockquote>where η is the efficiency of the plant <br>
+ρ the density of water (1000 kg/m<sup>3</sup>) <br>
+g the gravity term (9,81 m/s<sup>2</sup>) <br>
+Q the discharge of the river<br>
+Δh the gross head of the considered segment</blockquote><br>
+
+The module maximizes the power over a given range by a brute-force search in order to examine all possible arrangements of Q and Δh. Thus, the potential segments can be shorter than the maximum length plant chosen because it depends on the maximization of the product  Q * Δh. For each potential segment, the potential power is given in kW in attribute.<br><br>
+
+<h2>EXAMPLE</h2>
+This example is based on the case-study of Mis valley in Belluno province, Veneto, Italy.<br><br>
+
+Here is the vector file availablestreams of the considered streams. The river segments already exploited by an existing plant do not appear in the file.<br>
+In superimposition, there are the vector map (in grey) of the national park we want to exclude and the points of interest (in green) used to create the visibility zones. These points were placed according to experts' recommendations during a focus group made in Veneto region.
+
+<center>
+<img src="r_green_hydro_recommended_input.png" alt="input"><br>
+Input vector map availablestreams with the national park and points of interest
+</center><br><br>
+
+Points of interest are placed in the park so two different cases are presented here :<br>
+1) The national park and a buffer of 200 m around it are excluded.<br>
+2) The visibility zones from points of interest is excluded.<br><br>
+
+<blockquote>1) In the first case, the code used is :<br>
+<div class="code"><pre>r.green.hydro.recommended 
+discharge_current=currentdischarge
+discharge_natural=naturaldischarge
+percentage=25.00
+river=availablestreams 
+elevation=elevation 
+efficiency=0.8 
+len_plant=400 
+len_min=10 
+distance=150 
+area=nationalparks 
+buff=200 
+output_plant=potentialplants 
+output_point=potentialpoints<br>
+d.vect map= potentialpoints color=red<br>
+d.vect map= potentialplants color=blue<br>
+v.buffer input=nationalparks output=buff_park distance=200<br>
+d.vect map= buff_park color=255:179:179 fill_color=255:179:179 width=1<br></pre></div><br>
+
+This command calculates the energy potential for a range of plant length from 10 to 400 m and a distance between plants of 150 m. The areas with the national park and a buffer of 200 m around it are excluded. The discharge considered here is the current discharge of rivers subtracted by 25% of the natural discharge (the latter corresponds to the MFD).<br><br>
+
+<center>
+<img src="r_green_hydro_recommended_output_park.png" alt="output park"><br>
+Output vector map : superimposition of the potential segments vector file (potentialplants, in blue), the potential intakes and restitution vector file (potentialpoints, in red), the excluded national park (in grey) and the buffer (in light red)
+</center><br><br>
+
+2) In the second case, the code used is :<br>
+<div class="code"><pre>r.green.hydro.recommended 
+discharge_current=currentdischarge 
+mfd=mfd 
+river=availablestreams 
+elevation=elevation 
+efficiency=0.8 
+len_plant=400 
+len_min=10 
+distance=150 
+points_view=pointsinterest 
+n_points=1 
+output_plant=potentialplants 
+output_vis=vis 
+output_point=potentialpoints<br>
+d.vect map= potentialpoints color=red<br>
+d.vect map= potentialplants color=blue<br>
+d.vect map= pointsinterest color=green<br>
+d.vect map= vis color=144:224:144 fill_color=144:224:144 width=1<br></pre></div><br>
+
+This command calculates the energy potential for a plant length range from 10 to 400 m and a distance between plants of 150 m. The visibility zones from each point of interest are excluded. The discharge considered here is the current discharge of rivers subtracted by the MFD. The MFD was calculated previously and computed in a raster map.<br><br>
+
+<center>
+<img src="r_green_hydro_recommended_output_points.png" alt="output points"><br>
+Output vector map : superimposition of the potential segments vector file (potentialplants, in blue), the potential intakes and restitution vector file (potentialpoints, in red), the points of interest (in green) and the visibility zones (in light green)
+</center></blockquote>
+
 <h2>SEE ALSO</h2>
+<em>
+<a href="r.green.hydro.discharge.html">r.green.hydro.discharge</a><br>
+<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.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>AUTHORS</h2>
-Giulia Garegnani
+Giulia Garegnani (Eurac Research, Bolzano, Italy), Manual written by Julie Gros.<br>
+Last changed: $Date : 2015-07-08 14:46 GMT+1$
 
-<p><i>Last changed: $Date$</i>

Modified: grass-addons/grass7/raster/r.green/r.green.hydro/r.green.hydro.recommended/r.green.hydro.recommended.py
===================================================================
--- grass-addons/grass7/raster/r.green/r.green.hydro/r.green.hydro.recommended/r.green.hydro.recommended.py	2015-07-12 14:09:18 UTC (rev 65580)
+++ grass-addons/grass7/raster/r.green/r.green.hydro/r.green.hydro.recommended/r.green.hydro.recommended.py	2015-07-13 09:37:12 UTC (rev 65581)
@@ -3,10 +3,10 @@
 #
 ############################################################################
 #
-# MODULE:      r.green.hydro.reccomended
+# MODULE:      r.green.hydro.recommended
 # AUTHOR(S):   Giulia Garegnani
 # PURPOSE:     Calculate the optimal position of a plant along a river
-#              following user reccomandations
+#              following user's recommendations
 # COPYRIGHT:   (C) 2014 by the GRASS Development Team
 #
 #              This program is free software under the GNU General Public
@@ -17,102 +17,178 @@
 #
 
 #%module
-#% description: Hydropower energy potential with user reccomandations
+#% description: Calculate hydropower energy potential with user's recommendations
 #% keywords: raster
-#% overwrite: yes
 #%end
+
+##
+## REQUIRED INPUTS
+##
 #%option
-#% key: discharge
-#% type: string
-#% gisprompt: old,cell,raster
+#% key: elevation
 #% key_desc: name
-#% description: Name of river discharge [l/s]
+#% description: Name of elevation raster map [m]
 #% required: yes
 #%end
-#%option
+#%option G_OPT_V_INPUT
 #% key: river
-#% type: string
-#% gisprompt: old,vector,vector
-#% key_desc: name
-#% description: Name of vector map with interested segments of rivers
+#% label: Name of vector map with interested segments of rivers
+#% description: Vector map with the segments of the river that will be analysed
 #% required: yes
 #%end
+
+##
+## OPTIONAL INPUTS
+##
 #%option
-#% key: dtm
-#% type: string
-#% gisprompt: old,cell,raster
-#% key_desc: name
-#% description: Name of dtm [m]
-#% required: yes
-#%end
-#%flag
-#% key: d
-#% description: Debug with intermediate maps
-#%end
-#%flag
-#% key: c
-#% description: Clean vector lines
-#%end
-#%option
 #% key: efficiency
 #% type: double
-#% key_desc: name
-#% description: efficiency [-]]
-#% required: yes
-#% answer: 0.8
+#% key_desc: double
+#% description: Efficiency [0-1]
+#% required: no
+#% options: 0-1
+#% answer: 1
 #%end
 #%option
 #% key: len_plant
 #% type: double
-#% key_desc: name
-#% description: maximum length plant [m]
-#% required: yes
+#% key_desc: double
+#% description: Maximum plant length [m]
+#% required: no
 #% answer: 100
 #%end
 #%option
 #% key: len_min
 #% type: double
-#% key_desc: name
-#% description: minimum length plant [m]
-#% required: yes
+#% key_desc: double
+#% description: Minimum plant length [m]
+#% required: no
 #% answer: 10
 #%end
 #%option
 #% key: distance
 #% type: double
-#% description: minimum distance among plants.
-#% required: yes
+#% key_desc: double
+#% description: Minimum distance among plants [m]
+#% required: no
 #% answer: 0.5
 #%end
 #%option
+#% key: p_min
+#% type: double
+#% key_desc: double
+#% description: Minimum mean power [kW]
+#% answer: 10.0
+#% required: no
+#%end
+
+##
+## OPTIONAL INPUTS: LEGAL DISCHARGE
+##
+#%option
+#% key: discharge_current
+#% label: Current discharge [m3/s]
+#% required: yes
+#% guisection: Legal Discharge
+#%end
+#%option
+#% key: mfd
+#% label: Minimum Flow Discharge (MFD) [m3/s]
+#% required: no
+#% guisection: Legal Discharge
+#%end
+#%option
+#% key: discharge_natural
+#% label: Natural discharge [m3/s]
+#% required: no
+#% guisection: Legal Discharge
+#%end
+#%option
+#% key: percentage
+#% type: double
+#% key_desc: double
+#% description: MFD as percentage of natural discharge [%]
+#% options: 0-100
+#% answer: 20.00
+#% required: no
+#% guisection: Legal Discharge
+#%end
+
+##
+## OPTIONAL INPUTS: AREAS TO EXCLUDE
+##
+#%option G_OPT_V_INPUT
 #% key: area
-#% type: string
-#% gisprompt: old,vector,vector
-#% key_desc: name
-#% description: areas to be excluded.
+#% label: Areas to exclude
+#% description: Vector map with the areas that must be excluded (e.g. Parks)
 #% required: no
+#% guisection: Areas to exclude
 #%end
 #%option
 #% key: buff
 #% type: double
-#% description: buffer for areas to be excluded.
+#% key_desc: double
+#% description: Buffer for areas to exclude [m]
 #% required: no
+#% answer: 0
+#% guisection: Areas to exclude
 #%end
+#%option G_OPT_V_INPUT
+#% key: points_view
+#% label: Vector points of viewing position to exclude
+#% description: Vector with the point that are used to compute the visibility
+#% required: no
+#% guisection: Areas to exclude
+#%end
 #%option
+#% key: visibility_resolution
+#% type: double
+#% description: Resolution of the visibility map computation
+#% required: no
+#% answer: 250
+#% guisection: Areas to exclude
+#%end
+#%option
+#% key: n_points
+#% type: integer
+#% description: Number of points for the visibility
+#% required: no
+#% answer: 0
+#% guisection: Areas to exclude
+#%end
+
+##
+## OUTPUTS
+##
+#%option G_OPT_V_OUTPUT
 #% key: output_plant
-#% type: string
-#% key_desc: name
 #% description: Name of output vector with potential segments
-#% required: no
+#% required: yes
 #%end
-#%option
+#%option G_OPT_V_OUTPUT
 #% key: output_point
-#% type: string
-#% key_desc: name
 #% description: Name of output vector with potential intakes and restitution
-#% required: yes
-#%END
+#% required: no
+#%end
+#%option G_OPT_V_OUTPUT
+#% key: output_vis
+#% description: Name of output vector with viewed areas
+#% required: no
+#% guisection: Areas to exclude
+#%end
 
+##
+## FLAGS
+##
+#%flag
+#% key: d
+#% description: Debug with intermediate maps
+#%end
+#%flag
+#% key: c
+#% description: Clean vector lines
+#%end
+
 # import system libraries
 from __future__ import print_function
 import os
@@ -123,6 +199,8 @@
 from grass.script import core as gcore
 from grass.pygrass.utils import set_path
 from grass.pygrass.messages import get_msgr
+from grass.pygrass.vector import VectorTopo
+from grass.script import mapcalc
 
 # r.green lib
 set_path('r.green', 'libhydro', '..')
@@ -138,12 +216,29 @@
     sys.exit(1)
 
 
+def set_new_region(new_region):
+    gcore.run_command('g.region', res=new_region)
+    return
+
+
+def set_old_region(info):
+    gcore.run_command('g.region', rows=info['rows'], e=info['e'],
+                      cols=info['cols'], n=info['n'],
+                      s=info['s'], w=info['w'], ewres=info['ewres'],
+                      nsres=info['nsres'])
+    return
+
+
 def main(opts, flgs):
-    global DEBUG, TMPRAST
-    atexit.register(cleanup, rast=TMPRAST, debug=DEBUG)
-    dtm = options['dtm']
+    TMPRAST, TMPVECT, DEBUG = [], [], False
+    atexit.register(cleanup, rast=TMPRAST, vect=TMPVECT, debug=DEBUG)
+    OVW = gcore.overwrite()
+
+    dtm = options['elevation']
     river = options['river']  # raster
-    discharge = options['discharge']  # vec
+    discharge_current = options['discharge_current']  # vec
+    discharge_natural = options['discharge_natural']  # vec
+    mfd = options['mfd']
     len_plant = options['len_plant']
     len_min = options['len_min']
     distance = options['distance']
@@ -153,44 +248,110 @@
     buff = options['buff']
     efficiency = options['efficiency']
     DEBUG = flags['d']
-    c = flags['c']
+    points_view = options['points_view']
+    new_region = options['visibility_resolution']
+    final_vis = options['output_vis']
+    n_points = options['n_points']
+    p_min = options['p_min']
+    percentage = options['percentage']
     msgr = get_msgr()
 
-    TMPRAST = ['new_river', 'buff_area']
-    if not gcore.overwrite():
-        for m in TMPRAST:
-            if gcore.find_file(m)['name']:
-                msgr.fatal(_("Temporary raster map %s exists") % (m))
-                #FIXME:check if it works for vectors
+    # set the region
+    info = gcore.parse_command('g.region', flags='m')
+    if (info['nsres'] == 0) or (info['ewres'] == 0):
+        msgr.warning("set region to elevation raster")
+        gcore.run_command('g.region', raster=dtm)
 
     if area:
         if buff:
             gcore.run_command('v.buffer',
                               input=area,
                               output='buff_area',
-                              distance=buff)
+                              distance=buff, overwrite=OVW)
             area = 'buff_area'
+            TMPVECT.append('buff_area')
 
-        gcore.run_command('v.overlay',
+        gcore.run_command('v.overlay', flags='t',
                           ainput=river,
                           binput=area,
                           operator='not',
-                          output='new_river')
-        river = 'new_river'
+                          output='tmp1_river', overwrite=OVW)
+        river = 'tmp1_river'
+        TMPVECT.append('tmp1_river')
 
+    if points_view:
+        info_old = gcore.parse_command('g.region', flags='pg')
+        set_new_region(new_region)
+        pl, mset = points_view.split('@') if '@' in points_view else (points_view, '')
+        vec = VectorTopo(pl, mapset=mset, mode='r')
+        vec.open("r")
+        string = '0'
+        for i, point in enumerate(vec):
+            out = 'visual_%i' % i
+            gcore.run_command('r.viewshed', input=dtm, output=out,
+                              coordinates=point.coords(), overwrite=OVW,
+                              memory=1000, flags='b', max_distance=4000,
+                              )
+            TMPRAST.append(out)
+            # we use 4 km sice it the human limit
+            string = string + ('+%s' % out)
+        #import pdb; pdb.set_trace()
+
+        formula = 'final_vis = %s' % string
+        TMPRAST.append('final_vis')
+        mapcalc(formula, overwrite=OVW)
+        # change to old region
+        set_old_region(info_old)
+        gcore.run_command('r.to.vect', flags='v', overwrite=OVW,
+                          input='final_vis', output='tmp_vis',
+                          type='area')
+        TMPVECT.append('tmp_vis')
+        if int(n_points) > 0:
+            where = 'cat<%s' % (n_points)
+        else:
+            where = 'cat=0'
+        gcore.run_command('v.db.droprow', input='tmp_vis',
+                          where=where, output=final_vis, overwrite=OVW)
+        #TMPVECT.append('final_vis')
+        gcore.run_command('v.overlay', flags='t',
+                          ainput=river,
+                          binput=final_vis,
+                          operator='not',
+                          output='tmp2_river', overwrite=OVW)
+        river = 'tmp2_river'
+        TMPVECT.append('tmp2_river')
+
+        #import pdb; pdb.set_trace()
+
+    if mfd:
+        formula = 'tmp_discharge=%s-%s' % (discharge_current, mfd)
+        mapcalc(formula, overwrite=OVW)
+        TMPRAST.append('tmp_discharge')
+        discharge_current = 'tmp_discharge'
+
+    elif discharge_natural:
+        formula = 'tmp_discharge=%s-%s*%s/100.0' % (discharge_current,
+                                                    discharge_natural,
+                                                    percentage)
+        mapcalc(formula, overwrite=OVW)
+        TMPRAST.append('tmp_discharge')
+        discharge_current = 'tmp_discharge'
+
     gcore.run_command('r.green.hydro.optimal',
                       flags='c',
-                      discharge=discharge,
+                      discharge=discharge_current,
                       river=river,
-                      dtm=dtm,
+                      elevation=dtm,
                       len_plant=len_plant,
                       output_plant=output_plant,
                       output_point=output_point,
                       distance=distance,
                       len_min=len_min,
-                      efficiency=efficiency)
+                      efficiency=efficiency,
+                      p_min=p_min)
 
+    print('r.green.hydro.recommended completed!')
+
 if __name__ == "__main__":
-    atexit.register(cleanup)
     options, flags = gcore.parser()
     sys.exit(main(options, flags))

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


Property changes on: grass-addons/grass7/raster/r.green/r.green.hydro/r.green.hydro.recommended/r_green_hydro_recommended_input.png
___________________________________________________________________
Added: svn:mime-type
   + image/png

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


Property changes on: grass-addons/grass7/raster/r.green/r.green.hydro/r.green.hydro.recommended/r_green_hydro_recommended_output_park.png
___________________________________________________________________
Added: svn:mime-type
   + image/png

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


Property changes on: grass-addons/grass7/raster/r.green/r.green.hydro/r.green.hydro.recommended/r_green_hydro_recommended_output_points.png
___________________________________________________________________
Added: svn:mime-type
   + image/png

Modified: grass-addons/grass7/raster/r.green/r.green.hydro/r.green.hydro.structure/r.green.hydro.structure.html
===================================================================
--- grass-addons/grass7/raster/r.green/r.green.hydro/r.green.hydro.structure/r.green.hydro.structure.html	2015-07-12 14:09:18 UTC (rev 65580)
+++ grass-addons/grass7/raster/r.green/r.green.hydro/r.green.hydro.structure/r.green.hydro.structure.html	2015-07-13 09:37:12 UTC (rev 65581)
@@ -1,42 +1,57 @@
 <h2>DESCRIPTION</h2>
-<em>r.green.hydro.structure</em> computes the channels and the penstock between each intake and restitution. The input has to be a vector map with the intakes and restitution of the potential plants as the one computed by r.green.hydro.optimal.
+<em>r.green.hydro.structure</em> computes the derivation channel and the penstock for each potential plant and for both sides of the river.
 
-
 <h2>NOTES</h2>
-The structure of the plant is composed of a channel and a penstock. The channel conveys the water from the intake to the pentock along a very small slope and the penstock conveys the water to the turbine with the highest possible head. Indeed, the power is maximized for the highest head (the discharge is the same in the river and in the structure). Thus, the channel is computed along the same quote - even if in reality a slope is necessary, it's so small that it's neglected - until the point which maximizes the head of the pentock until the turbine. The structure is computed for both sides of the river in order to determine which one produces more power.
 
+The input maps are the elevation raster map and the one with the segments of potential plants (vector map which can be computed by r.green.hydro.optimal or r.green.hydro.recommended). <br>
+In the section "Input column", the column names in the table of the map with potential plants have to be reported in order to read correctly the corresponding values.<br>
+The module returns a vector map with the structure for each plant and on both sides of the river. The derivation channel and the penstock are distinguished and reported in the table.<br>
+In option, the module can also compute the vector map with the intake and restitution of each potential plant.<br><br>
 
+As the current potential concerns especially small hydropower (inferior to 20 MW), the structure suggested is the one for small hydropower detailed in the picture below. It is composed of an intake (A) which diverts water from the river. This water is conveyed into a derivation channel (B) with a very low slope and arrives in a forebay tank (C) which regulates the fluctuation of discharge. Finally, the penstock (D) conveys the water with the highest possible head to the turbine-alternator group (E) which produces electricity. The water is then released in the river (restitution F). We use the following vocabulary: the structure of the plant corresponds to the part with the derivation channel, the forebay tank and the penstock, whereas the segment of the plant corresponds to the part of the river (water not diverted) between the intake (A) and the restitution (F).<br><br>
+
+<center>
+<img src="r_green_hydro_technical_picstruct.png" alt="structure"><br>
+Structure of the plants considered in the module
+</center><br><br>
+
+The power is maximized for the highest head in the penstock so the derivation channel is computed along the same quote (the low slope is neglected here) until the point which maximizes the head along the penstock. The structure is computed for both sides of the river in order to determine which one produces the most power.
+
 <h2>EXAMPLE</h2>
-These examples are based on the Pnam file which refers to the Gesso and Vermenagna Valley in Piedmont, Italy.<br><br>
+This example is based on the case-study of Gesso and Vermenagna valleys in the Natural Park of the Maritime Alps, Piedmont, Italy.<br><br>
 
-Here is the input vector file potentialplants with the intakes and restitution (in red) computed by r.green.hydro.optimal. The vector map with the segments of river is also visibile in blue on this picture.<br><br>
+Here is the input vector map potentialplants with the segments of potential plants (in blue). The vector map with the intakes and restitution of potential plants is also visibile in red on this picture.<br><br>
 
 <center>
-<img src="r_green_hydro_structure_potentialplants.png" alt="r_green_hydro_structure_potentialplants"><br>
-Potential intakes and restitution
+<img src="r_green_hydro_structure_input.png" alt="potentialplants"><br>
+Input vector map potentialplants
 </center><br>
 
-The following command computes the channel and the pentock for each potential segment of river and for each side of the river from the input file potentialplants :<br>
-<div class="code"><pre>r.green.hydro.structure elevation=elevation plant=potentialplants output=structplants</pre></div><br><br>
+The following command computes the derivation channel and the pentock for each potential plant and for each side of the river :<br>
+<div class="code"><pre>r.green.hydro.structure elevation=elevation plant=potentialplants output_struct=structplants</pre></div><br><br>
 
-The result is shown in the following vector map structplants.<br><br>
+The result is shown in black in the following picture which gathers the input and output maps.<br><br>
 
 <center>
-<img src="r_green_hydro_structure_plantstructure.png" alt="r_green_hydro_structure_plantstructure"><br>
-Structure of the potential plants
+<img src="r_green_hydro_structure_output.png" alt="plantstructure"><br>
+Output vector map structplants in black
 </center>
 
 
 <h2>SEE ALSO</h2>
 <em>
-<a href="r.green.hydro.optimal.html">r.green.hydro.optimal</a>,
-<a href="r.green.hydro.technical.html">r.green.hydro.technical</a>
+<a href="r.green.hydro.discharge.html">r.green.hydro.discharge</a><br>
+<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.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>
+Picture of the plant structure taken from Micro-hydropower Systems - A Buyer's Guide, Natural Resources Canada, 2004<br>
 
 <h2>AUTHORS</h2>
-Pietro Zambelli,
-Julie Gros
-
-<p><i>Last changed: $Date$</i>
+Pietro Zambelli (Eurac Research, Bolzano, Italy), Manual written by Julie Gros.<br>
+Last changed: $Date : 2015-07-08 14:59 GMT+1$

Modified: grass-addons/grass7/raster/r.green/r.green.hydro/r.green.hydro.structure/r.green.hydro.structure.py
===================================================================
--- grass-addons/grass7/raster/r.green/r.green.hydro/r.green.hydro.structure/r.green.hydro.structure.py	2015-07-12 14:09:18 UTC (rev 65580)
+++ grass-addons/grass7/raster/r.green/r.green.hydro/r.green.hydro.structure/r.green.hydro.structure.py	2015-07-13 09:37:12 UTC (rev 65581)
@@ -21,16 +21,17 @@
 #%option G_OPT_R_ELEV
 #%  required: yes
 #%end
-#%option G_OPT_V_MAP
+#%option G_OPT_V_INPUT
 #%  key: plant
-#%  description: Name of the vector map points with the plants
+#%  label: Name of input vector map with segments of potential plants
 #%  required: yes
 #%end
-#%option G_OPT_V_INPUT
+#%option G_OPT_V_FIELD
 #%  key: plant_layer
-#%  description: Name of the vector map layer of plants
+#%  label: Name of the vector map layer of plants
 #%  required: no
 #%  answer: 1
+#%  guisection: Input columns
 #%end
 #%option
 #%  key: plant_column_plant_id
@@ -49,79 +50,95 @@
 #%  guisection: Input columns
 #%end
 #%option
-#%  key: plant_column_elevation
+#%  key: plant_column_stream_id
 #%  type: string
-#%  description: Column name with the elevation values [m]
+#%  description: Column name with the stream id
 #%  required: no
-#%  answer: elevation
+#%  answer: stream_id
 #%  guisection: Input columns
 #%end
 #%option
-#%  key: plant_column_discharge
+#%  key: plant_column_elevup
 #%  type: string
-#%  description: Column name with the discharge values [m3/s]
+#%  description: Column name with the elevation value at the intake (upstream) [m]
 #%  required: no
-#%  answer: discharge
+#%  answer: elev_up
 #%  guisection: Input columns
 #%end
 #%option
-#%  key: plant_column_kind
+#%  key: plant_column_elevdown
 #%  type: string
-#%  description: Column name (string) with the kind type of the points
+#%  description: Column name with the elevation value at the restitution (downstream) [m]
 #%  required: no
-#%  answer: kind_label
+#%  answer: elev_down
 #%  guisection: Input columns
 #%end
-
 #%option
-#%  key: plant_column_kind_intake
+#%  key: plant_column_discharge
 #%  type: string
-#%  description: Value contained in the column: hydro_kind that indicates the plant is an intake.
+#%  description: Column name with the discharge values [m3/s]
 #%  required: no
-#%  answer: intake
+#%  answer: discharge
 #%  guisection: Input columns
 #%end
 #%option
-#%  key: plant_column_kind_turbine
+#%  key: plant_column_power
 #%  type: string
-#%  description: Value contained in the column: hydro_kind that indicates the plant is a restitution.
+#%  description: Column name with the potential power [kW]
 #%  required: no
-#%  answer: restitution
+#%  answer: pot_power
 #%  guisection: Input columns
 #%end
 #%option G_OPT_V_OUTPUT
-#% key: output
+#% key: output_point
+#% label: Name of output vector map with potential intakes and restitution
+#% required: no
+#%end
+#%option G_OPT_V_OUTPUT
+#% key: output_struct
+#% label: Name of output vector map with the structure of the plants
 #% required: yes
 #%end
+##
+## FLAGS
+##
+#%flag
+#% key: d
+#% description: Debug with intermediate maps
+#%end
 from __future__ import print_function
 
 import os
 import atexit
 
 from grass.exceptions import ParameterError
-from grass.script.core import parser, run_command, overwrite
+from grass.script.core import parser, overwrite
 from grass.pygrass.utils import set_path
 from grass.pygrass.raster import RasterRow
-from grass.pygrass.vector import VectorTopo
 
+
 # set python path to the shared r.green libraries
 set_path('r.green', 'libhydro', '..')
 set_path('r.green', 'libgreen', os.path.join('..', '..'))
 
 from libgreen.utils import cleanup
+from libhydro.optimal import conv_segpoints
 from libgreen.checkparameter import check_required_columns, exception2error
 from libhydro.plant import read_plants, write_structures
 
 
 def main(opts, flgs):
-    #TMPVECT = []
-    #DEBUG = True if flgs['d'] else False
-    #atexit.register(cleanup, vect=TMPVECT, debug=DEBUG)
+    TMPVECT = []
+    DEBUG = True if flgs['d'] else False
+    atexit.register(cleanup, vector=TMPVECT, debug=DEBUG)
+
     # check input maps
-    plant = [opts['plant_column_kind'], opts['plant_column_discharge'],
-             opts['plant_column_point_id'], opts['plant_column_plant_id']]
+    plant = [opts['plant_column_discharge'], opts['plant_column_elevup'],
+             opts['plant_column_elevdown'], opts['plant_column_point_id'],
+             opts['plant_column_plant_id'], opts['plant_column_power'],
+             opts['plant_column_stream_id']]
     ovwr = overwrite()
-    #import pdb; pdb.set_trace()
+
     try:
         plnt = check_required_columns(opts['plant'], int(opts['plant_layer']),
                                       plant, 'plant')
@@ -129,25 +146,33 @@
         exception2error(exc)
         return
 
+    if not opts['output_point']:
+        output_point = 'tmp_output_point'
+        TMPVECT.append(output_point)
+    else:
+        output_point = opts['output_point']
+
+    plnt = conv_segpoints(opts['plant'], output_point)
+
     el, mset = (opts['elevation'].split('@') if '@' in opts['elevation']
                 else (opts['elevation'], ''))
 
     elev = RasterRow(name=el, mapset=mset)
     elev.open('r')
     plnt.open('r')
-    #import pdb; pdb.set_trace()
+
     plants, skipped = read_plants(plnt, elev=elev,
-                                  restitution=opts['plant_column_kind_turbine'],
-                                  intake=opts['plant_column_kind_intake'],
-                                  ckind_label=opts['plant_column_kind'],
-                                  cdischarge=opts['plant_column_discharge'],
-                                  celevation=opts['plant_column_elevation'],
-                                  cid_point=opts['plant_column_point_id'],
-                                  cid_plant=opts['plant_column_plant_id'])
+                                  restitution='restitution',
+                                  intake='intake',
+                                  ckind_label='kind_label',
+                                  cdischarge='discharge',
+                                  celevation='elevation',
+                                  cid_point='cat',
+                                  cid_plant='plant_id')
+
     plnt.close()
-    #import ipdb; ipdb.set_trace()
 
-    write_structures(plants, opts['output'], elev, overwrite=ovwr)
+    write_structures(plants, opts['output_struct'], elev, overwrite=ovwr)
     elev.close()
 
 

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


Property changes on: grass-addons/grass7/raster/r.green/r.green.hydro/r.green.hydro.structure/r_green_hydro_structure_input.png
___________________________________________________________________
Added: svn:mime-type
   + image/png

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


Property changes on: grass-addons/grass7/raster/r.green/r.green.hydro/r.green.hydro.structure/r_green_hydro_structure_output.png
___________________________________________________________________
Added: svn:mime-type
   + image/png

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


Property changes on: grass-addons/grass7/raster/r.green/r.green.hydro/r.green.hydro.structure/r_green_hydro_structure_picstruct.png
___________________________________________________________________
Added: svn:mime-type
   + image/png

Deleted: grass-addons/grass7/raster/r.green/r.green.hydro/r.green.hydro.structure/r_green_hydro_structure_plantstructure.png
===================================================================
(Binary files differ)

Deleted: grass-addons/grass7/raster/r.green/r.green.hydro/r.green.hydro.structure/r_green_hydro_structure_potentialplants.png
===================================================================
(Binary files differ)



More information about the grass-commit mailing list