Skip to content

Instantly share code, notes, and snippets.

@pyRobShrk
Last active July 1, 2018 20:01
Show Gist options
  • Save pyRobShrk/c7cde9319865b0cb9c35732d9c75fd78 to your computer and use it in GitHub Desktop.
Save pyRobShrk/c7cde9319865b0cb9c35732d9c75fd78 to your computer and use it in GitHub Desktop.
CE-QUAL-W2 bathymetry processing
## This script processes a bathymetric surface model into 2D blocks for CE-QUAL-W2
## "CEQUALRivSegm" is a shapefile with segment numbers, lengths, and reverse-azimuth directions
## "CEQUAL_seg" is a raster from a polygon file with segment numbers and pixels matching "DEM"
## The resulting histogram multiplied by the cell area gives the area-elevation curve for each segment
## The area-elevation curve divided by the segment length gives the average width for CE-QUAL-W2
from scipy import ndimage as ndi
import numpy as np
tabl = arcpy.da.TableToNumPyArray("CEQUALRivSegm",['OBJECTID','Length_m','Bearing'])
tabl = np.sort(tabl)
r = arcpy.Raster('cfw_t2rbathy3')
llc = arcpy.Point(r.extent.XMin,r.extent.YMin)
DEM = arcpy.RasterToNumPyArray(r)
zones = arcpy.RasterToNumPyArray("CEQUAL_seg",llc,DEM.shape[1],DEM.shape[0])
hist = ndi.measurements.histogram(DEM,145,305,80,zones,range(1,47))
#np.savetxt('C:/Users/rsherrick/Desktop/out.csv',np.column_stack(hist),delimiter=',')
#np.savetxt('C:/Users/rsherrick/Desktop/out2.csv',tabl,delimiter=',')
@khajehei
Copy link

khajehei commented Jul 1, 2018

Hello,
I would like to use this code to prepare the bathymetry for the CE-qual-w2. Did I understand correctly that I will give the bathymetry to it and it will give me the segments and all the values needed for the bathymetry file. I would appreciate if you can give me some example files and how the code is working.
Thank you so much,
Sepideh

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment