A number of settings of the framework can be set in the ini file for each model. The settings are explained din the section below.
Information for the current run can be given in the run section. Here the start and end-time of the run as well as the timestep can be given. Alternatively a link to a Delft-FEWS runinfo.xml file can be given. An example is shown below.
[run]
# either a runinfo file or a start and end-time are required
#runinfofile=runinfo.xml
starttime= 1995-01-31 00:00:00
endtime= 1995-02-28 00:00:00
# required, base timestep of the model
timestepsecs = 86400
The in/output file formats can be specified in the framework section. At present only pcraster mapstacks and netcdf are available fot input. See the supplied pcr2netcdf.py script for information on the layout of the netcdf files. If netcdf files are used the name of the mapstack is used as the standardname in the netcdf file.
[framework]
# outputformat for the *dynamic* mapstacks (not the states and summary maps)
# 1: pcraster
# 2: numpy
# 3: matlab
outputformat=1
# netcdfoutput requires also outputformat = 1 (default) and additionally the name of the file
netcdfoutput = outmaps.nc
netcdfwritebuffer=100
netcdfinput= inmaps.nc
# Provide a lot of debug info
# debug=1
In the ini file example below several variables are configured to be available via the API. For most settings this only defines what the API will expose to the outside world. However, if you specify 0 (input) as a role for one of the forcing variables the wf_readmap function will no longer read maps from disk for that variable but will return the contents of that variable via the API.
The API section specifies variables that are exposed via the api. Use the following convention:
variable_name_in_model=variable_role,variable_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 = -
Use role 0 for input maps to the model (those that are normally read from disk), role 1 for outputs, role 2 for state variables and role3 for model parameters.
example:
[API]
FreeWater=2,4
SoilMoisture=2,4
UpperZoneStorage=2,4
LowerZoneStorage=2,4
InterceptionStorage=2,4
SurfaceRunoff=2,1
WaterLevel=2,2
DrySnow=2,4
Percolation=1,0
ForecQ_qmec=0,1
PERC=3,5
FC=3,4
# Below are the forcing variables. By putting these here you MUST
# supply them via the API, if not these will default to 0.0
#P=0,0
PET=0,0
TEMP=0,3
Most of the time this section is not needed as this will mostly be configured in the python code by the model developer. However, in some case this section can be used alter the modell for example force the model to read RootingDepth from an external data source.
The format of entries in this section is as follows:
name=stack,type,default
# example:
# RootingDepth=monthlyclim/ROOT,monthyclim,100,1
name - Name of the parameter (internal variable, without the self.)
stack - Name of the mapstack (representation on disk or in mem) relative to case
type - Type of parameter (default = static)
default - Default value if map/tbl is not present
instead of a map
Possible parameter types (the second option)are:
Example:
[modelparameters]
RootingDepth=monthlyclim/ROOTS,monthlyclim,75,0
# Force the model to read monthly climatology of P
Precipitation=inmaps/P,monthlyclim,0.0,1
By adding variable in one or several of these sectiosn the framework will save these variables to disk (using the value at the end, sum, min, max or avg) at the end of a run.
the available sections are:
All maps are saved in the outsum directory of the current runid.
Example:
[summary]
self.MaxLeakage=MaxLeakage.map
# Save and average these per LU type
[summary_sum]
self.Precipitation=Sumprecip.map
[summary_max]
self.Precipitation=maxprecip.map
[summary_min]
self.Temperature=mintemp.map
[summary_avg]
self.Precipitation=avgprecip.map
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$ $Id$ $Rev$
Create runId dir and copy table files to it Also changes the working dir to the case/runid directory
Reads .ini file and returns a config object.
Sets up the logging system assuming we are in the runId directory
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.
Finally check of a tbl file exists with a .mult postfix (e.g. Cmax.tbl.mult) and apply the multiplication to the loaded data.
Todo
Add checking for missing values
Runs the dynamic model for all timesteps
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
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.
multiply a parameter map with a single scalar value. Current settings for dimensions are assumed.
This method must be called after the runinitial() method
| Returns: | 1 if the map was present, 0 if nothing was done |
|---|
multiply a parameter map with a single scalar value for area with id area only. Current settings for dimensions are assumed.
This method must be called after the runinitial() method
| Returns: | 1 if the map was present, 0 if nothing was done |
|---|
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
Read a climatology map. The current date/time is converted to: 1: a month and the file for the current month is returned 2: days of year and the file for the current day is returned 3: hour of day and the file for the current hours is returned
| Parameters: |
|
|---|---|
| Returns: | a map |
Resumes the state variables from disk as .map files (or arrays of maps files using a _? postfix)
Print .ini defined output csv/tss timeseries per timestep
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
Saves the maps defined in the summary section to disk [summary] # Single values or end values [summary_sum] # accumulative maps over the model run [summary_avg] # average of maps over the model run [summary_max] # max of maps over the model run [summary_min] # min of maps over the model run
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
mapname - string with name of map
scalar
| Returns: | 1 if the map was present, 0 if nothing was done |
|---|
set single value in a map on xcor, ycor (0 based). All other values in the map remain the same.
| Returns: | 1 if the map was present, 0 if nothing was done |
|---|
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
mapname of tipy ldd - string with name of map
xcor - xcor to set the value in
ycor - ycor to set the value in
e.g. use 5 for setting a pit
| Returns: | 1 if the map was present, 0 if nothing was done |
|---|
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.
| Returns: | 1 if the map was present, 0 if nothing was done |
|---|
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.
mapname - string with name of map
scalar
| Returns: | 1 if the map was present, 0 if a new map was created |
|---|
set a map with values from a numpy array. Current settings for dimensions are assumed.
| Returns: | 1 if the map was present, 0 if a new map was created |
|---|
set a map with values from a pcrmap. Current settings for dimensions are assumed.
| Returns: | 1 if the map was present, 0 if a new map was created |
|---|
gets the current time in seconds after the start of the run Assumed daily timesteps if not defined in the user model
gets the end time of the model run :return: current time as seconds since epoch
Supplies the time epoch as a CF string Output:
- current model time (since start of the run)
return the dimension of the current model grid as list:
[ Xul, Yul, xsize, ysize, rows, cols]
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
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
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
| Returns: | lower left corner of the map as X, Y |
|---|
| Return x-coordinates of the current clone map: | |
|---|---|
Missing value is -999
| Return y-coordinates of the current clone map: | |
|---|---|
Missing value is -999
| Return z-coordinates of the current clone map: | |
|---|---|
Assumes an Altitude map is present, otherwise return empty numpy Missing value is -999
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.
returns a tuple (Row,Col) for the given X and y coordinate
returns a single value for the x and y coordinates from the map given uses getValAtPoint(in_map,xcor,ycor) from terrain_lib.py
returns a single value for row and col from the map given (zero based).
gets the start time of the model run :return: current time as seconds since epoch
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.
Suspend the state variables to disk as .map files Also saves the summary maps
Update the model Parameters (can be used in static and dynamic part of the model)
It does this by looking at the parameters listed in [parameters] section in the ini file and those defined in the parameters() function in the actual model (defined by the model developer).
| Return nothing: |
|---|