webmap_diff
webmap_diff
Compare two Ribasim models for the model viewer, to review the changes of a pull request.
Nodes are matched by their key and water authority, see ribasim_nl.keys, or else by node_id, and links by from_node_id and to_node_id, since nodes and links get renumbered. A feature in both models is changed if its geometry, an attribute, its rows in an input table or its Basin / area differ. Initial Basin levels within 1 cm are equal, see TABLE_TOLERANCES. If both models have results, the Basin levels and flow rates that differ are listed too.
Functions
| Name | Description |
|---|---|
| compare_basin_areas | The node_ids whose Basin / area is added, removed or differs. |
| compare_config | The TOML settings that differ, as dicts with key, base and head value; None if not set. |
| compare_features | Compare features matched on the key columns, by default the id column. |
| compare_results | Compare a result variable at the time steps of both models, for the features matched by base_ids. |
| compare_tables | Return the names of the exported input tables whose rows differ, per node_id of the head model. |
| diff_models | Compare two models and their export_webmap output, and write the differences as JSON. |
| flatten | Flatten nested TOML tables to dotted keys with string values. |
| geometries_equal | Element-wise geometry equality within GEOMETRY_TOLERANCE, regardless of vertex order. |
| matched_ids | The base id of each feature in both models, indexed by head id, matched on the key columns. |
| node_digests | The row count and an order-sensitive digest of the rows of each node in a table sorted by node_id. |
| node_translation | The node_id in the head model of each node of the base model, or its negated node_id if it is only in the base. |
| nodes_differ_within | The node_ids whose rows in a table differ, with the columns of tolerances equal within their tolerance. |
| normalize_columns | Columns in a fixed order with dtypes that hash equally for equal values. |
| read_basin_areas | Basin / area geometries by node_id, with the areas of a node merged. |
| read_result | One result variable of an export, with a row per time step and a column per feature id. |
| results_match_links | Whether every link in the flow results connects the same nodes in the model, so the results are not outdated. |
| translate | The node_ids of the base model in the head model, see node_translation: an unknown node keeps its node_id. |
| values_equal | Element-wise equality where missing values are equal to each other. |
compare_basin_areas
webmap_diff.compare_basin_areas(base, head)The node_ids whose Basin / area is added, removed or differs.
compare_config
webmap_diff.compare_config(base, head)The TOML settings that differ, as dicts with key, base and head value; None if not set.
compare_features
webmap_diff.compare_features(base, head, id_column, key=None)Compare features matched on the key columns, by default the id column.
Return the added and changed features by head id, and the removed features by base id. Changed features list the columns that differ, and have their base_id if it differs from their head id.
compare_results
webmap_diff.compare_results(base, head, base_ids, atol, rtol)Compare a result variable at the time steps of both models, for the features matched by base_ids.
Returns the number of compared features, and the difference head - base with the largest magnitude per head id, for features where it exceeds atol plus rtol times the largest magnitude of the feature. A value missing in one model only is a difference of unknown size, reported as None.
compare_tables
webmap_diff.compare_tables(
base_dir,
base_manifest,
head_dir,
head_manifest,
translation=None,
)Return the names of the exported input tables whose rows differ, per node_id of the head model.
With a translation, see node_translation, the rows of a node are compared with those of the same node in the base model, whatever its node_id there. Nodes that are only in the base model have their negated node_id.
diff_models
webmap_diff.diff_models(
base_toml,
head_toml,
base_dir,
head_dir,
output_path,
labels=None,
)Compare two models and their export_webmap output, and write the differences as JSON.
Nodes and links map ids to {"status": "added" | "removed" | "changed", "changes": [...]}, where the changes name the attribute columns, the tables, “geometry” or “Basin / area” that differ. Changed nodes and links have a base_id if they were renumbered. Removed nodes and links are keyed by their negated id in the base model, since that id may be used by another node or link in the head model. base_node_ids has the id in the base model of every renumbered node in both models, changed or not, by its id in the head model, to find its results and tables in the base model. If both models have results, results has the Basin levels and flow rates that differ per head id, see compare_results, otherwise it is None. Results whose links are not those of their model are outdated, and are not compared; results_note then says why. The labels name the models, by default their model names.
flatten
webmap_diff.flatten(config, prefix='')Flatten nested TOML tables to dotted keys with string values.
geometries_equal
webmap_diff.geometries_equal(base, head)Element-wise geometry equality within GEOMETRY_TOLERANCE, regardless of vertex order.
matched_ids
webmap_diff.matched_ids(base, head, id_column, key)The base id of each feature in both models, indexed by head id, matched on the key columns.
node_digests
webmap_diff.node_digests(path, columns, string_columns=(), translation=None)The row count and an order-sensitive digest of the rows of each node in a table sorted by node_id.
With a translation, see node_translation, the node_ids are those of the head model.
node_translation
webmap_diff.node_translation(base, head)The node_id in the head model of each node of the base model, or its negated node_id if it is only in the base.
Nodes with the same key and water authority are the same node, whatever their node_id, see ribasim_nl.keys. A node without a key in one of the models is the same node as the one with its node_id in the other model, like in models without keys.
nodes_differ_within
webmap_diff.nodes_differ_within(
base_path,
head_path,
tolerances,
translation=None,
)The node_ids whose rows in a table differ, with the columns of tolerances equal within their tolerance.
Rows are matched by node_id and their order per node. The whole table is read, so this is only for small tables. With a translation, see node_translation, the node_ids of the base table are those of the head model.
normalize_columns
webmap_diff.normalize_columns(df, columns, string_columns=())Columns in a fixed order with dtypes that hash equally for equal values.
Missing columns are null, like an empty column: missing values of string_columns, NaN otherwise.
read_basin_areas
webmap_diff.read_basin_areas(database)Basin / area geometries by node_id, with the areas of a node merged.
read_result
webmap_diff.read_result(export_dir, manifest, kind, variable)One result variable of an export, with a row per time step and a column per feature id.
results_match_links
webmap_diff.results_match_links(toml_path, config, links)Whether every link in the flow results connects the same nodes in the model, so the results are not outdated.
translate
webmap_diff.translate(node_ids, translation)The node_ids of the base model in the head model, see node_translation: an unknown node keeps its node_id.
values_equal
webmap_diff.values_equal(base, head)Element-wise equality where missing values are equal to each other.