Skip to main content

webmap

webmap

Export a Ribasim model to web-friendly files for the documentation model viewer.

Functions

Name Description
attribute_tables List the non-spatial Ribasim tables in a GeoPackage.
checked_sets The tracer sets whose tracers are all in the concentrations data, checked to label no water twice.
color_domain Robust color scale domain: 2nd to 98th percentile, of magnitudes for log and diverging scales.
concentration_variable The color scale of a substance, linear from zero, and its group: the tracers or the nutrients.
derived_tracers The values of the derived tracers of the tracer sets from the concentrations data, see tracer_sets.
downcast_int64 Cast int64 columns that fit to int32, since JavaScript readers return int64 as BigInt.
export_basin_area Export Basin / area polygons as vector tiles; attributes are looked up by node_id.
export_concentration Export the Basin concentrations per Basin for charts and per time step for the map, with a column per substance.
export_control Export the control state changes per DiscreteControl node, sorted by control_node_id and time.
export_gpkg_table Export a GeoPackage attribute table sorted by node_id, return the number of rows.
export_links Export the Link table with simplified geometry as interleaved lon/lat coords, sorted by link_id.
export_netcdf_table Export a (time, node_id) NetCDF input table to long-format float32 Parquet sorted by node_id.
export_nodes Export the Node table with all attributes and lon/lat columns, sorted by node_id.
export_observations Export how well the results fit the measurements of the Observation nodes, see ribasim_nl.goodness_of_fit.
export_results Export Basin and flow results and Basin concentrations, both per feature for charts and per time step for the map.
export_waterboards Export simplified water board boundaries as GeoJSON.
export_webmap Export a Ribasim model to a directory of web-friendly files plus a manifest.json.
file_hash Return a short content hash of a file, used for cache busting.
flat_coords Return per-LineString interleaved float32 lon/lat coordinate arrays.
float32_column_paths The Parquet column path of each float32 column by name, also of float32 lists like the link coords.
float_encoding Parquet writer options that store float columns with byte stream split, which compresses well.
lhm_boundary_labels The LHM fraction that labels the water of each FlowBoundary and LevelBoundary node, see lhm_fractions.
lhm_fractions The substances that the model input marks as fractions of the LHM, see ribasim_nl.assign_lhm_fractions.
lonlat_columns Add float32 x (longitude) and y (latitude) columns from point geometries.
model_input_dir The input directory of a model, with its database.gpkg.
model_results_dir The results directory of a model, which may not exist.
netcdf_tables Map table names like “Basin / time” to the NetCDF files referenced in the TOML.
observed_variable_attrs The attributes of the simulated values of an observed variable: the flow rate of links, or a Basin variable.
read_config Read a Ribasim TOML, return the config, the input directory and the database path.
read_features Read a layer whose id column is the GeoPackage FID, so GDAL does not return it as a column.
read_netcdf Read the (time, id) variables of a Ribasim NetCDF file as float32 (id, time) arrays sorted by id.
run_info When the model was run, from ribasim.log, and from which commits, from runinfo.json next to the TOML.
table_slug Convert a Ribasim table name like “Basin / profile” to “basin_profile”.
tracer_sets The sets of tracers that each label the water by its source, which the viewer charts as stacked fractions.
write_by_id Write long-format Parquet sorted by id, one row group per block of ids, for per-feature time series.
write_by_time Write Parquet ordered by time then id, one row group per block of time steps, for map animation.
write_parquet Write a DataFrame to Parquet, see write_table.
write_table Write zstd compressed Parquet with column statistics for row group lookup.

attribute_tables

webmap.attribute_tables(database)

List the non-spatial Ribasim tables in a GeoPackage.

checked_sets

webmap.checked_sets(sets, data)

The tracer sets whose tracers are all in the concentrations data, checked to label no water twice.

color_domain

webmap.color_domain(values, scale)

Robust color scale domain: 2nd to 98th percentile, of magnitudes for log and diverging scales.

concentration_variable

webmap.concentration_variable(substance, values, units, fraction)

The color scale of a substance, linear from zero, and its group: the tracers or the nutrients.

The tracers are the fractions of the water and its residence time, which the core computes, and the nutrients the other substances, which Delwaq adds, see ribasim_nl.delwaq. A fraction goes up to its highest value, about 1 like the others, since a fraction that reaches few Basins would be saturated by a percentile. Other values go up to their 98th percentile: the few stagnant Basins would make all others look the same in the residence time, and so would the few nearly empty Basins in a nutrient.

derived_tracers

webmap.derived_tracers(sets, data)

The values of the derived tracers of the tracer sets from the concentrations data, see tracer_sets.

A derived tracer is a tracer minus the others that label part of its water, so it may not be negative. Returns the sets without the derived tracers that data lacks the tracers for, and the values of the derived tracers that data does not have yet. A derived tracer that is in data is no longer derived.

downcast_int64

webmap.downcast_int64(table)

Cast int64 columns that fit to int32, since JavaScript readers return int64 as BigInt.

export_basin_area

webmap.export_basin_area(database, nodes, path)

Export Basin / area polygons as vector tiles; attributes are looked up by node_id.

The areas of the storing (‘bergend’) Basins overlap those of the flowing Basins they belong to. The tiles keep this order and the viewer draws and picks the last feature on top, so the storing Basins come first, to show and select the flowing Basins by default.

export_concentration

webmap.export_concentration(source, ids, times, by_id, by_time, sets=())

Export the Basin concentrations per Basin for charts and per time step for the map, with a column per substance.

The tracers of the tracer sets are fractions of the water, like Continuity; their derived tracers are added to the substances, and the sets whose tracers are all in the results are kept, see tracer_sets. The viewer reads only the column of the chosen substance, so a long list of substances does not slow it down. The Basins and time steps must be those of the Basin results, so the viewer can reuse their order on the map.

