Table Of Contents

Previous topic

The wflow_floodmap model

Next topic

Building a model

This Page

wflow_adapt Module

Introduction

wflow_adapt is an adapter that links wflow to Delft-FEWS (http://publicwiki.deltares.nl/display/FEWSDOC/Home). 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:

  • wflow_[sbm|hbv].py needs to be run with the -F option where the argument refers to a Delft-FEWS runinfo.xml file
  • you need to specify fewsrun=1 in the model section of the .ini file
  • The postadapter (wflow_adapt.py) needs to be run after the wflow run

Because DELFT-FEWS exports the mapstacks beginning at 0 and pcraster expects them to start at 1 you will need to add a delay of one timesstep to mapstack timeseries exported to wflow. This will mean the first timestep (.000) is empty but that one will be ignored by wflow anyway.

The adapter also tries to convert 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:

<executeActivities>
<executeActivity>
<description>Run wflow</description>
<command><executable>bin-wflow\wflow_sbm.exe</executable></command>
    <arguments>
    <argument>-C</argument>
    <argument>rhine</argument>
    <argument>-F</argument>
    <argument>rhine/inmaps/runinfo.xml</argument>
    <argument>-f</argument>
</arguments>
<timeOut>7200000</timeOut>
</executeActivity>
<executeActivity>
<description>Run wflow post</description>
<command> <executable>bin-wflow\wflow_adapt.exe</executable> </command> <arguments>
    <argument>-M</argument>
    <argument>Post</argument>
    <argument>-s</argument>
    <argument>rhine/instate/state.xml</argument>
    <argument>-o</argument>
    <argument>rhine/instate/outstate.xml</argument>
    <argument>-r</argument>
    <argument>rhine/inmaps/runinfo.xml</argument>
    <argument>-w</argument>
    <argument>./</argument>
    <argument>-C</argument>
    <argument>rhine</argument>
    <argument>-I</argument>
    <argument>wflow_sbm.ini</argument>
    <argument>-T</argument>
    <argument>86400</argument>
</arguments>
<timeOut>1200000</timeOut>
<overrulingDiagnosticFile>wflow_diag.xml</overrulingDiagnosticFile>
</executeActivity>
</executeActivities>

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.

Module function documentation

wflow_adapt.py: 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 -T timestepInSeconds

Usage postadapter:

wflow_adapt-M Post -t InputTimeseriesXml -s inputStateFile -I inifile
-o outputStateFile -r runinfofile -w workdir -C case -T timestepInSeconds [-R runId]

Issues:

  • 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 :-())

Todo

rewrite and simplify convert log to XML

$Author$ $Id$ $Rev$

wflow_adapt.getEndTimefromRuninfo(xmlfile)

Gets the endtime of the run from the FEWS runinfo file

wflow_adapt.getMapStacksFromRuninfo(xmlfile)

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

wflow_adapt.getStartTimefromRuninfo(xmlfile)

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

wflow_adapt.main()

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.

Warning

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