<SYSTEM_TASK:>
Given the following text description, write Python code to implement the functionality described below step by step
<END_TASK>
<USER_TASK:>
Description:
 Use of the wflow OpenStreams framework API
This ipython notebook demonstrates how to load an openstreams python model and execute it step-by-step and investigate the (intermediate) results. The first steps is to load the model and framework
Step1:  Set model run-time parameters
Set the
Step2:  Investigate a couple of model variables
Step3:  Run for a number of timesteps
<ASSISTANT_TASK:>
Python Code:
# First import the model. Here we use the HBV version
%pylab inline 
from wflow.wflow_hbv import *
import IPython
from IPython.display import display, clear_output
#clear_output = IPython.core.display.clear_output
Explanation: Use of the wflow OpenStreams framework API
This ipython notebook demonstrates how to load an openstreams python model and execute it step-by-step and investigate the (intermediate) results. The first steps is to load the model and framework:
End of explanation
# define start and stop time of the run
startTime = 1
stopTime = 200
currentTime = 1
     
# set runid, cl;onemap and casename. Also define the ini file
runId = "memtest"
#configfile="wflow_hbv_mem.ini"
configfile="wflow_hbv.ini"
wflow_cloneMap = 'wflow_subcatch.map' 
# the casename points to the complete model setup with both static and dynamic input
caseName="../examples/wflow_rhine_hbv"
#make a usermodel object     
myModel = WflowModel(wflow_cloneMap, caseName,runId,configfile)
# initialise the framework
dynModelFw = wf_DynamicFramework(myModel, stopTime,startTime)
dynModelFw.createRunId(NoOverWrite=False,level=logging.ERROR)
dynModelFw.setQuiet(1)
# Run the initial part of the model (reads parameters and sets initial values)
dynModelFw._runInitial() # Runs initial part
dynModelFw._runResume() # gets the state variables from disk
# Get list of variables supplied by the model
print dynModelFw.wf_supplyVariableNamesAndRoles()
Explanation: Set model run-time parameters
Set the:
start and time time
set the runid (this is where the results are stored, relative to the casename)
set the name of the configfile (stire in the case directory
set the clone mape (usually the wflow_subcatch.map)
set the casename. This is where all the model the model resides
End of explanation
#
sm = dynModelFw.wf_supplyMapAsNumpy("SoilMoisture")
sm[sm == -999] = np.nan
uz = dynModelFw.wf_supplyMapAsNumpy("UpperZoneStorage")
uz[uz == -999] = np.nan
lz = dynModelFw.wf_supplyMapAsNumpy("LowerZoneStorage")
lz[lz == -999] = np.nan
imshow(sm)
title("Soilmoisture")
colorbar()
imshow(uz)
title("UpperZoneStorage")
colorbar()
imshow(lz)
title("LowerZoneStorage")
colorbar()
dynModelFw.wf_setValueLdd("TopoLdd",5.0,6.46823,51.6821)
npmap0 = dynModelFw.wf_supplyMapAsNumpy("TopoLdd")
ltt = dynModelFw.wf_supplyMapAsList("SurfaceRunoff")
Explanation: Investigate a couple of model variables
End of explanation
f, ax = plt.subplots(1,3,figsize=(16, 6))
plotar = []
for ts in range(20,80):
         # Get value at pit
      
        inflowQ = dynModelFw.wf_supplyScalar("SurfaceRunoff",6.46823,51.6821)
        plotar.append(inflowQ)
        
        dynModelFw.wf_setValues("PET",scalar(2.0))
        
        dynModelFw._runDynamic(ts,ts) # runs for all timesteps
        npmap1 = dynModelFw.wf_supplyMapAsNumpy("P")
        run = dynModelFw.wf_supplyMapAsNumpy("SurfaceRunoff")
        uz = dynModelFw.wf_supplyMapAsNumpy("UpperZoneStorage")
        sm = dynModelFw.wf_supplyMapAsNumpy("SoilMoisture")
        
        sm[sm == -999] = np.nan
        #dynModelFw.wf_setValues("UpperZoneStorage",uz * 10.1)
        uz[uz == -999] = np.nan
        run[run == -999] = np.nan
        ax[0].imshow(uz)
        ax[1].imshow(sm)
        #ax[2].imshow(log(run))
        ax[2].plot(plotar,'b')
        ax[2].set_title(str(ts))
        clear_output()
        display(f)
        
plt.close()
dynModelFw._runSuspend() # saves the state variables
dynModelFw._wf_shutdown()
run = dynModelFw.wf_supplyMapAsNumpy("SurfaceRunoff")
run[run == -999] = np.nan
imshow(log(run))
Explanation: Run for a number of timesteps
End of explanation
<END_TASK>