Skip to article frontmatterSkip to article content
Site not loading correctly?

This may be due to an incorrect BASE_URL configuration. See the MyST Documentation for reference.

Functions

The pyprodrisk python package contains some functions and properties in addition to the objects and attributes defined in the inner layer of the API. The entire code of the python package can be viewed in the open pyprodrisk repository.

A Prodrisk session has the following member functions:

Further functions are available through member objects:

In addition, in some special cases, you may have use for low-level advanced functions.

ProdriskSession (constructor)

A new ProdriskSession instance must be created for each simulation by calling the constructor:

set_optimization_period

Set the start date and time and the horizon of the simulation. This function must be called before time-dependent input can be set. It is recommended to call this function immediately after the constructor. Afterwards, the properties start_time, end_time, and n_weeks are available. If the start date includes a timezone, this will automatically be the base timezone of the Prodrisk session.

dump_model_yaml

Dump the static model to a yaml file. The routine loops over all objects and attributes and stores either input, output, or both input and output. All time series and large arrays (type xy_array) are ignored, as they are not suitable for storage in yaml format. Use this function together with dump_data_h5 and dump_cuts_h5 to dump the entire session.

dump_data_h5

Dump time series and large arrays (except cuts) from a session to an HDF5 file, where either input, output, or both input and output can be exported. Use this function together with dump_model_yaml and dump_cuts_h5 to dump the entire session.

dump_cuts_h5

Dump all cuts from the session to an HDF5 file. Use this function together with dump_model_yaml and dump_data_h5 to dump the entire session.

load_model_yaml

Load the static model from a yaml file which was created by dump_model_yaml. Use this function together with load_data_h5 and load_cuts_h5 to load an entire session.

load_data_h5

Load time series and large arrays (except cuts) from a session to an HDF5 file which was created by dump_data_h5. Use this function together with load_model_yaml and load_cuts_h5 to load an entire session.

load_cuts_h5

Load all cuts from the session to an HDF5 file which was created by dump_cuts_h5. Use this function together with load_model_yaml and load_data_h5 to dump the entire session.

plot_topology

Create a graph that schematically visualizes the watercourse, including some key numbers for the modules. This function depends on matplotlib and scipy and requires the installation of pyprodrisk with the [full] option.

run

Run the Prodrisk simulation:

  1. The files needed by the Prodrisk core are written to the temporary run directory of the session.

  2. Genpris is executed in the temporary run directory.

  3. Prodrisk is executed in the temporary run directory.

  4. Results are read from the result files created by the Prodrisk core inside the temporary run directory.

Destructor

When a ProdriskSession instance is destructed, the temporary run directory is deleted, unless keepWorkingDirectory was set to True. Python handles the destruction of expired objects automatically, so you will never call the destructor yourself. Just be aware that the lifetime of temporary files is linked to the session object.

add_object

Add a new object to the session.

get_object_names

Get a list of all names of objects of a certain type.

set

Set the value of an input attribute.

get

Get the current value of any attribute.

info

Get meta data of an attribute. The same information can also be found in the attribute table.

help

Get the description of an attribute. The same information can also be found in the attribute table.

build_connection_tree

A rudimentary tool to visualize the topology of the watercourse.

Properties

API core functions

These are “expert functions” from the API core. You will typically not need those, but we list some of them that provide functionality that is not yet accessible on the level of the ProdriskSession.