src.dynamic_boundary_conditions.river.river_network_to_from_db

This script handles the following tasks: storing both the REC river network and its associated data in files along with their metadata in the database, retrieving the existing REC river network and its associated data from the database, and managing the addition of REC geometries that have been excluded from the river network in the database, as well as retrieving them for an existing REC river network.

Attributes

log

Functions

get_next_network_id(→ int)

Get the next available REC River Network ID from the River Network Exclusions table.

add_network_exclusions_to_db(→ None)

Add REC geometries that are excluded from the river network for the current run in the database.

get_new_network_output_paths(→ Tuple[pathlib.Path, ...)

Get new file paths that incorporate the current timestamp into the filenames for storing both the REC Network and

get_network_output_metadata(→ Tuple[str, str, str])

Get metadata associated with the REC Network.

store_rec_network_to_db(→ None)

Store both the REC river network and its associated data in files, and their metadata in the database.

get_existing_network_metadata_from_db(...)

Retrieve existing REC river network metadata for the specified catchment area from the database.

get_existing_network(→ Tuple[networkx.Graph, ...)

Retrieve existing REC river network and its associated data.

Module Contents

src.dynamic_boundary_conditions.river.river_network_to_from_db.log
src.dynamic_boundary_conditions.river.river_network_to_from_db.get_next_network_id(engine: sqlalchemy.engine.Engine) int

Get the next available REC River Network ID from the River Network Exclusions table.

Parameters:

engine (Engine) – The engine used to connect to the database.

Returns:

An identifier for the river network associated with each run, representing the next available River Network ID.

Return type:

int

src.dynamic_boundary_conditions.river.river_network_to_from_db.add_network_exclusions_to_db(engine: sqlalchemy.engine.Engine, rec_network_id: int, rec_network_exclusions: geopandas.GeoDataFrame, exclusion_cause: str) None

Add REC geometries that are excluded from the river network for the current run in the database.

Parameters:
  • engine (Engine) – The engine used to connect to the database.

  • rec_network_id (int) – An identifier for the river network associated with the current run.

  • rec_network_exclusions (gpd.GeoDataFrame) – A GeoDataFrame containing the REC geometries that are excluded from the river network for the current run.

  • exclusion_cause (str) – Cause of exclusion, i.e., the reason why the REC river geometry was excluded.

Returns:

This function does not return any value.

Return type:

None

src.dynamic_boundary_conditions.river.river_network_to_from_db.get_new_network_output_paths() Tuple[pathlib.Path, pathlib.Path]

Get new file paths that incorporate the current timestamp into the filenames for storing both the REC Network and its associated data.

Returns:

A tuple containing the file path to the REC Network and the file path to the REC Network data.

Return type:

Tuple[pathlib.Path, pathlib.Path]

src.dynamic_boundary_conditions.river.river_network_to_from_db.get_network_output_metadata(network_path: pathlib.Path, network_data_path: pathlib.Path, catchment_area: geopandas.GeoDataFrame) Tuple[str, str, str]

Get metadata associated with the REC Network.

Parameters:
  • network_path (pathlib.Path) – The path to the REC Network file.

  • network_data_path (pathlib.Path) – The path to the REC Network data file.

  • catchment_area (gpd.GeoDataFrame) – A GeoDataFrame representing the catchment area.

Returns:

A tuple containing the absolute path to the REC Network file as a string, the absolute path to the REC Network data file as a string, and the Well-Known Text (WKT) representation of the catchment area’s geometry.

Return type:

Tuple[str, str, str]

src.dynamic_boundary_conditions.river.river_network_to_from_db.store_rec_network_to_db(engine: sqlalchemy.engine.Engine, catchment_area: geopandas.GeoDataFrame, rec_network_id: int, rec_network: networkx.Graph, rec_network_data: geopandas.GeoDataFrame) None

Store both the REC river network and its associated data in files, and their metadata in the database.

Parameters:
  • engine (Engine) – The engine used to connect to the database.

  • catchment_area (gpd.GeoDataFrame) – A GeoDataFrame representing the catchment area.

  • rec_network_id (int) – An identifier for the river network associated with the current run.

  • rec_network (nx.Graph) – The constructed REC river network, represented as a directed graph (DiGraph).

  • rec_network_data (gpd.GeoDataFrame) – A GeoDataFrame containing the REC river network data.

Returns:

This function does not return any value.

Return type:

None

src.dynamic_boundary_conditions.river.river_network_to_from_db.get_existing_network_metadata_from_db(engine: sqlalchemy.engine.Engine, catchment_area: geopandas.GeoDataFrame) geopandas.GeoDataFrame

Retrieve existing REC river network metadata for the specified catchment area from the database.

Parameters:
  • engine (Engine) – The engine used to connect to the database.

  • catchment_area (gpd.GeoDataFrame) – A GeoDataFrame representing the catchment area.

Returns:

A GeoDataFrame containing the existing REC river network metadata for the specified catchment area.

Return type:

gpd.GeoDataFrame

src.dynamic_boundary_conditions.river.river_network_to_from_db.get_existing_network(engine: sqlalchemy.engine.Engine, existing_network_meta: geopandas.GeoDataFrame) Tuple[networkx.Graph, geopandas.GeoDataFrame]

Retrieve existing REC river network and its associated data.

Parameters:
  • engine (Engine) – The engine used to connect to the database.

  • existing_network_meta (gpd.GeoDataFrame) – A GeoDataFrame containing the metadata for the existing REC river network.

Returns:

A tuple containing the existing REC river network as a directed graph (DiGraph) and its associated data as a GeoDataFrame.

Return type:

Tuple[nx.Graph, gpd.GeoDataFrame]