Skip to content

Commit

Permalink
work
Browse files Browse the repository at this point in the history
  • Loading branch information
keckje committed Jun 27, 2024
1 parent 7193af7 commit ddd4b5c
Show file tree
Hide file tree
Showing 7 changed files with 470 additions and 28 deletions.
64 changes: 64 additions & 0 deletions landlab/utils/channel_network_grid_tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -264,6 +264,70 @@ def map_nmg_links_to_rmg_nodes(self, linknodes, active_links, nmgx, nmgy):

return (Lnodelist, Ldistlist, Lxy)


def map_nmg_links_to_rmg_nodes_DHSVM(self, linknodes, active_links, nmgx, nmgy):
'''convert network model grid links to coincident raster model grid nodes.
Output is a list of lists. order of lists is order of links
'''
Lnodelist = [] #list of lists of all nodes that coincide with each link
Ldistlist = [] #list of lists of the distance on the link (measured from upstream link node) for all nodes that coincide with each link
xdDFlist = []
Lxy= [] #list of all nodes the coincide with the network links
#loop through all links in network grid to determine raster grid cells that coincide with each link
#and equivalent distance from upstream node on link
for k,lk in enumerate(linknodes) : #for each link in network grid
linkID = active_links[k] #link id (indicie of link in nmg fields)
lknd = lk #link node numbers
x0 = nmgx[lknd[0]] #x and y of downstream link node
y0 = nmgy[lknd[0]]
x1 = nmgx[lknd[1]] #x and y of upstream link node
y1 = nmgy[lknd[1]]
#create 1000 points along domain of link
X = np.linspace(x0,x1,1000)
Xs = X-x0 #change begin value to zero
#determine distance from upstream node to each point
#y value of points
if Xs.max() ==0: #if a vertical link (x is constant)
vals = np.linspace(y0,y1,1000)
dist = vals-y0 #distance along link, from downstream end upstream
dist = dist.max()-dist #distance from updtream to downstream
else: #all their lines
vals = y0+(y1-y0)/(x1-x0)*(Xs)
dist = ((vals-y0)**2+Xs**2)**.5
dist = dist.max()-dist #distance from updtream to downstream
#match points along link (vals) with grid cells that coincide with link
nodelist = [] #list of nodes along link
distlist = [] #list of distance along link corresponding to node
for i,v in enumerate(vals):
x = X[i]
mask = (self.ndyn>=v) & (self.ndys<=v) & (self.ndxe>=x) & (self.ndxw<=x) #mask - use multiple boolean tests to find cell that contains point on link
node = self.nodes[mask] #use mask to extract node value
if node.shape[0] > 1:
node = np.array([node[0]])
# create list of all nodes that coincide with linke
if node not in nodelist: #if node not already in list, append - many points will be in same cell; only need to list cell once
nodelist.append(node[0][0])
distlist.append(dist[i])
xy = {'linkID':linkID,
'node':node[0][0],
'x':self.gridx[node[0][0]],
'y':self.gridy[node[0][0]]}
Lxy.append(xy)



Lnodelist.append(nodelist)
Ldistlist.append(distlist)

df = pd.DataFrame.from_dict(Lxy)
df['row'] = self._grid.at_node['DHSVM_row'][df['node']]
df['column'] = self._grid.at_node['DHSVM_column'][df['node']]




return (Lnodelist, Ldistlist, Lxy, df)


def map_nmg1_links_to_nmg2_links(self,Lnodelist,xyDf_d):

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -374,7 +374,7 @@
"source": [
"%matplotlib inline\n",
"plt.figure()\n",
"plot_node_field_with_shaded_high_res_dem(mg=mg, mg_hs = mg_hs, field = 'topographic__elevation',cmap = 'gist_ncar',cbr = [0,1])\n",
"plot_node_field_with_shaded_high_res_dem(mg=mg, mg_hs = mg_hs, field = 'topographic__steepest_slope',cmap = 'gist_ncar',cbr = [0,1])\n",
"plt.show()"
]
},
Expand Down
2 changes: 1 addition & 1 deletion notebooks/tutorials/landslides/Pile_runout_animation.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -284,7 +284,7 @@
"id": "ed728e90",
"metadata": {},
"source": [
"### that's a nice looking pile...now set up an instance of MassWastingRuntout to and run it to model the pile collapse and runout "
"### that's a nice looking pile...now set up an instance of MassWastingRuntout and run it to model the pile collapse and runout "
]
},
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@
"metadata": {},
"outputs": [],
"source": [
"terrain_id = 'E'"
"terrain_id = 'A'"
]
},
{
Expand Down

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -520,7 +520,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.11.0"
"version": "3.11.2"
}
},
"nbformat": 4,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -633,7 +633,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.8.0"
"version": "3.11.2"
}
},
"nbformat": 4,
Expand Down

0 comments on commit ddd4b5c

Please sign in to comment.