Comments (5)
Okay - so, for the _read_control_line, it has to formatted like in the CONTROLS section, so that's why the first way didn't work, because this is a rule. So, the _EpanetRule class can be used as:
>>> control_objects = wntr.epanet.io._EpanetRule.parse_rules_lines(["RULE 1 IF TANK 1 LEVEL ABOVE 19.1 THEN PUMP 335 STATUS IS CLOSED AND PIPE 330 STATUS IS OPEN"], flow_units=wntr.epanet.util.FlowUnits.GPM)
>>> # Note that each rule should be it's own string -- no newlines -- within a list; so you can parse more than one rule at a time
>>> control_objects
[<wntr.epanet.io._EpanetRule at 0x7fbb10f61970>]
>>> for ctrl in control_objects:
... new_control = ctrl.generate_control(wn)
... wn.add_control(new_control.name, new_control)
>>> print(new_control)
<Control: '1', <ValueCondition: 1, level, >, 5.821680000000001>, [<ControlAction: 335, status, CLOSED>, <ControlAction: 330, status, OPEN>], [], priority=0>
>>> print([c for c in wn.controls()][-1])
('1', <Control: '1', <ValueCondition: 1, level, >, 5.821680000000001>, [<ControlAction: 335, status, CLOSED>, <ControlAction: 330, status, OPEN>], [], priority=0>)
So, I'm hoping that if you follow the above it works for you!
I realize this is a bit of work, but this is basically the internal guts of the I/O reader pulled out a bit.
from wntr.
There is a function that reads lines of control strings, it's used by read_inpfile. The function is private (underscore), but you can call it directly, see _read_control_line in wntr/epanet/io.py.
The to_dict and from_dict methods should read and write controls as well.
from wntr.
If I try to make the same thig for the rules, it returns me an error. Is there another method to create rules from a string input? I type this in epanet and creates a rule inside the inp:
Rule 1
IF TANK 1 LEVEL ABOVE 19.1
THEN PUMP 335 STATUS IS CLOSED
AND PIPE 330 STATUS IS OPEN
Is there a way to add a rule to a water network by typing the text above? I've tried to make the same thing as for the controls with "_read_control_line" which works fine and adds the control to the water network, but if I do the same thing passing the rule text, returns an error like this:
venv\lib\site-packages\wntr\network\base.py", line 597, in getitem
return self._data[key]
KeyError: 'TANK'
This is the way I'm trying to call it:
control_object = wntr.epanet.io._read_control_line(line="IF TANK 1 LEVEL ABOVE 19.1 THEN PUMP 335 STATUS "
"IS CLOSED AND PIPE 330 STATUS IS OPEN", wn=wn,
flow_units="GPM",
control_name="3")
Thank you!
from wntr.
Rules are parsed using the _EpanetRule class, see wntr.epanet.io._EpanetRule.parse_rules_lines.
from wntr.
Yes. It works for me. Thank you for the support!
from wntr.
Related Issues (20)
- Epaneet dylib not available for Darwin HOT 2
- wntr.network.io.from_gis does not capture vertices
- `network_animation` does not behave as intended in Jupyter Notebooks HOT 1
- POSSIBILITY OF NEGATIVE PRESSURE HOT 5
- Questions about optimal scheduling of pumping stations HOT 1
- runnin the program HOT 3
- wntr.network.options has some abnormal annotation contents HOT 1
- Writing an inp file 'self' argument error message HOT 2
- Get the reactions tab in the inp file from a water network instance HOT 1
- Add PBV support to [VALVES] section
- Generating Interactive leaflet networks HOT 7
- Pipe status problem HOT 4
- AttributeError: 'WaterNetworkModel' object has no attribute 'write_inpfile' HOT 3
- Differences with my epanet from zero model and inp from wntr model HOT 4
- Values in [DEMANDS] section are repetead and others are missing HOT 8
- Unable to remove leaks from network model HOT 3
- Not able to save the network with modified elements as an INP file. HOT 2
- EPANET Error 110 HOT 1
- leaflet map popups HOT 5
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from wntr.