-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Run AGV shortest_path and crossings_to_ribasim
- Loading branch information
Showing
6 changed files
with
226 additions
and
269 deletions.
There are no files selected for viewing
50 changes: 45 additions & 5 deletions
50
src/peilbeheerst_model/Shortest_path/10_shortest_path_AGV.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,47 @@ | ||
from peilbeheerst_model import shortest_path_waterschap | ||
# The AGV shortest path code is identical to the other water boards. | ||
# Below the content of shortest_path_waterschappen is spelled out to be able to | ||
# point to the right data from the cloud storage. | ||
|
||
import fiona | ||
import geopandas as gpd | ||
import pandas as pd | ||
from shapely.wkt import dumps | ||
|
||
from peilbeheerst_model.shortest_path import shortest_path | ||
from ribasim_nl import CloudStorage | ||
|
||
waterschap = "AmstelGooienVecht" | ||
gdf_out = shortest_path_waterschap(waterschap) | ||
gdf_out.to_file( | ||
f"/DATAFOLDER/projects/4750_30/Data_shortest_path/{waterschap}/{waterschap}_shortest_path.gpkg", driver="GPKG" | ||
) | ||
|
||
cloud = CloudStorage() | ||
# cloud.download_verwerkt(waterschap) | ||
# cloud.download_verwerkt("Rijkswaterstaat") | ||
# cloud.download_basisgegevens() | ||
|
||
# %% | ||
verwerkt_dir = cloud.joinpath(waterschap, "verwerkt") | ||
|
||
# Load Data | ||
# Define crossings file path | ||
data_path = verwerkt_dir / "crossings.gpkg" | ||
|
||
# Load crossings file | ||
DATA = {L: gpd.read_file(data_path, layer=L) for L in fiona.listlayers(data_path)} | ||
|
||
# Select rhws | ||
|
||
# Select RHWS peilgebeied & calculate representative point | ||
gdf_rhws = DATA["peilgebied"].loc[DATA["peilgebied"]["peilgebied_cat"] == 1].copy() | ||
gdf_rhws["representative_point"] = gdf_rhws.representative_point() | ||
|
||
# Apply aggregation level based filter | ||
gdf_cross = ( | ||
DATA["crossings_hydroobject_filtered"].loc[DATA["crossings_hydroobject_filtered"]["agg_links_in_use"]].copy() | ||
) # filter aggregation level | ||
|
||
gdf_crossings_out = shortest_path(waterschap, DATA, gdf_cross, gdf_rhws) | ||
# Write final output | ||
gdf_out = gpd.GeoDataFrame(pd.concat(gdf_crossings_out)) | ||
gdf_out["shortest_path"] = gdf_out["shortest_path"].apply(lambda geom: dumps(geom) if geom is not None else None) | ||
gdf_out.to_file(verwerkt_dir / "shortest_path.gpkg", driver="GPKG") | ||
|
||
# cloud.upload_verwerkt(waterschap) |
116 changes: 116 additions & 0 deletions
116
src/peilbeheerst_model/crossings_to_ribasim/AmstelGooienVecht.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,116 @@ | ||
# Modified version of the AGV part of 02_crossings_to_ribasim.py. | ||
|
||
# %% | ||
|
||
import pandas as pd | ||
from ribasim import Model | ||
|
||
from peilbeheerst_model import CrossingsToRibasim, RibasimNetwork, waterschap_data | ||
from ribasim_nl import CloudStorage | ||
|
||
# %% | ||
waterschap = "AmstelGooienVecht" | ||
waterschap_struct = waterschap_data[waterschap] | ||
|
||
cloud = CloudStorage() | ||
verwerkt_dir = cloud.joinpath(waterschap, "verwerkt") | ||
# cloud.download_verwerkt(waterschap) | ||
# cloud.download_basisgegevens() | ||
|
||
# %% | ||
|
||
pd.set_option("display.max_columns", None) | ||
# warnings.filterwarnings("ignore") | ||
|
||
|
||
model_characteristics = { | ||
# model description | ||
"waterschap": "AmstelGooienVecht", | ||
"modelname": "repro", | ||
"modeltype": "boezemmodel", | ||
# define paths | ||
"path_postprocessed_data": verwerkt_dir / "postprocessed.gpkg", | ||
"path_crossings": verwerkt_dir / "crossings.gpkg", | ||
"path_boezem": verwerkt_dir / "shortest_path.gpkg", | ||
"path_Pdrive": None, | ||
# apply filters | ||
"crossings_layer": "crossings_hydroobject_filtered", | ||
"in_use": True, | ||
"agg_links_in_use": True, | ||
"agg_areas_in_use": True, | ||
"aggregation": True, | ||
# data storage settings | ||
"write_goodcloud": False, # TODO | ||
"write_checks": True, | ||
# numerical settings | ||
"solver": None, | ||
"logging": None, | ||
"starttime": "2024-01-01 00:00:00", | ||
"endtime": "2024-01-02 00:00:00", | ||
} | ||
|
||
waterboard = CrossingsToRibasim(model_characteristics=model_characteristics) | ||
|
||
post_processed_data, crossings = waterboard.read_files() | ||
post_processed_data, crossings = waterboard.routing_processor(post_processed_data, crossings) | ||
crossings = waterboard.assign_node_ids(crossings) | ||
edges = waterboard.create_edges(crossings) | ||
nodes, edges = waterboard.create_nodes(crossings, edges) | ||
edges = waterboard.embed_boezems(edges, post_processed_data, crossings) | ||
|
||
# create individual model parts of the network | ||
network = RibasimNetwork(nodes=nodes, edges=edges, model_characteristics=model_characteristics) | ||
|
||
edge = network.edge() | ||
basin_node, basin_profile, basin_static, basin_state, basin_area = network.basin() | ||
pump_node, pump_static = network.pump() | ||
tabulated_rating_curve_node, tabulated_rating_curve_static = network.tabulated_rating_curve() | ||
level_boundary_node, level_boundary_static = network.level_boundary() | ||
flow_boundary_node, flow_boundary_static = network.flow_boundary() | ||
manning_resistance_node, manning_resistance_static = network.manning_resistance() | ||
terminal_node = network.terminal() | ||
|
||
# linear_resistance = network.linear_resistance() | ||
# fractional_flow = network.fractional_flow() | ||
# outlet = network.outlet() | ||
# discrete_control = network.discrete_control() | ||
# pid_control = network.pid_control() | ||
|
||
# insert the individual model modules in an actual model | ||
model = Model(starttime=model_characteristics["starttime"], endtime=model_characteristics["endtime"], crs="EPSG:28992") | ||
|
||
model.edge.df = edge | ||
|
||
model.basin.node.df = basin_node | ||
model.basin.profile = basin_profile | ||
model.basin.static = basin_static | ||
model.basin.state = basin_state | ||
model.basin.area = basin_area | ||
|
||
model.pump.node.df = pump_node | ||
model.pump.static = pump_static | ||
|
||
model.tabulated_rating_curve.node.df = tabulated_rating_curve_node | ||
model.tabulated_rating_curve.static = tabulated_rating_curve_static | ||
|
||
model.manning_resistance.node.df = manning_resistance_node | ||
model.manning_resistance.static = manning_resistance_static | ||
|
||
model.level_boundary.node.df = level_boundary_node | ||
model.level_boundary.static = level_boundary_static | ||
|
||
model.flow_boundary.node.df = flow_boundary_node | ||
model.flow_boundary.static = flow_boundary_static | ||
|
||
model.terminal.node.df = terminal_node | ||
|
||
# add checks and metadata | ||
checks = network.check(model, post_processed_data=post_processed_data, crossings=crossings) | ||
model = network.add_meta_data(model, checks, post_processed_data, crossings) | ||
|
||
# write the result | ||
network.WriteResults(model=model, checks=checks) | ||
|
||
# %% | ||
|
||
# cloud.upload_verwerkt(waterschap) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,14 @@ | ||
__version__ = "0.1.0" | ||
|
||
from peilbeheerst_model.parse_crossings import ParseCrossings | ||
from peilbeheerst_model.shortest_path import shortest_path_waterschap | ||
from peilbeheerst_model.waterschappen import waterschap_data | ||
from .crossings_to_ribasim import CrossingsToRibasim, RibasimNetwork | ||
from .parse_crossings import ParseCrossings | ||
from .shortest_path import shortest_path_waterschap | ||
from .waterschappen import waterschap_data | ||
|
||
__all__ = ["ParseCrossings", "shortest_path_waterschap", "waterschap_data"] | ||
__all__ = [ | ||
"CrossingsToRibasim", | ||
"ParseCrossings", | ||
"RibasimNetwork", | ||
"shortest_path_waterschap", | ||
"waterschap_data", | ||
] |
Oops, something went wrong.