<SYSTEM_TASK:>
Given the following text description, write Python code to implement the functionality described below step by step
<END_TASK>
<USER_TASK:>
Description:
 <a href="http
Step1:  Import a square DEM that includes the watershed
Step2:  Run the FlowAccumulator and the DepressionFinderAndRouter components to find depressions, to route the flow across them and to calculate flow direction and drainage area
Step3:  Set the id of the outlet. The value indicated here is the node id of the entire watershed's outlet
Step4:  Run the watershed utility and show the watershed mask
Step5:  Run the flow__distance utility
Step6:  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.
Step7:  Add the flow__distance field to the grid and show the spatial distribution of the distances from each node to the watershed's outlet
<ASSISTANT_TASK:>
Python Code:
from landlab.io import read_esri_ascii
from landlab.components import FlowAccumulator
from landlab.plot import imshow_grid
from matplotlib.pyplot import figure
%matplotlib inline
from landlab.utils import watershed
import numpy as np
from landlab.utils.flow__distance import calculate_flow__distance
Explanation: <a href="http://landlab.github.io"><img style="float: left" src="../../../landlab_header.png"></a>
For more Landlab tutorials, click here: https://landlab.readthedocs.io/en/latest/user_guide/tutorials.html
Application of the flow__distance utility on a Sicilian basin
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.
First, import what we'll need:
End of explanation
(mg, z) = read_esri_ascii("nocella_resampled.txt", name="topographic__elevation")
Explanation: Import a square DEM that includes the watershed:
End of explanation
fr = FlowAccumulator(
    mg, flow_director="D8", depression_finder="DepressionFinderAndRouter"
)
fr.run_one_step()
Explanation: Run the FlowAccumulator and the DepressionFinderAndRouter components to find depressions, to route the flow across them and to calculate flow direction and drainage area:
End of explanation
outlet_id = 15324
Explanation: Set the id of the outlet. The value indicated here is the node id of the entire watershed's outlet:
End of explanation
ws_mask = watershed.get_watershed_mask(mg, outlet_id)
figure()
imshow_grid(mg, ws_mask, allow_colorbar=False)
Explanation: Run the watershed utility and show the watershed mask:
End of explanation
flow__distance = calculate_flow__distance(mg, add_to_grid=True, clobber=True)
Explanation: Run the flow__distance utility:
End of explanation
flow_distance = np.zeros(mg.number_of_nodes)
flow_distance[ws_mask] = flow__distance[ws_mask] - flow__distance[outlet_id]
Explanation: 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.
End of explanation
mg.add_field("flow_distance", flow_distance, at="node", clobber=True)
figure()
imshow_grid(mg, mg.at_node["flow_distance"], colorbar_label="flow distance (m)")
Explanation: Add the flow__distance field to the grid and show the spatial distribution of the distances from each node to the watershed's outlet:
End of explanation
<END_TASK>