Skip to content

Commit 9312a0e

Browse files
Add files via upload
1 parent ec6c690 commit 9312a0e

2 files changed

Lines changed: 368 additions & 0 deletions

File tree

Lines changed: 197 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,197 @@
1+
{
2+
"cells": [
3+
{
4+
"cell_type": "markdown",
5+
"metadata": {},
6+
"source": [
7+
"<a href=\"http://landlab.github.io\"><img style=\"float: left\" src=\"https://raw.githubusercontent.com/landlab/tutorials/master/landlab_header.png\"></a>"
8+
]
9+
},
10+
{
11+
"cell_type": "markdown",
12+
"metadata": {},
13+
"source": [
14+
"For instructions on how to run an interactive iPython notebook, click here: https://github.com/landlab/tutorials/blob/master/README.md\n",
15+
"For the unexpanded version to download and run, click here:http://nbviewer.jupyter.org/github/landlab/tutorials/blob/master/component_tutorial/component_tutorial_unexpanded.ipynb\n",
16+
"For more Landlab tutorials, click here: https://github.com/landlab/landlab/wiki/Tutorials"
17+
]
18+
},
19+
{
20+
"cell_type": "markdown",
21+
"metadata": {},
22+
"source": [
23+
"**Application of the stream_length utility on a Sicilian basin**"
24+
]
25+
},
26+
{
27+
"cell_type": "markdown",
28+
"metadata": {},
29+
"source": [
30+
"This notebook illustrates how to run the stream_length utility on a real topography. For first, a watershed will be extracted from an input DEM by using the watershed utility. Then, a spatial distribution of the distances from each node to the watershed's outlet according to the path set with the D8 algorithm, will be obtained with the stream_length utility."
31+
]
32+
},
33+
{
34+
"cell_type": "markdown",
35+
"metadata": {},
36+
"source": [
37+
"First, import what we'll need:"
38+
]
39+
},
40+
{
41+
"cell_type": "code",
42+
"execution_count": 1,
43+
"metadata": {},
44+
"outputs": [],
45+
"source": [
46+
"from landlab.io import read_esri_ascii\n",
47+
"from landlab.components import FlowAccumulator\n",
48+
"from landlab.plot import imshow_grid\n",
49+
"from matplotlib.pyplot import figure\n",
50+
"from landlab.utils import watershed\n",
51+
"import numpy as np\n",
52+
"from landlab.utils.stream_length import calculate_stream_length"
53+
]
54+
},
55+
{
56+
"cell_type": "markdown",
57+
"metadata": {},
58+
"source": [
59+
"Import a square DEM that includes the watershed:"
60+
]
61+
},
62+
{
63+
"cell_type": "code",
64+
"execution_count": 2,
65+
"metadata": {},
66+
"outputs": [],
67+
"source": [
68+
"(mg, z) = read_esri_ascii('nocella_resampled.txt', name='topographic__elevation')"
69+
]
70+
},
71+
{
72+
"cell_type": "markdown",
73+
"metadata": {},
74+
"source": [
75+
"Run the FlowAccumulator and the DepressionFinderAndRouter components to find depressions, to route the flow across them and to calculate flow direction and drainage area:"
76+
]
77+
},
78+
{
79+
"cell_type": "code",
80+
"execution_count": 3,
81+
"metadata": {},
82+
"outputs": [],
83+
"source": [
84+
"fr = FlowAccumulator(mg, flow_director = 'D8', depression_finder = 'DepressionFinderAndRouter')\n",
85+
"fr.run_one_step()"
86+
]
87+
},
88+
{
89+
"cell_type": "markdown",
90+
"metadata": {},
91+
"source": [
92+
"Fix the outlet's id (the one indicated in this example is the whole watershed's outlet):"
93+
]
94+
},
95+
{
96+
"cell_type": "code",
97+
"execution_count": 4,
98+
"metadata": {},
99+
"outputs": [],
100+
"source": [
101+
"outlet_id = 15324"
102+
]
103+
},
104+
{
105+
"cell_type": "markdown",
106+
"metadata": {},
107+
"source": [
108+
"Run the watershed utility and show the watershed mask:"
109+
]
110+
},
111+
{
112+
"cell_type": "code",
113+
"execution_count": 5,
114+
"metadata": {},
115+
"outputs": [],
116+
"source": [
117+
"ws_mask = watershed.get_watershed_mask(mg, outlet_id)\n",
118+
"figure(); imshow_grid(mg, ws_mask)"
119+
]
120+
},
121+
{
122+
"cell_type": "markdown",
123+
"metadata": {},
124+
"source": [
125+
"Run the stream_length utility:"
126+
]
127+
},
128+
{
129+
"cell_type": "code",
130+
"execution_count": 6,
131+
"metadata": {},
132+
"outputs": [],
133+
"source": [
134+
"stream__length = calculate_stream_length(mg, add_to_grid=True, noclobber=False)"
135+
]
136+
},
137+
{
138+
"cell_type": "markdown",
139+
"metadata": {},
140+
"source": [
141+
"Mask the stream__length to the watershed mask:"
142+
]
143+
},
144+
{
145+
"cell_type": "code",
146+
"execution_count": 7,
147+
"metadata": {},
148+
"outputs": [],
149+
"source": [
150+
"flow_length = np.zeros(len(ws_mask))\n",
151+
"for i in range (0,len(ws_mask)):\n",
152+
" if ws_mask[i] == True:\n",
153+
" flow_length[i] = stream__length[i]-stream__length[outlet_id]\n",
154+
" else:\n",
155+
" flow_length[i] = 0"
156+
]
157+
},
158+
{
159+
"cell_type": "markdown",
160+
"metadata": {},
161+
"source": [
162+
"Add the flow_length field to the grid and show the spatial distribution of the distances from each node to the watershed's outlet:"
163+
]
164+
},
165+
{
166+
"cell_type": "code",
167+
"execution_count": 8,
168+
"metadata": {},
169+
"outputs": [],
170+
"source": [
171+
"mg.add_field('node','flow_length',flow_length)\n",
172+
"figure(); imshow_grid(mg, mg['node']['flow_length'])"
173+
]
174+
}
175+
],
176+
"metadata": {
177+
"kernelspec": {
178+
"display_name": "Python 3",
179+
"language": "python",
180+
"name": "python3"
181+
},
182+
"language_info": {
183+
"codemirror_mode": {
184+
"name": "ipython",
185+
"version": 3
186+
},
187+
"file_extension": ".py",
188+
"mimetype": "text/x-python",
189+
"name": "python",
190+
"nbconvert_exporter": "python",
191+
"pygments_lexer": "ipython3",
192+
"version": "3.6.4"
193+
}
194+
},
195+
"nbformat": 4,
196+
"nbformat_minor": 2
197+
}

0 commit comments

Comments
 (0)