The wflow Delft-FEWS adapter¶
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:
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 (wflow_adapt.py) 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:
<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>
</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>-w</argument>
<argument>./</argument>
<argument>-C</argument>
<argument>rhine</argument>
<argument>-I</argument>
<argument>wflow_sbm.ini</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.
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:
<stateLocation>
<readLocation>WaterLevel.map</readLocation>
<writeLocation>../run_default/outstate/WaterLevel.map</writeLocation>
</stateLocation>
# Repeat for all state variables
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
Usage postadapter:
- wflow_adapt-M Post -t InputTimeseriesXml -s inputStateFile -I inifile
-o outputStateFile -r runinfofile -w workdir -C case [-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
$Author: schelle $ $Id: wflow_adapt.py 915 2014-02-10 07:33:56Z schelle $ $Rev: 915 $
- 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