You are viewing an old version of this page. View the current version.

Compare with Current View Page History

« Previous Version 3 Next »

iMOD

iMOD is an easy-to-use Graphical User Interface with Deltares' innovative version of MODFLOW (called iMODFLOW). Both iMOD and iMODFLOW are freely available here: https://oss.deltares.nl/web/imod

iMOD Adapter

This page describes the iMOD module adapter, its functions, and provides an example for configuring an iMOD run in Delft-FEWS.

The iMOD Adapter is a Python script designed to make running iMODFLOW models from Delft-FEWS as easy as possible. This includes not only iMODFLOW, but also the coupled MetaSWAP and WOFOST models, as described below. It builds on the iMOD Python package found at https://gitlab.com/deltares/imod-python and uses the iMOD RUNFILE batch function to create run files from project files.

iMODFLOW

MODFLOW is a popular open-source groundwater flow model distributed by the U.S. Geological Survey. iMODFLOW is characterized by fast, flexible and consistent high resolution and sub-domain modelling techniques. It enables very large, high resolution groundwater modelling. Results include the groundwater heads of the various aquifers.

MetaSWAP

MetaSWAP can model both shallow and deep groundwater levels; it is intended for regions with an undulating topography and unconsolidated sediments. Its strength lies in modelling the unsaturated zone and shallow subsurface. MetaSWAP covers plant-atmosphere interactions and groundwater. Results include the fluxes to and from the unsaturated zone.

WOFOST

WOrld FOod STudies (WOFOST) is a crop growth model for the quantitative analysis of the growth and production of annual field crops. WOFOST can be used to calculate attainable crop production, biomass, water use, etc. for a given location. Calculations are made based on local soil type, crop type, weather data, and crop management factors (e.g. sowing date). Results include the root zone depth, leaf area index, and water demand.

iMODFLOW-MetaSWAP-WOFOST coupling

The coupled iMODFLOW-MetaSWAP-WOFOST model benefits from the strengths of each model: iMODFLOW for the groundwater flow, MetaSWAP for the unsaturated zone, and WOFOST for the crop growth aspect. A schema of hte fluxes between the models is provided in Figure 1.

iMODFLOW-MetaSWAP-WOFOST coupling

Figure 1. iMODFLOW-MetaSWAP-WOFOST coupling.

Adapter installation instructions

The adapter is a Python package and requires Python 3.6 or higher. A number of packages need to be installed prior to installing the adapter. This can be done by using a file called "environment.yml" as follows:

environment.yml
name: fews

channels:
  - conda-forge
  - defaults

dependencies:
  - python=3.6
  - numpy
  - xarray
  - numba
  - pandas
  - geopandas
  - dask
  - rasterio
  - git
  - git-lfs
  - jupyterlab
  - spyder
  - jinja2
  - cookiecutter
  - matplotlib
  - pytest
  - cftime
  - netcdf4
  - black

This file can be installed as follows:

conda env create -f environment.yml

Once Python and the required packages are installed and the package manager pip is available on the Path, the adapter can be installed as follows:

pip install git+https://gitlab.com/deltares/imod/imod-fews-adapter

To test if the installation was successful, try starting the Python interpreter and type "import imodfews".

Notes to users

  • For all files that are written by this adapter, if the file to be written already exists, it will be overwritten.
  • This adapter only handles osil moisture retention curves (pF curves) as input for hte init_svat.inp file (MetaSWAP), not "MeteoInputP" as input.

Input

Project file

An iMOD project file (*.PRJ) that describes the model and provides links to the input files needs to be available to the adapter. This project file needs to cover at least the time period that you intend to run. If you only have a runfile (*.RUN), a corresponding project file can be created in iMOD (refer to the iMOD user manual).

RUNFILE_TEMPLATE.INI template

The iMOD Adapter creates a runfile using iMOD batch functionality. For this batch function, a RUNFILE_TEMPLATE.INI file is needed with, among other things, the start and end time of the desired runfile. The highlighted fields below can be left blank and are filled in by the adapter before calling the iMOD batch function.

FUNCTION=RUNFILE

ISS=1

ITT=2
IDT=1
SAVESHD=-1
SAVERIV=-1
SAVERCH=1
SAVEDRN=1
SAVEWEL=-1
SAVEFLX=-1
WINDOW=165000.00, 390000.00, 200000.00, 424000.00
CELLSIZE=100.00

