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

Add model.node_table() #1276

Closed
wants to merge 3 commits into from
Closed

Add model.node_table() #1276

wants to merge 3 commits into from

Conversation

visr
Copy link
Member

@visr visr commented Mar 15, 2024

With the add API the full Node table is never created in memory, but the rows are available per node type. Users that need just the network need a way to compute the table when needed.

Marking this as a draft because I'm stuck. The new function works fine, but I tried re-enabling the round trip test, and found that the read from #1243 creates empty node tables for each node type due to the way it filters. I wanted to fix that by setting node.df = None if the filtered Node table was empty (if the node type doesn't occur).

But that triggers behavior I do not understand.

from ribasim import Model, Node
from ribasim.nodes import basin
from shapely.geometry import Point

model = Model(
    starttime="2020-01-01",
    endtime="2020-01-20",
)

model.basin.add(Node(5, Point(0, 0)), [basin.State(level=[1.0])])
# now both model.basin.node and model.basin.state have 1 row
model.basin.add(Node(8, Point(3, 0)), [basin.State(level=[2.0])])
# now model.basin.state has 2 rows, but model.basin.node only the last node 8

The setattr in the add method triggers this, so if you pass no tables like basin.State, model.basin.node contains both rows. I rewrote the if/else in add a bit but no real changes, the logic there seems ok. We just seem to trigger something pydantic that I find hard to debug, so any help welcome.

This is all triggered by my change to filter, so perhaps if there are better ways to fix that, by e.g. pruning empty node types at the end of model reading or something like that, I'm also happy.

@visr
Copy link
Member Author

visr commented Mar 15, 2024

Closing in favor of a working PR #1279 and an issue #1278.

@visr visr closed this Mar 15, 2024
@visr visr deleted the node_table branch March 15, 2024 20:53
Huite pushed a commit that referenced this pull request Mar 18, 2024
This supersedes #1276 by working around #1278 and still enabling the
round tripping tests.

Also simplifies `__assert_equal` a bit and stimulates
`Model.read(toml_path)` usage over `Model(filepath=toml_path)`.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant