The wflow Delft-FEWS adapter

wflow_adapt Module


wflow_adapt is an adapter that links wflow to Delft-FEWS ( it is typically run from the Delft-FEWS general adapter.

Linking wflow models to Delft-FEWS

To run the model from Delft-FEWS the following actions need to be performed:

  • The runinfo.xml file should be specified in the [run]section of the ini file

  • The use of netcdf input and output should be switched on

  • The postadapter ( needs to be run after the wflow run

The postadapter also converts the log messages of the model into Delft-FEWS diagnostics XML format.

  • Casenamerunidwflow.log is converted to wflow_diag.xml

  • Also the adapter log files is converted to wflow_adapt_diag.xml

Command line arguments:

An example of executing wflow from the Delft-FEWS general adapter is shown below:

<description>Run wflow</description>
<description>Run wflow post</description>
<command> <executable>bin-wflow\wflow_adapt.exe</executable> </command> <arguments>

The wflow_adapt module can also be used by other programs to convert .tss files to pi-xml vv. Below the API documentation of the module is given.

In the above example the state files belonging to the model should be configed as per below in the General Adapter XML. In Fews the read and write locations are as viewed from the model’s point of view:

# Repeat for all state variables

Module function documentation Simple wflow Delft-FEWS adapter in python. This file can be run as a script from the command-line or be used as a module that provides (limited) functionality for converting PI-XML files to .tss and back.

Usage pre adapter:

wflow_adapt -M Pre -t InputTimeseriesXml -I inifile

Usage postadapter:

wflow_adapt-M Post -t InputTimeseriesXml -s inputStateFile -I inifile

-o outputStateFile -r runinfofile -w workdir -C case [-R runId]


  • Delft-Fews exports data from 0 to timestep. PCraster starts to count at 1. Renaming the files is not desireable. The solution is the add a delay of 1 timestep in the GA run that exports the mapstacks to wflow.

  • Not tested very well.

  • There is a considerable amount of duplication (e.g. info in the runinfo.xml and the .ini file that you need to specify again :-())


rewrite and simplify

$Author: schelle $ $Id: 915 2014-02-10 07:33:56Z schelle $ $Rev: 915 $


Gets the endtime of the run from the FEWS runinfo file


Gets the list of mapstacks fews expect from the runinfo file and create those


Gets the starttime from the FEWS runinfo file

wflow_adapt.getTimeStepsfromRuninfo(xmlfile, timestepsecs)

Gets the number of timesteps from the FEWS runinfo file.

wflow_adapt.log2xml(logfile, xmldiag)

Converts a wflow log file to a Delft-Fews XML diag file


Main entry for using the module as a command line program (e.g. from the Delft-FEWS GA)

wflow_adapt.mapstackxml(mapstackxml, mapstackname, locationname, parametername, Sdate, Edate, timestepsecs)

writes a mapstack xml file

wflow_adapt.pixml_state_updateTime(inxml, outxml, DT)

Reads the pi-state xml file inxml and updates the data/time of the state using datetime. Writes updated file to outxml

  • Can be use in scripts to set the date.time of the output state.xml that Delft-FEWS writes.


This function does not fully parse the xml file and will only work properly

if the xml files date the dateTime element written on one line.

wflow_adapt.pixml_totss(nname, outputdir)

Converts and PI xml timeseries file to a number of tss files.

The tss files are created using the following rules:

  • tss filename determined by the content of the parameter element with a “.tss” postfix

  • files are created in “outputdir”

  • multiple locations will be multiple columns in the tss file written in order of appearance in the XML file

wflow_adapt.pixml_totss_dates(nname, outputdir)

Gets Date/time info from XML file and creates .tss files with:

  • Day of year

  • Hour of day

  • Others may follow

wflow_adapt.setlogger(logfilename, loggername, thelevel=20)

Set-up the logging system and return a logger object. Exit if this fails

wflow_adapt.tss_topixml(tssfile, xmlfile, locationname, parametername, Sdate, timestep)

Converts a .tss file to a PI-xml file