run_info.xml

A run_info.xml

s a first activity it can be useful to delete all files present in the workDir, if for example it would be filled with files from a previous run.

start up activities
		<startUpActivities>
			<purgeActivity>
				<filter>workDir*</filter>
			</purgeActivity>
		</startUpActivities>

Export activities

The first steps in the general adapter run are the netcdf and run file export activities. The <exportNetcdfActivity> will be a netcdf file which can have any name containing the variables called: lateral, longitudinal, Method, Vmax, Rmax, R100, R65, R50, R35, Par_A, Par_B, Pdrop. 

The <exportNetcdfRunFileActivity> will be a netcdf run file that contains information needed by the pre adapter. The information will be automatically filled by the general adapter.

export activities
		<exportActivities>
			<exportNetcdfActivity>
				<exportFile>zs0file.nc</exportFile>
				<timeSeriesSets>
					<timeSeriesSet>
						<moduleInstanceId>Run_XBeach</moduleInstanceId>
						<valueType>scalar</valueType>
						<parameterId>lateral</parameterId>
						<locationId>Dummy</locationId>
						<timeSeriesType>external historical</timeSeriesType>
						<timeStep unit="hour" multiplier="6"/>
						<relativeViewPeriod unit="day" start="-15" end="-9"/>
						<readWriteMode>editing visible to all future task runs</readWriteMode>
					</timeSeriesSet>
					<timeSeriesSet>
						<moduleInstanceId>Run_XBeach</moduleInstanceId>
						<valueType>scalar</valueType>
						<parameterId>longitudinal</parameterId>
						<locationId>Dummy</locationId>
						<timeSeriesType>external historical</timeSeriesType>
						<timeStep unit="hour" multiplier="6"/>
						<relativeViewPeriod unit="day" start="-15" end="-9"/>
						<readWriteMode>editing visible to all future task runs</readWriteMode>
					</timeSeriesSet>
					<timeSeriesSet>
						<moduleInstanceId>Run_XBeach</moduleInstanceId>
						<valueType>scalar</valueType>
						<parameterId>Method</parameterId>
						<locationId>Dummy</locationId>
						<timeSeriesType>external historical</timeSeriesType>
						<timeStep unit="hour" multiplier="6"/>
						<relativeViewPeriod unit="day" start="-15" end="-9"/>
						<readWriteMode>editing visible to all future task runs</readWriteMode>
					</timeSeriesSet>
					<timeSeriesSet>
						<moduleInstanceId>Run_XBeach</moduleInstanceId>
						<valueType>scalar</valueType>
						<parameterId>Vmax</parameterId>
						<locationId>Dummy</locationId>
						<timeSeriesType>external historical</timeSeriesType>
						<timeStep unit="hour" multiplier="6"/>
						<relativeViewPeriod unit="day" start="-15" end="-9"/>
						<readWriteMode>editing visible to all future task runs</readWriteMode>
					</timeSeriesSet>
					<timeSeriesSet>
						<moduleInstanceId>Run_XBeach</moduleInstanceId>
						<valueType>scalar</valueType>
						<parameterId>Rmax</parameterId>
						<locationId>Dummy</locationId>
						<timeSeriesType>external historical</timeSeriesType>
						<timeStep unit="hour" multiplier="6"/>
						<relativeViewPeriod unit="day" start="-15" end="-9"/>
						<readWriteMode>editing visible to all future task runs</readWriteMode>
					</timeSeriesSet>
					<timeSeriesSet>
						<moduleInstanceId>Run_XBeach</moduleInstanceId>
						<valueType>scalar</valueType>
						<parameterId>R100</parameterId>
						<locationId>Dummy</locationId>
						<timeSeriesType>external historical</timeSeriesType>
						<timeStep unit="hour" multiplier="6"/>
						<relativeViewPeriod unit="day" start="-15" end="-9"/>
						<readWriteMode>editing visible to all future task runs</readWriteMode>
					</timeSeriesSet>
					<timeSeriesSet>
						<moduleInstanceId>Run_XBeach</moduleInstanceId>
						<valueType>scalar</valueType>
						<parameterId>R65</parameterId>
						<locationId>Dummy</locationId>
						<timeSeriesType>external historical</timeSeriesType>
						<timeStep unit="hour" multiplier="6"/>
						<relativeViewPeriod unit="day" start="-15" end="-9"/>
						<readWriteMode>editing visible to all future task runs</readWriteMode>
					</timeSeriesSet>
					<timeSeriesSet>
						<moduleInstanceId>Run_XBeach</moduleInstanceId>
						<valueType>scalar</valueType>
						<parameterId>R50</parameterId>
						<locationId>Dummy</locationId>
						<timeSeriesType>external historical</timeSeriesType>
						<timeStep unit="hour" multiplier="6"/>
						<relativeViewPeriod unit="day" start="-15" end="-9"/>
						<readWriteMode>editing visible to all future task runs</readWriteMode>
					</timeSeriesSet>
					<timeSeriesSet>
						<moduleInstanceId>Run_XBeach</moduleInstanceId>
						<valueType>scalar</valueType>
						<parameterId>R35</parameterId>
						<locationId>Dummy</locationId>
						<timeSeriesType>external historical</timeSeriesType>
						<timeStep unit="hour" multiplier="6"/>
						<relativeViewPeriod unit="day" start="-15" end="-9"/>
						<readWriteMode>editing visible to all future task runs</readWriteMode>
					</timeSeriesSet>
					<timeSeriesSet>
						<moduleInstanceId>Run_XBeach</moduleInstanceId>
						<valueType>scalar</valueType>
						<parameterId>Par_B</parameterId>
						<locationId>Dummy</locationId>
						<timeSeriesType>external historical</timeSeriesType>
						<timeStep unit="hour" multiplier="6"/>
						<relativeViewPeriod unit="day" start="-15" end="-9"/>
						<readWriteMode>editing visible to all future task runs</readWriteMode>
					</timeSeriesSet>
					<timeSeriesSet>
						<moduleInstanceId>Run_XBeach</moduleInstanceId>
						<valueType>scalar</valueType>
						<parameterId>Par_A</parameterId>
						<locationId>Dummy</locationId>
						<timeSeriesType>external historical</timeSeriesType>
						<timeStep unit="hour" multiplier="6"/>
						<relativeViewPeriod unit="day" start="-15" end="-9"/>
						<readWriteMode>editing visible to all future task runs</readWriteMode>
					</timeSeriesSet>
					<timeSeriesSet>
						<moduleInstanceId>Run_XBeach</moduleInstanceId>
						<valueType>scalar</valueType>
						<parameterId>Pdrop</parameterId>
						<locationId>Dummy</locationId>
						<timeSeriesType>external historical</timeSeriesType>
						<timeStep unit="hour" multiplier="6"/>
						<relativeViewPeriod unit="day" start="-15" end="-9"/>
						<readWriteMode>editing visible to all future task runs</readWriteMode>
					</timeSeriesSet>
				</timeSeriesSets>
			</exportNetcdfActivity>
			<exportNetcdfRunFileActivity>
				<description>This run file is passed as argument to WesPreAdapter</description>
				<exportFile>run.nc</exportFile>
				<properties>
					<double value="1000000.0" key="RADIUS_OF_CYCLONE"/>
					<double value="0.88" key="WIND_CONV_FAC"/>
				</properties>
			</exportNetcdfRunFileActivity>
		</exportActivities>

Execute activities

The next steps are the execute activities. 
The first will be the pre adapter. 
The second execute activity will be the module run. 
The third execute activity will be the post adapter.

execute activities
		<executeActivities>
            <executeActivity>
				<command>
					<className>nl.deltares.wes.pre.WesPreAdapter</className>
					<binDir>adapter\bin</binDir>
				</command>
				<arguments>
					<argument>run.nc</argument>
				</arguments>
				<logFile>
					<file>wes.log</file>
					<errorLinePattern>ERROR*</errorLinePattern>
					<warningLinePattern>WARN*</warningLinePattern>
					<infoLinePattern>INFO*</infoLinePattern>
					<debugLinePattern>DEBUG*</debugLinePattern>
				</logFile>
				<timeOut>99999999</timeOut>
				<ignoreDiagnostics>true</ignoreDiagnostics>
			</executeActivity>		
			<executeActivity>
				<command>
					<executable>wes.exe</executable>
				</command>
				<arguments>
					<argument>wes_input.inp</argument>
				</arguments>
				<timeOut>99999999</timeOut>
				<ignoreDiagnostics>true</ignoreDiagnostics>
			</executeActivity>
			<executeActivity>
				<command>
					<className>nl.deltares.wes.post.WesPostAdapter</className>
					<binDir>adapter\bin</binDir>
				</command>
				<arguments>
					<argument>run.nc</argument>
				</arguments>
				<logFile>
					<file>wes.log</file>
					<errorLinePattern>ERROR*</errorLinePattern>
					<warningLinePattern>WARN*</warningLinePattern>
					<infoLinePattern>INFO*</infoLinePattern>
					<debugLinePattern>DEBUG*</debugLinePattern>
				</logFile>
				<timeOut>99999999</timeOut>
				<ignoreDiagnostics>true</ignoreDiagnostics>
			</executeActivity>
		</executeActivities>

