{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "\n", "*This notebook contains material from [Controlling Natural Watersheds](https://jckantor.github.io/Controlling-Natural-Watersheds);\n", "content is available [on Github](https://github.com/jckantor/Controlling-Natural-Watersheds.git).*" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "\n", "< [Implementation of Rainy Lake Rule Curves with Feedback Control](http://nbviewer.jupyter.org/github/jckantor/Controlling-Natural-Watersheds/blob/master/notebooks/05.02-Implementation_of_Rainy_Lake_Rule_Curves_with_Feedback_Control.ipynb) | [Contents](toc.ipynb) | [Adaptive Managment](http://nbviewer.jupyter.org/github/jckantor/Controlling-Natural-Watersheds/blob/master/notebooks/06.00-Adaptive_Management.ipynb) >
" ] }, { "cell_type": "markdown", "metadata": { "deletable": true, "editable": true }, "source": [ "# Model Predictive Control" ] }, { "cell_type": "markdown", "metadata": { "deletable": true, "editable": true }, "source": [ "## Initialization" ] }, { "cell_type": "code", "execution_count": 1, "metadata": { "collapsed": false, "deletable": true, "editable": true }, "outputs": [], "source": [ "# Display graphics inline with the notebook\n", "%matplotlib inline\n", "\n", "# Standard Python modules\n", "import numpy as np\n", "import matplotlib.pyplot as plt\n", "import matplotlib.dates as mdates\n", "import seaborn as sns\n", "import pandas as pd\n", "import os\n", "import datetime\n", "import scipy.stats as stats\n", "import pickle\n", "\n", "# Modules to display images and data tables\n", "from IPython.display import Image\n", "from IPython.core.display import display\n", "\n", "# graphics context\n", "sns.set_context(\"poster\")" ] }, { "cell_type": "markdown", "metadata": { "deletable": true, "editable": true }, "source": [ "## Load Data Sources" ] }, { "cell_type": "code", "execution_count": 2, "metadata": { "collapsed": false, "deletable": true, "editable": true }, "outputs": [], "source": [ "dir = '../data/'\n", "\n", "# Rainy River Flowrate, units of cubic meters per second\n", "RR = pd.read_pickle(dir+'RR.pkl')\n", "\n", "# Rainy Lake Level, units of meters\n", "RL = pd.read_pickle(dir+'RL.pkl')\n", "\n", "# Stage-Area function for Rainy Lake, units of ?\n", "area = pd.read_pickle(dir+'area.pkl')['Rainy Lake']\n", "\n", "# Stage-Volume function for Rainy Lake, units of millions of cubic meters\n", "volume = pd.read_pickle(dir+'volume.pkl')['Rainy Lake']\n", "\n", "# Rule Curves for Rainy Lake, units of meters\n", "RL2000 = pd.read_pickle(dir+'RL2000.pkl')\n", "RL1970 = pd.read_pickle(dir+'RL1970.pkl')\n", "\n", "# Discharge Relationship (Thompson, 2014), units of meters\n", "Qdata = pd.DataFrame([\n", " [335.40, 0.0],\n", " [336.00, 399.0],\n", " [336.50, 425.0],\n", " [336.75, 443.0],\n", " [337.00, 589.0],\n", " [337.25, 704.0],\n", " [337.50, 792.0],\n", " [337.75, 909.0],\n", " [338.00, 1014.0],\n", " [338.50, 1156.0],\n", " [339.00, 1324.0],\n", " [339.50, 1550.0],\n", " [340.00, 1778.0]\n", "])\n", "\n", "# Create a function to compute maximum discharge as function of lake elevation\n", "from scipy.interpolate import interp1d\n", "Qmax = interp1d(Qdata[0].map(volume),Qdata[1]*86400/1000000)\n", "\n", "\n", "#RL2000['DOY'] = RL2000.index.dayofyear" ] }, { "cell_type": "code", "execution_count": 3, "metadata": { "collapsed": false, "deletable": true, "editable": true }, "outputs": [ { "data": { "text/html": [ "
\n", " | ELW | \n", "LRC | \n", "URC | \n", "EDL | \n", "EHW | \n", "AGO | \n", "
---|---|---|---|---|---|---|
2014-12-27 | \n", "336.68 | \n", "337.213333 | \n", "337.470 | \n", "336.917647 | \n", "337.75 | \n", "337.9 | \n", "
2014-12-28 | \n", "336.68 | \n", "337.210000 | \n", "337.465 | \n", "336.913235 | \n", "337.75 | \n", "337.9 | \n", "
2014-12-29 | \n", "336.68 | \n", "337.206667 | \n", "337.460 | \n", "336.908824 | \n", "337.75 | \n", "337.9 | \n", "
2014-12-30 | \n", "336.68 | \n", "337.203333 | \n", "337.455 | \n", "336.904412 | \n", "337.75 | \n", "337.9 | \n", "
2014-12-31 | \n", "336.68 | \n", "337.200000 | \n", "337.450 | \n", "336.900000 | \n", "337.75 | \n", "337.9 | \n", "
" ] } ], "metadata": { "anaconda-cloud": {}, "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 }