Deltares / Ribasim

Water resources modeling
https://ribasim.org/
MIT License
39 stars 5 forks source link

Improve Edge duplication validation #1857

Open visr opened 2 weeks ago

visr commented 2 weeks ago

This edge validation error is not correct:

image

It states a certain edge already exists, but it doesn't. There is another duplicate edge that is already present. If a user only adds edges with the add API in the current version you cannot get here, but this is an existing model with duplicate edges. We should amend https://github.com/Deltares/Ribasim/pull/1765 for this case.

Found by @DanielTollenaar.

visr commented 5 days ago

In AmstelGooienVecht_parametrized_2024_10_1 this error in the validation code also popped up:

File D:\repo\ribasim\Ribasim\python\ribasim\ribasim\model.py:402, in Model._has_valid_neighbor_amount(self, df_graph, edge_amount, edge_type, nodes)
    [400](file:///D:/repo/ribasim/Ribasim/python/ribasim/ribasim/model.py:400) # loop over all the "to_node" and check if they have enough inneighbor
    [401](file:///D:/repo/ribasim/Ribasim/python/ribasim/ribasim/model.py:401) for _, row in to_node_info.iterrows():
--> [402](file:///D:/repo/ribasim/Ribasim/python/ribasim/ribasim/model.py:402)     if row["to_node_count"] < edge_amount[row["to_node_type"]][0]:
    [403](file:///D:/repo/ribasim/Ribasim/python/ribasim/ribasim/model.py:403)         is_valid = False
    [404](file:///D:/repo/ribasim/Ribasim/python/ribasim/ribasim/model.py:404)         logging.error(
    [405](file:///D:/repo/ribasim/Ribasim/python/ribasim/ribasim/model.py:405)             f"Node {row['to_node_id']} must have at least {edge_amount[row['to_node_type']][0]} inneighbor(s) (got {row['to_node_count']})"
    [406](file:///D:/repo/ribasim/Ribasim/python/ribasim/ribasim/model.py:406)         )

KeyError: nan

The node_id 0 doesn't exist in Node, so gets a to_node_type value of NaN:

row=to_node_id         0
to_node_count     80
to_node_type     NaN
Name: 888, dtype: object

That should be handled as well.