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.
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.
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.
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”.
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.

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)

The color scale of a substance, linear from zero.

Up to the highest value, since a substance that reaches few Basins would be saturated by a percentile, and a fraction of the water then goes up to about 1, like the others. The residence time has no such limit: the few stagnant Basins would make all others look the same.

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)

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

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. Returns None if no Observation node is compared.

export_results

webmap.export_results(results_dir, output_dir)

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

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.

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”.

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.