{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# HydroTrend\n", "\n", "* Link to this notebook: https://github.com/csdms/pymt/blob/master/notebooks/hydrotrend.ipynb\n", "* Package installation command: `$ conda install notebook pymt_hydrotrend`\n", "* Command to download a local copy:\n", "\n", " `$ curl -O https://raw.githubusercontent.com/csdms/pymt/master/notebooks/hydrotrend.ipynb`\n", " \n", "HydroTrend is a 2D hydrological water balance and transport model that simulates water discharge and sediment load at a river outlet. You can read more about the model, find references or download the C source code at: https://csdms.colorado.edu/wiki/Model:HydroTrend.\n", "\n", "This notebook has been created by Irina Overeem, September 18, 2019.\n", "\n", "\n", "### River Sediment Supply Modeling\n", "\n", "This notebook is meant to give you a better understanding of what HydroTrend is capable of. In this example we are using a theoretical river basin of ~1990 km2, with 1200m of relief and a river length of\n", "~100 km. All parameters that are shown by default once the HydroTrend Model is loaded are based\n", "on a present-day, temperate climate. Whereas these runs are not meant to be specific, we are\n", "using parameters that are realistic for the [Waiapaoa River][map_of_waiapaoa] in New Zealand. The Waiapaoa River\n", "is located on North Island and receives high rain and has erodible soils, so the river sediment\n", "loads are exceptionally high. It has been called the *\"dirtiest small river in the world\"*.\n", "\n", "\n", "A more detailed description of applying HydroTrend to the Waipaoa basin, New Zealand has been published in WRR: [hydrotrend_waipaoa_paper]. \n", "\n", "\n", "[map_of_waiapaoa]: https://www.google.com/maps/place/Waipaoa+River/@-38.5099042,177.7668002,71814m/data=!3m1!1e3!4m5!3m4!1s0x6d65def908624859:0x2a00ef6165e1dfa0!8m2!3d-38.5392405!4d177.8843782\n", "[hydrotrend_presentation]: https://csdms.colorado.edu/wiki/File:SedimentSupplyModeling02_2013.ppt\n", "[hydrotrend_waipaoa_paper]: http://dx.doi.org/10.1029/2006WR005570" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Run HydroTrend Simulations with pymt\n", "\n" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Now we will be using the capability of the Python Modeling Tool, pymt. Pymt is a Python toolkit for running and coupling Earth surface models. \n", "\n", "https://csdms.colorado.edu/wiki/PyMT\n" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "# To start, import numpy and matplotlib.\n", "import matplotlib.pyplot as plt\n", "import numpy as np" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "# Then we import the package\n", "import pymt.models\n", "\n", "hydrotrend = pymt.models.Hydrotrend()" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "import pymt\n", "\n", "pymt.__version__" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Learn about the Model Input\n", "
\n", "HydroTrend will now be activated in PyMT. You can find information on the model, the developer, the papers that describe the moel in more detail etc. \n", "Importantly you can scroll down a bit to the Parameters list, it shows what parameters the model uses to control the simulations. The list is alphabetical and uses precisely specified 'Standard Names'.\n", "Note that every parameter has a 'default' value, so that when you do not list it in the configure command, you will run with these values.\n" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "# Get basic information about the HydroTrend model\n", "help(hydrotrend)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Exercise 1: Explore the Hydrotrend base-case river simulation\n", "\n", "For this case study, first we will create a subdirectory in which the basecase (BC) simulation will be implemented. \n", "\n", "Then we specify for how long we will run a simulation: for 100 years at daily time-step.\n", "This means you run Hydrotrend for 36,500 days total. \n", "This is also the line of code where you would add other input parameters with their values." ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "# Set up Hydrotrend model by indicating the number of years to run\n", "config_file, config_folder = hydrotrend.setup(\"_hydrotrendBC\", run_duration=100)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "With the cat command you can print character by character one of the two input files that HydroTrend uses.\n", "HYDRO0.HYPS: This first file specifies the River Basin Hysometry - the surface area per elevation zone. The hypsometry captures the geometric characteristics of the river basin, how high is the relief, how much uplands are there versus lowlands, where would the snow fall elevation line be etcetera.
\n", "HYDRO.IN: This other file specifies the basin and climate input data. " ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "cat _hydrotrendBC/HYDRO0.HYPS" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "cat _hydrotrendBC/HYDRO.IN" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "# In pymt one can always find out what output a model generates by using the .output_var_names method.\n", "hydrotrend.output_var_names" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "# Now we initialize the model with the configure file and in the configure folder\n", "hydrotrend.initialize(config_file, config_folder)" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "# this line of code lists time parameters, when, how long and at what timestep will the model simulation work?\n", "hydrotrend.start_time, hydrotrend.time, hydrotrend.end_time, hydrotrend.time_step, hydrotrend.time_units" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "# this code declares numpy arrays for several important parameters we want to save.\n", "n_days = int(hydrotrend.end_time)\n", "q = np.empty(n_days) # river discharge at the outlet\n", "qs = np.empty(n_days) # sediment load at the outlet\n", "cs = np.empty(\n", " n_days\n", ") # suspended sediment concentration for different grainsize classes at the outlet\n", "qb = np.empty(n_days) # bedload at the outlet\n", "\n", "# here we have coded up the time loop using i as the index\n", "# we update the model with one timestep at the time, untill we reach the end time\n", "# for each time step we also get the values for the output parameters we wish to\n", "for i in range(n_days):\n", " hydrotrend.update()\n", " q[i] = hydrotrend.get_value(\"channel_exit_water__volume_flow_rate\")\n", " qs[i] = hydrotrend.get_value(\n", " \"channel_exit_water_sediment~suspended__mass_flow_rate\"\n", " )\n", " cs[i] = hydrotrend.get_value(\n", " \"channel_exit_water_sediment~suspended__mass_concentration\"\n", " )\n", " qb[i] = hydrotrend.get_value(\"channel_exit_water_sediment~bedload__mass_flow_rate\")" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "# We can plot the simulated output timeseries of Hydrotrend, for example the river discharge\n", "\n", "plt.plot(q)\n", "plt.title(\"HydroTrend simulation of 100 year river discharge, Waiapaoa River\")\n", "plt.ylabel(\"river discharge in m3/sec\")\n", "plt.show" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "# Or you can plot a subset of the simulated daily timeseries using the index\n", "\n", "# for example the first year\n", "plt.plot(q[0:365], \"black\")\n", "# compare with the last year\n", "plt.plot(q[-366:-1], \"grey\")\n", "plt.title(\"HydroTrend simulation of first and last year discharge, Waiapaoa River\")\n", "plt.show()" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "# Of course, it is important to calculate statistical properties of the simulated parameters\n", "\n", "print(q.mean())\n", "hydrotrend.get_var_units(\"channel_exit_water__volume_flow_rate\")" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ " ## Assignment 1 \n", "\n", "Calculate mean water discharge Q, mean suspended load Qs, mean sediment concentration Cs, and mean bedload Qb for this 100 year simulation of the river dynamics of the Waiapaoa River.\n", "Note all values are reported as daily averages. What are the units?\n" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "# your code goes here" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Assignment 2 \n", "\n", "Identify the highest flood event for this simulation. Is this the 100-year flood? Please list a definition of a 100 year flood, and discuss whether the modeled extreme event fits this definition. \n", "Plot the year of Q-data which includes the flood.\n" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "# here you can calculate the maximum river discharge." ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "# your code to determine which day and which year encompass the maximum discharge go here\n", "# Hint: you will want to determine the ndex of htis day first, look into the numpy.argmax and numpy.argmin\n", "\n", "# as a sanity check you can see whether the plot y-axis seems to go up to the maximum you had calculated in the previous step\n", "# as a sanity check you can look in the plot of all the years to see whether the timing your code predicts is correct" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "# type your explanation about the 100 year flood here." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Assignment 3 \n", "\n", "Calculate the mean annual sediment load for this river system.\n", "\n", "Then compare the annual load of the Waiapaoha river to the Mississippi River.
\n", "To compare the mean annual load to other river systems you will need to calculate its sediment yield. \n", "Sediment Yield is defined as sediment load normalized for the river drainage area; \n", "so it can be reported in T/km2/yr.\n", "\n" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "# your code goes here\n", "# you will have to sum all days of the individual years, to get the annual loads, then calculate the mean over the 100 years.\n", "# one possible trick is to use the .reshape() method\n", "# plot a graph of the 100 years timeseries of the total annual loads" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "# take the mean over the 100 years" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "# your evaluation of the sediment load of the Waiapaoha River and its comparison to the Mississippi River goes here.\n", "# Hint: use the following paper to read about the Mississippi sediment load (Blum, M, Roberts, H., 2009. Drowning of the Mississippi Delta due to insufficient sediment supply and global sea-level rise, Nature Geoscience)." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### HydroTrend Exercise 2: How does a river system respond to climate change; two simple scenarios for the coming century.\n", "\n", "Now we will look at changing climatic conditions in a small river basin. We'll change temperature and precipitation regimes and compare discharge and sediment load characteristics to the original basecase. And we will look at the are potential implications of changes in the peak events.\n", "\n", "Modify the mean annual temperature T, the mean annual precipitation P. You can specify trends over time, by modifying the parameter ‘change in mean annual temperature’ or ‘change in mean annual precipitation’. HydroTrend runs at daily timestep, and thus can deal with seasonal variations in temperature and precipitation for a basin. The model ingests monthly mean input values for these two climate parameters and their monthly standard deviations, ideally the values would be derived from analysis of a longterm record of daily climate data. You can adapt seasonal trends by using the monthly values." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Assignment 4 \n", "What happens to river discharge, suspended load and bedload if the mean annual temperature in this specific river basin increases by 4 °C over the next 50 years? In this assignment we set up a new simulation for a warming climate." ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "# Set up a new run of the Hydrotrend model\n", "# Create a new config file a different folder for input and output files, indicating the number of years to run, and specify the change in mean annual temparture parameter\n", "hydrotrendHT = pymt.models.Hydrotrend()\n", "config_file, config_folder = hydrotrendHT.setup(\n", " \"_hydrotrendhighT\", run_duration=50, change_in_mean_annual_temperature=0.08\n", ")" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "# intialize the new simulation\n", "hydrotrendHT.initialize(config_file, config_folder)" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "# the code for the timeloop goes here\n", "# I use the abbrevation HT for 'High Temperature' scenario\n", "n_days = int(hydrotrendHT.end_time)\n", "q_HT = np.empty(n_days) # river discharge at the outlet\n", "qs_HT = np.empty(n_days) # sediment load at the outlet\n", "cs_HT = np.empty(\n", " n_days\n", ") # suspended sediment concentration for different grainsize classes at the outlet\n", "qb_HT = np.empty(n_days) # bedload at the outlet\n", "for i in range(n_days):\n", " hydrotrendHT.update()\n", " q_HT[i] = hydrotrendHT.get_value(\"channel_exit_water__volume_flow_rate\")\n", " qs_HT[i] = hydrotrendHT.get_value(\n", " \"channel_exit_water_sediment~suspended__mass_flow_rate\"\n", " )\n", " cs_HT[i] = hydrotrendHT.get_value(\n", " \"channel_exit_water_sediment~suspended__mass_concentration\"\n", " )\n", " qb_HT[i] = hydrotrendHT.get_value(\n", " \"channel_exit_water_sediment~bedload__mass_flow_rate\"\n", " )" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "# your code that prints out the mean river discharge, the mean sediment load and the mean bedload goes here\n", "\n", "\n", "# print out these same parameters for the basecase for comparison" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Assignment 5 \n", "\n", "So what is the effect of a warming basin temperature? \n", "How much increase or decrease of river discharge do you see after 50 years?
\n", "How is the mean suspended load affected?
\n", "How does the mean bedload change?
\n", "What happens to the peak event; look at the maximum sediment load event of the last 5 years of the simulation?" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "# type your answers here" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Assignment 6 \n", "What happens to river discharge, suspended load and bedload if the mean annual precipitation would increase by 50% in this specific river basin over the next 50 years? Create a new simulation folder, High Precipitation, HP, and set up a run with a trend in future precipitation. " ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "# Set up a new run of the Hydrotrend model\n", "# Create a new config file indicating the number of years to run, and specify the change in mean annual precipitation parameter" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "# initialize the new simulation" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "# your code for the timeloop goes here" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "# your code that prints out the mean river discharge, the mean sediment load and the mean bedload goes here" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Assignment 7 \n", "\n", "In addition, climate model predictions indicate that perhaps precipitation intensity and variability could increase. How would you possibly model this? Discuss how you would modify your input settings for precipitation.\n", "\n" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "# type your answer here" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Exercise 3: How do humans affect river sediment loads?\n", "\n", "Here we will look at the effect of human in a river basin. Humans can accelerate erosion\n", "processes, or reduce the sediment loads traveling through a river system. Both concepts can\n", "be simulated, first run 3 simulations systematically increasing the anthropogenic factor (0.5-8.0 is the range)." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Assignment 8 \n", "Describe in your own words the meaning of the human-induced erosion factor, (Eh). This factor is parametrized as the “Antropogenic” factor in HydroTrend. Read more about this in: Syvitski & Milliman, 2007, Geology, Geography, and Humans Battle for Dominance over the Delivery of Fluvial Sediment to the Coastal Ocean. 2007, 115, p. 1–19. " ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "# your explanation goes here, can you list two reasons why this factor would be unsuitable or it would fall short?" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Bonus Assignment 9 \n", "Model a scenario of a drinking water supply reservoir to be planned in the coastal area of the basin. The reservoir would have 800 km 2of contributing drainage area and be 3 km long, 200m wide and 100m deep. Set up a simulation with these parameters." ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "# Set up a new 50 year of the Hydrotrend model\n", "# Create a new directory, and a config file indicating the number of years to run, and specify different reservoir parameters" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "# initialize the new simulation" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "# your code for the timeloop and update loop goes here" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "# plot a bar graph comparing Q mean, Qs mean, Qmax, Qs Max, Qb mean and Qbmax for the basecase run and the reservoir run" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "# Describe how such a reservoir affects the water and sediment load at the coast (i.e. downstream of the reservoir)?" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Bonus Assignment 10 \n", "Set up a simulation for a different river basin. \n", "This means you would need to change the HYDRO0.HYPS file and change some climatic parameters. \n", "There are several hypsometric files packaged with HydroTrend, you can use one of those, but are welcome to do something different!" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "# write a short motivation and description of your scenario" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "# make a 2 panel plot using the subplot functionality of matplotlib\n", "# One panel would show the hypsometry of the Waiapohoa and the other panel the hypsometry of your selected river basin" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "# Set up a new 50 year of the Hydrotrend model\n", "# Create a new directory for this different basin" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "# initialize the new simulation" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "# your code for the timeloop and update loop goes here" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "# plot a line graph comparing Q mean, Qs mean, for the basecase run and the new river basin run" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## ALL DONE! " ] } ], "metadata": { "kernelspec": { "display_name": "Python 3 (ipykernel)", "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.9.12" } }, "nbformat": 4, "nbformat_minor": 2 }