webmap_diff
webmap_diff
Compare two Ribasim models for the model viewer, to review the changes of a pull request.
Nodes are matched by node_id, and links by from_node_id and to_node_id, since 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. |
| 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. |
| 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. |
| 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)Return the names of the exported input tables whose rows differ, per 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 links have a base_id if they were renumbered. Removed links are keyed by their negated base link_id, since that id may be used by another link in the head 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=())The row count and an order-sensitive digest of the rows of each node in a table sorted by node_id.
nodes_differ_within
webmap_diff.nodes_differ_within(base_path, head_path, tolerances)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.
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.
values_equal
webmap_diff.values_equal(base, head)Element-wise equality where missing values are equal to each other.