Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Info

This is a tutorial of level 'beginner'. If you have not done so already, familiarise familiarize yourself with the DeltaShell User interface here before starting this tutorial.

This tutorial requires no knowledge of Python.

 

This tutorial is for users that want to run many computations automatically in a batch run.

Step-by-step guide

 

. We are going to make use of the console interface of DeltaShell, a .bat script and a single Python script to do so. Finally we will discuss some ways in which this simple set-up can be expanded to more elaborate batch schemes.

This tutorial assumes that you have a SOBEK 3 model at your disposal. If you have not, follow this tutorial first to build one.

Running a single model using only the command line in three easy steps

  1. Navigate to the directory in which you model (*.dsproj) is located. If you have no model, follow this tutorial first to build one.
  2. Create a new .bat file in the same directory with your favorite text editor. In the bat file, enter 1 line using the following syntax: Path_To_DSConsole -p path_to_dsproj -f path_toscript. For example:

    Code Block
    languagepowershell
    themeDJango
    firstline1
    titleRunModel.bat
    linenumberstrue
    "d:\software\SOBEK (3.4.0.32140)\bin\DeltaShell.Console.exe" -s -p SingleChannel.dsproj -r "water flow 1d" >> output.txt

    This script consists of the following items:

    • '(....)\bin\DeltaShell.Console.exe' is the path to DeltaShell's console interface. For more information on this interface, please check the 'Command Line and Scripting' chapter of the DeltaShell User Manual.

    • "-s" This tells DeltaShell to not lead standard Python libraries (we don't need them, so this reduces the start-up time)
    • '-p *.dsproj' This tells DeltaShell to load a project

    • '-r "water flow 1d"'  This tells DeltaShell to execute a model within the loaded project

    • >> output.txt The output of the bat script will be written to file, instead echoed to the command prompt

  3. Save the .bat script and run it by double clicking on the file. Your model should now run! The command prompt will automatically close after the model run has finished. Check 'output.txt' if the model run was succesful. If it was, it should say 'normal end of sobeksim'.

Running a single model using a Python script in four easy steps

Alternatively, we can use a Python script to run the model. While this does bring a little extra overhead (although generally not significant compared to model run times), it does allow us to expand our options quite a bit. In this tutorial we will show you the 'bare basics'. In the next one, we will take it one step further.

  1. Navigate to the directory in which you model (*.dsproj) is located. If you have no model, follow this tutorial first to build one.
  2. Create a new .bat file in the same directory with your favorite text editor. In the bat file, enter 1 line using the following syntax: Path_To_DSConsole -p path_to_dsproj -f path_toscript. For example:

    Code Block
    languagepowershell
    themeConfluence
    firstline1
    titleRunModel.bat
    linenumberstrue
    "d:\software\SOBEK (3.4.0.32140)\bin\DeltaShell.Console.exe" -p SingleChannel.dsproj -f "RunModel.py" >> output.txt

    This script consists of the following items:

    • '(....)\bin\DeltaShell.Console.exe' is the path to DeltaShell's console interface. For more information on this interface, please check the 'Command Line and Scripting' chapter of the DeltaShell User Manual.

    • '-p *.dsproj' This tells DeltaShell to load a project

    • '-f RunModel.py'  This tells DeltaShell to execute a Python Script. We will write this script in the next step

    • >> output.txt The output of the bat script will be written to file, instead echoed to the command prompt

  3. Create a new Python file with your favorite text editor and copy-paste the following code. Note, you need the package 'ModellerFunctions' - available from OpenEarth - to run the code below:

    Code Block
    languagepy
    firstline1
    titleRunModel.py
    linenumberstrue
    collapsetrue
    from ModellerFunctions import dsget
    
    # Load the integrated model
    model = dsget.GetIntegratedModel()
    
    # Run, save and close
    Application.RunActivity(model)
    Application.SaveProject()
    Application.CloseProject()
  4. Save the .bat script and run it by double clicking on the file. Your model should now run! The command prompt will automatically close after the model run has finished. Check 'output.txt' if the model run was succesful. If it was, it should say 'normal end of sobeksim'.

...

Content by Label
showLabelsfalse
max5
spacesSobek
showSpacefalse
sortmodified
showSpacefalse
reversetrue
typepage
cqllabel in ("tut-scripting","tutorial") and type = "page" and space = "Sobek"
labelstutorial tut-scripting