Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Edit elements id #224

Open
GalPerelman opened this issue Sep 14, 2021 · 3 comments
Open

Edit elements id #224

GalPerelman opened this issue Sep 14, 2021 · 3 comments
Assignees

Comments

@GalPerelman
Copy link
Contributor

Is it possible to change the name attribute of junctions and pipes?
For example, if I want to change junctions id that contains 'NN' to 'J'
When using the following code, the output inp file will change the junction names in the PIPES section but not in the JUNCTIONS section. (COORDINATES section is also not changed)

for junction_name, junction in self.wn.junctions():
    junction._name = junction_name.replace(NN, J)
[JUNCTIONS]
;ID                      Elevation   Demand Pattern                 
 1                        0               0                            ;
 2                        0               0                            ;
 3                        0               0                            ;
 NN_4                     0               0                            ;
 5                        0               0                            ;
 6                        0               0                            ;
 7                        0               0                            ;


[PIPES]
;ID           Node1       Node2              Length    Diameter   Roughness  Minor Loss   Status
 1            2           3                  1000       480       120        0            Open   ;
 2            3           J_4                2500       480       120        0            Open   ;
 4            J_4         5                  300        480       120        0            Open   ;
 5            6           1                  10         1000      140        0            Open   ;
 6            8           4                  500        250       120        0            Open   ;
 7            7           9                  10         1200      120        0            Closed   ;

When trying to use junction.name instead of junction._name AttributeError is raised
AttributeError: can't set attribute

@dbhart
Copy link
Collaborator

dbhart commented Sep 17, 2021

So you are correct - this is not implemented. The main reason is because there are multiple places where a name might need to be changed, thus disconnecting things and breaking the simulation. However, we can look into making it so this can happen.
That said, it is weird that the junction name doesn't pass through to the junctions section... that shouldn't be able to happen...
Let me look into this more

@dbhart
Copy link
Collaborator

dbhart commented Sep 17, 2021

@GalPerelman I did find the issue. I will need to make a function to perform a rename for nodes and links. The registries for nodes, links, patterns and sources, all use the name of the originally created junction/link/etc. as a key index. That is what gets looped over when you call (for node in wn.node_names), for example. So even though the internal name is changed, you can't actually find that new name in the registry, and it pulls out the old name. But for links, it's getting the internal name for the end nodes. So I will go in and make that change, though it may be a few days for a PR to go all the way up.

@GalPerelman
Copy link
Contributor Author

@dbhart Thanks for your response and the suggested solution, it seems that this will do the work for my needs
Let me know if there is anything I can do to help

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants