Index: wflow-py/notebooks/BMI-Test.ipynb =================================================================== diff -u -r54d5ebe9f713a1e1647a642ca924e17c98523693 -r60deb0d27020da029709d73a4c08b424cfa9d1a6 --- wflow-py/notebooks/BMI-Test.ipynb (.../BMI-Test.ipynb) (revision 54d5ebe9f713a1e1647a642ca924e17c98523693) +++ wflow-py/notebooks/BMI-Test.ipynb (.../BMI-Test.ipynb) (revision 60deb0d27020da029709d73a4c08b424cfa9d1a6) @@ -1,294 +1,311 @@ -{ - "cells": [ - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "

Basic test of the wflow BMI interface" - ] - }, - { - "cell_type": "code", - "execution_count": 3, - "metadata": { - "collapsed": false - }, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "Populating the interactive namespace from numpy and matplotlib\n" - ] - } - ], - "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": 4, - "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": 5, - "metadata": { - "collapsed": false - }, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "86400\n", - "791506800.0\n" - ] - } - ], - "source": [ - "print(LA_model.get_value(\"timestepsecs\"))\n", - "print LA_model.get_start_time()" - ] - }, - { - "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 -} +{ + "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", + "print LA_model.get_start_time()" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "collapsed": false + }, + "outputs": [], + "source": [ + "LA_model.get_attribute_names()" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "collapsed": false + }, + "outputs": [], + "source": [ + "LA_model.get_attribute_value(\"run:reinit\")" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "collapsed": false + }, + "outputs": [], + "source": [ + "LA_model.set_attribute_value(\"run:reinit\",'1')\n", + "LA_model.get_attribute_value(\"run:reinit\")" + ] + }, + { + "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.10" + } + }, + "nbformat": 4, + "nbformat_minor": 0 +}