wolfhece.dike

Module Contents

class wolfhece.dike.DikeWolf(idx='', plotted=True, mapviewer=None, need_for_wx=False)[source]

Bases: wolfhece.drawing_obj.Element_To_Draw

Inheritance diagram of wolfhece.dike.DikeWolf

Base class of element to add into WolfMapViewer or another GUI

property mainOutputs_dict[source]

Get the main outputs of the simulation as a dictionary. Time [s] / Qin [m^3/s] / Btop_US [m] / Btop_DS [m] / z_b [m] / Qb [m^3/s] / z_s [m] / z_t [m] :return: dictionary containing the main outputs

property triangulation_dict[source]

Get the triangulation of the simulation. :return: dictionary containing the triangulation

run(store_dir=None)[source]

Run the dike breaching simulation. :param store_dir: Directory where the simulation will be run.

callback_apply()[source]

Callback function to apply changes made in the Wolf_Param window. Update the parameters in the dike object.

show_properties()[source]

Show properties window

hide_properties()[source]

Hide properties window

from_wp_to_dict(wolf_dict, dict_ref) dict[source]

Convert a Wolf_Param dictionary to a “normal” dictionary used as parameters dictionary in the pydike object + updates pydike attributes accordingly. ‘dict_ref’ used to rename keys (=mapping). :param wolf_dict: Dictionary containing the parameters from the Wolf_Param object. :param dict_ref: Dictionary mapping pydike parameter names (keys) to explicit names in wolf_param. :return: Dictionary with pydike parameter names as keys, containing values and metadata.

from_dict_to_wp(params_dict) wolfhece.PyParams.Wolf_Param[source]

Modify the Wolf_Param object to represent the dike parameters.

load_results()[source]

Load the main outputs and/or the triangulation of the simulation.

set_series(mainOutputs_dict)[source]

Set the main outputs in the dike object.

set_triangulation(triangulation_dict)[source]

Set the triangulation in the dike object.

show_triangulation()[source]

Plot a graph that shows the dike triangulation.

extract_triangulation(time_idx: int) dict[source]

Extract the triangulation for a specific time index. :param time_idx: Time index to extract the triangulation. :return: Triangulation object.

plot_mainOutputs(output_type: int)[source]
save()[source]

Save the parameters in a .json text file

save_as()[source]

Save the parameters in a .json text file

get_params()[source]

Get the parameters of the dike model :return: dictionary containing the parameters

read_params(file_name: str, store_dir: pathlib.Path = None)[source]

Read the model parameters and store them in a dictionary + updates attributes accordingly :param file_name: name of the file to read :param store_dir: directory where to read the file

class wolfhece.dike.Wolf_Param_dike(parent=None, title=_('Default Title'), w=500, h=800, ontop=False, to_read=True, filename='', withbuttons=True, DestroyAtClosing=True, toShow=True, init_GUI=True, force_even_if_same_default=False, toolbar=True)[source]

Bases: wolfhece.PyParams.Wolf_Param

Inheritance diagram of wolfhece.dike.Wolf_Param_dike
FR

Gestion des paramètres au format WOLF.

Fichier texte

Les fichiers ‘.param’ sont des fichiers texte contenant des paramètres de type nom=valeur et compatibles avec les codes Fortran. L’extension ‘.param.default’ est utilisée pour stocker les paramètres par défaut.

Une autre extension est possible mais un fichier ‘.default’ sera créé automatiquement si ce fichier n’existe pas.

Le séparateur (nom, valeur, commentaire) est la tabulation ‘ ‘. Aucun autre caractère ne doit être utilisé comme séparateur.

Les groupes sont définis par un nom suivi de ‘:’. Cela signifie que ‘:’ ne peut pas être utilisé dans un nom de paramètre.

Les lignes débutant par ‘%’ sont des commentaires. Il est possible d’ajouter du code JSON dans un commentaire. Pour cela, il faut ajouter ‘%json’ au début de la ligne suivi d’un dictionnaire (e.g. %json{“Values”:{‘key1’:1, ‘key2’:2}, “Full_Comment”:”fullcomment”} ).

Organisation Python

L’objet Python est basé sur des dictionnaires Python. Un dictionnaire par groupe de paramètres.

Les paramètres sont donc stockés dans un dictionnaire de dictionnaires. Le premier niveau est le nom du groupe, le second niveau est le nom du paramètre.

Les paramètres disposent des clés suivantes :
  • name : nom du paramètre (str)

  • type : type du paramètre (str) – see Type_Param

  • value : valeur du paramètre (str) – peut être converti dynamiquement en int, float, bool, str, … sur base du type

  • comment : commentaire du paramètre (str) – helpful to understand the parameter

  • added_json : dictionnaire contenant des informations supplémentaires (optionnel) – permet de stocker des informations supplémentaires sur le paramètre (ex : valeurs possibles, commentaires étendus, …)

Dictionnaires

Il existe un dictionnaire de valeurs par défaut “myparams_default”. Pour l’interaction Python-Fortran, c’est le Fortran qui écrit ces paramètres. Il existe un dictionnaire de paramètres actifs “myparams”. Il est utilisé pour stocker les paramètres modifiés par l’utilisateur. Normalement, seuls les paramètres modifiés par l’utilisateur sont stockés dans ce dictionnaire et sont écrits sur disque.

Groupe/Paramètre incrémentable

Il est également possible de définir des groupes ou des paramètres incrémentables. Pour cela, dans le nom du groupe/paramètre, il faut ajouter, à l’emplacement souhaité du numéro du groupe/paramètre, des informations entre ‘$…$’ :

  • groupname : nom du groupe (uniquement pour groupe incrémentable)

  • paramname : nom du paramètre contenant le nombre de groupe/paramètre

  • min : valeur minimale

  • max : valeur maximale

Le nombre de groupes est ainsi défini par le couple (key:value) = (groupname:paramname). Le nombre de groupes doit donc être logiquement positionné dans un groupe distinct. Le nombre de paramètres est ainsi défini par le paramètre “paramname” qui est attendu dans le groupe contenant le paramètre incrémentable. Le nombre de groupes/paramètres est un entier compris entre ‘min’ et ‘max’.

Les informations génériques sont stockées dans les dictionnaires “myIncGroup” et “myIncParam”.

UI

Une interface graphique est disponible pour modifier les paramètres. Elle est basée sur “wxPython” et la classe “wxPropertyGrid”. L’attribut wx_exists permet de savoir si wxPython est en cours d’excution ou non.

Accès aux données

Les paramètres sont accessibles via la procédure __getitem__ en fournissant un tuple (groupname, paramname). Il est possible de modifier un paramètre via la procédure __setitem__.

Il est possible :
  • d’ajoutrer un groupe via la procédure add_group. Pour un groupe incrémentabe, le nom doit contenir les infos génériques entre ‘$…$’.

  • d’ajouter un paramètre ou un paramètre incrémentable via la procédure addparam :
    • pour un paramètre classique en choisissant le dictionnaire cible [‘All’, ‘Default’, ‘Active’, ‘IncGroup’, ‘’]
      • ‘’ == ‘Active’

      • ‘All’ == ‘Default’ + ‘Active’

      • ‘IncGroup’ pour ajouter un paramètre au template du groupe incrémentable –> sera dupliqué lors de la MAJ du nompbre réel de groupes

    • pour un paramètre incrémentable, en fournissant les données nécessaires dans une chaîne $n(refname,min,max)$ ou $n(groupname,refname,min,max)$

    • si le groupe visé n’existe pas, il sera créé si toutes les infos sont disponibles.

  • d’ajouter seulement un paramètre incrémentable via la procédure add_IncParam.

EN

Management of parameters in WOLF format.

Text File

‘.param’ files are text files containing parameters in the name=value format and compatible with Fortran codes. The ‘.param.default’ extension is used to store default parameters.

Another extension is possible, but a ‘.default’ file will be automatically created if this file does not exist.

The separator (name, value, comment) is the tab character ‘ ‘. No other character should be used as a separator.

Groups are defined by a name followed by ‘:’. This means that ‘:’ cannot be used in a parameter name.

Lines starting with ‘%’ are comments. It is possible to add JSON code in a comment. To do this, add ‘%json’ at the beginning of the line followed by a dictionary (e.g., %json{“Values”:{‘key1’:1, ‘key2’:2}, “Full_Comment”:”fullcomment”}).

Python Organization

The Python object is based on Python dictionaries. One dictionary per parameter group.

Therefore, parameters are stored in a dictionary of dictionaries. The first level is the group name, and the second level is the parameter name.

Parameters have the following keys:
  • name: parameter name (str)

  • type: parameter type (str) – see Type_Param

  • value: parameter value (str) – can be dynamically converted to int, float, bool, str, … based on the type

  • comment: parameter comment (str) – helpful to understand the parameter

  • added_json: dictionary containing additional information (optional) – used to store additional information about the parameter (e.g., possible values, extended comments, …)

Dictionaries

There is a default values dictionary “myparams_default.” For Python-Fortran interaction, Fortran writes these parameters. There is an active parameters dictionary “myparams.” It is used to store parameters modified by the user. Normally, only parameters modified by the user are stored in this dictionary and written to disk.

Incrementable Group/Parameter

It is also possible to define incrementable groups or parameters. To do this, in the group/parameter name, add information between ‘$…$’ at the desired number location of the group/parameter:

  • groupname: group name (only for incrementable group)

  • paramname: parameter name containing the group/parameter number

  • min: minimum value

  • max: maximum value

The number of groups is defined by the (key:value) pair (groupname:paramname). The number of groups must logically be positioned in a distinct group. The number of parameters is defined by the “paramname” parameter expected in the group containing the incrementable parameter. The number of groups/parameters is an integer between ‘min’ and ‘max’.

Generic information is stored in the “myIncGroup” and “myIncParam” dictionaries.

UI

A graphical interface is available to modify parameters. It is based on “wxPython” and the “wxPropertyGrid” class. The wx_exists attribute indicates whether wxPython is currently running or not.

Data Access

Parameters are accessible via the __getitem__ method by providing a tuple (groupname, paramname). It is possible to modify a parameter via the __setitem__ method.

It is possible to:
  • add a group via the add_group method. For an incrementable group, the name must contain generic information between ‘$…$’.

  • add a parameter or an incrementable parameter via the addparam method:
    • for a regular parameter by choosing the target dictionary [‘All’, ‘Default’, ‘Active’, ‘IncGroup’, ‘’]
      • ‘’ == ‘Active’

      • ‘All’ == ‘Default’ + ‘Active’

      • ‘IncGroup’ to add a parameter to the template of the incrementable group –> will be duplicated when updating the actual number of groups

    • for an incrementable parameter, by providing the necessary data in a string $n(refname,min,max)$ or $n(groupname,refname,min,max)$

    • if the targeted group does not exist, it will be created if all information is available.

  • only add an incrementable parameter via the add_IncParam method.

_set_gui_dike(parent: wx.Window = None, title: str = _('Default Title'), w: int = 500, h: int = 800, ontop: bool = False, to_read: bool = True, withbuttons: bool = True, DestroyAtClosing: bool = False, toShow: bool = True, full_style=False, toolbar: bool = True)[source]

Set the GUI if wxPython is running. This function is specifically dedicated to the creation of a dike object.

Gui is based on wxPropertyGridManager.

On the left, there is a group of buttons to load, save, apply or reload the parameters. On the right, there is the wxPropertyGridManager for the default and active parameters. Active parameters are displayed in bold.

To activate a parameter, double-click on it in the default tab. It will be copied to the active tab and the value will be modifiable.

:param parent : parent frame :param title : title of the frame :param w : width of the frame :param h : height of the frame :param ontop : if True, the frame will be on top of all other windows :param to_read : if True, the file will be read :param withbuttons : if True, buttons will be displayed :param DestroyAtClosing : if True, the frame will be destroyed when closed :param toShow : if True, the frame will be displayed :param full_style : if True, the full style of the PropertyGridManager will be displayed even if ontop is True

LoadFromFile_json(event: wx.MouseEvent)[source]

Load parameters from file

update_param_window(params_dict, whichdict) wolfhece.PyParams.Wolf_Param[source]

Transforms a params_dict into a Wolf_Param object to fill the ‘whichdict’ page of the parameters window. :param params_dict: dictionary containing the parameters :param whichdict: dictionary to fill (default or active)

merge_dicts(dict_new=None, dict_ref=None)[source]

Merge values of dict_new into dict_ref.