Executing pre adapter

This program will read the run.nc input file and use the contents for instructions on which directory and files should be used to convert to the correct WES input format.
The Pre adapter generates a log file called wes.log, which can be read into FEWS by coupling line patterns to FEWS log messages

Take the values of the properties RADIUS_OF_CYCLONE and WIND_CONV_FAC from run.nc to write it to wes_input.inp.

 Take the values for all parameters and time steps from a netcdf file exported by FEWS and write it them to wes_adapter_track.trk.

wes_input.inp
CYCLONE_PAR._FILE   = wes_adapter_track.trk
SPIDERS_WEB_DIMENS. = 500  36
RADIUS_OF_CYCLONE   = 1000000.0
WIND CONV. FAC (TRK)= 0.88
NO._OF_HIS._DATA    = 0
HIS._DATA_FILE_NAME =
OBS._DATA_FILE_NAME =
EXTENDED_REPORT     = yes

wes_adapter_track.trk
* File for tropical cyclone
* File contains Cyclone information ; TIMES in UTC
* File generated by WES adapter
* UNIT = Kts, Nmi ,Pa
* METHOD= 1:A&B;           4:Vm,Pd; Rw default
*         2:R100_etc;      5:Vm & Rw(RW may be default - US data; Pd = 2 Vm*Vm);
*         3:Vm,Pd,RmW,     6:Vm (Indian data); 7: OLD METHOD - Not adviced
* Dm    Vm
0.0 0.0
*    Date and time     lat     lon Method    Vmax    Rmax   R100    R65    R50    R35  Par B  Par A  Pdrop
* yyyy  mm  dd  HH     deg     deg    (-)   (kts)    (NM)   (NM)   (NM)   (NM)   (NM)    (-)    (-)   (Pa)
  2000  11  03  00   14.00  -80.00     4      30   1E+30   1E+30   1E+30   1E+30   1E+30   1E+30   1E+30    1400
  2000  11  03  06   15.00  -80.00     4      35   1E+30   1E+30   1E+30   1E+30   1E+30   1E+30   1E+30    1500
  2000  11  03  12   16.00  -80.00     4      40   1E+30   1E+30   1E+30   1E+30   1E+30   1E+30   1E+30    1600
  2000  11  03  18   17.00  -80.00     4      45   1E+30   1E+30   1E+30   1E+30   1E+30   1E+30   1E+30    2000
  2000  11  04  00   17.00  -80.00     4      50   1E+30   1E+30   1E+30   1E+30   1E+30   1E+30   1E+30    4000
  2000  11  04  06   17.00  -81.00     4      55   1E+30   1E+30   1E+30   1E+30   1E+30   1E+30   1E+30    7000
  2000  11  04  12   18.00  -81.00     4      60   1E+30   1E+30   1E+30   1E+30   1E+30   1E+30   1E+30   10000
  2000  11  04  18   18.00  -81.00     4      65   1E+30   1E+30   1E+30   1E+30   1E+30   1E+30   1E+30   12000
  2000  11  05  00   18.00  -81.00     4      70   1E+30   1E+30   1E+30   1E+30   1E+30   1E+30   1E+30   13000
  2000  11  05  06   18.00  -81.00     4      75   1E+30   1E+30   1E+30   1E+30   1E+30   1E+30   1E+30   13000
  2000  11  05  12   19.00  -82.00     4      80   1E+30   1E+30   1E+30   1E+30   1E+30   1E+30   1E+30   12000
  2000  11  05  18   19.00  -82.00     4      85   1E+30   1E+30   1E+30   1E+30   1E+30   1E+30   1E+30   12000
  2000  11  06  00   19.00  -82.00     4      90   1E+30   1E+30   1E+30   1E+30   1E+30   1E+30   1E+30   11000
  2000  11  06  06   20.00  -82.00     4      95   1E+30   1E+30   1E+30   1E+30   1E+30   1E+30   1E+30   11000
  2000  11  06  12   20.00  -82.00     4     100   1E+30   1E+30   1E+30   1E+30   1E+30   1E+30   1E+30   11000
  2000  11  06  18   20.00  -81.00     4     105   1E+30   1E+30   1E+30   1E+30   1E+30   1E+30   1E+30   10000
  2000  11  07  00   21.00  -81.00     4     110   1E+30   1E+30   1E+30   1E+30   1E+30   1E+30   1E+30   10000
  2000  11  07  06   21.00  -81.00     4     115   1E+30   1E+30   1E+30   1E+30   1E+30   1E+30   1E+30    9000
  2000  11  07  12   21.00  -81.00     4     120   1E+30   1E+30   1E+30   1E+30   1E+30   1E+30   1E+30    9000
  2000  11  07  18   21.00  -80.00     4     125   1E+30   1E+30   1E+30   1E+30   1E+30   1E+30   1E+30    8000
  2000  11  08  00   20.00  -80.00     4     130   1E+30   1E+30   1E+30   1E+30   1E+30   1E+30   1E+30    7000
  2000  11  08  06   20.00  -80.00     4     135   1E+30   1E+30   1E+30   1E+30   1E+30   1E+30   1E+30    6000
  2000  11  08  12   19.00  -80.00     4     140   1E+30   1E+30   1E+30   1E+30   1E+30   1E+30   1E+30    5000
  2000  11  08  18   19.00  -80.00     4     145   1E+30   1E+30   1E+30   1E+30   1E+30   1E+30   1E+30    4000
  2000  11  09  00   18.00  -79.00     4     150   1E+30   1E+30   1E+30   1E+30   1E+30   1E+30   1E+30    3000

