1 Model
Model(**data)The main class to represent a Ribasim model.
It represents the toml file almost directly (same fields).
1.1 Attributes
| Name | Description |
|---|---|
| allocation | |
| basin | |
| continuous_control | |
| crs | |
| database_path | Get the path to the database file. |
| discrete_control | |
| endtime | |
| experimental | |
| filepath | |
| flow_boundary | |
| flow_demand | |
| input_dir | |
| interpolation | |
| junction | |
| lazy | |
| level_boundary | |
| level_demand | |
| linear_resistance | |
| link | |
| logging | |
| manning_resistance | |
| model_config | |
| node | |
| observation | |
| outlet | |
| pid_control | |
| pump | |
| results | |
| results_dir | |
| results_path | Get the path to the results directory if it exists. |
| ribasim_version | |
| solver | |
| starttime | |
| tabulated_rating_curve | |
| terminal | |
| toml_path | Get the path to the TOML file if it exists. |
| use_validation | |
| user_demand |
1.2 Methods
| Name | Description |
|---|---|
| allows_lazy | Whether this FileModel allows lazy loading. |
| default_filepath | Return the default filepath for this FileModel. |
| diff | Compare two instances of a BaseModel. |
| model_dump | |
| model_post_init | |
| node_table | Return the node table of the model. |
| plot | Plot the nodes, links and allocation networks of the model. |
| read | Read a model from a TOML file. |
| remove_link | Remove a link from the model. |
| remove_node | Remove a node from the model, including connected links. |
| set_crs | Set the coordinate reference system of the data in the model. |
| to_crs | |
| to_xugrid | Convert the network to a xugrid.UgridDataset. |
| write | Write the contents of the model to disk and save it as a TOML configuration file. |
1.2.1 allows_lazy
Model.allows_lazy()Whether this FileModel allows lazy loading.
1.2.2 default_filepath
Model.default_filepath()Return the default filepath for this FileModel.
1.2.3 diff
Model.diff(other, ignore_meta=False)Compare two instances of a BaseModel.
** Warning: This method is experimental and is likely to change. **
If they are equal, return None. Otherwise, return a nested dictionary with the differences. When the differences are not a DataFrame (like the toml config), the dict has self and other as key. For DataFrames we return a dict with diff as key, and a datacompy Comparison object.
When ignore_meta is set to True, the meta_* columns in the DataFrames are ignored. Note that in that case the key will still be returned and the value will be None.
1.2.3.1 Examples
>>> nbasic == basic
False
>>> x = nbasic.diff(basic)
{'basin': {'node': {'diff': <datacompy.core.Compare object at 0x16e5a45c0>},
'static': {'diff': <datacompy.core.Compare object at 0x16eb90080>}},
'solver': {'saveat': {'other': 86400.0, 'self': 0.0}}}
>>> x["basin"]["static"]["diff"].report()
DataComPy Comparison
--------------------
...1.2.4 model_dump
Model.model_dump(**kwargs)1.2.5 model_post_init
Model.model_post_init(__context)1.2.6 node_table
Model.node_table()Return the node table of the model.
1.2.7 plot
Model.plot(ax=None, indicate_subnetworks=True, aspect_ratio_bound=0.33)Plot the nodes, links and allocation networks of the model.
1.2.7.1 Parameters
| Name | Type | Description | Default |
|---|---|---|---|
| ax | matplotlib.pyplot.Artist | Axes on which to draw the plot. | None |
| indicate_subnetworks | bool | Whether to indicate subnetworks with a convex hull backdrop. | True |
| aspect_ratio_bound | float | The maximal aspect ratio in (0,1). The smaller this number, the further the figure shape is allowed to be from a square | 0.33 |
1.2.7.2 Returns
| Name | Type | Description |
|---|---|---|
| ax | matplotlib.pyplot.Artist | Axis on which the plot is drawn. |
1.2.8 read
Model.read(filepath, internal=True, external=True)Read a model from a TOML file.
1.2.8.1 Parameters
| Name | Type | Description | Default |
|---|---|---|---|
| filepath | str | PathLike[str] | The path to the TOML file. | required |
| internal | bool | Load data from the database. Default is True. | True |
| external | bool | Load data from the NetCDF input files. Default is True. | True |
1.2.9 remove_link
Model.remove_link(link_id)Remove a link from the model.
1.2.10 remove_node
Model.remove_node(node_id)Remove a node from the model, including connected links.
1.2.11 set_crs
Model.set_crs(crs)Set the coordinate reference system of the data in the model.
1.2.11.1 Parameters
| Name | Type | Description | Default |
|---|---|---|---|
| crs | str | Coordinate reference system, like “EPSG:4326” for WGS84 latitude longitude. | required |
1.2.12 to_crs
Model.to_crs(crs)1.2.13 to_xugrid
Model.to_xugrid(add_flow=False, add_allocation=False)Convert the network to a xugrid.UgridDataset.
Either the flow or the allocation data can be added, but not both simultaneously. This method will throw ImportError if the optional dependency xugrid isn’t installed.
1.2.13.1 Parameters
| Name | Type | Description | Default |
|---|---|---|---|
| add_flow | bool | add flow results (Optional, defaults to False) | False |
| add_allocation | bool | add allocation results (Optional, defaults to False) | False |
1.2.14 write
Model.write(filepath, toml=True, internal=True, external=True)Write the contents of the model to disk and save it as a TOML configuration file.
If filepath.parent does not exist, it is created before writing.
1.2.14.1 Parameters
| Name | Type | Description | Default |
|---|---|---|---|
| filepath | str | PathLike[str] | A file path with .toml extension. | required |
| toml | bool | Write the TOML configuration file. Default is True. | True |
| internal | bool | Write the database. Default is True. | True |
| external | bool | Write the NetCDF input files. Default is True. | True |