tools.CreateValvesFromPointsTool
The Create Valves from Point Locations tool from MIKE+ (water distribution only).
Usage
tools.CreateValvesFromPointsTool(database)Reads a point shapefile and adds one valve to mw_Valve per point. A point within the search radius of a junction with one or two pipes gets a valve at that junction: the valve takes the first valve_length of a pipe and a new junction joins the two. Otherwise, the nearest pipe within the search radius is split where the point projects onto it, and the valve takes valve_length centred there. Points that can’t be placed are skipped with a message.
The points must be in the model’s coordinate system.
Examples
>>> import mikeplus as mp
>>> from mikeplus.tools import CreateValvesFromPointsTool
>>> db = mp.open("path/to/model.sqlite")
>>> tool = CreateValvesFromPointsTool(db)
>>> messages = tool.run(
... "path/to/valves.shp",
... search_radius=5.0,
... valve_length=1.0,
... muid_field="ID",
... type_field="VTYPE",
... )
>>> print(messages[0])
2 valves have been created out of 3 points in the input file
>>> db.close()Methods
| Name | Description |
|---|---|
| __init__() | Initialize the CreateValvesFromPointsTool with the given Database. |
| run() | Create valves at the points in a shapefile. |
__init__()
Initialize the CreateValvesFromPointsTool with the given Database.
Usage
__init__(database)Parameters
database: Database- A Database object for a MIKE+ water distribution model.
run()
Create valves at the points in a shapefile.
Usage
run(
points_file,
search_radius,
valve_length,
*,
muid_field=None,
type_field=None,
status_field=None,
diameter_field=None,
setting_field=None,
description_field=None
)The *_field arguments name the shapefile column to read each valve attribute from. Attributes without a column keep the MIKE+ defaults. Column names are matched case-insensitively. Values that can’t be read fall back to a default and add a message.
If the database was closed after the tool was created, it is opened again.
Parameters
points_file: str or os.PathLike-
Path to a point shapefile (
.shp). search_radius: float-
How far from each point to look for a junction or pipe, in model units.
valve_length: float-
Length of each new valve, in model units.
muid_field: str = None-
Column with the valve ID. Missing or already used IDs get a generated one.
type_field: str = None-
Column with the valve type: a number from 1 to 6 or one of
PRV,PSV,PBV,FCV,TCVandGPV. Other values becomePRV. status_field: str = None-
Column with the valve status: 0 (regulating), 1 (open) or 2 (closed). Other values become regulating.
diameter_field: str = None-
Column with the valve diameter.
setting_field: str = None-
Column with the valve setting.
description_field: str = None- Column with the valve description.
Returns
list[str]- Messages from MIKE+. The first summarises how many valves were created out of how many points; the rest explain each point that was skipped and each value that couldn’t be imported.
Raises
ValueError-
If the model is not a water distribution model, if
search_radiusorvalve_lengthis not a positive finite number, ifpoints_fileis not a point shapefile, or if a*_fieldnames a column the shapefile doesn’t have. FileNotFoundError-
If
points_filedoes not exist. DatabaseError- If MIKE+ fails while creating valves. Valves created before the failure are kept.