Executing model run

This activity runs the model (wes.exe) in the workdir containing the model files with the input file names as arguments. The model creates the output file wes_input.spw which contains the grid information for FEWS (and the output file wes_input_wes.dia which is not used yet).

module run execute activity
			<executeActivity>
				<command>
					<executable>wes.exe</executable>
				</command>
				<arguments>
					<argument>wes_input.inp</argument>
				</arguments>
				<timeOut>99999999</timeOut>
				<ignoreDiagnostics>true</ignoreDiagnostics>
			</executeActivity>

Executing post adapter

Converts model output (wes_input.spw) in spiderweb grid format to fews netcdf rotated pole grid format, for each time step a seperate netcdf file is created because each time step has a seperate grid definition.

The post adapter writes log messages to log file called wes.log which can be read into FEWS by coupling line patterns to FEWS log messages.

post adapter execute activity
			<executeActivity>
				<command>
					<className>nl.deltares.wes.post.WesPostAdapter</className>
					<binDir>adapter\bin</binDir>
				</command>
				<arguments>
					<argument>run.nc</argument>
				</arguments>
				<logFile>
					<file>wes.log</file>
					<errorLinePattern>ERROR*</errorLinePattern>
					<warningLinePattern>WARN*</warningLinePattern>
					<infoLinePattern>INFO*</infoLinePattern>
					<debugLinePattern>DEBUG*</debugLinePattern>
				</logFile>
				<timeOut>99999999</timeOut>
				<ignoreDiagnostics>true</ignoreDiagnostics>
			</executeActivity>

Importing post adapter output

The last part of the general adapter run is importing the post adapter output. It uses <folder> and <fileNamePattern> in order to import the netcdf files for each time step.

model run output import activity
		<importActivities>
			<importNetcdfActivity>
				<folder>workdir</folder>
				<fileNamePatternFilter>wes_grid_*.nc</fileNamePatternFilter>
				<timeSeriesSets>
					<timeSeriesSet>
						<moduleInstanceId>Run_WES_Import</moduleInstanceId>
						<valueType>grid</valueType>
						<parameterId>Wind.speed</parameterId>
						<locationId>WilmaTest21</locationId>
						<timeSeriesType>external historical</timeSeriesType>
						<timeStep unit="hour" multiplier="1"/>
						<readWriteMode>read complete forecast</readWriteMode>
					</timeSeriesSet>
				</timeSeriesSets>
			</importNetcdfActivity>
		</importActivities>
  • No labels