{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "

Basic test of the wflow BMI interface" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false }, "outputs": [], "source": [ "import wflow.wflow_bmi as bmi\n", "import logging\n", "\n", "reload(bmi)\n", "%pylab inline \n", "import datetime\n", "from IPython.html.widgets import interact" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Startup two models:\n", "\n", "+ The wflow_sbm model calculates the runoff from each cell (the LA land-atmosphere model)\n", "+ the wflow_routing model that uses a kinimatic wave for routing the flow (the RT routing model)" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false }, "outputs": [], "source": [ "# This is the LAnd Atmophere (LA) model\n", "LA_model = bmi.wflowbmi_csdms()\n", "LA_model.initialize('../../examples/wflow_rhine_sbm/wflow_sbm.ini',loglevel=logging.ERROR)\n", "\n", "# This is the routing (RT) model\n", "RT_model = bmi.wflowbmi_csdms()\n", "RT_model.initialize('../../examples/wflow_rhine_sbm/wflow_routing.ini',loglevel=logging.ERROR)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "

Now we can investigate some model parameters" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false }, "outputs": [], "source": [ "print(LA_model.get_value(\"timestepsecs\"))\n" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false }, "outputs": [], "source": [ "imshow(LA_model.get_value(\"Altitude\"))" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false }, "outputs": [], "source": [ "imshow(LA_model.get_value(\"Slope\"))" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false }, "outputs": [], "source": [ "imshow(LA_model.get_value(\"FirstZoneDepth\"))" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false }, "outputs": [], "source": [ "a =LA_model.get_value(\"TopoId\")\n", "a[a==-2147483648] = 0\n", "imshow(a)" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false }, "outputs": [], "source": [ "imshow(LA_model.get_value(\"River\"))" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "

Start and end times" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false }, "outputs": [], "source": [ "t_end = RT_model.get_end_time()\n", "t_start = RT_model.get_start_time()\n", "t = RT_model.get_current_time()\n", "\n", "(t_end - t_start)/(86400)\n" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "

Now start the models" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false }, "outputs": [], "source": [ "t_end = RT_model.get_end_time()\n", "t = RT_model.get_start_time()\n", "\n", "res = []\n", "resq = []\n", "\n", "# Loop in time and put output of SBM in seperate routing module - 1way link\n", "while t < t_end:\n", " LA_model.update()\n", " # Now set the output from the LA model (specific Q) as input to the RT model\n", " thevar = LA_model.get_value(\"InwaterMM\")\n", " RT_model.set_value(\"IW\",thevar) # The IW is set in the wflow_routing.ini var as a forcing\n", " RT_model.update()\n", " resq.append(RT_model.get_value(\"SurfaceRunoff\"))\n", " res.append(thevar)\n", " t = RT_model.get_current_time()\n", " \n", " print datetime.datetime.fromtimestamp(t)\n" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false }, "outputs": [], "source": [ "LA_model.finalize()\n", "RT_model.finalize()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "

Define function to view the results" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false }, "outputs": [], "source": [ "def browse_res(digits):\n", " n = len(digits)\n", " def view_image(i):\n", " plt.imshow(log(digits[i]+1))\n", " plt.title('Step: %d' % i)\n", " plt.colorbar()\n", " plt.show()\n", " interact(view_image, i=(0,n-1))" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false }, "outputs": [], "source": [ "browse_res(res)\n" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false }, "outputs": [], "source": [ " browse_res(resq)" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": true }, "outputs": [], "source": [] } ], "metadata": { "kernelspec": { "display_name": "Python 2", "language": "python", "name": "python2" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 2 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython2", "version": "2.7.8" } }, "nbformat": 4, "nbformat_minor": 0 }