Skip to content

Command Module#

The Command module serves as the main entry point for the D-FAST Bank Erosion software, handling command-line arguments and orchestrating the execution of the different operational modes.

Overview#

The Command module provides the interface between the user (via command-line or GUI) and the core functionality of the D-FAST Bank Erosion software. It parses command-line arguments, initializes the appropriate language settings, and launches the requested operational mode (BANKLINES, BANKEROSION, or GUI).

Components#

The Command module consists of the following components:

Run Function#

dfastbe.cmd #

Copyright (C) 2020 Stichting Deltares.

This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation version 2.1.

This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.

You should have received a copy of the GNU Lesser General Public License along with this library; if not, see http://www.gnu.org/licenses/.

contact: delft3d.support@deltares.nl Stichting Deltares P.O. Box 177 2600 MH Delft, The Netherlands

All indications and logos of, and references to, "Delft3D" and "Deltares" are registered trademarks of Stichting Deltares, and remain the property of Stichting Deltares. All rights reserved.

INFORMATION This file is part of D-FAST Bank Erosion: https://github.com/Deltares/D-FAST_Bank_Erosion

run(language: str = 'UK', run_mode: str = 'GUI', configfile: str = 'dfastbe.cfg') -> None #

Initializes the language file and starts the chosen run mode.

This function loads the appropriate language file and executes one of the available modes: 'BANKLINES', 'BANKEROSION', or 'GUI'. The default configuration file is dfastbe.cfg.

Parameters:

Name Type Description Default
language str

Display language code. Acceptable values are 'NL' (Dutch) or 'UK' (English). Defaults to 'UK'.

'UK'
run_mode str

Mode in which the program should run. Available options:

  • 'BANKLINES': Runs the bank lines processing.
  • 'BANKEROSION': Runs the bank erosion processing.
  • 'GUI': Launches the graphical user interface.

Defaults to 'GUI'.

'GUI'
configfile str

Path to the configuration file. Defaults to 'dfastbe.cfg'.

'dfastbe.cfg'

Raises:

Type Description
Exception

If an invalid run_mode is provided. The valid options are 'BANKLINES', 'BANKEROSION', or 'GUI'.

Example

Running the program with Dutch language and bank erosion mode:

run(language="NL", run_mode="BANKEROSION", configfile="custom_config.cfg")

Running the program in default mode (GUI) with the English language:

run()
Source code in src/dfastbe/cmd.py
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
def run(
    language: str = "UK",
    run_mode: str = "GUI",
    configfile: str = "dfastbe.cfg",
) -> None:
    """
    Initializes the language file and starts the chosen run mode.

    This function loads the appropriate language file and executes one of the
    available modes: 'BANKLINES', 'BANKEROSION', or 'GUI'. The default configuration
    file is `dfastbe.cfg`.

    Args:
        language (str, optional):
            Display language code. Acceptable values are 'NL' (Dutch) or 'UK' (English).
            Defaults to 'UK'.
        run_mode (str, optional):
            Mode in which the program should run. Available options:

            - 'BANKLINES': Runs the bank lines processing.
            - 'BANKEROSION': Runs the bank erosion processing.
            - 'GUI': Launches the graphical user interface.

            Defaults to 'GUI'.
        configfile (str, optional):
            Path to the configuration file. Defaults to 'dfastbe.cfg'.

    Raises:
        Exception: If an invalid `run_mode` is provided. The valid options are
            'BANKLINES', 'BANKEROSION', or 'GUI'.

    Example:
        Running the program with Dutch language and bank erosion mode:

        ```python
        run(language="NL", run_mode="BANKEROSION", configfile="custom_config.cfg")
        ```

        Running the program in default mode (GUI) with the English language:

        ```python
        run()
        ```
    """
    language = language.upper()
    load_program_texts( LOG_DATA_DIR / f"messages.{language}.ini")
    run_mode = run_mode.upper()

    if run_mode == "GUI":
        main(configfile)
    else:
        config_file = ConfigFile.read(configfile)

        if run_mode == "BANKLINES":
            bank_lines = BankLines(config_file)
            bank_lines.detect()
        elif run_mode == "BANKEROSION":
            erosion = Erosion(config_file)
            erosion.run()
        else:
            raise ValueError(f"Invalid run mode {run_mode} specified. Should read 'BANKLINES', 'BANKEROSION' or 'GUI'.")

The run function is the main entry point for the D-FAST Bank Erosion software. It initializes the language settings and launches the requested operational mode.

Operational Modes#

The D-FAST Bank Erosion software supports three operational modes:

  1. BANKLINES: Detects bank lines from hydrodynamic simulation results
  2. BANKEROSION: Calculates bank erosion based on detected bank lines and hydrodynamic data
  3. GUI: Provides a graphical user interface for configuring and running the above processes

Workflow#

The typical workflow for using the Command module is:

  1. Call the run function with the desired language, run mode, and configuration file
  2. The run function initializes the language settings
  3. Depending on the run mode, the run function:
  4. Launches the GUI
  5. Runs bank line detection
  6. Runs bank erosion calculation

Usage Example#

from dfastbe.cmd import run

# Run in GUI mode with English language
run(language="UK", run_mode="GUI", configfile="config.cfg")

# Run bank line detection with Dutch language
run(language="NL", run_mode="BANKLINES", configfile="config.cfg")

# Run bank erosion calculation with English language
run(language="UK", run_mode="BANKEROSION", configfile="config.cfg")

For more details on the specific functions, refer to the API reference below.