wf_DynamicFramework Module¶
wf_DynamicFramework¶
This is a replacement for the standard pcraster/python DynamicFramwork class.It provides extra functionality to simplify linking the models build in the framwork with other models. The provided functionality allows external programs to control and interrogate the model.
Compared to the original pcraster class the usermodel needs to be extended with the stateVariables() method which lists the state variables. Other items to be exchanged most be listed in the API section of the .ini file
In addition, the following methods must also be called at startup:
- createRunId()
$Author: schelle $ $Id: wf_DynamicFramework.py 915 2014-02-10 07:33:56Z schelle $ $Rev: 915 $
- class wf_DynamicFramework.wf_DynamicFramework(userModel, lastTimeStep=0, firstTimestep=1)¶
- createRunId(intbl='intbl', logfname='wflow.log', NoOverWrite=True, model='model', modelVersion='no version', level=10)¶
Create runId dir and copy table files to it Also changes the working dir to the case/runid directory
- iniFileSetUp(caseName, runId, configfile)¶
Reads .ini file and returns a config object.
- Input:
- caseName - dir with case
- runId - run dir within case
- configfile - name of the configfile (.ini type)
- Output:
- python config object
- loggingSetUp(caseName, runId, logfname, model, modelversion, level=20)¶
Sets up the logging system assuming we are in the runId directory
- readtblDefault(pathtotbl, landuse, subcatch, soil, default, cloneMap=None)¶
First check if a prepared maps of the same name is present in the staticmaps directory. next try to read a tbl file to match a landuse, catchment and soil map. Returns the default value if the tbl file is not found.
- Input:
- pathtotbl: full path to table file
- landuse: landuse map
- subcatch: subcatchment map
- soil: soil map
- default: default value
- optional clonemap to check maps against
- Output:
- map constructed from tbl file or map with default value
Todo
Add checking for missing values
- run()¶
Runs the dynamic model for all timesteps
- setQuiet(quiet)¶
- wf_QuickResume()¶
Resumes the state variable of the previous timestep in memory it uses the wf_supplyVariableNamesAndRoles() function to find them. The variables are inserted into the model object
- wf_QuickSuspend()¶
Save the state variable of the current timestep in memory it uses the wf_supplyVariableNamesAndRoles() function to find them. The variables are inserted into the model object This function is normally called as part of the run. Normally there is no need to call it directly.
- wf_multParameterValues(mapname, value)¶
multiply a parameter map with a single scalar value. Current settings for dimensions are assumed.
This method must be called after the runinitial() method
- Input:
- mapname - string with name of map
- value - single scalar
Returns: 1 if the map was present, 0 if nothing was done
- wf_readmap(name, default)¶
Adjusted version of readmapNew. the style variable is used to indicated how the data is read:
1 - default: reads pcrmaps 2 - memory: assumes the map is made available (in memory) using the in-memory interface
- wf_resume(directory)¶
Resumes the state variables from disk as .map files (or arrays of maps files using a _? postfix)
- wf_saveTimeSeries()¶
- wf_savedynMaps()¶
Save the maps defined in the ini file for the dynamic section
Todo
Save maps to be used in memory at startup and do not call the ini file each time
- wf_setParameterValues(mapname, values)¶
set a parameter map with values from a python list or a single scalar value. In case a single value is specified the value will be distributed uniformly over the map. Current settings for dimensions are assumed.
This method must be called _after_ the runinitial() method
- Input:
mapname - string with name of map
- values - single list of value of length rows * cols or a single
scalar
Returns: 1 if the map was present, 0 if nothing was done
- wf_setValue(mapname, value, xcor, ycor)¶
set single value in a map on xcor, ycor (0 based). All other values in the map remain the same.
- Input:
- mapname - string with name of map
- xcor - xcor to set the value in
- ycor - ycor to set the value in
- value - single scalar
Returns: 1 if the map was present, 0 if nothing was done
- wf_setValueLdd(mapname, value, xcor, ycor)¶
set single value in an ldd on xcor, ycor (0 based). All other values in the map remain the same. Calls lddrepair to ensure the ldd is sound
- Input:
mapname of tipy ldd - string with name of map
xcor - xcor to set the value in
ycor - ycor to set the value in
- values - single scalar (see pcraster ldddescription for legal values)
e.g. use 5 for setting a pit
Returns: 1 if the map was present, 0 if nothing was done
- wf_setValueRowCol(mapname, value, row, col)¶
set single value in a map on row, col (0 based). All other values in the map remain the same. Numbering starts at the upper left corner.
- Input:
- mapname - string with name of map
- row - row to set the value in
- col - column to set the value in
- values - single scalar
Returns: 1 if the map was present, 0 if nothing was done
- wf_setValues(mapname, values)¶
set a map with values from a python list or a single scalar value. In case a single value is specified the value will be distributed uniformly over the map. Current settings for dimensions are assumed.
- Input:
mapname - string with name of map
- values - single list of value of length rows * cols or a single
scalar
Returns: 1 if the map was present, 0 if a new map was created
- wf_setValuesAsNumpy(mapname, values)¶
set a map with values from a numpy array. Current settings for dimensions are assumed.
- Input:
- mapname - string with name of map
- values - numpy array
Returns: 1 if the map was present, 0 if a new map was created
- wf_setValuesAsPcrMap(mapname, pcrmap)¶
set a map with values from a pcrmap. Current settings for dimensions are assumed.
- Input:
- mapname - string with name of map
- pcrmap - pcraster map
Returns: 1 if the map was present, 0 if a new map was created
- wf_supplyCurrentTime()¶
gets the current time in seconds after the start of the run Assumed daily timesteps if not defined in the user model
- Output:
- current model time (since start of the run)
Todo
Get timestep info from from config file
- wf_supplyGridDim()¶
return the dimension of the current model grid as list:
[ Xul, Yul, xsize, ysize, rows, cols]
- wf_supplyMapAsList(mapname)¶
Returns a python list for the specified map and the current timestep. If the maps is not dynamic the current status of the map is returned which may be undefined for maps that are filled with data at the end of a run
- Input:
- mapname (string)
- Output:
- list
- wf_supplyMapAsNumpy(mapname)¶
Returns a numpy array (matrix) for the specified map and the current timestep. If the maps is not dynamic the current staus of the map is returns which may be undefined for maps that are filled with data at the end of a run Missing value is -999
- Input:
- mapname (string)
- Output:
- numpy array
- wf_supplyMapAsPcrMap(mapname)¶
Returns a pcrmap for the specified map and the current timestep. If the maps is not dynamic the current staus of the map is returns which may be undefined for maps that are filled with data at the end of a run Missing value is -999
- Input:
- mapname (string)
- Output:
- numpy array
- wf_supplyParameterAsList(mapname)¶
Returns a python list for the specified parameter map and the current timestep. If the maps is not dynamic the current status of the map is returned.
- Input:
- mapname (string)
- Output:
- list
- wf_supplyRowCol(mapname, xcor, ycor)¶
returns a tuple (Row,Col) for the given X and y coordinate
- Input:
- mapname
- xcor
- ycor
- Output:
- tuple with row, col
- wf_supplyScalar(mapname, xcor, ycor)¶
returns a single value for the x and y coordinates from the map given uses getValAtPoint(in_map,xcor,ycor) from terrain_lib.py
- Input:
- mapname
- xcor
- ycor
- Output:
- value at location xcor, ycor
- wf_supplyScalarRowCol(mapname, row, col)¶
returns a single value for row and col from the map given.
- Input:
- mapname
- xcor
- ycor
- Output:
- value at location row, col
- wf_supplyVariableCount()¶
- returns:
- the number of exchangable variables
- wf_supplyVariableNames()¶
- returns:
- the a list of variable names
- wf_supplyVariableNamesAndRoles()¶
Returns a list of variables List of list with the following structure:
[[ name, role, unit] [ name, role, unit] ... ] role: 0 = input (to the model) 1 = is output (from the model) 2 = input/output (state information) 3 = model parameter unit: 0 = mm/timestep 1 = m^3/sec 2 = m 3 = degree Celcius 4 = mm 5 = -The first time this function is called the exchangeitems object is filled with data from the ini file.
- wf_supplyVariableRoles()¶
- returns:
- the a list of variable roles
- wf_supplyVariableUnits()¶
- returns:
- the a list of variable units
- wf_suspend(directory)¶
Suspend the state variables to disk as .map files