|
| 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', \n", |
| 69 | + " name='topographic__elevation')" |
| 70 | + ] |
| 71 | + }, |
| 72 | + { |
| 73 | + "cell_type": "markdown", |
| 74 | + "metadata": {}, |
| 75 | + "source": [ |
| 76 | + "Run the FlowAccumulator and the DepressionFinderAndRouter components to find depressions, to route the flow across them and to calculate flow direction and drainage area:" |
| 77 | + ] |
| 78 | + }, |
| 79 | + { |
| 80 | + "cell_type": "code", |
| 81 | + "execution_count": 3, |
| 82 | + "metadata": {}, |
| 83 | + "outputs": [], |
| 84 | + "source": [ |
| 85 | + "fr = FlowAccumulator(mg, flow_director='D8', \n", |
| 86 | + " depression_finder='DepressionFinderAndRouter')\n", |
| 87 | + "fr.run_one_step()" |
| 88 | + ] |
| 89 | + }, |
| 90 | + { |
| 91 | + "cell_type": "markdown", |
| 92 | + "metadata": {}, |
| 93 | + "source": [ |
| 94 | + "Fix the outlet's id (the one indicated in this example is the whole watershed's outlet):" |
| 95 | + ] |
| 96 | + }, |
| 97 | + { |
| 98 | + "cell_type": "code", |
| 99 | + "execution_count": 4, |
| 100 | + "metadata": {}, |
| 101 | + "outputs": [], |
| 102 | + "source": [ |
| 103 | + "outlet_id = 15324" |
| 104 | + ] |
| 105 | + }, |
| 106 | + { |
| 107 | + "cell_type": "markdown", |
| 108 | + "metadata": {}, |
| 109 | + "source": [ |
| 110 | + "Run the watershed utility and show the watershed mask:" |
| 111 | + ] |
| 112 | + }, |
| 113 | + { |
| 114 | + "cell_type": "code", |
| 115 | + "execution_count": 5, |
| 116 | + "metadata": {}, |
| 117 | + "outputs": [], |
| 118 | + "source": [ |
| 119 | + "ws_mask = watershed.get_watershed_mask(mg, outlet_id)\n", |
| 120 | + "figure(); imshow_grid(mg, ws_mask)" |
| 121 | + ] |
| 122 | + }, |
| 123 | + { |
| 124 | + "cell_type": "markdown", |
| 125 | + "metadata": {}, |
| 126 | + "source": [ |
| 127 | + "Run the stream_length utility:" |
| 128 | + ] |
| 129 | + }, |
| 130 | + { |
| 131 | + "cell_type": "code", |
| 132 | + "execution_count": 6, |
| 133 | + "metadata": {}, |
| 134 | + "outputs": [], |
| 135 | + "source": [ |
| 136 | + "stream__length = calculate_stream_length(mg, add_to_grid=True, \n", |
| 137 | + " noclobber=False)" |
| 138 | + ] |
| 139 | + }, |
| 140 | + { |
| 141 | + "cell_type": "markdown", |
| 142 | + "metadata": {}, |
| 143 | + "source": [ |
| 144 | + "Mask the stream__length to the watershed mask:" |
| 145 | + ] |
| 146 | + }, |
| 147 | + { |
| 148 | + "cell_type": "code", |
| 149 | + "execution_count": 7, |
| 150 | + "metadata": {}, |
| 151 | + "outputs": [], |
| 152 | + "source": [ |
| 153 | + "flow_length = np.zeros(len(ws_mask))\n", |
| 154 | + "for i in range (0, len(ws_mask)):\n", |
| 155 | + " if ws_mask[i] == True:\n", |
| 156 | + " flow_length[i] = stream__length[i]-stream__length[outlet_id]\n", |
| 157 | + " else:\n", |
| 158 | + " flow_length[i] = 0" |
| 159 | + ] |
| 160 | + }, |
| 161 | + { |
| 162 | + "cell_type": "markdown", |
| 163 | + "metadata": {}, |
| 164 | + "source": [ |
| 165 | + "Add the flow_length field to the grid and show the spatial distribution of the distances from each node to the watershed's outlet:" |
| 166 | + ] |
| 167 | + }, |
| 168 | + { |
| 169 | + "cell_type": "code", |
| 170 | + "execution_count": 8, |
| 171 | + "metadata": {}, |
| 172 | + "outputs": [], |
| 173 | + "source": [ |
| 174 | + "mg.add_field('node', 'flow_length', flow_length)\n", |
| 175 | + "figure(); imshow_grid(mg, mg['node']['flow_length'])" |
| 176 | + ] |
| 177 | + } |
| 178 | + ], |
| 179 | + "metadata": { |
| 180 | + "kernelspec": { |
| 181 | + "display_name": "Python 3", |
| 182 | + "language": "python", |
| 183 | + "name": "python3" |
| 184 | + }, |
| 185 | + "language_info": { |
| 186 | + "codemirror_mode": { |
| 187 | + "name": "ipython", |
| 188 | + "version": 3 |
| 189 | + }, |
| 190 | + "file_extension": ".py", |
| 191 | + "mimetype": "text/x-python", |
| 192 | + "name": "python", |
| 193 | + "nbconvert_exporter": "python", |
| 194 | + "pygments_lexer": "ipython3", |
| 195 | + "version": "3.6.4" |
| 196 | + } |
| 197 | + }, |
| 198 | + "nbformat": 4, |
| 199 | + "nbformat_minor": 2 |
| 200 | +} |
0 commit comments