Table Of Contents

Previous topic

Using the framework

Next topic

Questions and answers

This Page

Using the .ini file

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.

Settings in the run section

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

Settings in the framework section

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

Settings in the API section

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

Settings in the modelparameters section

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

  • verbose - If set to 1 (True) the maps a log log message will be generated is a default values is used

    instead of a map

Possible parameter types (the second option)are:

  • staticmap: Read at startup from map
  • statictbl: Read at startup from tbl, fallback to map (need Landuse, Soil and TopoId (subcatch) maps)!
  • timeseries: read map for each timestep
  • monthlyclim: read a map corresponding to the current month (12 maps in total)
  • dailyclim: read a map corresponding to the current day of the year (366 maps in total)
  • hourlyclim: read a map corresponding to the current hour of the day (24 maps in total)

Example:

[modelparameters]
RootingDepth=monthlyclim/ROOTS,monthlyclim,75,0
# Force the model to read monthly climatology of P
Precipitation=inmaps/P,monthlyclim,0.0,1

Settings in the summary_* sections

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:

  • summary - Saves the actual value of the variable
  • summary_avg - Saves the average value over all timesteps of the variable
  • summary_sum - Saves the sum over all timesteps of the variable
  • summary_min - Saves the minimum value over all timesteps of the variable
  • summary_max - Saves the maximum value over all timesteps of the variable

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

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$ $Id$ $Rev$

class wf_DynamicFramework.wf_DynamicFramework(userModel, lastTimeStep=0, firstTimestep=1, datetimestart=datetime.datetime(1990, 1, 1, 0, 0), timestepsecs=86400)
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.

Finally check of a tbl file exists with a .mult postfix (e.g. Cmax.tbl.mult) and apply the multiplication to the loaded data.

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_multParameterValuesArea(mapname, value, areacode, areamapname)

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

Input:
  • mapname - string with name of map
  • value - single scalar
  • areacode - id of the area in the areamap
  • areamapname - name of the areamap
Returns:1 if the map was present, 0 if nothing was done
wf_readmap(name, default, verbose=True, filetype='PCRaster')

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_readmapClimatology(name, kind=1, default=0.0, verbose=1)

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:
  • name – name if the mapstack
  • kind – type of the climatology
Returns:

a map

wf_resume(directory)

Resumes the state variables from disk as .map files (or arrays of maps files using a _? postfix)

wf_saveTimeSeries()

Print .ini defined output csv/tss timeseries per timestep

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_savesummarymaps()

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

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)
wf_supplyEndTime()

gets the end time of the model run :return: current time as seconds since epoch

wf_supplyEpoch()

Supplies the time epoch as a CF string Output:

  • current model time (since start of the run)
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_supplyMapOrigin()
Returns:lower left corner of the map as X, Y
wf_supplyMapXAsNumpy()
Return x-coordinates of the current clone map:
 

Missing value is -999

wf_supplyMapYAsNumpy()
Return y-coordinates of the current clone map:
 

Missing value is -999

wf_supplyMapZAsNumpy()
Return z-coordinates of the current clone map:
 

Assumes an Altitude map is present, otherwise return empty numpy Missing value is -999

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 (zero based).

Input:
  • mapname
  • xcor
  • ycor
Output:
  • value at location row, col
wf_supplyStartTime()

gets the start time of the model run :return: current time as seconds since epoch

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 Also saves the summary maps

wf_updateparameters()

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: