[GRASS-SVN] r72638 - grass-addons/grass7/vector/v.gsflow.segments

svn_grass at osgeo.org svn_grass at osgeo.org
Sun Apr 22 08:55:08 PDT 2018


Author: awickert
Date: 2018-04-22 08:55:07 -0700 (Sun, 22 Apr 2018)
New Revision: 72638

Modified:
   grass-addons/grass7/vector/v.gsflow.segments/v.gsflow.segments.html
   grass-addons/grass7/vector/v.gsflow.segments/v.gsflow.segments.py
Log:
v.gsflow.segments: variable channel/floodplain width and Manning's n
from grid or from point data


Modified: grass-addons/grass7/vector/v.gsflow.segments/v.gsflow.segments.html
===================================================================
--- grass-addons/grass7/vector/v.gsflow.segments/v.gsflow.segments.html	2018-04-20 12:39:07 UTC (rev 72637)
+++ grass-addons/grass7/vector/v.gsflow.segments/v.gsflow.segments.html	2018-04-22 15:55:07 UTC (rev 72638)
@@ -16,6 +16,7 @@
 <a href="v.gsflow.hruparams">v.gsflow.hruparams</a>
 <a href="v.gsflow.reaches">v.gsflow.reaches</a>
 <a href="v.gsflow.segments">v.gsflow.segments</a>
+<a href="v.gsflow.mapdata">v.gsflow.mapdata</a>
 <a href="v.stream.inbasin">v.stream.inbasin</a>
 <a href="v.stream.network">v.stream.network</a>
 
@@ -23,4 +24,4 @@
 
 Andrew D. Wickert<br>
 
-<p><i>Last changed: $Date 2016-09-27$</i>
+<p><i>Last changed: $Date 2018-04-22$</i>

Modified: grass-addons/grass7/vector/v.gsflow.segments/v.gsflow.segments.py
===================================================================
--- grass-addons/grass7/vector/v.gsflow.segments/v.gsflow.segments.py	2018-04-20 12:39:07 UTC (rev 72637)
+++ grass-addons/grass7/vector/v.gsflow.segments/v.gsflow.segments.py	2018-04-22 15:55:07 UTC (rev 72638)
@@ -94,7 +94,7 @@
 #%option
 #%  key: flow
 #%  type: string
-#%  description: Streamflow entering the upstream-most segments (cat,Q,cat,Q,...)
+#%  description: Streamflow entering the upstream-most segs (cat,Q,cat,Q,...)
 #%  answer: 0,0
 #%  required: no
 #%end
@@ -124,15 +124,36 @@
 #%end
 
 #%option
-#%  key: roughch
+#%  key: roughch_value
 #%  type: double
-#%  description: In-channel Manning's n for ICALC=1,2
+#%  description: In-channel Manning's n (single value) for ICALC=1,2
 #%  answer: 0.035
 #%  required: no
 #%end
 
 #%option
-#%  key: roughbk
+#%  key: roughch_raster
+#%  type: string
+#%  description: In-channel Manning's n raster map for ICALC=1,2
+#%  required: no
+#%end
+
+#%option
+#%  key: roughch_points
+#%  type: string
+#%  description: In-channel Manning's n vector point meas for ICALC=1,2
+#%  required: no
+#%end
+
+#%option
+#%  key: roughch_pt_col
+#%  type: string
+#%  description: Column name for in-channel n point measurements
+#%  required: no
+#%end
+
+#%option
+#%  key: roughbk_value
 #%  type: double
 #%  description: Overbank Manning's n for ICALC=2
 #%  answer: 0.06
@@ -140,9 +161,30 @@
 #%end
 
 #%option
+#%  key: roughbk_raster
+#%  type: string
+#%  description: Overbank Manning's n raster map for ICALC=2
+#%  required: no
+#%end
+
+#%option
+#%  key: roughbk_points
+#%  type: string
+#%  description: Overbank Manning's n vector point meas for ICALC=2
+#%  required: no
+#%end
+
+#%option
+#%  key: roughbk_pt_col
+#%  type: string
+#%  description: Column name for overbank n point measurements
+#%  required: no
+#%end
+
+#%option
 #%  key: width1
 #%  type: double
-#%  description: Upstream width in segment [m], uniform through watershed
+#%  description: Upstream width in segment [m], uniform in watershed
 #%  answer: 5
 #%  required: no
 #%end
@@ -150,11 +192,77 @@
 #%option
 #%  key: width2
 #%  type: double
-#%  description: Downstream width in segment [m], uniform through watershed
+#%  description: Downstream width in segment [m], uniform in watershed
 #%  answer: 5
 #%  required: no
 #%end
 
+#%option
+#%  key: width_points
+#%  type: string
+#%  description: Channel width point meas vect (instead of width1,width2)
+#%  required: no
+#%end
+
+#%option
+#%  key: width_points_col
+#%  type: string
+#%  description: Channel width point meas vect column
+#%  required: no
+#%end
+
+#%option
+#%  key: width1
+#%  type: double
+#%  description: Upstream width in segment [m], uniform in watershed
+#%  answer: 5
+#%  required: no
+#%end
+
+#%option
+#%  key: width2
+#%  type: double
+#%  description: Downstream width in segment [m], uniform in watershed
+#%  answer: 5
+#%  required: no
+#%end
+
+#%option
+#%  key: width_points
+#%  type: string
+#%  description: Channel width point meas vect (instead of width1,width2)
+#%  required: no
+#%end
+
+#%option
+#%  key: width_points_col
+#%  type: string
+#%  description: Channel width point meas vect column
+#%  required: no
+#%end
+
+#%option
+#%  key: fp_width_value
+#%  type: double
+#%  description: Floodplain width as constant value (ICALC=2)
+#%  answer: 0
+#%  required: no
+#%end
+
+#%option
+#%  key: fp_width_pts
+#%  type: string
+#%  description: Floodplain width measurement vector (ICALC=2)
+#%  required: no
+#%end
+
+#%option
+#%  key: fp_width_pts_col
+#%  type: string
+#%  description: Floodplain width measurement column (ICALC=2)
+#%  required: no
+#%end
+
 ##################
 # IMPORT MODULES #
 ##################
@@ -172,6 +280,9 @@
 from grass.pygrass.raster import RasterRow
 from grass.pygrass import utils
 from grass import script as gscript
+#from pygrass.messages import Messenger
+import sys
+import time
 
 ###############
 # MAIN MODULE #
@@ -194,18 +305,14 @@
     segments = options['output']
     
     # Hydraulic geometry
-    ICALC = options['icalc']
+    ICALC = int(options['icalc'])
     
     # ICALC=0: Constant depth
     WIDTH1 = options['width1']
     WIDTH2 = options['width2']
     
-    # ICALC=1: Manning
-    ROUGHCH = options['roughch']
+    # ICALC=1,2: Manning (in channel and overbank): below
     
-    # ICALC=2: Manning
-    ROUGHBK = options['roughbk']
-
     # ICALC=3: Power-law relationships (following Leopold and others)
     # The at-a-station default exponents are from Rhodes (1977)
     CDPTH = str(float(options['cdpth']) / 35.3146667) # cfs to m^3/s
@@ -221,7 +328,7 @@
         if CDPTH and FDPTH and AWDTH and BWDTH:
             pass
         else:
-            grass.fatal('Missing CDPTH, FDPTH, AWDTH, and/or BWDTH. \
+            gscript.fatal('Missing CDPTH, FDPTH, AWDTH, and/or BWDTH. \
                          These are required when ICALC = 3.')
 
     ###########
@@ -235,7 +342,7 @@
     segment_columns.append('ISEG integer') # segment number
     segment_columns.append('NSEG integer') # segment number
     # for GSFLOW
-    segment_columns.append('ICALC integer') # 3 for power function
+    segment_columns.append('ICALC integer') # 1 for channel, 2 for channel+fp, 3 for power function
     segment_columns.append('OUTSEG integer') # downstream segment -- tostream, renumbered
     segment_columns.append('ROUGHCH double precision') # overbank roughness
     segment_columns.append('ROUGHBK double precision') # in-channel roughness
@@ -245,6 +352,7 @@
     segment_columns.append('FDPTH double precision') # depth exp
     segment_columns.append('AWDTH double precision') # width coeff
     segment_columns.append('BWDTH double precision') # width exp
+    segment_columns.append('floodplain_width double precision') # floodplain width (8-pt approx channel + flat fp)
     # The below will be all 0
     segment_columns.append('IUPSEG varchar') # upstream segment ID number, for diversions
     segment_columns.append('FLOW varchar')
@@ -287,17 +395,61 @@
     cur.execute("update "+segments+" set OUTSEG=0")
     cur.executemany("update "+segments+" set OUTSEG=? where tostream=?", nseg_cats)
 
-    # Discharge and hydraulic geometry
-    cur.execute("update "+segments+" set WIDTH1="+str(WIDTH1))
-    cur.execute("update "+segments+" set WIDTH2="+str(WIDTH2))
-    cur.execute("update "+segments+" set ROUGHCH="+str(ROUGHCH))
-    cur.execute("update "+segments+" set ROUGHBK="+str(ROUGHBK))
+    # Hydraulic geometry selection
     cur.execute("update "+segments+" set ICALC="+str(ICALC))
-    cur.execute("update "+segments+" set CDPTH="+str(CDPTH))
-    cur.execute("update "+segments+" set FDPTH="+str(FDPTH))
-    cur.execute("update "+segments+" set AWDTH="+str(AWDTH))
-    cur.execute("update "+segments+" set BWDTH="+str(BWDTH))
-
+    segmentsTopo.table.conn.commit()
+    segmentsTopo.close()
+    if ICALC == 0:
+        gscript.message('')
+        gscript.message('ICALC=0 (constant) not supported')
+        gscript.message('Continuing nonetheless.')
+        gscript.message('')
+    if ICALC == 1:
+        if options['width_points'] is not '':
+            # Can add machinery here for separate upstream and downstream widths
+            # But really should not vary all that much
+            #v.to_db(map=segments, option='start', columns='xr1,yr1')
+            #v.to_db(map=segments, option='end', columns='xr2,yr2')
+            gscript.run_command('v.distance', from_=segments, to=options['width_points'], upload='to_attr', to_column=options['width_points_col'], column='WIDTH1')
+            v.db_update(map=segments, column='WIDTH2', query_column='WIDTH1')
+        else:
+            segmentsTopo = VectorTopo(segments)
+            segmentsTopo.open('rw')
+            cur = segmentsTopo.table.conn.cursor()
+            cur.execute("update "+segments+" set WIDTH1="+str(WIDTH1))
+            cur.execute("update "+segments+" set WIDTH2="+str(WIDTH2))
+            segmentsTopo.table.conn.commit()
+            segmentsTopo.close()
+    if ICALC == 2:
+        # REMOVE THIS MESSAGE ONCE THIS IS INCLUDED IN INPUT-FILE BUILDER
+        gscript.message('')
+        gscript.message('ICALC=2 (8-point channel + floodplain) not supported')
+        gscript.message('Continuing nonetheless.')
+        gscript.message('')
+        if options['fp_width_pts'] is not '':
+            gscript.run_command('v.distance', from_=segments, 
+                                to=options['fp_width_pts'], upload='to_attr', 
+                                to_column=options['fp_width_pts_col'], 
+                                column='floodplain_width')
+        else:
+            segmentsTopo = VectorTopo(segments)
+            segmentsTopo.open('rw')
+            cur = segmentsTopo.table.conn.cursor()
+            cur.execute("update "+segments+" set floodplain_width="+str(options['fp_width_value']))
+            segmentsTopo.table.conn.commit()
+            segmentsTopo.close()
+    if ICALC == 3:
+        segmentsTopo = VectorTopo(segments)
+        segmentsTopo.open('rw')
+        cur = segmentsTopo.table.conn.cursor()
+        cur.execute("update "+segments+" set CDPTH="+str(CDPTH))
+        cur.execute("update "+segments+" set FDPTH="+str(FDPTH))
+        cur.execute("update "+segments+" set AWDTH="+str(AWDTH))
+        cur.execute("update "+segments+" set BWDTH="+str(BWDTH))
+        segmentsTopo.table.conn.commit()
+        segmentsTopo.close()
+    
+    # values that are 0
     gscript.message('')
     gscript.message('NOTICE: not currently used:')
     gscript.message('IUPSEG, FLOW, RUNOFF, ETSW, and PPTSW.')
@@ -304,16 +456,57 @@
     gscript.message('All set to 0.')
     gscript.message('')
 
-    # values that are 0
+    segmentsTopo = VectorTopo(segments)
+    segmentsTopo.open('rw')
+    cur = segmentsTopo.table.conn.cursor()
     cur.execute("update "+segments+" set IUPSEG="+str(0))
     cur.execute("update "+segments+" set FLOW="+str(0))
     cur.execute("update "+segments+" set RUNOFF="+str(0))
     cur.execute("update "+segments+" set ETSW="+str(0))
     cur.execute("update "+segments+" set PPTSW="+str(0))
-
     segmentsTopo.table.conn.commit()
     segmentsTopo.close()
 
+    # Roughness
+    # ICALC=1,2: Manning (in channel)
+    if (options['roughch_raster'] is not '') and (options['roughch_points'] is not ''):
+        gscript.fatal("Choose either a raster or vector or a value as Manning's n input.")
+    if options['roughch_raster'] is not '':
+        ROUGHCH = options['roughch_raster']
+        v.rast_stats(raster=ROUGHCH, method='average', column_prefix='tmp', map=segments, flags='c')
+        #v.db_renamecolumn(map=segments, column='tmp_average,ROUGHCH', quiet=True)
+        v.db_update(map=segments, column='ROUGHCH', query_column='tmp_average', quiet=True)
+        v.db_dropcolumn(map=segments, columns='tmp_average', quiet=True)
+    elif options['roughch_points'] is not '':
+        ROUGHCH = options['roughch_points']
+        gscript.run_command('v.distance', from_=segments, to=ROUGHCH, upload='to_attr', to_column=options['roughch_pt_col'], column='ROUGHCH')
+    else:
+        segmentsTopo = VectorTopo(segments)
+        segmentsTopo.open('rw')
+        cur = segmentsTopo.table.conn.cursor()
+        ROUGHCH = options['roughch_value']
+        cur.execute("update "+segments+" set ROUGHCH="+str(ROUGHCH))
+        segmentsTopo.table.conn.commit()
+        segmentsTopo.close()
+    
+    # ICALC=2: Manning (overbank)
+    if (options['roughbk_raster'] is not '') and (options['roughbk_points'] is not ''):
+        gscript.fatal("Choose either a raster or vector or a value as Manning's n input.")
+    if options['roughbk_raster'] is not '':
+        ROUGHBK = options['roughbk_raster']
+        v.rast_stats(raster=ROUGHBK, method='average', column_prefix='tmp', map=segments, flags='c')
+        v.db_renamecolumn(map=segments, column='tmp_average,ROUGHBK', quiet=True)
+    elif options['roughbk_points'] is not '':
+        ROUGHBK = options['roughbk_points']
+        gscript.run_command('v.distance', from_=segments, to=ROUGHBK, upload='to_attr', to_column=options['roughbk_pt_col'], column='ROUGHBK')
+    else:
+        segmentsTopo = VectorTopo(segments)
+        segmentsTopo.open('rw')
+        cur = segmentsTopo.table.conn.cursor()
+        ROUGHBK = options['roughbk_value']
+        cur.execute("update "+segments+" set ROUGHBK="+str(ROUGHBK))
+        segmentsTopo.table.conn.commit()
+        segmentsTopo.close()
 
 if __name__ == "__main__":
     main()



More information about the grass-commit mailing list