epanet_plus
epanet_plus.epanet_wrapper
This module contains a Python wrapper (incl. error handling) for EPANET and EPANET-MSX functions.
- class epanet_plus.epanet_wrapper.EpanetAPI(use_project: bool = False, raise_exception_on_error: bool = True, warn_on_error: bool = False, ignore_error_codes: list[int] = [])[source]
Bases:
objectInterface for EPANET and EPANET-MSX functions, incl. a proper error handling.
- Parameters:
use_project (bool, optional) –
If True, projects will be used when calling EPANET functions (default in EPANET >= 2.2). Note that this is incompatible with EPANET-MSX. Please set to False when using EPANET-MSX.
The default is False.
raise_on_error (bool, optional) –
True if an exception should be raised in the case of an error/warning, False otherwise.
The default is True.
warn_on_error (bool, optional) –
True if a warning should be generated in the case of an error/warning, False otherwise.
The default is False.
ignore_error_codes (list[int], optional) –
List of error codes that should be ignored – i.e., no exception or warning will be generated.
The default is an empty list.
- MSXENopen(inp_file: str, rpt_file: str, out_file: str)[source]
- Parameters:
inp_file (str)
rpt_file (str)
out_file (str)
- MSXgetinitqual(item_type: int, index: int, species: int)[source]
- Parameters:
item_type (int)
index (int)
species (int)
- MSXgetparameter(item_type: int, index: int, param: int)[source]
- Parameters:
item_type (int)
index (int)
param (int)
- MSXgetqual(item_type: int, index: int, species: int)[source]
- Parameters:
item_type (int)
index (int)
species (int)
- MSXsetinitqual(item_type: int, index: int, species: int, value: float)[source]
- Parameters:
item_type (int)
index (int)
species (int)
value (float)
- MSXsetparameter(item_type: int, index: int, param: int, value: float)[source]
- Parameters:
item_type (int)
index (int)
param (int)
value (float)
- MSXsetpattern(pat: int, mult: list[float], len: int)[source]
- Parameters:
pat (int)
mult (list[float])
len (int)
- MSXsetpatternvalue(pat: int, period: int, value: float)[source]
- Parameters:
pat (int)
period (int)
value (float)
- MSXsetsource(node: int, species: int, item_type: int, level: float, pat: int)[source]
- Parameters:
node (int)
species (int)
item_type (int)
level (float)
pat (int)
- addcontrol(type: int, link_index: int, setting: float, node_index: int, level: float)[source]
EN_addcontrol
- Parameters:
type (int)
link_index (int)
setting (float)
int (node_index .)
level (float)
- adddemand(node_index: int, base_demand: float, demand_pattern: str, demand_name: str)[source]
EN_adddemand
node_index : int base_demand : float demand_pattern : str demand_name : str
- addlink(id: str, link_type: int, from_node: str, to_node: str)[source]
EN_addlink
- Parameters:
id (str)
link_type (int)
from_node (str)
to_node (str)
- deletedemand(node_index: int, demand_index: int)[source]
EN_deletedemand
- Parameters:
node_index (int)
demand_index (int)
- deletelink(index: int, action_code: int)[source]
EN_deletelink
- Parameters:
index (int)
action_code (int)
- deletenode(index: int, action_code: int)[source]
EN_deletenode
- Parameters:
index (int)
action_code (int)
- get_last_error_code() int[source]
Returns the code of the last EPANET-(MSX) error/warnning (if any).
Refer to the EPANET documentation for a list of all possible warning codes and their meanings.
- Returns:
Code of the last error/warning. 0, if there was no error/warning.
- Return type:
int
- get_last_error_desc() str[source]
Returns the description of the last EPANET-(MSX) error/warning (if any).
- Returns:
Description of the last error/warning. None, if there was no error/warning.
- Return type:
str
- getbasedemand(node_index: int, demand_index: int)[source]
EN_getbasedemand
- Parameters:
node_index (int)
demand_index (int)
- getcurvevalue(curve_index: int, point_index: int)[source]
EN_getcurvevalue
- Parameters:
curve_index (int)
point_index (int)
- getdemandindex(node_index: int, demand_name: str)[source]
EN_getdemandindex
- Parameters:
node_index (int)
demand_name (str)
- getdemandname(node_index: int, demand_index: int)[source]
EN_getdemandname
- Parameters:
node_index (int)
demand_index (int)
- getdemandpattern(node_index: int, demand_index: int)[source]
EN_getdemandpattern
- Parameters:
node_index (int)
demand_index (int)
- getelseaction(rule_index: int, action_index: int)[source]
EN_getelseaction
- Parameters:
rule_index (int)
action_index (int)
- getlinkvalue(index: int, property: int)[source]
EN_getlinkvalue
- Parameters:
index (int)
property (int)
- getnodevalue(index: int, node_property: int)[source]
EN_getnodevalue
- Parameters:
index (int)
node_property (int)
- getpatternvalue(index: int, period: int)[source]
EN_getpatternvalue
- Parameters:
index (int)
period (int)
- getpremise(rule_index: int, premise_index: int)[source]
EN_getpremise
- Parameters:
rule_index (int)
premise_index (int)
- getresultindex(result_type: int, index: int)[source]
EN_getresultindex
- Parameters:
result_type (int)
index (int)
- getthenaction(rule_index: int, action_index: int)[source]
EN_getthenaction
- Parameters:
rule_index (int)
action_index (int)
- init(rptFile: str, outFile: str, unitsType: int, headLossType: int)[source]
EN_init
- Parameters:
rptFile (str)
outFile (str)
unitsType (int)
headLossType (int)
- loadpatternfile(filename: str, id: str)[source]
EN_loadpatternfile
- Parameters:
filename (str)
id (str)
- open(inpFile: str, rptFile: str, outFile: str)[source]
EN_open
- Parameters:
inpFile (str)
rptFile (str)
outFile (str)
- openX(inpFile: str, rptFile: str, outFile: str)[source]
EN_openX
- Parameters:
inpFile (str)
rptFile (str)
outFile (str)
- openfrombuffer(inpBuffer: str, inpFile: str, rptFile: str, outFile: str)[source]
EN_openfrombuffer – extension of EPANET and part of EPANET-PLUS
- Parameters:
inpBuffer (str)
inpFile (str)
rptFile (str)
outFile (str)
- property ph: int
Returns a pointer (memory address) to the project structure.
- Returns:
Pointer to project structure – please do not change or access the memory location!
- Return type:
int
- set_error_handling(raise_exception_on_error: bool, warn_on_error: bool, ignore_error_codes: list[int] = []) None[source]
Specifies the behavior in the case of an error/warning – i.e. should an exception or warning be raised or not?
- Parameters:
raise_exception_on_error (bool) – True if an exception should be raised, False otherwise.
warn_on_error (bool) – True if a warning should be generated, False otherwise.
ignore_error_codes (list[int]) – List of error codes that should be ignored – i.e., no exception or warning will be generated.
- setbasedemand(node_index: int, demand_index: int, base_demand: float)[source]
EN_setbasedemand
- Parameters:
node_index (int)
demand_index (int)
base_demand (float)
- setcomment(obj: int, index: int, comment: str)[source]
EN_setcomment
- Parameters:
obj (int)
index (int)
comment (str)
- setcontrol(index: int, type: int, link_index: int, setting: float, node_index: int, level: float)[source]
EN_setcontrol
- Parameters:
index (int)
type (int)
link_index (int)
setting (float)
node_index (int)
level (float)
- setcontrolenabled(control_idx: int, enabled: int)[source]
EN_setcontrolenabled
- Parameters:
control_idx (int)
enabled (int)
- setcoord(index: int, x: float, y: float)[source]
EN_setcoord
- Parameters:
index (int)
x (float)
y (float)
- setcurve(index: int, x_values: list[float], y_values: list[float], n_points: int)[source]
EN_setcurve
- Parameters:
index (int)
x_values (list[float])
y_values (list[float])
n_points (int)
- setcurvetype(curve_idx: int, curve_type: int)[source]
EN_setcurvetype
- Parameters:
curve_idx (int)
curve_type (int)
- setcurvevalue(curve_index: int, point_index: int, x: float, y: float)[source]
EN_setcurvevalue
- Parameters:
curve_index (int)
point_index (int)
x (float)
y (float)
- setdemandmodel(demand_type: int, pmin: float, preq: float, pexp: float)[source]
EN_setdemandmodel
- Parameters:
demand_type (int)
pmin (float)
preq (float)
pexp (float)
- setdemandname(node_index: int, demand_index: int, demand_name: str)[source]
EN_setdemandname
- Parameters:
node_index (int)
demand_index (int)
demand_name (str)
- setdemandpattern(node_index: int, demand_index: int, pat_index: int)[source]
EN_setdemandpattern
- Parameters:
node_index (int)
demand_index (int)
pat_index (int)
- setelseaction(rule_index: int, action_index: int, link_index: int, status: int, setting: float)[source]
EN_setelseaction
- Parameters:
rule_index (int)
action_index (int)
link_index (int)
status (int)
setting (float)
- setheadcurveindex(link_index: int, curve_index: int)[source]
EN_setheadcurveindex
- Parameters:
link_index (int)
curve_index (int)
- setjuncdata(index: int, elev: float, dmnd: float, dmnd_pat: str)[source]
EN_setjuncdata
- Parameters:
index (int)
elev (float)
dmnd (float)
dmdn_pat (float)
- setlinknodes(index: int, node1: int, node2: int)[source]
EN_setlinknodes
- Parameters:
index (int)
node1 (int)
node2 (int)
- setlinktype(index: int, link_type: int, action_code: int)[source]
EN_setlinktype
- Parameters:
index (int)
link_type (int)
action_code (int)
- setlinkvalue(index: int, property: int, value: float)[source]
EN_setlinkvalue
- Parameters:
index (int)
property (int)
value (float)
- setnodevalue(index: int, node_property: int, value: float)[source]
EN_setnodevalue
- Parameters:
index (int)
node_property (int)
value (float)
- setnodevaluse(node_property: int, values: list[float])[source]
EN_setnodevalues
- Parameters:
node_property (int)
values (list[float])
- setpattern(index: int, values: list[float], len: int)[source]
EN_setpattern
- Parameters:
index (int)
values (list[float])
len (int)
- setpatternvalue(index: int, period: int, value: float)[source]
EN_setpatternvalue
- Parameters:
index (int)
period (int)
value (float)
- setpipedata(index: int, length: float, diam: float, rough: float, mloss: float)[source]
EN_setpipedata
- Parameters:
index (int)
length (float)
diam (float)
rough (float)
mloss (float)
- setpremise(rule_index: int, premise_index: int, logop: int, object: int, obj_index: int, variable: int, relop: int, status: int, value: float)[source]
EN_setpremise
- Parameters:
rule_index (int)
premise_index (int)
logop (int)
object (int)
obj_index (int)
variable (int)
relop (int)
status (int)
value (float)
- setpremiseindex(rule_index: int, premise_index: int, obj_index: int)[source]
EN_setpremiseindex
- Parameters:
rule_index (int)
premise_index (int)
obj_index (int)
- setpremisestatus(rule_index: int, premise_index: int, status: int)[source]
EN_setpremisestatus
- Parameters:
rule_index (int)
premise_index (int)
status (int)
- setpremisevalue(rule_index: int, premise_index: int, value: float)[source]
EN_setpremisevalue
- Parameters:
rule_index (int)
premise_index (int)
value (float)
- setqualtype(qual_type: int, chem_name: str, chem_units: str, trace_node_id: str)[source]
EN_setqualtype
- Parameters:
qual_type (int)
chem_name (str)
chem_units (str)
trace_node_id (str)
- setruleenabled(rule_idx: int, enabled: int)[source]
EN_setruleenabled
- Parameters:
rule_idx (int)
enabled (int)
- setrulepriority(index: int, priority: float)[source]
EN_setrulepriority
- Parameters:
index (int)
priority (float)
- settag(obj_type: int, obj_idx: int, tag: str)[source]
EN_settag
- Parameters:
obj_type (int)
obj_idx (int)
tag (str)
- settankdata(index: int, elev: float, initlvl: float, minlvl: float, maxlvl: float, diam: float, minvol: float, volcurve: str)[source]
EN_settankdata
- Parameters:
index (int)
elev (float)
initlvl (float)
minlvl (float)
maxlvl (float)
diam (float)
minvol (float)
volcurve (str)
- setthenaction(rule_index: int, action_index: int, link_index: int, status: int, setting: float)[source]
EN_setthenaction
- Parameters:
rule_index (int)
action_index (int)
link_index (int)
status (int)
setting (float)
- settitle(line1: str, line2: str, line3: str)[source]
EN_settitle
- Parameters:
line1 (str)
line2 (str)
line3 (str)
- setvertex(link_idx: int, vertex_idx: int, x: float, y: float)[source]
EN_setvertex
- Parameters:
link_idx (int)
vertex_idx (int)
x (float)
y (float)
- setvertices(index: int, x: list[float], y: list[float], count: int)[source]
EN_setvertices
- Parameters:
index (int)
x (list[float])
y (list[float])
count (int)
- property use_project: bool
Returns whether EPANET projects are used or not.
- Returns:
True, if EPANET projects are used, False otherwise.
- Return type:
bool
epanet_plus.epanet_toolkit
This module contains a Python toolkit with higher-level functions for working with EPANET and EPANET-MSX.
- class epanet_plus.epanet_toolkit.EPyT(inp_file_in: str | None = None, msx_file_in: str | None = None, use_project: bool = False, inp_buffer: str | None = None, **kwds)[source]
Bases:
EpanetAPIPython toolkit for EPANET and EPANET-MSX.
- Parameters:
inp_file_in (str, optional) –
Path to .inp file. Note that the file will be created automatically if it does not exist.
If None, an empty network will be created in the temp folder.
The default is None.
msx_file_in (str, optional) –
Path to .msx file. If this is not None, use_project must be set to False.
The default is None.
use_project (bool, optional) –
If True, projects will be used when calling EPANET functions (default in EPANET >= 2.2). Note that this is incompatible with EPANET-MSX. Please set to False when using EPANET-MSX or when specifying an .msx file in msx_file_in.
The default is False.
inp_buffer (str, optional,) –
Buffer containing the network – i.e., content of an .inp file.
The default is None.
- add_control(control_type: int, link_index: int, setting: float, node_index: int, level: float) None[source]
Adds a control.
- Parameters:
control_type (int) –
Type of control. Must be one of the following:
EN_LOWLEVEL
EN_HILEVEL
EN_TIMER
EN_TIMEOFDAY
link_index (int) – Index of the link (i.e., valve or pump) that is being controlled.
setting (float) – Link control setting (e.g., pump speed).
node_index (int) – Index of the node that is controlling the link.
level (float) – Control activation level – pressure for junction nodes, water level for tank nodes or time value for time-based control.
- add_curve(curve_id: str, values: list[tuple[float, float]]) None[source]
Adds a new curve – e.g., a head curve for a pump or a volume curve for a (non-cylindric) tank.
- Parameters:
curve_id (str) – ID of the curve.
values (list[tuple[float, float]]) – Curve values/points.
- add_msx_pattern(pattern_id: str, pattern_mult: list[float]) None[source]
Adds a new MSX pattern.
- Parameters:
pattern_id (str) – ID of the new pattern.
pattern_mult (list[float]) – Pattern values (i.e., multipliers).
- add_pattern(pattern_id: str, pattern_values: list[float]) None[source]
Adds a new pattern.
- Parameters:
pattern_id (str) – ID of the pattern.
pattern_values (list[float]) – Pattern values.
- can_tank_overflow(tank_idx: int) bool[source]
Checks if a given tank can overflow or not.
- Parameters:
tank_idx (int) – Index of the tank.
- Returns:
True if the tank can overflow, False otherwise.
- Return type:
bool
- get_all_bulk_species_id() list[str][source]
Returns the IDs of all bulk species.
- Returns:
List of IDs.
- Return type:
list[int]
- get_all_bulk_species_idx() list[int][source]
Returns the indices of all bulk species.
- Returns:
List of indices.
- Return type:
list[int]
- get_all_junctions_id() list[str][source]
Returns all junction IDs – i.e., IDs of nodes that are neither a reservoir nor a tank.
- Returns:
List of all junction IDs.
- Return type:
list[str]
- get_all_junctions_idx() list[int][source]
Returns all junction indices – i.e., indices of nodes that are neither a reservoir nor a tank.
- Returns:
List of all junction indices.
- Return type:
list[int]
- get_all_links_connecting_nodes_id() list[tuple[str]][source]
Returns a list of all connecting node IDs for each link in the network.
- Returns:
List of tuple of connecting node IDs of all links.
- Return type:
list[tuple[str]]
- get_all_links_id() list[str][source]
Returns all link IDs.
- Returns:
List of all link IDs.
- Return type:
list[str]
- get_all_links_idx() list[int][source]
Returns all link indcies.
- Returns:
List of all link indices.
- Return type:
list[int]
- get_all_msx_pattern_id() list[str][source]
Returns a list of the IDs of all MSX patterns.
- Returns:
List of patterns (IDs).
- Return type:
list[str]
- get_all_msx_species_id() list[str][source]
Returns a list of all species IDs.
- Returns:
List of all species IDs.
- Return type:
list[str]
- get_all_msx_species_info() list[dict][source]
Returns information about all species.
- Returns:
List of species information – ordered by species index.# Each entry in the list contains a dictionary with the following entries:
’type’: MSX_BULK for a bulk flow species or MSX_WALL for a surface species;
’units’: mass units;
’atol’: absolute concentration tolerance (concentration units);
’rtol’: relative concentration tolerance (unitless);
- Return type:
list[dict]
- get_all_nodes_id() list[str][source]
Returns all node IDs.
- Returns:
List of node IDs.
- Return type:
list[str]
- get_all_nodes_idx() list[int][source]
Returns all node indices.
- Returns:
List of node indices:
- Return type:
list[int]
- get_all_patterns_id() list[str][source]
Returns a list of all pattern IDs.
- Returns:
List of IDs.
- Return type:
list[str]
- get_all_pipes_id() list[str][source]
Returns the IDs of all pipes in the network.
- Returns:
List of pipe IDs.
- Return type:
list[str]
- get_all_pipes_idx() list[int][source]
Return the indices of all pipes in the network.
- Returns:
List of pipe indices.
- Return type:
list[int]
- get_all_pumps_id() list[str][source]
Returns all pump IDs.
- Returns:
List of all pump IDs.
- Return type:
list[str]
- get_all_pumps_idx() list[int][source]
Returns all pump_indices.
- Returns:
List of all pump indices.
- Return type:
list[int]
- get_all_reservoirs_id() list[str][source]
Returns all reservoir IDs.
- Returns:
List of all reservoir IDs.
- Return type:
list[str]
- get_all_reservoirs_idx() list[int][source]
Returns all reservoir indices.
- Returns:
List of all reservoir indices.
- Return type:
list[int]
- get_all_rules_id() list[str][source]
Returns the IDs of all rules.
- Returns:
List of rule IDs – ordered by their index.
- Return type:
list[str]
- get_all_tanks_id() list[str][source]
Returns all tank IDs.
- Returns:
List of all tank IDs.
- Return type:
list[str]
- get_all_tanks_idx() list[int][source]
Returns all tank indices.
- Returns:
List of all tank indices.
- Return type:
list[int]
- get_all_valves_id() list[str][source]
Returns a list of all valve IDs.
- Returns:
List of all valve IDs.
- Return type:
list[str]
- get_all_valves_idx() list[int][source]
Returns all valve indices.
- Returns:
List of all valve indices.
- Return type:
list[int]
- get_all_wall_species_id() list[str][source]
Returns the IDs of all wall species.
- Returns:
List of IDs.
- Return type:
list[int]
- get_all_wall_species_idx() list[int][source]
Returns the indices of all wall species.
- Returns:
List of indices.
- Return type:
list[int]
- get_curve(curve_id: str) list[tuple[float, float]][source]
Returns the values/points of a given curve.
- Parameters:
curve_id (str) – ID of the curve.
- Returns:
List of all values/points of the curve.
- Return type:
list[tuple[float, float]]
- get_demand_model() dict[source]
Returns the specifications of the demand model.
- Returns:
Dictionary contains the specifications of the demand model:
’type’: type of demand model (either EN_DDA or EN_PDA);
’pmin’: minimum pressure for any demand;
’preq’: required pressure for full demand;
’pexp’: exponent in pressure dependent demand formula;
- Return type:
dict
- get_hydraulic_time_step() int[source]
Returns the hydraulic time step in seconds.
- Returns:
Hydraulic time step.
- Return type:
int
- get_limiting_concentration() float[source]
Returns the limiting concentration in reactions.
- Returns:
Limiting concentration.
- Return type:
float
- get_link_bulk_decay(link_idx: int) float[source]
Returns the bulk decay rate at a given link.
- Parameters:
link_idx (int) – Index of the link.
- Returns:
Bulk decay rate.
- Return type:
float
- get_link_bulk_reaction_coeff(link_idx: int) float[source]
Returns the bulk reaction coefficient of a link.
- Parameters:
link_idx (int) – Index of the link.
- Returns:
Bulk reaction coefficient.
- Return type:
float
- get_link_diameter(link_idx: int) float[source]
Returns the diameter of a given link.
- Parameters:
link_idx (int) – Index of the link.
- Returns:
Diameter of the link.
- Return type:
float
- get_link_flow(link_idx: int) float[source]
Returns the current flow rate at a given link.
- Parameters:
link_idx – Index of the link.
- Returns:
Current flow rate.
- Return type:
float
- get_link_id(link_idx) str[source]
Returns the ID of a given link.
- Parameters:
link_idx (int) – Index of the link.
- Returns:
ID of the link.
- Return type:
str
- get_link_idx(link_id: str) int[source]
Returns the index of a given link.
- Parameters:
link_id (str) – ID of the link.
- Returns:
Index of the link.
- Return type:
int
- get_link_init_setting(link_idx: int) float[source]
Returns the initial setting of a given link.
- Parameters:
link_idx (int) – Index of the link.
- Returns:
Initial setting.
- Return type:
float
- get_link_init_status(link_idx: int) int[source]
Returns the initial status (open or closed) of a given link.
- Parameters:
link_idx (int) – Index of the link.
- Returns:
Initial status of the link. Will be one of the following:
EN_CLOSED
EN_OPEN
- Return type:
int
- get_link_length(link_idx: int) float[source]
Returns the length of a given link.
- Parameters:
link_idx (int) – Index of the link.
- Returns:
Length of the link.
- Return type:
float
- get_link_minorloss(link_idx: int) float[source]
Returns the minor loss coefficient of a given link.
- Parameters:
link_idx (int) – Index of the link.
- Returns:
Minor loss coefficient of the link.
- Return type:
float
- get_link_quality(link_idx: int) float[source]
Returns the current quality value (e.g., concentration, age, …) at a given link.
- Parameters:
link_idx – Index of the link.
- Returns:
Current link quality value.
- Return type:
float
- get_link_roughness(link_idx: int) dict[source]
Returns the roughness coefficient of a given link.
- Parameters:
link_idx (int) – Index of the link.
- Returns:
Roughness coefficient of the link.
- Return type:
float
- get_link_type(link_idx: int) int[source]
Returns the type of a given link.
- Parameters:
link_idx (int) – Index of the link.
- Returns:
Type of the link. Will be one of the following:
EN_CVPIPE
EN_PIPE
EN_PUMP
EN_PRV
EN_PSV
EN_PBV
EN_FCV
EN_TCV
EN_GPV
- Return type:
int
- get_link_wall_decay(link_idx: int) float[source]
Returns the wall decay rate at a given link.
- Parameters:
link_idx (int) – Index of the link.
- Returns:
Wall decay rate.
- Return type:
float
- get_link_wall_reaction_coeff(link_idx: int) float[source]
Returns the wall reaction coefficient of a given link.
- Parameters:
link_idx (int) – Index of the link.
- Returns:
Wall reaction coefficient.
- Return type:
float
- get_msx_options() dict[source]
Returns the MSX options as specified in the .msx file.
- Returns:
Dictionary of MSX options as specified in the .msx file – note that not all options might be specified. Possible options (dictinary keys) are: REA_UNITS, RATE_UNITS, SOLVER, COUPLING, TIMESTEP, ATOL, RTOL, COMPILER, SEGMENTS, PECLET
- Return type:
dict
- get_msx_pattern(pattern_idx: int) list[float][source]
Returns a particular MSX pattern – i.e., returns the multipliers.
- Parameters:
pattern_idx (int) – Index of the pattern.
- Returns:
Pattern multipliers.
- Return type:
list[float]
- get_msx_species_concentration(obj_type: int, obj_index: int, species_idx: int) float[source]
Returns the current concentration of a given species at a given location in the network.
- Parameters:
obj_type (int) –
Type of the location (i.e., node or link). Must be one of the following:
MSX_NODE
MSX_LINK
obj_index (int) – Index of the link or node.
species_idx (int) – Index of the species.
- Returns:
Species concentration.
- Return type:
float
- get_msx_species_idx(species_id) int[source]
Returns the index of a given species.
- Parameters:
species_id (str) – ID of the species.
- Returns:
Index of the species.
- Return type:
int
- get_msx_species_info(species_idx: int) dict[source]
Returns information about a given species.
- Parameters:
species_idx (int) – Index of the species.
- Returns:
Information as a dictionary. Will contains the following entries:
’type’: MSX_BULK for a bulk flow species or MSX_WALL for a surface species;
’units’: mass units;
’atol’: absolute concentration tolerance (concentration units);
’rtol’: relative concentration tolerance (unitless);
- Return type:
dict
- get_msx_species_init_concentration(obj_type: int, obj_index: int, species_idx: int) float[source]
Returns the initial concentration of a given species at a given location in the network.
- Parameters:
obj_type (int) –
Type of the location (i.e., node or link). Must be one of the following:
MSX_NODE
MSX_LINK
obj_index (int) – Index of the link or node.
species_idx (int) – Index of the species.
- Returns:
Initial concentration.
- Return type:
float
- get_node_base_demand(node_idx: int) float[source]
Returns the primary base demand of a given node.
- Parameters:
node_idx (int) – Index of the node.
- Returns:
Primary base demand.
- Return type:
int
- get_node_base_demands(node_idx: int) list[float][source]
Returns all base demands of a given node.
- Parameters:
node_idx (int) – Index of the node.
- Returns:
List of base demands.
- Return type:
list[int]
- get_node_comment(node_idx: int) str[source]
Returns the comment of a given node.
- Parameters:
node_idx (int) – Index of the node.
- Returns:
Comment.
- Return type:
str
- get_node_demand(node_idx: int) float[source]
Returns the current demand at a given node.
- Parameters:
node_idx (int) – Index of the node.
- Returns:
Current demand.
- Return type:
float
- get_node_demand_patterns_idx(node_idx: int) list[int][source]
Returns the index of all demand patterns of a given node.
- Parameters:
node_idx (int) – Index of the node.
- Returns:
List of indices of the demand patterns.
- Return type:
list[int]
- get_node_elevation(node_idx: int) float[source]
Returns the evelvation of a given node.
- Parameters:
node_idx (int) – Index of the node.
- Returns:
Elevation.
- Return type:
float
- get_node_emitter_coeff(node_idx: int) float[source]
Returns the roughness coefficient of a given node.
- Parameters:
node_idx (int) – Index of the node.
- Returns:
Emitter coefficient of the node.
- Return type:
float
- get_node_head(node_idx: int) float[source]
Returns the current hydraulic head at a given node.
- Parameters:
node_idx (int) – Index of the node.
- Returns:
Current hydraulic head.
- Return type:
float
- get_node_id(node_idx) str[source]
Returns the ID of a given node.
- Parameters:
node_idx (int) – Index of the node.
- Returns:
ID of the node.
- Return type:
str
- get_node_idx(node_id: str) int[source]
Returns the index of a given node.
- Parameters:
node_id (str) – ID of the node.
- Returns:
Index of the node.
- Return type:
int
- get_node_init_qual(node_idx: int) float[source]
Returns the initial quality value/state of a given node.
- Parameters:
node_idx (int) – Index of the node.
- Returns:
Initial quality state/value.
- Return type:
float
- get_node_init_quality(node_idx: int) float[source]
Returns the initial quality (e.g., concentration) of a given node.
- Parameters:
node_idx (int) – Index of the node.
- Returns:
Initial quality.
- Return type:
float
- get_node_pattern_idx(node_idx: int) float[source]
Returns the index of the primary demand pattern of a given node.
- Parameters:
node_idx (int) – Index of the node.
- Returns:
Index of the primary demand pattern.
- Return type:
int
- get_node_pressure(node_idx: int) float[source]
Returns the current pressure at a given node.
- Parameters:
node_idx (int) – Index of the node.
- Returns:
Current pressure.
- Return type:
float
- get_node_quality(node_idx: int) float[source]
Returns the current quality value at a given node.
- Parameters:
node_idx (int) – Index of the node.
- Returns:
Current node quality value.
- Return type:
float
- get_node_source_pattern_idx(node_idx: int) int[source]
Returns the index of the quality source pattern at a given node.
- Parameters:
node_idx (int) – Index of the node.
- Returns:
Index of the pattern.
- Return type:
int
- get_node_source_qual(node_idx: int) float[source]
Returns the current quality state/value at a given node.
- Parameters:
node_idx (int) – Index of the node.
- Returns:
Current quality state/value.
- Return type:
float
- get_node_source_type(node_idx: int) int[source]
Returns the type of the water quality source at a given node.
- Parameters:
node_idx (int) – Index of the node.
- Returns:
Type of the water quality source. Will be one of the following:
EN_CONCEN
EN_MASS
EN_SETPOINT
EN_FLOWPACED
- Return type:
int
- get_node_type(node_idx: int) int[source]
Returns the type of a given node.
- Parameters:
node_idx (int) – Index of the node.
- Returns:
Type of the node. Will be one of the following:
EN_JUNCTION
EN_TANK
EN_RESERVOIR
- Return type:
int
- get_num_controls() int[source]
Returns the number of controls.
- Returns:
Number of controls.
- Return type:
int
- get_num_junctions() int[source]
Returns the number of junctions – i.e., number of nodes that are neither a tank nor a reservoir.
- Returns:
Number of junctions.
- Return type:
int
- get_num_links() int[source]
Returns the number of links in the network.
- Returns:
Number of links.
- Return type:
int
- get_num_msx_species() int[source]
Returns the total number of bulk and wall species.
- Returns:
Number of species.
- Return type:
int
- get_num_nodes() int[source]
Returns the number of nodes in the network.
- Returns:
Number of nodes.
- Return type:
int
- get_num_pipes() int[source]
Returns the number of pipes in the network.
- Returns:
Returns the maximum number of pipes.
- Return type:
int
- get_num_pumps() int[source]
Returns the number of pumps in the network.
- Returns:
Number of pumps.
- Return type:
int
- get_num_reservoirs() int[source]
Returns the number of reservoirs in the network.
- Returns:
Number of reservoirs.
- Return type:
int
- get_num_tanks() int[source]
Returns the number of tanks in the network.
- Returns:
Number of tanks.
- Return type:
int
- get_num_valves() int[source]
Returns the number of valves.
- Returns:
Number of valves.
- Return type:
int
- get_pattern(pattern_idx: int) list[float][source]
Returns the values of a given pattern.
- Parameters:
pattern_idx (int) – Index of the pattern.
- Returns:
Pattern values.
- Return type:
list[float]
- get_pattern_start_time() int[source]
Returns the pattern offset in seconds, which will start to be applied at simulation start.
- Returns:
Pattern offset time.
- Return type:
int
- get_pattern_time_step() int[source]
Returns the pattern time step in seconds.
- Returns:
Pattern time step.
- Return type:
int
- get_pipe_bulk_reaction_order() int[source]
Returns the the pipe bulk reaction order.
- Returns:
Reaction order.
- Return type:
int
- get_pipe_wall_reaction_order() int[source]
Returns the pipe wall reaction order.
- Returns:
Reaction oder.
- Return type:
int
- get_pump_avg_energy_price(pump_idx: int) float[source]
Returns the average energy price of a given pump.
- Parameters:
pump_idx (int) – Index of the pump
- Returns:
Average energy price.
- Return type:
float
- get_pump_efficiency(pump_idx: int) float[source]
Returns the current effciency of a given pump.
- Parameters:
pump_idx (int) – Index of the pump
- Returns:
Current pump effciency.
- Return type:
float
- get_pump_energy_price_pattern(pump_idx) int[source]
Returns the index of the energy price pattern of a given pump.
- Parameters:
pump_idx (int) – Index of the pump.
- Returns:
Pattern index.
- Return type:
int
- get_pump_energy_usage(pump_idx: int) float[source]
Returns the current energy usage of a given pump.
- Parameters:
pump_idx (int) – Index of the pump
- Returns:
Current energy usage.
- Return type:
float
- get_pump_pattern(pump_idx: int) int[source]
Returns the pattern of a given pump.
- Parameters:
pump_idx (int) – Index of the pump
- Returns:
Index of the pump pattern.
- Return type:
int
- get_pump_status(pump_idx: int) int[source]
Returns the current pump status.
- Parameters:
pump_idx (int) – Index of the pump.
- Returns:
Current pump status. Will be one of the following:
EN_PUMP_XHEAD
EN_PUMP_CLOSED
EN_PUMP_OPEN
EN_PUMP_XFLOW
- Return type:
int
- get_pump_type(pump_idx: int) int[source]
Returns the type (type of pump curve) of a given pump.
- Parameters:
pump_idx (int) – Index of the pump.
- Returns:
Pump curve type. Will be one of the following:
EN_CONST_HP
EN_POWER_FUNC
EN_CUSTOM
EN_NOCURVE
- Return type:
int
- get_quality_info() dict[source]
Returns the water quality analysis parameters.
- Returns:
Water quality analysis information as a dictionary with the following entries:
’qualType’: type of quality analysis (EN_NONE, EN_CHEM, EN_AGE, or EN_TRACE);
’chemName’: name of chemical constituent;
’chemUnits’: concentration units of constituent;
- ’traceNode’: ID of node being traced (if applicable,
only if ‘qualType’ = EN_TRACE);
- Return type:
dict
- get_quality_time_step() int[source]
Returns the quality time step in seconds.
- Returns:
Quality time step.
- Return type:
int
- get_quality_tolerance() float[source]
Returns the water quality tolerance.
- Returns:
Water quality tolerance.
- Return type:
float
- get_quality_type() dict[source]
Returns the type of quality analysis.
- Returns:
Dictioanry containing the type of quality analysis and the ID of the node being traced (if applicable):
’qualType’: type of quality analysis (EN_NONE, EN_CHEM, EN_AGE, or EN_TRACE);
’traceNode’: ID of node being traced (if applicable, only if ‘qualType’ = EN_TRACE);
- Return type:
dict
- get_reporting_start_time() int[source]
Returns the reporting start time in seconds since the simulation start.
- Returns:
Reporting start time.
- Return type:
int
- get_reporting_time_step() int[source]
Returns the reporting time step in seconds.
- Returns:
Reporting time step.
- Return type:
int
- get_simulation_duration() int[source]
Returns the simulation duration in seconds.
- Returns:
Simulation duration.
- Return type:
int
- get_specific_diffusivity() float[source]
Returns the specific diffusivity.
- Returns:
Specific diffusivity.
- Return type:
float
- get_specific_gravity() float[source]
Returns the specific gravity.
- Returns:
Specific gravity.
- Return type:
float
- get_specific_viscosity() float[source]
Returns the specific viscosity.
- Returns:
Specific viscosity.
- Return type:
float
- get_tank_bulk_decacy(tank_idx: int) float[source]
Returns the bulk decay rate in a given tank.
- Parameters:
tank_idx (int) – Index of the tank.
- Returns:
Bulk decay rate.
- Return type:
float
- get_tank_bulk_reaction_coeff(tank_idx: int) float[source]
Returns the bulk reaction coefficient of a given tank.
- Parameters:
tank_idx (int) – Index of the tank.
- Returns:
Bulk reaction coefficient.
- Return type:
float
- get_tank_bulk_reaction_order() int[source]
Returns the bulk reaction order in tanks.
- Returns:
Bulk reaction order.
- Return type:
int
- get_tank_diameter(tank_idx: int) float[source]
Return the diameter of given tank.
- Parameters:
tank_idx (int) – Index of the tank.
- Returns:
Diameter of the tank.
- Return type:
float
- get_tank_init_vol(tank_idx) float[source]
Return the inital water volume in a given tank.
- Parameters:
tank_idx (int) – Index of the tank.
- Returns:
Initial water volume.
- Return type:
float
- get_tank_level(tank_idx: int) float[source]
Returns the current water level in a given tank.
- Parameters:
tank_idx (int) – Index of the tank.
- Returns:
Current water level.
- Return type:
float
- get_tank_max_level(tank_idx: int) float[source]
Returns the maximum water level of a given tank.
- Parameters:
tank_idx (int) – Index of the tank.
- Returns:
Maximum water level.
- Return type:
float
- get_tank_max_vol(tank_idx: int) float[source]
Return the maxmium volume of given tank.
- Parameters:
tank_idx (int) – Index of the tank.
- Returns:
Maximum volume.
- Return type:
float
- get_tank_min_level(tank_idx: int) float[source]
Returns the minimum water level of a given tank.
- Parameters:
tank_idx (int) – Index of the tank.
- Returns:
Minimum water level.
- Return type:
float
- get_tank_min_vol(tank_idx: int) float[source]
Return the minimum volume of given tank.
- Parameters:
tank_idx (int) – Index of the tank.
- Returns:
Minimum volume.
- Return type:
float
- get_tank_mix_fraction(tank_idx: int) float[source]
Returns the mixing fraction of a given tank.
- Parameters:
tank_idx (int) – Index of the tank.
- Returns:
Mixing fraction.
- Return type:
float
- get_tank_mix_model(tank_idx: int) int[source]
Returns the mixing model of a given tank.
- Parameters:
tank_idx (int) – Index of the tank.
- Returns:
Type of mixing model. Will be one of the following:
EN_MIX1
EN_MIX2
EN_FIFO
EN_LIFO
- Return type:
int
- get_tank_mix_zone_vol(tank_idx: int) float[source]
Returns the mixing zone volume of a given tank.
- Parameters:
tank_idx (int) – Index of the tank.
- Returns:
Tank mixing zone valume.
- Return type:
float
- get_tank_vol_curve_idx(tank_idx: int) int[source]
Returns the index of the volume curve of a given tank.
- Parameters:
tank_idx (int) – Index of the tank.
- Returns:
Index of the volume curve.
- Return type:
int
- get_tank_volume(tank_idx: int) float[source]
Returns the current water volume inside a given tank.
- Parameters:
tank_idx (int) – Index of the tank.
- Returns:
Current water volume.
- Return type:
float
- get_valve_status(valve_idx: int) int[source]
Returns the current status of a given valve.
- Parameters:
valve_idx (int) – Index of the valve.
- Returns:
Current status. Will be one of the following:
EN_CLOSED
EN_OPEN
- Return type:
int
- load_msx_file(msx_file_in: str) None[source]
Loads an EPANET-MSX file.
- Parameters:
msx_file_in (str) – Path to .msx file.
- property msx_file: str
Returns the file path to the .msx file.
- Returns:
File path to .msx file.
- Return type:
str
- remove_curve(curve_id: str) None[source]
Deletes a given curve.
- Parameters:
curve_id (str) – ID of the curve.
- set_demand_model(model_type: int, pmin: float, preq: float, pexp: float) None[source]
Specifies the demand model.
- Parameters:
model_type (int) –
Type of demand model. Must be one of the following:
EN_DDA
EN_PDA
pmin (float) – Minimum pressure for any demand.
preq (float) – Required pressure for full demand.
pexp (float) – Exponent in pressure dependent demand formula.
- set_hydraulic_time_step(time_step: int) None[source]
Specifies the hydraulic time step.
- Parameters:
time_step (int) – Hydraulic time step in seconds.
- set_msx_source(node_id: str, species_id: str, source_type: int, source_concentration: float, msx_pattern_id: str) None[source]
Adds a species source (i.e., injection of a given species) at a given node.
- Parameters:
node_id (str) – ID of the node where the species in injected into the network.
species_id (str) – ID of the species to be injected.
source_type (int) –
Type of injection/source. Must be one of the following:
MSX_NOSOURCE = -1 for no source,
MSX_CONCEN = 0 for a concentration source,
MSX_MASS = 1 for a mass booster source,
MSX_SETPOINT = 2 for a setpoint source,
MSX_FLOWPACED = 3 for a flow paced source;
source_concentration (float) – Injetion concentration – can change over time according the the pattern of multiplies.
msx_pattern_id (str) – ID of the injection pattern – i.e., multipliers.
- set_msx_time_step(time_step: int) None[source]
Specifies the MSX time step.
- Parameters:
time_step (int) – New MSX time step.
- set_node_data(node_idx: int, elev: float, base_demand: float, demand_pattern_id: str) None[source]
Specifies some properties, such as elevation and demand, of a given node.
- Parameters:
node_idx (int) – Index of the node.
elev (float) – Elevation of the node.
base_demand (float) – Base demand of the node.
demand_pattern_id (str) – ID of the primary demand pattern of the node.
- set_node_init_quality(node_idx: int, init_qual: float) None[source]
Specifies the initial quality (e.g., concentration) of a given node.
- Parameters:
node_idx (int) – Index of the node.
init_qual (float) – Initial quality.
- set_node_source(node_idx: int, source_type: int, source_strengh: float, pattern_idx: int) None[source]
Specifies the quality source of a given node.
- Parameters:
node_idx (int) – Index of the node.
source_type (int) –
Type of the source. Must be one of the following:
EN_CONCEN
EN_MASS
EN_SETPOINT
EN_FLOWPACED
source_strength (float) – Source strength.
pattern_idx (int) – Index of the source pattern.
- set_node_source_quality(node_idx, source_strength: float) None[source]
Specifies the strength of a node quality source.
- Parameters:
node_idx (int) – Index of the node.
source_strength (float) – Source strength.
- set_pattern(pattern_idx: int, pattern_values: list[float]) None[source]
Set the values of a given pattern.
- Parameters:
pattern_idx (int) – Index of the pattern.
pattern_values (list[float]) – New pattern values.
- set_pattern_start_time(start_time: int) None[source]
Specifies the pattern offset in seconds, which will start to be applied at simulation start.
- Parameters:
start_time (int) – Pattern offset time step in seconds since simulation start.
- set_pattern_time_step(time_step: int) None[source]
Specifies the pattern time step.
- Parameters:
time_step (int) – Pattern time step in seconds.
- set_pump_avg_energy_price(pump_idx: int, price: float) float[source]
Specifies the average energy price of a given pump.
- Parameters:
pump_idx (int) – Index of the pump
price (float) – Average energy price.
- set_pump_energy_price_pattern(pump_idx: int, pattern_idx: int) None[source]
Sets the energy price pattern of a given pump.
- Parameters:
pump_idx (int) – Index of the pump.
pattern_idx (int) – Index of the pattern.
- set_pump_pattern(pump_idx: int, pattern_idx: int) None[source]
Specifies the pattern of a given pump.
- Parameters:
pump_idx (int) – Index of the pump
pattern_idx (int) – Index of the pattern.
- set_pump_status(pump_idx: int, status: int) None[source]
Sets the the current status of a given pump.
- Parameters:
pump_idx (int) – Index of the pump
status (int) –
Pump status. Must be one of the following:
EN_CLOSED
EN_OPEN
- set_quality_time_step(time_step: int) None[source]
Specifies the water quality time step.
- Parameters:
time_step (int) – Water quality time step in seconds.
- set_quality_type(qual_code: int, chem_name: str, chem_units: str, tracenode_id: str) None[source]
Specifies the water quality analysis parameters.
- Parameters:
qual_code (int) –
Type of quality analysis. Must be one of the following:
EN_NONE
EN_CHEM
EN_AGE
EN_TRACE
chem_name (str) – Name of chemical constituent
chem_units (str) – Concentration units of constituent
tracenode_id (str) – ID of node being traced (if applicable, only if ‘qualType’ = EN_TRACE).
- set_reporting_start_time(start_time: int) None[source]
Specifies the start time of reporting.
- Parameters:
start_time (int) – Reporting start time step in seconds since simulation start.
- set_reporting_time_step(time_step: int) None[source]
Specifies the reporting time step.
- Parameters:
time_step (int) – Reporting time step in seconds.
- set_simulation_duration(duration: int) None[source]
Sets the simulation duration.
- Parameters:
duration (int) – Simulation duration in seconds.
- set_valve_status(valve_idx, status: int)[source]
Sets the current status of a given valve.
- Parameters:
valve_idx (int) – Index of the valve.
status (int) –
New status of the valve. Must be one of the following:
EN_CLOSED
EN_OPEN
- split_pipe(pipe_id: str, new_pipe_id: str, new_node_id: str) None[source]
Splits a pipe (pipeID), creating two new pipes (pipeID and newPipeID) and adds a junction/node (newNodeID) in between. If the pipe is linear the pipe is splitted in half, otherwisw the middle point of the vertice array elemnts is taken as the split point. The two new pipes have the same properties as the one which is splitted. The new node’s properties are the same with the nodes on the left and right and New Node Elevation and Initial quality is the average of the two.
Note that this code is taken from EPyT – slightly modified to fit into this toolkit.
- Parameters:
pipe_id (str) – ID of the pipe to be split.
new_pipe_id (str) – ID of the new pipe.
new_node_id (str) – ID of the new node, placed in the middle of the splitted pipe.