Contents

Introduction

WATFLOOD is a set of computer programs for hydrological forecasting and modelling. 

http://www.civil.uwaterloo.ca/watflood/


Two modes of parameter updating of WATFLOOD are supported by the Delft-FEWS General adapter (2020.01 release), using a specifically designed preAdapter:

In November 2022 the model adapter was updated to update model routing parameters on-the-fly for a model simulation in the WATFLOOD basin parameter file

This documentation page is under development


Operating WATFLOOD Model and FEWS Adapter

The WATFLOOD Adapter forms the interface between the FEWS Forecasting Shell and the WATFLOOD model, supporting parameter updating as preAdapter functionality. The Adapter is not responsible for  adapting timeseries and grids to/from the model. WATFLOOD is (re)coded in 2019 to take NetCDF (.nc) scalar/grid timeseries directly as inputs.

Applications

This adapter has been developed and is implemented in the following configurations:

  1. FEWS Manitoba Hydro (Ivo Miltenburg, Ben Balk)

Download

Download of the model adapter is not available here: please e-mail to Delft-FEWS Product Management for more information.

Configuring WATFLOOD adapter

The WATFLOOD model adapter follows standard way of integrating external models into the Delft-FEWS system by use of General Adapter. For more details about configuration of General Adapter please check 05 General Adapter Module.

Example configuration of the WATFLOOD adapter:

<?xml version="1.0" encoding="UTF-8"?>
<generalAdapterRun xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://www.wldelft.nl/fews" xsi:schemaLocation="http://www.wldelft.nl/fews http://fews.wldelft.nl/schemas/version1.0/generalAdapterRun.xsd">
	<general>
		<description>WATFLOOD Model for $LOCATION_ID$</description>
		<piVersion>1.5</piVersion>
		<rootDir>%REGION_HOME%/Modules/WATFLOOD/$BASIN$</rootDir>
		<workDir>%ROOT_DIR%</workDir>
		<exportDir>%ROOT_DIR%</exportDir>
		<exportDataSetDir>%ROOT_DIR%</exportDataSetDir>
		<exportIdMap>IdExportWATFLOOD</exportIdMap>
		<importDir>%ROOT_DIR%/results</importDir>
		<importIdMap>IdImportWATFLOOD</importIdMap>
		<dumpFileDir>$GA_DUMPFILEDIR$</dumpFileDir>
		<dumpDir>%ROOT_DIR%</dumpDir>
		<diagnosticFile>%ROOT_DIR%/diagnostics/diagnostic.xml</diagnosticFile>
		<missVal>-999.0</missVal>
	</general>
	<activities>
		<startUpActivities>
			<purgeActivity>
				<filter>%ROOT_DIR%/*.*</filter>
			</purgeActivity>
			<purgeActivity>
				<filter>%ROOT_DIR%/basin/*.*</filter>
			</purgeActivity>
			<purgeActivity>
				<filter>%ROOT_DIR%/strfw/*.*</filter>
			</purgeActivity>
		</startUpActivities>
		<exportActivities>
			<exportStateActivity>
				<moduleInstanceId>WATFLOOD_$BASIN$_UpdateStates</moduleInstanceId>
				<stateExportDir>%ROOT_DIR%</stateExportDir>
				<stateConfigFile>%ROOT_DIR%/state.xml</stateConfigFile>
				<stateLocations type="file">
					<stateLocation>
						<readLocation>flow_init.r2c</readLocation>
						<writeLocation>flow_init.r2c</writeLocation>
					</stateLocation>
					<stateLocation>
						<readLocation>lake_level_init.pt2</readLocation>
						<writeLocation>lake_level_init.pt2</writeLocation>
					</stateLocation>
					<stateLocation>
						<readLocation>resume.txt</readLocation>
						<writeLocation>resume.txt</writeLocation>
					</stateLocation>
					<stateLocation>
						<readLocation>soil_init.r2c</readLocation>
						<writeLocation>soil_init.r2c</writeLocation>
					</stateLocation>
				</stateLocations>
			</exportStateActivity>
			<exportTimeSeriesActivity>
				<exportFile>%ROOT_DIR%/snow1/swe_update.xml</exportFile>
				<timeSeriesSets>
					<timeSeriesSet>
						<moduleInstanceId>WATFLOOD_SWE_UpdateStates</moduleInstanceId>
						<valueType>scalar</valueType>
						<parameterId>SW.add</parameterId>
						<locationId>$LOCATION_ID$</locationId>
						<timeSeriesType>external historical</timeSeriesType>
						<timeStep unit="nonequidistant"/>
						<relativeViewPeriod unit="hour" end="0"/>
						<readWriteMode>read only</readWriteMode>
						<ensembleId>main</ensembleId>
					</timeSeriesSet>
					<timeSeriesSet>
						<moduleInstanceId>WATFLOOD_SWE_UpdateStates</moduleInstanceId>
						<valueType>scalar</valueType>
						<parameterId>SW.mult</parameterId>
						<locationId>$LOCATION_ID$</locationId>
						<timeSeriesType>external historical</timeSeriesType>
						<timeStep unit="nonequidistant"/>
						<relativeViewPeriod unit="hour" end="0"/>
						<readWriteMode>read only</readWriteMode>
						<ensembleId>main</ensembleId>
					</timeSeriesSet>
				</timeSeriesSets>
			</exportTimeSeriesActivity>
			<exportTimeSeriesActivity>
				<exportFile>%ROOT_DIR%/moist/uzs_update.xml</exportFile>
				<timeSeriesSets>
					<timeSeriesSet>
						<moduleInstanceId>WATFLOOD_UZS_UpdateStates</moduleInstanceId>
						<valueType>scalar</valueType>
						<parameterId>UZS.add</parameterId>
						<locationId>$LOCATION_ID$</locationId>
						<timeSeriesType>external historical</timeSeriesType>
						<timeStep unit="nonequidistant"/>
						<relativeViewPeriod unit="hour" end="0"/>
						<readWriteMode>read only</readWriteMode>
						<ensembleId>main</ensembleId>
					</timeSeriesSet>
					<timeSeriesSet>
						<moduleInstanceId>WATFLOOD_UZS_UpdateStates</moduleInstanceId>
						<valueType>scalar</valueType>
						<parameterId>UZS.mult</parameterId>
						<locationId>$LOCATION_ID$</locationId>
						<timeSeriesType>external historical</timeSeriesType>
						<timeStep unit="nonequidistant"/>
						<relativeViewPeriod unit="hour" end="0"/>
						<readWriteMode>read only</readWriteMode>
						<ensembleId>main</ensembleId>
					</timeSeriesSet>
				</timeSeriesSets>
			</exportTimeSeriesActivity>
			<exportDataSetActivity>
				<moduleInstanceId>WATFLOOD_exe_dll</moduleInstanceId>
			</exportDataSetActivity>
			<exportDataSetActivity>
				<moduleInstanceId>WATFLOOD_$BASIN$_resume</moduleInstanceId>
			</exportDataSetActivity>
			<exportParameterActivity>
				<fileName>%ROOT_DIR%/basin/$BASIN$_basin_params.xml</fileName>
				<templateLocationLooping>
					<locationModelLoop>
						<locationId>WF_$BASIN$_params</locationId>
						<model>WF_fm_param</model>
					</locationModelLoop>
					<locationModelLoop>
						<locationId>WF_$BASIN$_params</locationId>
						<model>WF_base_param</model>
					</locationModelLoop>
				</templateLocationLooping>
				<moduleInstanceId>WATFLOOD_Parameters</moduleInstanceId>
			</exportParameterActivity>
			<exportParameterActivity>
				<fileName>%ROOT_DIR%/strfw/$BASIN$_NudgeFlags_params.xml</fileName>
				<templateLocationLooping>
					<locationModelLoop>
						<locationSetId>WATFLOOD_$BASIN$_nudge_flags</locationSetId>
						<model>WF_Nudge</model>
					</locationModelLoop>
				</templateLocationLooping>
				<moduleInstanceId>WATFLOOD_Parameters</moduleInstanceId>
			</exportParameterActivity>
			<exportNetcdfActivity>
				<exportFile>%ROOT_DIR%/radcl/precip.nc</exportFile>
				<timeSeriesSets>
					<timeSeriesSet>
						<moduleInstanceId>$GRIDDED_INPUT_MODULE$</moduleInstanceId>
						<valueType>grid</valueType>
						<parameterId>PP.obs</parameterId>
						<locationId>$LOCATION_ID$</locationId>
						<timeSeriesType>external historical</timeSeriesType>
						<timeStep unit="hour" multiplier="6"/>
						<relativeViewPeriod unit="day" end="0" startOverrulable="true"/>
						<readWriteMode>read only</readWriteMode>
					</timeSeriesSet>
				</timeSeriesSets>
			</exportNetcdfActivity>
			<exportNetcdfActivity>
				<exportFile>%ROOT_DIR%/tempr/tempt.nc</exportFile>
				<timeSeriesSets>
					<timeSeriesSet>
						<moduleInstanceId>$GRIDDED_INPUT_MODULE$</moduleInstanceId>
						<valueType>grid</valueType>
						<parameterId>TA.obs</parameterId>
						<locationId>$LOCATION_ID$</locationId>
						<timeSeriesType>external historical</timeSeriesType>
						<timeStep unit="hour" multiplier="6"/>
						<relativeViewPeriod unit="day" end="0" startOverrulable="true"/>
						<readWriteMode>read only</readWriteMode>
					</timeSeriesSet>
				</timeSeriesSets>
			</exportNetcdfActivity>
			<exportNetcdfActivity>
				<exportFile>%ROOT_DIR%/strfw/flow.nc</exportFile>
				<timeSeriesSets>
					<timeSeriesSet>
						<moduleInstanceId>Preprocess_WATFLOOD_$BASIN$_QR_UpdateStates</moduleInstanceId>
						<valueType>scalar</valueType>
						<parameterId>QR.obs</parameterId>
						<locationSetId>WATFLOOD_$BASIN$_QR_strfw_spl</locationSetId>
						<timeSeriesType>external historical</timeSeriesType>
						<timeStep id="day_CST"/>
						<relativeViewPeriod unit="day" end="0" startOverrulable="true"/>
						<readWriteMode>read only</readWriteMode>
						<ensembleId>main</ensembleId>
					</timeSeriesSet>
				</timeSeriesSets>
			</exportNetcdfActivity>
			<exportNetcdfActivity>
				<exportFile>%ROOT_DIR%/level/level.nc</exportFile>
				<timeSeriesSets>
					<timeSeriesSet>
						<moduleInstanceId>Preprocess_WATFLOOD_$BASIN$_HF_UpdateStates</moduleInstanceId>
						<valueType>scalar</valueType>
						<parameterId>HF.obs</parameterId>
						<locationSetId>WATFLOOD_$BASIN$_HF_input_lvl</locationSetId>
						<timeSeriesType>external historical</timeSeriesType>
						<timeStep id="day_CST"/>
						<relativeViewPeriod unit="day" end="0" startOverrulable="true"/>
						<readWriteMode>read only</readWriteMode>
						<ensembleId>main</ensembleId>
					</timeSeriesSet>
				</timeSeriesSets>
			</exportNetcdfActivity>
			<exportNetcdfRunFileActivity>
				<exportFile>%ROOT_DIR%/run_info.nc</exportFile>
				<properties>
					<string key="WFNudgeFlagsFile" value="strfw/nudge_flags.xyz"/>
					<string key="NudgeFlagsParamsFile" value="strfw/$BASIN$_NudgeFlags_params.xml"/>
					<string key="WFBasinParFile" value="basin/$BASIN$_par.csv"/>
					<string key="BasinParamsFile" value="basin/$BASIN$_Basin_params.xml"/>
				</properties>
			</exportNetcdfRunFileActivity>
		</exportActivities>
		<executeActivities>
			<executeActivity>
				<description>run WATFLOOD preAdapter</description>
				<command>
					<className>nl.wldelft.fews.adapter.watflood.WatFloodPreAdapter</className>
					<binDir>$REGION_HOME$/Modules/WATFLOOD/binAdapter</binDir>
				</command>
				<arguments>
					<argument>%ROOT_DIR%/run_info.nc</argument>
				</arguments>
				<logFile>
					<file>%ROOT_DIR%\watflood_pre_adapter.log</file>
					<errorLinePattern>*ERROR*</errorLinePattern>
					<warningLinePattern>*WARN*</warningLinePattern>
					<infoLinePattern>*INFO*</infoLinePattern>
					<debugLinePattern>*DEBUG*</debugLinePattern>
				</logFile>
				<timeOut>300000</timeOut>
				<ignoreDiagnostics>true</ignoreDiagnostics>
			</executeActivity>
			<executeActivity>
				<description>run WATFLOOD diff64</description>
				<command>
					<executable>%ROOT_DIR%/diff64.exe</executable>
				</command>
				<timeOut>300000</timeOut>
				<ignoreDiagnostics>true</ignoreDiagnostics>
			</executeActivity>
			<executeActivity>
				<description>run WATFLOOD model</description>
				<command>
					<executable>%ROOT_DIR%/charm64x.exe</executable>
				</command>
				<logFile>
					<file>%ROOT_DIR%\debug\warnings.txt</file>
					<errorLinePattern>*ERROR*</errorLinePattern>
					<warningLinePattern>*WARN*</warningLinePattern>
					<infoLinePattern>*INFO*</infoLinePattern>
					<debugLinePattern>*DEBUG*</debugLinePattern>
				</logFile>
				<timeOut>300000</timeOut>
				<ignoreDiagnostics>true</ignoreDiagnostics>
			</executeActivity>
		</executeActivities>
		<importActivities>
			<importStateActivity>
				<stateImportDir>%ROOT_DIR%/resume</stateImportDir>
				<stateFile>
					<importFile>flow_init.r2c</importFile>
					<relativeExportFile>flow_init.r2c</relativeExportFile>
				</stateFile>
				<stateFile>
					<importFile>lake_level_init.pt2</importFile>
					<relativeExportFile>lake_level_init.pt2</relativeExportFile>
				</stateFile>
				<stateFile>
					<importFile>resume.txt</importFile>
					<relativeExportFile>resume.txt</relativeExportFile>
				</stateFile>
				<stateFile>
					<importFile>soil_init.r2c</importFile>
					<relativeExportFile>soil_init.r2c</relativeExportFile>
				</stateFile>
			</importStateActivity>
			<importNetcdfActivity>
				<importFile>CHARM_flow_2D.nc</importFile>
				<timeSeriesSets>
					<timeSeriesSet>
						<moduleInstanceId>WATFLOOD_$BASIN$_UpdateStates</moduleInstanceId>
						<valueType>grid</valueType>
						<parameterId>QR.sim</parameterId>
						<locationId>$LOCATION_ID$</locationId>
						<timeSeriesType>simulated historical</timeSeriesType>
						<timeStep unit="hour" multiplier="6"/>
						<readWriteMode>add originals</readWriteMode>
					</timeSeriesSet>
				</timeSeriesSets>
			</importNetcdfActivity>
			<importNetcdfActivity>
				<importFile>CHARM_swe_2D.nc</importFile>
				<timeSeriesSets>
					<timeSeriesSet>
						<moduleInstanceId>WATFLOOD_$BASIN$_UpdateStates</moduleInstanceId>
						<valueType>grid</valueType>
						<parameterId>SW.sim</parameterId>
						<locationId>$LOCATION_ID$</locationId>
						<timeSeriesType>simulated historical</timeSeriesType>
						<timeStep unit="hour" multiplier="6"/>
						<readWriteMode>add originals</readWriteMode>
					</timeSeriesSet>
				</timeSeriesSets>
			</importNetcdfActivity>
			<importNetcdfActivity>
				<importFile>CHARM_uzs_2D.nc</importFile>
				<timeSeriesSets>
					<timeSeriesSet>
						<moduleInstanceId>WATFLOOD_$BASIN$_UpdateStates</moduleInstanceId>
						<valueType>grid</valueType>
						<parameterId>UZS:RETN.sim</parameterId>
						<locationId>$LOCATION_ID$</locationId>
						<timeSeriesType>simulated historical</timeSeriesType>
						<timeStep unit="hour" multiplier="6"/>
						<readWriteMode>add originals</readWriteMode>
					</timeSeriesSet>
				</timeSeriesSets>
			</importNetcdfActivity>
			<importNetcdfActivity>
				<importFile>CHARM_grid_runoff_2D.nc</importFile>
				<timeSeriesSets>
					<timeSeriesSet>
						<moduleInstanceId>WATFLOOD_$BASIN$_UpdateStates</moduleInstanceId>
						<valueType>grid</valueType>
						<parameterId>QR.sim.grid</parameterId>
						<locationId>$LOCATION_ID$</locationId>
						<timeSeriesType>simulated historical</timeSeriesType>
						<timeStep unit="hour" multiplier="6"/>
						<readWriteMode>add originals</readWriteMode>
					</timeSeriesSet>
				</timeSeriesSets>
			</importNetcdfActivity>
			<importNetcdfActivity>
				<importFile>CHARM_cumm_ET_2D.nc</importFile>
				<timeSeriesSets>
					<timeSeriesSet>
						<moduleInstanceId>WATFLOOD_$BASIN$_UpdateStates</moduleInstanceId>
						<valueType>grid</valueType>
						<parameterId>ET.sim.acc</parameterId>
						<locationId>$LOCATION_ID$</locationId>
						<timeSeriesType>simulated historical</timeSeriesType>
						<timeStep unit="hour" multiplier="6"/>
						<readWriteMode>add originals</readWriteMode>
					</timeSeriesSet>
				</timeSeriesSets>
			</importNetcdfActivity>
			<importNetcdfActivity>
				<importFile>CHARM_flow_vector.nc</importFile>
				<timeSeriesSets>
					<timeSeriesSet>
						<moduleInstanceId>WATFLOOD_$BASIN$_UpdateStates</moduleInstanceId>
						<valueType>scalar</valueType>
						<parameterId>QR.sim</parameterId>
						<locationSetId>WATFLOOD_$BASIN$_QR_strfw_spl</locationSetId>
						<timeSeriesType>simulated historical</timeSeriesType>
						<timeStep unit="hour" multiplier="6"/>
						<readWriteMode>add originals</readWriteMode>
					</timeSeriesSet>
				</timeSeriesSets>
			</importNetcdfActivity>
			<importNetcdfActivity>
				<importFile>CHARM_lake_inflow.nc</importFile>
				<timeSeriesSets>
					<timeSeriesSet>
						<moduleInstanceId>WATFLOOD_$BASIN$_UpdateStates</moduleInstanceId>
						<valueType>scalar</valueType>
						<parameterId>QI.sim</parameterId>
						<locationSetId>WATFLOOD_$BASIN$_HF_output_lake_sd</locationSetId>
						<timeSeriesType>simulated historical</timeSeriesType>
						<timeStep unit="hour" multiplier="6"/>
						<readWriteMode>add originals</readWriteMode>
					</timeSeriesSet>
				</timeSeriesSets>
			</importNetcdfActivity>
			<importNetcdfActivity>
				<importFile>CHARM_lake_levels.nc</importFile>
				<timeSeriesSets>
					<timeSeriesSet>
						<moduleInstanceId>WATFLOOD_$BASIN$_UpdateStates</moduleInstanceId>
						<valueType>scalar</valueType>
						<parameterId>HF.sim</parameterId>
						<locationSetId>WATFLOOD_$BASIN$_HF_output_lake_sd</locationSetId>
						<timeSeriesType>simulated historical</timeSeriesType>
						<timeStep unit="hour" multiplier="6"/>
						<readWriteMode>add originals</readWriteMode>
					</timeSeriesSet>
				</timeSeriesSets>
			</importNetcdfActivity>
			<importNetcdfActivity>
				<importFile>CHARM_lake_outflow.nc</importFile>
				<timeSeriesSets>
					<timeSeriesSet>
						<moduleInstanceId>WATFLOOD_$BASIN$_UpdateStates</moduleInstanceId>
						<valueType>scalar</valueType>
						<parameterId>QO.sim</parameterId>
						<locationSetId>WATFLOOD_$BASIN$_HF_output_lake_sd</locationSetId>
						<timeSeriesType>simulated historical</timeSeriesType>
						<timeStep unit="hour" multiplier="6"/>
						<readWriteMode>add originals</readWriteMode>
					</timeSeriesSet>
				</timeSeriesSets>
			</importNetcdfActivity>
		</importActivities>
	</activities>
</generalAdapterRun>



The WATFLOOD model files, including the WATFLOOD binaries are saved in the /Config/ModuleDataSet directory. These are copied to the /Modules/WATFLOOD/$BASIN$ directory during the exportDataSet activity in the General Adapter file.

General Design choices for the WATFLOOD preAdapter

Update Nudge_Flags file

The nudge_flags file is part of the model configuration. It is typically located in the following directory: /strfw/nudge_flags.xyz

nudge_flags.xyz


The file is space delineated. Only the first 4 columns are read by WATFLOOD. The rest of the line is ignored. The nudge flag is stored in column 3 (see image above - green box), the preAdapter will use the stationId (column 4, see image above - red box) to make the connection to update the correct row in the nudge_flags.xyz file. The nudge flags file has 8 characters for the stationId. Reading the nudge_flags.xyz file is automatically left justified. Trailing blanks are chopped and not used for matching. 

The WATFLOOD executable (version October 2019) now pick up the stationId instead of lat/lon to match to the flows for nudging. 


Design Choices for nudge_flag updating

We assume that all locations in the nudge flags params xml (as exported by the General Adapter from Delft-FEWS) file are present in the nudge_flags.xyz file, no new locations can be dynamically introduced by the params file. 

To indicate to the preAdapter that nudge flags updating should take place, 2 specific keys need to be defined in the RunInfo file:


the location of the nudge_flag and Params files should be defined relative to the directory where the run_info file is written.


Convention for the IdMapping in the params xml file for Nudge Flags

locationId will match with the station Id as present in column 4 of the .xyz file
The parameterId of the value does not matter, in the current design only a single value can be overwritten per locationId. An example of the parameterId can be 'nudge_flag'
The value in the nudge flags params xml file will be used to overwrite the existing nudge_flag in column 3 of the .xyz file. It will be provided as a intValue, but the preAdapter should parse it as 'text'/string


Configuration instructions for updating Nudge_Flags



WATFLOOD Parameter updating

Convention for the IdMapping in the params xml file for Parameter Updating:

locationId is free, not required to be equal to the 'Parameter block name' in the *_par.csv file. E.g. 'SnowParameters', because all parameters are unique
parameterId: The naming convention for the parameter id's is as follows: <parameter_id>-<column number>[*-**]
The <parameter_id> part is required. It should be equal to the WATFLOOD parameter id. The <parameter_id> element is 'closed' by a "-"(hyphen) character
The <column number> bit is required. It specifies which column needs to be updated by the preAdapter.
"01" is to be interpreted as the first column after the column with the parameterId
Leading zero's are not required, this part of the parameterId will be parsed as a number
The [-*] part is free to choose (and optional).

The values in the parameter.xml files from Delft-FEWS will be read as strings and are not interpreted.
This means that the representation in the params file should be correct.
Only exception is NaN's. These will not be read in/used and will be ignored. For parameterId's with NaN's, no warning/info message will be generated

An example where these design choices are followed is given in the screenshot below, where we want to update the "base" parameter in the basin file, for 19 landclasses

Design Choices

The adapter will parse the relevant lines of the WF parameter csv file to columns (comma separated) and replace . A parameter_id in the par file from Watflood always starts with a ":", e.g. ":fm" or ":base"
One can update all parameters with this design, if the parameterId convention is followed.
If less parameters are provided in the params.xml file as compared to the amount of columns as defined in the WATFLOOD par.csv file, the remainder of parameters will not be touched and stay in place. A WARN message should be thrown if this is the case to indicate to the user/configurator that only a subset of available parameters are being updated/passed to the model.
We will provide a specific key in the RunInfo file:

<string key="WFBasinParFile" value="%ROOT_DIR%/basin/lnrb_par.csv"/>
This file will be used for the parameter updating.
<string key="BasinParamsFile" value="%ROOT_DIR%/basin/$BASIN$_Basin_params.xml"/>
indicates to the preAdapter where the parameter file for parameter updating is located.
This then also indicates that parameter updating should take place.

Since November 2022, Routing parameters can also be changed on the fly when specified in a separate *_params.xml file

<string key="RoutingParamsFile" value="%ROOT_DIR%/basin/$BASIN$_Routing_params.xml"/>
indicates to the preAdapter where the routing parameter file for parameter updating is located.
This then also indicates that routing parameter updating should take place


Configuration Instructions for updating Basin Parameters