export_control

webmap.export_control(source, path)

Export the control state changes per DiscreteControl node, sorted by control_node_id and time.

export_gpkg_table

webmap.export_gpkg_table(database, name, path)

Export a GeoPackage attribute table sorted by node_id, return the number of rows.

export_netcdf_table

webmap.export_netcdf_table(source, path)

Export a (time, node_id) NetCDF input table to long-format float32 Parquet sorted by node_id.

export_nodes

webmap.export_nodes(database, path)

Export the Node table with all attributes and lon/lat columns, sorted by node_id.

export_observations

webmap.export_observations(database, results_dir, times, output_dir)

Export how well the results fit the measurements of the Observation nodes, see ribasim_nl.goodness_of_fit.

The fit of each observed variable over the whole run is written as a table, and the difference simulated - observed at each of the times for the map, which is NaN where either value is missing. The flow links whose total flow is the simulated flow rate of each Observation node are written for its chart in the panel. Returns None if no Observation node is compared.

export_results

webmap.export_results(results_dir, output_dir, sets=())

Export Basin and flow results and Basin concentrations, both per feature for charts and per time step for the map.

The sets are the tracer sets of the model, see tracer_sets.

export_waterboards

webmap.export_waterboards(source, path)

Export simplified water board boundaries as GeoJSON.

export_webmap

webmap.export_webmap(toml_path, waterboards_path, output_dir)

Export a Ribasim model to a directory of web-friendly files plus a manifest.json.

The water boards are left out if waterboards_path is None. The viewer fetches files as <path>?v=<hash> so they can be cached indefinitely.

file_hash

webmap.file_hash(path)

Return a short content hash of a file, used for cache busting.

flat_coords

webmap.flat_coords(geometry)

Return per-LineString interleaved float32 lon/lat coordinate arrays.

float32_column_paths

webmap.float32_column_paths(schema)

The Parquet column path of each float32 column by name, also of float32 lists like the link coords.

float_encoding

webmap.float_encoding(*dictionary_columns, data)

Parquet writer options that store float columns with byte stream split, which compresses well.

lhm_boundary_labels

webmap.lhm_boundary_labels(database)

The LHM fraction that labels the water of each FlowBoundary and LevelBoundary node, see lhm_fractions.

Each boundary has at most one, with a concentration of 1, so it labels all its water.

lhm_fractions

webmap.lhm_fractions(database)

The substances that the model input marks as fractions of the LHM, see ribasim_nl.assign_lhm_fractions.

lonlat_columns

webmap.lonlat_columns(gdf)

Add float32 x (longitude) and y (latitude) columns from point geometries.

model_input_dir

webmap.model_input_dir(toml_path, config)

The input directory of a model, with its database.gpkg.

model_results_dir

webmap.model_results_dir(toml_path, config)

The results directory of a model, which may not exist.

netcdf_tables

webmap.netcdf_tables(config, input_dir)

Map table names like “Basin / time” to the NetCDF files referenced in the TOML.

observed_variable_attrs

webmap.observed_variable_attrs(results_dir, variable)

The attributes of the simulated values of an observed variable: the flow rate of links, or a Basin variable.

read_config

webmap.read_config(toml_path)

Read a Ribasim TOML, return the config, the input directory and the database path.

read_features

webmap.read_features(database, layer, id_column)

Read a layer whose id column is the GeoPackage FID, so GDAL does not return it as a column.

read_netcdf

webmap.read_netcdf(source, id_dim)

Read the (time, id) variables of a Ribasim NetCDF file as float32 (id, time) arrays sorted by id.

run_info

webmap.run_info(toml_path, results_dir)

When the model was run, from ribasim.log, and from which commits, from runinfo.json next to the TOML.

Only what is known is included, so the result may be empty.

table_slug

webmap.table_slug(name)

Convert a Ribasim table name like “Basin / profile” to “basin_profile”.

tracer_sets

webmap.tracer_sets(database, nodes)

The sets of tracers that each label the water by its source, which the viewer charts as stacked fractions.

Within a set, all water has one label at most, so its tracers add up to Continuity, except for the water without a label, see https://github.com/Deltares/Ribasim/issues/3438#issuecomment-6834960461. The LHM fractions come first, as the default, with the Initial water, ordered like the figures of ribasim_nl.analyse_results; then the default tracers of the core, which label the water by the type of its source.

Each set lists its tracers in the order of the stacked charts from the bottom, and the label of the water of the FlowBoundary and LevelBoundary nodes, since that water flows over links without passing a Basin. A set can have derived tracers, which are a tracer of the results minus others, see derived_tracers: the LHM fractions that the model input lacks, but that follow from the default tracers of the core, see DERIVED_LHM_FRACTIONS.

write_by_id

webmap.write_by_id(ids, times, data, id_dim, path)

Write long-format Parquet sorted by id, one row group per block of ids, for per-feature time series.

The viewer finds the row group of an id by the statistics of the id column. Those of the other columns are left out, since they would be read with the file metadata of each feature, and grow with the number of columns.

write_by_time

webmap.write_by_time(ids, data, id_dim, path)

Write Parquet ordered by time then id, one row group per block of time steps, for map animation.

write_parquet

webmap.write_parquet(df, path, row_group_size=ROW_GROUP_SIZE)

Write a DataFrame to Parquet, see write_table.

write_table

webmap.write_table(table, path, row_group_size=ROW_GROUP_SIZE)

Write zstd compressed Parquet with column statistics for row group lookup.

The float32 coordinates are stored with byte stream split, which compresses the link coordinates about 40% better than the plain encoding. The float64 input tables repeat many values, which suit dictionary encoding.