Basic test of the wflow BMI interface"
]
},
{
"cell_type": "code",
"execution_count": 1,
"metadata": {
"collapsed": false
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Populating the interactive namespace from numpy and matplotlib\n"
]
},
{
"name": "stderr",
"output_type": "stream",
"text": [
"C:\\Anaconda\\lib\\site-packages\\IPython\\html.py:14: ShimWarning: The `IPython.html` package has been deprecated. You should import from `notebook` instead. `IPython.html.widgets` has moved to `ipywidgets`.\n",
" \"`IPython.html.widgets` has moved to `ipywidgets`.\", ShimWarning)\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": 2,
"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_bmi.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_bmi.ini',loglevel=logging.ERROR)"
]
},
{
"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": [
"