{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "For more Landlab tutorials, click here: https://landlab.readthedocs.io/en/latest/user_guide/tutorials.html" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "**Application of the flow__distance utility on a Sicilian basin**" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "This notebook illustrates how to run the flow**__**distance utility on a digital elevation model (DEM) that represents a real basin in Sicily. First, a watershed will be extracted from the input DEM by using the watershed utility. Then, the distances from each node to the watershed's outlet will be obtained with the flow**__**distance utility. Flow is routed using the D8 algorithm." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "First, import what we'll need:" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "from landlab.io import read_esri_ascii\n", "from landlab.components import FlowAccumulator\n", "from landlab.plot import imshow_grid\n", "from matplotlib.pyplot import figure\n", "%matplotlib inline\n", "from landlab.utils import watershed\n", "import numpy as np\n", "from landlab.utils.flow__distance import calculate_flow__distance" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Import a square DEM that includes the watershed:" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "(mg, z) = read_esri_ascii('nocella_resampled.txt',\n", " name='topographic__elevation')" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Run the FlowAccumulator and the DepressionFinderAndRouter components to find depressions, to route the flow across them and to calculate flow direction and drainage area:" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "fr = FlowAccumulator(mg,\n", " flow_director='D8',\n", " depression_finder='DepressionFinderAndRouter')\n", "fr.run_one_step()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Set the id of the outlet. The value indicated here is the node id of the entire watershed's outlet:" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "outlet_id = 15324" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Run the watershed utility and show the watershed mask:" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "ws_mask = watershed.get_watershed_mask(mg, outlet_id)\n", "figure()\n", "imshow_grid(mg, ws_mask, allow_colorbar=False)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Run the flow**__**distance utility:" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "flow__distance = calculate_flow__distance(mg, add_to_grid=True, clobber=True)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Mask the flow**__**distance to the watershed mask. This operation has to be done because the flow**__**distance utility is applied to the entire grid that contains other streams not connected with our stream network and, for this reason, not belonging to our watershed." ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "flow_distance = np.zeros(mg.number_of_nodes)\n", "flow_distance[ws_mask] = flow__distance[ws_mask] - flow__distance[outlet_id]" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Add the flow**__**distance field to the grid and show the spatial distribution of the distances from each node to the watershed's outlet:" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "mg.add_field('flow_distance', flow_distance, at='node', clobber=True)\n", "figure()\n", "imshow_grid(mg,\n", " mg.at_node['flow_distance'],\n", " colorbar_label='flow distance (m)')" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [] } ], "metadata": { "kernelspec": { "display_name": "Python 3", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.7.3" } }, "nbformat": 4, "nbformat_minor": 2 }