In [1]:
import wflow.wflow_bmi as bmi
import logging
reload(bmi)
%pylab inline
import datetime
from IPython.html.widgets import interact
Startup two models:
In [2]:
# This is the LAnd Atmophere (LA) model
LA_model = bmi.wflowbmi_csdms()
LA_model.initialize('../examples/wflow_rhine_sbm/wflow_sbm_bmi.ini',loglevel=logging.ERROR)
# This is the routing (RT) model
RT_model = bmi.wflowbmi_csdms()
RT_model.initialize('../examples/wflow_rhine_sbm/wflow_routing_bmi.ini',loglevel=logging.ERROR)
In [3]:
print(LA_model.get_value("timestepsecs"))
print LA_model.get_start_time()
In [4]:
aa = LA_model.get_attribute_names()
In [5]:
LA_model.get_attribute_value("run:reinit")
Out[5]:
In [6]:
LA_model.set_attribute_value("run:reinit",'1')
LA_model.get_attribute_value("run:reinit")
Out[6]:
In [7]:
imshow(LA_model.get_value("Altitude"))
Out[7]:
In [13]:
# Save the old dem, chnage the dem in the model and set it back
origdem = LA_model.get_value("Altitude")
newdem = origdem * 1.6
LA_model.set_value('Altitude',newdem)
diff = origdem - LA_model.get_value("Altitude")
imshow(diff)
Out[13]:
In [ ]:
imshow(LA_model.get_value("FirstZoneDepth"))
In [ ]:
imshow(LA_model.get_value("River"))
In [ ]:
t_end = RT_model.get_end_time()
t_start = RT_model.get_start_time()
t = RT_model.get_current_time()
(t_end - t_start)/(86400)
In [ ]:
t_end = RT_model.get_end_time()
t = RT_model.get_start_time()
res = []
resq = []
# Loop in time and put output of SBM in seperate routing module - 1way link
while t < t_end:
LA_model.update()
# Now set the output from the LA model (specific Q) as input to the RT model
thevar = LA_model.get_value("InwaterMM")
RT_model.set_value("IW",thevar) # The IW is set in the wflow_routing.ini var as a forcing
RT_model.update()
resq.append(RT_model.get_value("SurfaceRunoff"))
res.append(thevar)
t = RT_model.get_current_time()
print datetime.datetime.fromtimestamp(t)
In [ ]:
LA_model.finalize()
RT_model.finalize()
In [ ]:
def browse_res(digits):
n = len(digits)
def view_image(i):
plt.imshow(log(digits[i]+1))
plt.title('Step: %d' % i)
plt.colorbar()
plt.show()
interact(view_image, i=(0,n-1))
In [ ]:
browse_res(res)
In [ ]:
browse_res(resq)
In [ ]: