Skip to main content

Model

Model(**data)

Attributes

Name Description
basin_node_without_area Get basin node without area
computation_time Get computation time of last run as timedelta
unassigned_basin_area Get unassigned basin area

Methods

Name Description
add_basin_area Add geometry to the basin area of Basin node_id, taking it from the other basin areas.
add_control_node Add a control_node to the network
add_link Alternative method to add links to the model.
add_links Add straight links between pairs of (from_node, to_node), like add_link.
add_node Add a node with a new node_id, using default tables if none are given.
apply_edits Apply model edits stored in a GeoPackage, with a layer per edit method (action).
clean_basin_area Make the basin areas valid, without slivers, see ribasim_nl.geometry.without_slivers.
deactivate_node Deactivate a node by setting its flow_rate to 0.0 or manning_n to 100.0, if possible.
dissolve_basin_area Make one basin area per Basin, the union of its basin areas, keeping the first values of other columns.
downstream_node_id Get downstream node_id(s)
downstream_profile Get upstream basin-profile
fill_basin_area_holes Give the parts of the areas of areas_gpkg that no basin area covers to a Basin, one basin area per Basin.
filter_nodes Return the rows of the Node table of one node type.
find_closest_basin Find the closest basin_node.
find_node_id Find a node_id by it’s properties
fix_unassigned_basin_area Assign a Basin node_id to a Basin / Area if the Area doesn’t contain a basin node_id.
get_component Return model component for a given node_type string (e.g. ‘Outlet’ → model.outlet)
get_node Return model-node by node_id
merge_outlets Merge outlet_b into outlet_a. Outlet a is considered upstream, and b donwstream.
remove_link Remove an link and disconnected nodes
remove_links Remove links, and release their IDs so they can be reused
remove_node Remove node from model
remove_nodes Remove nodes with remove_node, removing duplicated node_ids once.
replace_flow_boundaries_by_level_boundaries Replace each FlowBoundary by a LevelBoundary, with an Outlet on its link to the node downstream.
reverse_link Reverse a link
run Run your Ribasim model
select_basin_area Select the basin areas that equal geometry, or else each of its polygons.
set_link_id Change the ID of a link, for instance to reuse the ID of a link it replaces
split_basin Split the basin area that geometry crosses in two parts along it.
update_basin_area Give the basin areas that geometry selects to node_id, see select_basin_area.
update_nodes Change the node type of nodes with update_node, updating duplicated node_ids once.
update_state Update basin.state with results or final basin_state (outstate)
upstream_node_id Get upstream node_id(s)
upstream_profile Get upstream basin-profile
validate_link_source_destination Check if links exist with reversed source-destination
validate_ribasim_nl Validate Ribasim-NL-specific model conventions, see ribasim_nl.validation.validate_model.

add_basin_area

Model.add_basin_area(
    geometry,
    node_id=None,
    meta_streefpeil=None,
    tolerance=0.001,
)

Add geometry to the basin area of Basin node_id, taking it from the other basin areas.

Without node_id, it is added to the one Basin within geometry. The polygons on average narrower than tolerance are slivers, which are not added, see select_basin_area.

add_control_node

Model.add_control_node(
    to_node_id,
    data,
    ctrl_type='DiscreteControl',
    node_geom=None,
    node_offset=100,
    node_properties=None,
    node_id=None,
    link_id=None,
)

Add a control_node to the network

Parameters

to_node_id : int | list node_id or list of node_ids to connect control node to data: data for the control node

offset_node_id : int | None, optional User can explicitly specify a offset_node_id for a left-offset of the control-node. by default None node_geom : tuple | None, optional User can explicitly specify an Point for the control node. Has to be set if multiple to_node_ids are defined. If None, see node_offset. by default None node_offset : int, optional left-side offset of control node to to_node_id in case it’s one node_id and node_geom is not defined, In other cases this value is ignored. By default 100 node_properties: dict, optional extra properties to add to the control node id. node_id: int, optional ID of the control node, by default next_node_id. Reuse the ID of a node it replaces to keep IDs stable. link_id: int, optional ID of the control link, only with a single to_node_id. By default a new ID.

add_node

Model.add_node(node_type, geometry, name='', tables=None, **kwargs)

Add a node with a new node_id, using default tables if none are given.

Keyword arguments are added as node properties, prefixed with meta_ if they aren’t already.

apply_edits

Model.apply_edits(edits_gpkg, actions, *, sort_by_order=False, drop_na=False)

Apply model edits stored in a GeoPackage, with a layer per edit method (action).

Every row of the layer is a call of the method with the columns that are arguments of the method.

Args: edits_gpkg: GeoPackage with a layer per action, e.g. “merge_basins” or “remove_node” actions: names of the methods to apply, in this order sort_by_order: apply the rows in the order of an “order” column, if the layer has one drop_na: don’t pass missing values, so the method’s defaults are used

clean_basin_area

Model.clean_basin_area()

Make the basin areas valid, without slivers, see ribasim_nl.geometry.without_slivers.

Raises if a basin area is a sliver as a whole.

deactivate_node

Model.deactivate_node(node_id)

Deactivate a node by setting its flow_rate to 0.0 or manning_n to 100.0, if possible.

dissolve_basin_area

Model.dissolve_basin_area()

Make one basin area per Basin, the union of its basin areas, keeping the first values of other columns.

Raises if a basin area belongs to no Basin.

downstream_node_id

Model.downstream_node_id(node_id, link_type='flow')

Get downstream node_id(s)

downstream_profile

Model.downstream_profile(node_id)

Get upstream basin-profile

fill_basin_area_holes

Model.fill_basin_area_holes(areas_gpkg, excluded=None)

Give the parts of the areas of areas_gpkg that no basin area covers to a Basin, one basin area per Basin.

The uncovered part of an area goes to the Basin that covers most of that area, and an area that none covers to the Basin it shares the longest border with, preferably in the same drainage area, as in the lumping, see ribasim_nl.lumping.network.fill_holes. What lies within excluded is not part of the model: it is removed from the basin areas, and not filled. Raises if a basin area belongs to no Basin, or a Basin has no basin area.

filter_nodes

Model.filter_nodes(node_type)

Return the rows of the Node table of one node type.

Cheaper than model.<node_type>.node.df, which builds and validates a new NodeTable on every access.

find_closest_basin

Model.find_closest_basin(geometry, max_distance)

Find the closest basin_node.

find_node_id

Model.find_node_id(ds_node_id=None, us_node_id=None, **kwargs)

Find a node_id by it’s properties

fix_unassigned_basin_area

Model.fix_unassigned_basin_area(method='within', distance=100)

Assign a Basin node_id to a Basin / Area if the Area doesn’t contain a basin node_id.

Args: method (str): method to find basin node_id; within or closest. First start with within. Default is within distance (float, optional): for method closest, the distance to find an unassigned basin node_id. Defaults to 100.

get_component

Model.get_component(node_type)

Return model component for a given node_type string (e.g. ‘Outlet’ → model.outlet)

get_node

Model.get_node(node_id)

Return model-node by node_id

merge_outlets

Model.merge_outlets(outlet_a_id=None, outlet_b_id=None)

Merge outlet_b into outlet_a. Outlet a is considered upstream, and b donwstream.

remove_node

Model.remove_node(node_id, remove_links=False)

Remove node from model

remove_nodes

Model.remove_nodes(node_ids, remove_links=False)

Remove nodes with remove_node, removing duplicated node_ids once.

replace_flow_boundaries_by_level_boundaries

Model.replace_flow_boundaries_by_level_boundaries()

Replace each FlowBoundary by a LevelBoundary, with an Outlet on its link to the node downstream.

The Outlet is placed 10 m from the boundary, or at 10% of links of at most 20 m.

run

Model.run(**kwargs)

Run your Ribasim model

select_basin_area

Model.select_basin_area(geometry, tolerance=0.001)

Select the basin areas that equal geometry, or else each of its polygons.

Geometries are taken as equal if their boundaries are on average at most tolerance m apart. That allows for the differences between the results of versions of GEOS, which can also merge or separate adjacent parts of an area. So without a basin area that equals a polygon, the basin areas that together make it up are selected, or else the polygon is split from the basin areas that cover it, as basin areas of the same nodes. Polygons on average narrower than tolerance are slivers, which differ between versions of GEOS, and are not selected.

split_basin

Model.split_basin(
    line=None,
    basin_id=None,
    geometry=None,
    assign_unique_node=True,
)

Split the basin area that geometry crosses in two parts along it.

The basin area is the one of basin_id that the line crosses, or else the one that contains its middle. The parts keep its node, or with assign_unique_node, go to the one Basin within them that has no basin area.

update_basin_area

Model.update_basin_area(node_id, geometry)

Give the basin areas that geometry selects to node_id, see select_basin_area.

update_nodes

Model.update_nodes(node_ids, node_type)

Change the node type of nodes with update_node, updating duplicated node_ids once.

update_state

Model.update_state(time_stamp=None)

Update basin.state with results or final basin_state (outstate)

Args: time_stamp (pd.Timestamp | None, optional): Timestamp in results to update basin.state with . Defaults to None.

upstream_node_id

Model.upstream_node_id(node_id, link_type='flow')

Get upstream node_id(s)

upstream_profile

Model.upstream_profile(node_id)

Get upstream basin-profile

validate_ribasim_nl

Model.validate_ribasim_nl(layout=True)

Validate Ribasim-NL-specific model conventions, see ribasim_nl.validation.validate_model.