From 6ea29f201f2cabc6d7755016583663af25259fde Mon Sep 17 00:00:00 2001 From: Martijn Visser Date: Tue, 30 Jul 2024 17:03:37 +0200 Subject: [PATCH] Ignore ruff less (#119) This removes a bunch of ruff ignores, with partly automatic and partly manual fixes. --- ruff.toml | 18 +++++- .../hydamo_0_analyse_data_waterboard.ipynb | 3 - .../hydamo_1_process_hydamo_data.ipynb | 5 +- ...amo_2_run_ribasim_lumping_waterboard.ipynb | 4 -- ...damo_3_create_ribasim_model_networks.ipynb | 4 -- ...hydamo_4_create_dummy_ribasim_models.ipynb | 4 -- .../notebooks/hydamo_preprocessing/general.py | 60 ++++++++----------- .../hydamo_preprocessing/preprocessing.py | 23 ++----- .../run_ribasim_lumping_waterboard.py | 3 - scripts/ribasim_lumping/__init__.py | 2 + .../dhydro/read_dhydro_network.py | 6 +- .../dhydro/read_dhydro_simulations.py | 4 +- .../dhydro/read_dhydro_simulations_utils.py | 15 +++-- .../hydamo/preprocess_hydamo_dataset.py | 30 ++++------ scripts/ribasim_lumping/ribasim_lumping.py | 16 +++-- .../generate_ribasim_model.py | 37 ++++++++---- .../generate_ribasim_model_preprocessing.py | 1 - .../ribasim_model_results/__init__.py | 9 +++ .../ribasim_model_results/ribasim_results.py | 2 +- .../export_load_split_nodes.py | 11 ++-- .../generate_ribasim_network.py | 32 +++++----- .../generate_split_nodes.py | 11 +++- .../utils/general_functions.py | 11 ++-- .../utils/remove_holes_from_polygons.py | 1 - src/hydamo/hydamo/datamodel.py | 14 ++--- src/hydamo/hydamo/geometry.py | 1 - src/hydamo/hydamo/styles.py | 2 +- .../AmstelGooienVecht_parametrize.ipynb | 32 ++-------- .../Parametrize/Delfland_parametrize.ipynb | 32 ++-------- .../HollandsNoorderkwartier_parametrize.ipynb | 28 +-------- .../HollandseDelta_parametrize.ipynb | 34 ++--------- .../Parametrize/Rijnland_nieuw.ipynb | 30 +--------- .../Parametrize/Rijnland_parametrize.ipynb | 18 +----- .../Rivierenland_parametrize.ipynb | 17 +----- .../Scheldestromen_parametrize.ipynb | 23 ++----- ...ielandendeKrimpenerwaard_parametrize.ipynb | 32 ++-------- .../WetterskipFryslan_parametrize.ipynb | 26 ++------ .../Zuiderzeeland_parametrize.ipynb | 20 +------ .../peilbeheerst_model/add_storage_basins.py | 4 -- .../crossings_to_ribasim.py | 4 -- .../peilbeheerst_model/parse_crossings.py | 7 --- .../postprocess_data/general_functions.py | 4 -- .../postprocess_data/post-process_WSRL.ipynb | 6 +- .../postprocess_data/post-process_agv.ipynb | 7 +-- .../post-process_delfland.ipynb | 6 +- .../post-process_rijnland.ipynb | 7 +-- .../post-process_wetterskip.ipynb | 9 +-- .../post-process_zuiderzeeland.ipynb | 9 ++- .../postprocess_data/post-processing_HD.ipynb | 7 +-- .../post-processing_HHNK.ipynb | 7 +-- .../post-processing_HHSK.ipynb | 8 +-- .../post-processing_scheldestromen.ipynb | 7 +-- .../preprocess_data/AmstelGooienVecht.ipynb | 9 +-- .../preprocess_data/Delfland.ipynb | 7 +-- .../preprocess_data/HHNK.ipynb | 9 +-- .../preprocess_data/HHSK.ipynb | 6 +- .../preprocess_data/Hollandse_Delta.ipynb | 6 +- .../preprocess_data/Rijnland.ipynb | 2 +- .../preprocess_data/Rivierenland.ipynb | 7 +-- .../preprocess_data/Scheldestromen.ipynb | 7 ++- .../preprocess_data/Wetterskip.ipynb | 6 +- .../preprocess_data/Zuiderzeeland.ipynb | 8 +-- .../preprocess_data/general_functions.py | 4 -- .../ribasim_parametrization.py | 1 - src/ribasim_nl/ribasim_nl/case_conversions.py | 2 - src/ribasim_nl/ribasim_nl/cloud.py | 5 -- src/ribasim_nl/ribasim_nl/concat.py | 1 - src/ribasim_nl/ribasim_nl/geometry.py | 3 - src/ribasim_nl/ribasim_nl/geoseries.py | 1 - src/ribasim_nl/ribasim_nl/model.py | 4 -- src/ribasim_nl/ribasim_nl/model_old.py | 1 - src/ribasim_nl/ribasim_nl/raster.py | 2 - src/ribasim_nl/ribasim_nl/styles.py | 2 +- src/ribasim_nl/ribasim_nl/tables.py | 2 - src/ribasim_nl/tests/test_cloud.py | 1 - 75 files changed, 258 insertions(+), 551 deletions(-) diff --git a/ruff.toml b/ruff.toml index 870a25c..c916187 100644 --- a/ruff.toml +++ b/ruff.toml @@ -5,7 +5,23 @@ line-length = 120 [lint] # See https://docs.astral.sh/ruff/rules/ select = ["D", "E", "F", "NPY", "PD", "C4", "I", "UP"] -ignore = ["D1", "D202", "D205", "D400", "D401", "D404", "E402", "E501", "E712", "E721", "F401", "F403", "F405", "PD002", "PD003", "PD008", "PD009", "PD010", "PD011", "PD013", "PD015", "PD901"] +ignore = [ + "D1", + "D400", + "D401", + "E501", # TODO https://docs.astral.sh/ruff/rules/line-too-long/ + "F403", # TODO https://docs.astral.sh/ruff/rules/undefined-local-with-import-star/ + "F405", # TODO https://docs.astral.sh/ruff/rules/undefined-local-with-import-star-usage/ + "PD002", + "PD003", + "PD008", + "PD009", + "PD010", + "PD011", + "PD013", + "PD015", + "PD901", +] fixable = ["ALL"] [lint.pydocstyle] diff --git a/scripts/notebooks/hydamo_0_analyse_data_waterboard.ipynb b/scripts/notebooks/hydamo_0_analyse_data_waterboard.ipynb index b74705a..2372830 100644 --- a/scripts/notebooks/hydamo_0_analyse_data_waterboard.ipynb +++ b/scripts/notebooks/hydamo_0_analyse_data_waterboard.ipynb @@ -11,15 +11,12 @@ "source": [ "from pathlib import Path\n", "\n", - "import geopandas as gpd\n", - "import numpy as np\n", "import pandas as pd\n", "from hydamo.datamodel import HyDAMO\n", "from pandas_xlsx_tables import xlsx_tables_to_dfs\n", "from ribasim_lumping_tools.LHM_data_bewerking_analyse_utils import (\n", " check_ids_hydamo_data,\n", " check_if_object_on_hydroobject,\n", - " export_to_geopackage,\n", " read_original_data,\n", " translate_data_to_hydamo_format,\n", ")" diff --git a/scripts/notebooks/hydamo_1_process_hydamo_data.ipynb b/scripts/notebooks/hydamo_1_process_hydamo_data.ipynb index c089d15..ccf6472 100644 --- a/scripts/notebooks/hydamo_1_process_hydamo_data.ipynb +++ b/scripts/notebooks/hydamo_1_process_hydamo_data.ipynb @@ -25,11 +25,10 @@ "import geopandas as gpd\n", "import numpy as np\n", "import pandas as pd\n", + "from hydamo_preprocessing.preprocessing import preprocess_hydamo_hydroobjects\n", "\n", "warnings.simplefilter(action=\"ignore\", category=UserWarning)\n", - "warnings.simplefilter(action=\"ignore\", category=FutureWarning)\n", - "\n", - "from hydamo_preprocessing.preprocessing import preprocess_hydamo_hydroobjects" + "warnings.simplefilter(action=\"ignore\", category=FutureWarning)" ] }, { diff --git a/scripts/notebooks/hydamo_2_run_ribasim_lumping_waterboard.ipynb b/scripts/notebooks/hydamo_2_run_ribasim_lumping_waterboard.ipynb index 5a8da15..64c0795 100644 --- a/scripts/notebooks/hydamo_2_run_ribasim_lumping_waterboard.ipynb +++ b/scripts/notebooks/hydamo_2_run_ribasim_lumping_waterboard.ipynb @@ -6,13 +6,9 @@ "metadata": {}, "outputs": [], "source": [ - "import os\n", "import warnings\n", "from pathlib import Path\n", "\n", - "import geopandas as gpd\n", - "import matplotlib.pyplot as plt\n", - "import numpy as np\n", "import pandas as pd\n", "from ribasim_lumping_tools.run_ribasim_lumping_waterboard import run_ribasim_lumping_for_waterboard\n", "\n", diff --git a/scripts/notebooks/hydamo_3_create_ribasim_model_networks.ipynb b/scripts/notebooks/hydamo_3_create_ribasim_model_networks.ipynb index d8b0680..e161cdc 100644 --- a/scripts/notebooks/hydamo_3_create_ribasim_model_networks.ipynb +++ b/scripts/notebooks/hydamo_3_create_ribasim_model_networks.ipynb @@ -10,11 +10,7 @@ "from pathlib import Path\n", "\n", "import geopandas as gpd\n", - "import matplotlib.pyplot as plt\n", - "import networkx as nx\n", - "import numpy as np\n", "import pandas as pd\n", - "import ribasim\n", "\n", "warnings.simplefilter(action=\"ignore\", category=UserWarning)\n", "warnings.simplefilter(action=\"ignore\", category=FutureWarning)" diff --git a/scripts/notebooks/hydamo_4_create_dummy_ribasim_models.ipynb b/scripts/notebooks/hydamo_4_create_dummy_ribasim_models.ipynb index ee5e1ad..0e1693f 100644 --- a/scripts/notebooks/hydamo_4_create_dummy_ribasim_models.ipynb +++ b/scripts/notebooks/hydamo_4_create_dummy_ribasim_models.ipynb @@ -12,11 +12,7 @@ "\n", "import fiona\n", "import geopandas as gpd\n", - "import matplotlib.pyplot as plt\n", - "import networkx as nx\n", - "import numpy as np\n", "import pandas as pd\n", - "import ribasim\n", "from ribasim_lumping_tools.default_model import DEFAULTS, default_model\n", "\n", "warnings.simplefilter(action=\"ignore\", category=UserWarning)\n", diff --git a/scripts/notebooks/hydamo_preprocessing/general.py b/scripts/notebooks/hydamo_preprocessing/general.py index 15c93a6..7c276ba 100644 --- a/scripts/notebooks/hydamo_preprocessing/general.py +++ b/scripts/notebooks/hydamo_preprocessing/general.py @@ -1,16 +1,12 @@ import datetime import itertools import logging -import os import time import warnings import geopandas as gpd -import networkx as nx -import numpy as np import pandas as pd -from shapely.geometry import LineString, Point, Polygon -from shapely.ops import snap, split +from shapely.geometry import LineString, Point # %% Monitoring @@ -76,9 +72,7 @@ def get_endpoints_from_lines(lines: gpd.GeoDataFrame) -> gpd.GeoDataFrame: def add_point_to_linestring(point: Point, linestring: LineString) -> LineString: """ - Inserts point into a linestring, placing the point next to its - nearest neighboring point in a way that minimizes the total length - of the linestring. + Inserts point into a linestring, placing the point next to its nearest neighboring point in a way that minimizes the total length of the linestring. Args: point (Point): point @@ -108,8 +102,7 @@ def add_point_to_linestring(point: Point, linestring: LineString) -> LineString: def split_linestring_by_indices(linestring: LineString, split_indices: list) -> list: """ - Divides a linestring into multiple linestrings based on a list that contains - the indices of the split points within the linestring + Divides a linestring into multiple linestrings based on a list that contains the indices of the split points within the linestring. Args: linestring (LineString): Linestring @@ -129,8 +122,9 @@ def split_linestring_by_indices(linestring: LineString, split_indices: list) -> def remove_duplicate_split_lines(lines: gpd.GeoDataFrame) -> gpd.GeoDataFrame: """ - Removes duplicates of split lines from line feature vector dataset. Duplicates - are removed from a subselection from the line feature dataset that contains + Removes duplicates of split lines from line feature vector dataset. + + Duplicates are removed from a subselection from the line feature dataset that contains all line features that have been split. Args: @@ -160,8 +154,9 @@ def remove_duplicate_split_lines(lines: gpd.GeoDataFrame) -> gpd.GeoDataFrame: def connect_lines_by_endpoints(split_endpoints: gpd.GeoDataFrame, lines: gpd.GeoDataFrame) -> gpd.GeoDataFrame: """ - Connects boundary lines to other lines, based on instructions for each line endpoint. Connections are - created by inserting the endpoints into their target lines. The target line features are + Connects boundary lines to other lines, based on instructions for each line endpoint. + + Connections are created by inserting the endpoints into their target lines. The target line features are split afterwards in order to create nodes at the intersection of the connected linestrings. Args: @@ -172,7 +167,6 @@ def connect_lines_by_endpoints(split_endpoints: gpd.GeoDataFrame, lines: gpd.Geo ------- gpd.GeoDataFrame: line feature dataframe """ - listed_lines = list(itertools.chain.from_iterable(split_endpoints["target_lines"])) listed_points = list(itertools.chain.from_iterable(split_endpoints["points_to_target_lines"])) connections_to_create = pd.DataFrame({"lines": listed_lines, "point": listed_points}) @@ -193,12 +187,12 @@ def connect_lines_by_endpoints(split_endpoints: gpd.GeoDataFrame, lines: gpd.Geo (modified_linestring, index_nearest_neighbour) = add_point_to_linestring(Point(node), linestring) if index_nearest_neighbour == 0 and linestring.coords[0] in list( - connections_to_create.loc[connections_to_create["inserted"] == True, "point"].values + connections_to_create.loc[connections_to_create["inserted"], "point"].values ): continue elif index_nearest_neighbour == len(linestring.coords) - 1 and linestring.coords[-1] in list( - connections_to_create.loc[connections_to_create["inserted"] == True, "point"].values + connections_to_create.loc[connections_to_create["inserted"], "point"].values ): continue @@ -231,9 +225,9 @@ def connect_lines_by_endpoints(split_endpoints: gpd.GeoDataFrame, lines: gpd.Geo def connect_endpoints_by_buffer(lines: gpd.GeoDataFrame, buffer_distance: float = 0.5) -> gpd.GeoDataFrame: """ - Connects boundary line endpoints within a vector dataset to neighbouring lines that pass - within a specified buffer distance with respect to the the boundary endpoints. The boundary - endpoints are inserted into the passing linestrings + Connects boundary line endpoints to neighbouring lines that pass within a specified buffer distance with respect to the the boundary endpoints. + + The boundary endpoints are inserted into the passing linestrings Args: lines (gpd.GeoDataFrame): Line vector data @@ -281,9 +275,9 @@ def connect_endpoints_by_buffer(lines: gpd.GeoDataFrame, buffer_distance: float boundary_endpoints["crossed_by_unconnected_lines"] = boundary_endpoints.apply( lambda x: True in [True not in y for y in x["start_or_endpoint_overlaying_line_buffers"]], axis=1 ) - unconnected_endpoints = boundary_endpoints[ - boundary_endpoints["crossed_by_unconnected_lines"] == True - ].reset_index(drop=True) + unconnected_endpoints = boundary_endpoints[boundary_endpoints["crossed_by_unconnected_lines"]].reset_index( + drop=True + ) unconnected_endpoints["target_lines"] = unconnected_endpoints.apply( lambda x: [ x["overlaying_line_buffers"][i] @@ -323,14 +317,14 @@ def connect_endpoints_by_buffer(lines: gpd.GeoDataFrame, buffer_distance: float def add_overlapping_polygons( - left_geodataframe: gpd.GeoDataFrame(), - right_geodataframe: gpd.GeoDataFrame(), + left_geodataframe: gpd.GeoDataFrame, + right_geodataframe: gpd.GeoDataFrame, left_id_column: str, right_id_column: str, ): """ - creates a column in a left geodataframe where it lists the overlapping - polygons from the right geodataframe for each polygon in the left geodataframe. + Create a column in a left geodataframe where it lists the overlapping polygons from the right geodataframe for each polygon in the left geodataframe. + The id columns of the right and left dataframe have to be defined. Parameters @@ -352,7 +346,6 @@ def add_overlapping_polygons( insights in the overlapping polygons from the right dataframe """ - # Calculate total areas of left and right polygons left_geodataframe["left_area"] = left_geodataframe["geometry"].apply(lambda x: x.area) right_geodataframe["surface_area"] = right_geodataframe.area @@ -409,8 +402,8 @@ def get_most_overlapping_polygon( right_id_column: str, ): """ - creates a column in a left geodataframe that contains IDs of the most overlapping - polygon from the right geodataframe based on their geometries. + Create a column in a left geodataframe that contains IDs of the most overlapping polygon from the right geodataframe based on their geometries. + The id columns of the left and right dataframe have to be defined. Parameters @@ -431,7 +424,6 @@ def get_most_overlapping_polygon( the updated left geodataframe """ - left_geodataframe = add_overlapping_polygons(left_geodataframe, right_geodataframe, left_id_column, right_id_column) left_geodataframe["overlapping_areas"] = left_geodataframe["overlapping_areas"].apply(lambda x: pd.DataFrame(x)) @@ -511,15 +503,15 @@ def get_most_intersecting(gdf, polygon, left_id): return None left_gdf = get_touching_polygons_from_within_gdf(left_gdf, left_id) - if type(right_gdf) == gpd.GeoDataFrame: + if isinstance(right_gdf, gpd.GeoDataFrame): left_gdf = get_most_overlapping_polygon_from_other_gdf(left_gdf, right_gdf, left_id, right_id) left_gdf["right_id"][left_gdf[left_id] == left_gdf["right_id"]] = None left_gdf["touching_polygons"] = left_gdf["touching_polygons"].apply( lambda x: pd.DataFrame(left_gdf[left_gdf[left_id].isin(x)]) ) left_gdf["touching_polygons"] = left_gdf["touching_polygons"].apply(lambda x: x[x["basin"] is not None]) - left_gdf["touching_polygons"] = left_gdf["touching_polygons"].apply(lambda x: x[x["basin"].isna() == False]) - if type(right_gdf) == gpd.GeoDataFrame: + left_gdf["touching_polygons"] = left_gdf["touching_polygons"].apply(lambda x: x[x["basin"].notna()]) + if isinstance(right_gdf, gpd.GeoDataFrame): left_gdf["touching_polygons"] = left_gdf.apply( lambda x: x["touching_polygons"][x["touching_polygons"]["right_id"] == x["right_id"]] if x["right_id"] is not None diff --git a/scripts/notebooks/hydamo_preprocessing/preprocessing.py b/scripts/notebooks/hydamo_preprocessing/preprocessing.py index d6893a4..af9d825 100644 --- a/scripts/notebooks/hydamo_preprocessing/preprocessing.py +++ b/scripts/notebooks/hydamo_preprocessing/preprocessing.py @@ -1,27 +1,14 @@ -import datetime -import itertools import logging -import os import time import warnings import geopandas as gpd -import networkx as nx -import numpy as np import pandas as pd -from shapely.geometry import LineString, Point, Polygon -from shapely.ops import snap, split from .general import ( - add_overlapping_polygons, - add_point_to_linestring, connect_endpoints_by_buffer, - connect_lines_by_endpoints, - get_endpoints_from_lines, get_most_overlapping_polygon, - remove_duplicate_split_lines, report_time_interval, - split_linestring_by_indices, ) # %% wfd @@ -36,7 +23,7 @@ def add_wfd_id_to_hydroobjects( overlap_ratio: float = 0.9, ) -> gpd.GeoDataFrame: """ - + Assign Water Framework Directive (WFD) waterbody ID to hydroobjects based on overlap ratio. Parameters ---------- @@ -58,7 +45,6 @@ def add_wfd_id_to_hydroobjects( GeoDataFrame that contains hydroobjects with their assigned wfd body id """ - warnings.filterwarnings("ignore") start_time = time.time() @@ -94,7 +80,7 @@ def add_wfd_id_to_hydroobjects( lambda x: x["most_overlapping_polygon_id"] if x["most_overlapping_polygon_area"] > overlap_ratio * x["left_area"] else None - if type(x["most_overlapping_polygon_area"]) == float + if isinstance(x["most_overlapping_polygon_area"], float) else None, axis=1, ) @@ -105,8 +91,8 @@ def add_wfd_id_to_hydroobjects( end_time = time.time() passed_time = report_time_interval(start_time, end_time) - nr_hydroobjects_wfd = len(hydroobjects[hydroobjects[wfd_id_column].isna() == False][wfd_id_column]) - nr_unique_wfd_ids = len(hydroobjects[hydroobjects[wfd_id_column].isna() == False][wfd_id_column].unique()) + nr_hydroobjects_wfd = len(hydroobjects[hydroobjects[wfd_id_column].notna()][wfd_id_column]) + nr_unique_wfd_ids = len(hydroobjects[hydroobjects[wfd_id_column].notna()][wfd_id_column].unique()) hydroobjects = hydroobjects.drop( columns=[ @@ -143,6 +129,7 @@ def preprocess_hydamo_hydroobjects( overlap_ratio_wfd: float = 0.9, ) -> gpd.GeoDataFrame: """ + Preprocess hydamo hydroobjects. Parameters ---------- diff --git a/scripts/notebooks/ribasim_lumping_tools/run_ribasim_lumping_waterboard.py b/scripts/notebooks/ribasim_lumping_tools/run_ribasim_lumping_waterboard.py index 6c4e4f3..cfcc927 100644 --- a/scripts/notebooks/ribasim_lumping_tools/run_ribasim_lumping_waterboard.py +++ b/scripts/notebooks/ribasim_lumping_tools/run_ribasim_lumping_waterboard.py @@ -10,9 +10,6 @@ import warnings from pathlib import Path -import geopandas as gpd -import matplotlib.pyplot as plt -import numpy as np import pandas as pd from ribasim_lumping import create_ribasim_lumping_network diff --git a/scripts/ribasim_lumping/__init__.py b/scripts/ribasim_lumping/__init__.py index 5ee5348..48f2970 100644 --- a/scripts/ribasim_lumping/__init__.py +++ b/scripts/ribasim_lumping/__init__.py @@ -1 +1,3 @@ from ribasim_lumping.ribasim_lumping import create_ribasim_lumping_network + +__all__ = ["create_ribasim_lumping_network"] diff --git a/scripts/ribasim_lumping/dhydro/read_dhydro_network.py b/scripts/ribasim_lumping/dhydro/read_dhydro_network.py index a481fc8..3b8c800 100644 --- a/scripts/ribasim_lumping/dhydro/read_dhydro_network.py +++ b/scripts/ribasim_lumping/dhydro/read_dhydro_network.py @@ -1,5 +1,6 @@ """ Read network locations from D-Hydro simulation + Harm Nomden (Sweco) """ @@ -202,7 +203,9 @@ def get_dhydro_structures_locations(structures_file: Path, branches_gdf: gpd.Geo def check_number_of_pumps_at_pumping_station(pumps_gdf: gpd.GeoDataFrame, set_name: str): - """Check number of pumps at pumping station and combine them into one representative pump + """ + Check number of pumps at pumping station and combine them into one representative pump. + Input: Geodataframe with pumps with multiple per location Output: Geodataframe with one pump per location. Total capacity (sum), Max start level, Min stop level @@ -241,7 +244,6 @@ def check_number_of_pumps_at_pumping_station(pumps_gdf: gpd.GeoDataFrame, set_na def split_dhydro_structures(structures_gdf: gpd.GeoDataFrame, set_name: str): """Get all DHydro structures dataframes""" - list_structure_types = list(structures_gdf["object_type"].unique()) structures_gdf_dict = {} for structure_type in list_structure_types: diff --git a/scripts/ribasim_lumping/dhydro/read_dhydro_simulations.py b/scripts/ribasim_lumping/dhydro/read_dhydro_simulations.py index 9517600..5078714 100644 --- a/scripts/ribasim_lumping/dhydro/read_dhydro_simulations.py +++ b/scripts/ribasim_lumping/dhydro/read_dhydro_simulations.py @@ -90,7 +90,9 @@ def add_dhydro_simulation_data( his_data: xr.Dataset = None, map_data: xu.UgridDataset = None, ): - """Receives his- and map-data. calculations should be placed in dhydro_results_dir + """ + Receives his- and map-data. calculations should be placed in dhydro_results_dir. + - set_name - within directory: simulations_dir - at timestamps: simulations_ts diff --git a/scripts/ribasim_lumping/dhydro/read_dhydro_simulations_utils.py b/scripts/ribasim_lumping/dhydro/read_dhydro_simulations_utils.py index 3ba163c..8c5cc30 100644 --- a/scripts/ribasim_lumping/dhydro/read_dhydro_simulations_utils.py +++ b/scripts/ribasim_lumping/dhydro/read_dhydro_simulations_utils.py @@ -24,10 +24,13 @@ def get_data_from_simulation( simulations_ts: list | pd.DatetimeIndex, n_start: int = 0, ) -> tuple[xr.Dataset, xu.UgridDataset]: - """Gets simulation data + """ + Gets simulation data + - from a simulation - at certain timestamps. - Replaces time coordinate with counter 'condition' (int). Starts counting at n_start + Returns: map_data (edges/nodes) and his_data (structures) from one simulation """ files = get_dhydro_files(simulation_path) @@ -73,11 +76,13 @@ def get_data_from_simulations_set( simulations_names: list[str], simulations_ts: list | pd.DatetimeIndex, ) -> tuple[xr.Dataset, xu.UgridDataset]: - """Combines simulation data: + """Combines simulation data + - from several simulations (names) - from simulation folder (dir) - at predefined timestamps (ts) - replaces simulation timestamp with condition (int) + Returns: map_data (edges/nodes), his_data (structures) and boundary data, all simulations combined """ print("Read D-HYDRO simulations sets") @@ -131,8 +136,10 @@ def combine_data_from_simulations_sets( xugrid: bool = False, dim: str = "set", ) -> xr.Dataset | xu.UgridDataset: - """Combine his.nc and map.nc data from two cases over dimension DIM assuming - that all nc-variables not including DIM as dimension are equal + """ + Combine his.nc and map.nc data from two cases over dimension DIM. + + Assumes that all nc-variables not including DIM as dimension are equal. """ nc_set_vars = [v_n for v_n, v in nc_data_new.data_vars.items() if dim in v.dims] nc_nonset_vars = [v_n for v_n, v in nc_data_new.data_vars.items() if dim not in v.dims] diff --git a/scripts/ribasim_lumping/hydamo/preprocess_hydamo_dataset.py b/scripts/ribasim_lumping/hydamo/preprocess_hydamo_dataset.py index 5c97482..961c881 100644 --- a/scripts/ribasim_lumping/hydamo/preprocess_hydamo_dataset.py +++ b/scripts/ribasim_lumping/hydamo/preprocess_hydamo_dataset.py @@ -1,14 +1,13 @@ import itertools import logging -import os import time import warnings import geopandas as gpd import networkx as nx import pandas as pd -from shapely.geometry import LineString, Point, Polygon -from shapely.ops import snap, split +from shapely.geometry import LineString, Point +from shapely.ops import snap warnings.filterwarnings("ignore") @@ -86,22 +85,16 @@ def snap_connect_lines_by_endpoints(split_endpoints, lines): if dist1pos == 0: if linestring.coords[0] in list(connections_to_create["point"].values): - if ( - connections_to_create["inserted"][ - connections_to_create["point"] == linestring.coords[0] - ].values[0] - == True - ): + if connections_to_create["inserted"][connections_to_create["point"] == linestring.coords[0]].values[ + 0 + ]: continue elif dist1pos == len(linestring.coords) - 1: if linestring.coords[len(linestring.coords) - 1] in list(connections_to_create["point"].values): - if ( - connections_to_create["inserted"][ - connections_to_create["point"] == linestring.coords[len(linestring.coords) - 1] - ].values[0] - == True - ): + if connections_to_create["inserted"][ + connections_to_create["point"] == linestring.coords[len(linestring.coords) - 1] + ].values[0]: continue # else: @@ -218,9 +211,9 @@ def connect_endpoints_by_buffer(lines, buffer_distance=0.5): axis=1, ) - unconnected_endpoints = boundary_endpoints[ - boundary_endpoints["crossed_by_unconnected_lines"] == True - ].reset_index(drop=True) + unconnected_endpoints = boundary_endpoints[boundary_endpoints["crossed_by_unconnected_lines"]].reset_index( + drop=True + ) unconnected_endpoints["target_lines"] = unconnected_endpoints.apply( lambda x: [ @@ -377,6 +370,7 @@ def create_graph_based_on_nodes_edges( ) -> nx.DiGraph: """ create networkx graph from ribasim model. + input: nodes and edges """ graph = nx.DiGraph() diff --git a/scripts/ribasim_lumping/ribasim_lumping.py b/scripts/ribasim_lumping/ribasim_lumping.py index 442aa93..d243616 100644 --- a/scripts/ribasim_lumping/ribasim_lumping.py +++ b/scripts/ribasim_lumping/ribasim_lumping.py @@ -155,8 +155,9 @@ def add_basis_network( hydamo_split_network_dx: float = None, ) -> tuple[gpd.GeoDataFrame]: """ - Add (detailed) base network which will used to derive Ribasim network. Source type can either be "dhydro" or - "hydamo". + Add (detailed) base network which will used to derive Ribasim network. + + Source type can either be "dhydro" or "hydamo". If "dhydro", provide arguments for D-HYDRO volume tool (arguments dhydro_volume_*) and model simulation (model_dir, simulation_name). All necessary information (like boundaries and split nodes) will be derived from the D-HYDRO model data. @@ -286,6 +287,7 @@ def read_areas( ): """ Add discharge unit areas (e.g. "afwateringseenheden" or "peilgebiedenpraktijk") from file. + In case of geopackage, provide layer_name. Overwrites previously defined areas """ print(f"Network {self.name} - Analysis Areas") @@ -304,6 +306,7 @@ def read_drainage_areas( ): """ Add drainage areas (e.g. "afvoergebieden") from file. + In case of geopackage, provide layer_name. Overwrites previously defined drainage areas """ @@ -326,7 +329,9 @@ def read_supply_areas( crs: int = 28992, ): """ - Add supply areas (e.g. "afvoergebieden") from file. In case of geopackage, provide layer_name. + Add supply areas (e.g. "afvoergebieden") from file. + + In case of geopackage, provide layer_name. Overwrites previously defined supply areas Args: @@ -353,7 +358,9 @@ def read_boundaries( min_length_edge: float = 2.0, ): """ - Add Ribasim boundaries from file. In case of geopackage, provide layer_name. + Add Ribasim boundaries from file. + + In case of geopackage, provide layer_name. Overwrites previously defined boundaries Args: @@ -477,7 +484,6 @@ def add_split_nodes( edge_ids_to_exclude: list[int] = [], ) -> gpd.GeoDataFrame: """Set split nodes geodataframe in network object. Overwrites previously defined split nodes""" - self.split_nodes = add_split_nodes_based_on_selection( stations=stations, pumps=pumps, diff --git a/scripts/ribasim_lumping/ribasim_model_generator/generate_ribasim_model.py b/scripts/ribasim_lumping/ribasim_model_generator/generate_ribasim_model.py index c2c7b8e..8c31949 100644 --- a/scripts/ribasim_lumping/ribasim_model_generator/generate_ribasim_model.py +++ b/scripts/ribasim_lumping/ribasim_model_generator/generate_ribasim_model.py @@ -62,7 +62,9 @@ def generate_ribasim_basins( basin_subgrid: pd.DataFrame, basin_areas: gpd.GeoDataFrame, ): - """Generate settings for Ribasim Basins: + """ + Generate settings for Ribasim Basins. + static: node_id, drainage, potential_evaporation, infiltration, precipitation, urban_runoff profile: node_id, level, area, storage """ @@ -80,7 +82,9 @@ def generate_ribasim_level_boundaries( level_boundary_static: gpd.GeoDataFrame, level_boundary_time: pd.DataFrame, ): - """Generate ribasim level boundaries for all level boundary nodes + """ + Generate ribasim level boundaries for all level boundary nodes + static: node_id, level """ if level_boundary_time is not None: @@ -94,7 +98,9 @@ def generate_ribasim_level_boundaries( def generate_ribasim_flow_boundaries(flow_boundary_static: gpd.GeoDataFrame, flow_boundary_time: pd.DataFrame): - """Generate ribasim flow boundaries for all flow boundary nodes + """ + Generate ribasim flow boundaries for all flow boundary nodes + static: node_id, flow_rate """ print("flow_boundaries ", end="", flush=True) @@ -107,7 +113,9 @@ def generate_ribasim_flow_boundaries(flow_boundary_static: gpd.GeoDataFrame, flo def generate_ribasim_pumps(pump_static: gpd.GeoDataFrame): - """Generate ribasim pumps for all pump nodes + """ + Generate ribasim pumps for all pump nodes + static: node_id, flow_rate """ print("pumps ", end="", flush=True) @@ -118,7 +126,9 @@ def generate_ribasim_pumps(pump_static: gpd.GeoDataFrame): def generate_ribasim_outlets(outlet_static: gpd.GeoDataFrame): - """Generate ribasim outlets for all outlet nodes + """ + Generate ribasim outlets for all outlet nodes + static: node_id, flow_rate """ print("outlets ", end="", flush=True) @@ -129,7 +139,9 @@ def generate_ribasim_outlets(outlet_static: gpd.GeoDataFrame): def generate_ribasim_tabulatedratingcurves(tabulated_rating_curve_static: pd.DataFrame): - """Generate ribasim tabulated rating using dummyvalues for level and flow_rate + """ + Generate ribasim tabulated rating using dummyvalues for level and flow_rate + static: node_id, level, flow_rate """ print("tabulatedratingcurve ", end="", flush=True) @@ -140,7 +152,9 @@ def generate_ribasim_tabulatedratingcurves(tabulated_rating_curve_static: pd.Dat def generate_ribasim_manningresistances(manningresistance_static: gpd.GeoDataFrame): - """Generate ribasim manning resistances + """ + Generate ribasim manning resistances + static: node_id, length, manning_n, profile_width, profile_slope """ print("manningresistances ", end="", flush=True) @@ -151,7 +165,9 @@ def generate_ribasim_manningresistances(manningresistance_static: gpd.GeoDataFra def generate_ribasim_linear_resistances(linearresistance_static: gpd.GeoDataFrame): - """Generate ribasim linear resistances + """ + Generate ribasim linear resistances + static: node_id, resistance, max_flow_rate """ print("linearresistances ", end="", flush=True) @@ -204,10 +220,11 @@ def generate_ribasim_model( database_gpkg: str = "database.gpkg", results_dir: str = "results", ): - """Generate ribasim model from ribasim nodes and edges and - optional input; ribasim basins, level boundary, flow_boundary, pump, tabulated rating curve and manning resistance """ + Generate ribasim model from ribasim nodes and edges + optional input; ribasim basins, level boundary, flow_boundary, pump, tabulated rating curve and manning resistance + """ print("Generate ribasim model: ", end="", flush=True) ribasim_nodes = generate_ribasim_nodes_static( diff --git a/scripts/ribasim_lumping/ribasim_model_generator/generate_ribasim_model_preprocessing.py b/scripts/ribasim_lumping/ribasim_model_generator/generate_ribasim_model_preprocessing.py index b6a4809..6dffb64 100644 --- a/scripts/ribasim_lumping/ribasim_model_generator/generate_ribasim_model_preprocessing.py +++ b/scripts/ribasim_lumping/ribasim_model_generator/generate_ribasim_model_preprocessing.py @@ -14,7 +14,6 @@ def generate_ribasim_types_for_all_split_nodes( split_node_id_conversion: dict, ) -> tuple[gpd.GeoDataFrame, gpd.GeoDataFrame, gpd.GeoDataFrame]: """Generate Ribasim Types for all split nodes""" - print(" - define Ribasim-Nodes types based on input conversion table(s)") # Basins basins["ribasim_type"] = "Basin" diff --git a/scripts/ribasim_lumping/ribasim_model_results/__init__.py b/scripts/ribasim_lumping/ribasim_model_results/__init__.py index 1a5b3ca..6bba96f 100644 --- a/scripts/ribasim_lumping/ribasim_model_results/__init__.py +++ b/scripts/ribasim_lumping/ribasim_model_results/__init__.py @@ -6,3 +6,12 @@ plot_results_basins_ribasim_model, read_ribasim_model_results, ) + +__all__ = [ + "RibasimBasinResults", + "RibasimModelResults", + "get_ribasim_basin_data_from_model", + "plot_results_basin_ribasim_model", + "plot_results_basins_ribasim_model", + "read_ribasim_model_results", +] diff --git a/scripts/ribasim_lumping/ribasim_model_results/ribasim_results.py b/scripts/ribasim_lumping/ribasim_model_results/ribasim_results.py index 5fa470d..892c11b 100644 --- a/scripts/ribasim_lumping/ribasim_model_results/ribasim_results.py +++ b/scripts/ribasim_lumping/ribasim_model_results/ribasim_results.py @@ -5,6 +5,7 @@ import matplotlib import matplotlib.pyplot as plt import pandas as pd +import ribasim from numba.core.errors import NumbaDeprecationWarning from pydantic import BaseModel, ConfigDict @@ -12,7 +13,6 @@ warnings.simplefilter("ignore", category=UserWarning) warnings.simplefilter("ignore", category=FutureWarning) pd.options.mode.chained_assignment = None -import ribasim class RibasimModelResults(BaseModel): diff --git a/scripts/ribasim_lumping/ribasim_network_generator/export_load_split_nodes.py b/scripts/ribasim_lumping/ribasim_network_generator/export_load_split_nodes.py index 7adb9f7..8f903ee 100644 --- a/scripts/ribasim_lumping/ribasim_network_generator/export_load_split_nodes.py +++ b/scripts/ribasim_lumping/ribasim_network_generator/export_load_split_nodes.py @@ -16,10 +16,11 @@ def write_structures_to_excel( split_node_id_conversion: dict = None, results_dir: Path | str = None, ): - """Export all structures and splitnode info to excel file with seperate sheet per structure type - input: network with structure gdfs, splitnodes, split node type conversion tables """ + Export all structures and splitnode info to excel file with seperate sheet per structure type + input: network with structure gdfs, splitnodes, split node type conversion tables + """ list_gdfs = [pumps, weirs, orifices, bridges, culverts, uniweirs] structures = pd.DataFrame(columns=["mesh1d_node_id", "mesh1d_nEdges", "geometry", "object_type"]) @@ -80,8 +81,10 @@ def write_structures_to_excel( def read_structures_from_excel(excel_path): - """Import all structure ids from excelfile - use columns mesh1d_node_id, use_splitnode and type + """ + Import all structure IDs from an Excel file. + + Use columns mesh1d_node_id, use_splitnode and type and output: - dictionary with excel data - list of structures to include as splitnode diff --git a/scripts/ribasim_lumping/ribasim_network_generator/generate_ribasim_network.py b/scripts/ribasim_lumping/ribasim_network_generator/generate_ribasim_network.py index d253dfa..72f6e49 100644 --- a/scripts/ribasim_lumping/ribasim_network_generator/generate_ribasim_network.py +++ b/scripts/ribasim_lumping/ribasim_network_generator/generate_ribasim_network.py @@ -22,8 +22,9 @@ def create_graph_based_on_nodes_edges( print_logmessage: bool = True, ) -> nx.Graph | nx.DiGraph: """ - create networkx graph based on geographic nodes and edges. - default a directional graph. + Create networkx graph based on geographic nodes and edges. + + Defaults to a directional graph. """ if directional_graph: graph = nx.DiGraph() @@ -47,12 +48,13 @@ def split_graph_based_on_split_nodes( graph: nx.DiGraph, split_nodes: gpd.GeoDataFrame, edges: gpd.GeoDataFrame ) -> tuple[nx.DiGraph, gpd.GeoDataFrame]: """ - Split networkx graph at split_edge or split_node. It removes the original edges(s)/node(s) which are the same as split_edge and + Split networkx graph at split_edge or split_node. + + It removes the original edges(s)/node(s) which are the same as split_edge and split_node and inserts new edges and nodes such that the graph becomes disconnected at the split point. After this edges don't connect to 1 node (at split point) but each end in each own new node. Because of this removing and adding edges and nodes in the graph, these new nodes no in graph are added to split_nodes gdf and also returned as result of this function. """ - split_nodes = split_nodes.copy() # copy to make sure gdf variable is not linked split_nodes["graph_node_no"] = pd.Series( [-1] * len(split_nodes), index=split_nodes.index, dtype=object @@ -166,7 +168,6 @@ def check_if_split_node_is_used( edges: gpd.GeoDataFrame, ) -> gpd.GeoDataFrame: """Check whether split_nodes are used, split_nodes and split_edges""" - split_nodes = split_nodes.copy() # copy to make sure gdf variable is not linked split_nodes["status"] = True @@ -208,10 +209,10 @@ def create_basin_areas_based_on_drainage_areas( laterals: gpd.GeoDataFrame = None, ) -> tuple[gpd.GeoDataFrame, gpd.GeoDataFrame]: """ - find areas with spatial join on edges. add subgraph code to areas - and combine all areas with certain subgraph code into one basin - """ + Find areas with spatial join on edges. + Add subgraph code to areas and combine all areas with certain subgraph code into one Basin. + """ if areas is None: return None, None else: @@ -232,7 +233,7 @@ def get_area_code_for_lateral(laterals, areas): def get_basin_code_from_lateral(area_code, laterals_join): basins = list( laterals_join["basin"][ - (laterals_join["area_code_included"] == area_code) & (laterals_join["basin"].isna() == False) + (laterals_join["area_code_included"] == area_code) & laterals_join["basin"].notna() ].values ) if len(basins) == 0: @@ -383,7 +384,6 @@ def check_if_nodes_edges_within_basin_areas( nodes: gpd.GeoDataFrame, edges: gpd.GeoDataFrame, basin_areas: gpd.GeoDataFrame ) -> tuple[gpd.GeoDataFrame]: """Check whether nodes assigned to a basin are also within the polygon assigned to that basin""" - edges, nodes, basin_areas = ( edges.copy(), nodes.copy(), @@ -680,9 +680,10 @@ def remove_boundary_basins_if_not_needed( include_level_boundary_basins: bool = False, ): """ - FlowBoundaries and LevelBoundaries are connected to basins using the subgraph method. - When include_flow_boundary_basins=False or include_level_boundary_basins=False - the basins are removed and boundaries_nodes are directly connected to the split_nodes + FlowBoundaries and LevelBoundaries are connected to Basins using the subgraph method. + + When `include_flow_boundary_basins=False` or `include_level_boundary_basins=False` + the Basins are removed and boundaries_nodes are directly connected to the split_nodes """ flow_boundary_connections = boundary_connections[boundary_connections.boundary_type == "FlowBoundary"] level_boundary_connections = boundary_connections[boundary_connections.boundary_type == "LevelBoundary"] @@ -870,6 +871,7 @@ def remove_isolated_basins_and_update_administration( ) -> tuple[gpd.GeoDataFrame, gpd.GeoDataFrame, gpd.GeoDataFrame, gpd.GeoDataFrame, gpd.GeoDataFrame]: """ Remove isolated basins (including 1-on-1 connected basin areas) based on basin and boundary connections. + Update the basin administration in basin areas, areas, edges and nodes Returns basin, basin areas, areas, edges and nodes """ @@ -932,8 +934,8 @@ def generate_ribasim_network_using_split_nodes( option_edges_hydroobjects: bool = False, ) -> dict: """ - Create basins (nodes) and basin_areas (large polygons) and connections (edges) - based on nodes, edges, split_nodes and areas (discharge units). + Create basins (nodes) and basin_areas (large polygons) and connections (edges) based on nodes, edges, split_nodes and areas (discharge units). + This function calls all other functions """ network_graph = None diff --git a/scripts/ribasim_lumping/ribasim_network_generator/generate_split_nodes.py b/scripts/ribasim_lumping/ribasim_network_generator/generate_split_nodes.py index 5542b03..8e44981 100644 --- a/scripts/ribasim_lumping/ribasim_network_generator/generate_split_nodes.py +++ b/scripts/ribasim_lumping/ribasim_network_generator/generate_split_nodes.py @@ -13,7 +13,9 @@ def get_split_nodes_based_on_type( list_gdfs: list[gpd.GeoDataFrame] = None, crs: int = 28992, ): - """Get split_nodes based on weirs and/or pumps. + """ + Get split_nodes based on weirs and/or pumps. + list_gdfs is a list of geodataframes including stations, pumps, weirs, orifices, bridges, culverts, uniweirs """ @@ -48,9 +50,12 @@ def add_split_nodes_based_on_selection( edge_ids_to_include: list[int] = [], edge_ids_to_exclude: list[int] = [], ) -> gpd.GeoDataFrame: - """Receive node id's of splitnodes - by choosing which structures to use as splitnodes locations + """ + Receive node ID's of splitnodes. + + Works by choosing which structures to use as splitnodes locations and including or excluding specific nodes as splitnode + returns splitnodes """ network_edges = list_gdfs[-1] diff --git a/scripts/ribasim_lumping/utils/general_functions.py b/scripts/ribasim_lumping/utils/general_functions.py index 8c24248..0928510 100644 --- a/scripts/ribasim_lumping/utils/general_functions.py +++ b/scripts/ribasim_lumping/utils/general_functions.py @@ -298,6 +298,7 @@ def log_and_remove_duplicate_geoms(gdf: gpd.GeoDataFrame, colname: str = None) - def generate_nodes_from_edges(edges: gpd.GeoDataFrame) -> tuple[gpd.GeoDataFrame, gpd.GeoDataFrame]: """ Generate start/end nodes from edges and update node information in edges GeoDataFrame. + Return updated edges geodataframe and nodes geodataframe Parameters @@ -354,7 +355,6 @@ def snap_to_network( ------- GeoDataFrame with snapped geometries that are either snapped or not (based on edge_no or node_no column value) """ - if snap_type == "split_node": print( f" - Snapping split nodes: buffer distance to nodes ({buffer_distance * 0.1:.3f} m) or edges ({buffer_distance:.3f} m)..." @@ -434,7 +434,6 @@ def snap_points_to_nodes_and_edges( ------- GeoDataFrame with snapped points (whether or not it's snapped can be derived from edge_no or node_no column value) """ - print(" - Snapping points to nodes and/or edges") new_points = points.geometry.tolist() for i, point in points.iterrows(): @@ -523,7 +522,6 @@ def get_node_no_and_edge_no_for_points( ------- Original GeoDataFrame of split nodes with extra edge_no and node_no column """ - print(" - Retrieving edge no or node no for point locations...") prev_typs = None for typ, gdf in zip(["node_no", "edge_no"], [nodes, edges]): @@ -555,7 +553,9 @@ def split_edges_by_split_nodes( split_nodes: gpd.GeoDataFrame, edges: gpd.GeoDataFrame, buffer_distance: float = 0.5 ) -> tuple[gpd.GeoDataFrame, gpd.GeoDataFrame]: """ - Splits edges (lines) by split node locations. Split nodes should be (almost) perfectly be aligned to edges (within buffer distance). + Splits edges (lines) by split node locations. + + Split nodes should be (almost) perfectly be aligned to edges (within buffer distance). If not, use .snap_nodes_to_edges() before to align them to edges within a buffer distance. If split nodes gdf contains edge_no column (which is filled with only integers), only those edges will be split. If the column is missing @@ -577,7 +577,6 @@ def split_edges_by_split_nodes( ------- Tuple containing GeoDataFrame with split nodes, GeoDataFrame with edges and GeoDataFrame (start/end)nodes of edges """ - print(" - Split edges by split nodes locations...") split_nodes["edge_no"] = [None] * len(split_nodes) edge_no_col_present = "edge_no" in split_nodes.columns @@ -766,6 +765,7 @@ def assign_unassigned_areas_to_basin_areas( ) -> dict[str, gpd.GeoDataFrame]: """ Assign unassigned areas to basin areas based on neighbouring basin areas within optionally the same drainage area if possible. + Optionally, if edges are provided, the basin and basin_area columns will be updated in those gdfs for edges where no basin/basin_area is filled in (equals to -1). Those will be filled based on overlapping basin area after assignment of unassigned areas. The edges will also be used to assign unassigned areas more logically based on network connections. @@ -784,7 +784,6 @@ def assign_unassigned_areas_to_basin_areas( Dict of basin areas where unassigned areas are assigned to basin areas and areas geodataframe with updated basin codes It will also include edges if they are provided as input """ - areas = areas.copy() basin_areas = basin_areas.copy() drainage_areas = drainage_areas.copy() if drainage_areas is not None else None diff --git a/scripts/ribasim_lumping/utils/remove_holes_from_polygons.py b/scripts/ribasim_lumping/utils/remove_holes_from_polygons.py index 164a361..d00b73e 100644 --- a/scripts/ribasim_lumping/utils/remove_holes_from_polygons.py +++ b/scripts/ribasim_lumping/utils/remove_holes_from_polygons.py @@ -1,4 +1,3 @@ -from collections.abc import Callable from typing import TypeVar import geopandas as gpd diff --git a/src/hydamo/hydamo/datamodel.py b/src/hydamo/hydamo/datamodel.py index 69812f3..c227431 100644 --- a/src/hydamo/hydamo/datamodel.py +++ b/src/hydamo/hydamo/datamodel.py @@ -50,7 +50,7 @@ def map_definition(definition: dict[str, Any]) -> list[dict[str, Any]]: """ - + Validation schema for the HyDAMO class. Parameters ---------- @@ -63,7 +63,6 @@ def map_definition(definition: dict[str, Any]) -> list[dict[str, Any]]: Validation schema for the HyDAMO class. """ - # start with an empty list to populate result = [] @@ -201,7 +200,7 @@ def set_data( extra_attributes={}, ): """ - + Set data to the ExtendedGeoDataFrame. Parameters ---------- @@ -220,7 +219,6 @@ def set_data( None. """ - if not self.empty: self.delete_all() @@ -265,7 +263,7 @@ def delete_all(self): def snap_to_branch(self, branches, snap_method, maxdist=5): """ - + Snap the geometries to the branch. Parameters ---------- @@ -281,8 +279,6 @@ def snap_to_branch(self, branches, snap_method, maxdist=5): None. """ - - """Snap the geometries to the branch.""" geometry.find_nearest_branch(branches=branches, geometries=self, method=snap_method, maxdist=maxdist) @@ -372,7 +368,7 @@ def set_data( extra_values={}, ): """ - + Set data to a HyDAMO object-layer. Parameters ---------- @@ -393,7 +389,6 @@ def set_data( None. """ - getattr(self, layer).set_data( gdf, index_col=index_col, @@ -404,6 +399,7 @@ def set_data( def to_geopackage(self, file_path, use_schema=True): """ + Write HyDAMO object to a GeoPackage. Parameters ---------- diff --git a/src/hydamo/hydamo/geometry.py b/src/hydamo/hydamo/geometry.py index e9751e4..fb82d92 100644 --- a/src/hydamo/hydamo/geometry.py +++ b/src/hydamo/hydamo/geometry.py @@ -15,7 +15,6 @@ def possibly_intersecting(dataframebounds, geometry, buffer=0): dataframebounds : numpy.array geometry : shapely.geometry.Polygon """ - geobounds = geometry.bounds idx = ( (dataframebounds[0] - buffer < geobounds[2]) diff --git a/src/hydamo/hydamo/styles.py b/src/hydamo/hydamo/styles.py index f8d12fe..85c01b5 100644 --- a/src/hydamo/hydamo/styles.py +++ b/src/hydamo/hydamo/styles.py @@ -61,6 +61,7 @@ def read_style(style_path: Path) -> str: """ To make style-text sql-compatible, we need to replace single ' to ''. + Example 'http://mrcc.com/qgis.dtd -> ''http://mrcc.com/qgis.dtd'' Parameters @@ -96,7 +97,6 @@ def add_styles_to_geopackage(gpkg_path: Path): None. """ - with sqlite3.connect(gpkg_path) as conn: # create table conn.execute(DROP_TABLE_SQL) diff --git a/src/peilbeheerst_model/Parametrize/AmstelGooienVecht_parametrize.ipynb b/src/peilbeheerst_model/Parametrize/AmstelGooienVecht_parametrize.ipynb index 7c638f5..b8c646f 100644 --- a/src/peilbeheerst_model/Parametrize/AmstelGooienVecht_parametrize.ipynb +++ b/src/peilbeheerst_model/Parametrize/AmstelGooienVecht_parametrize.ipynb @@ -10,31 +10,16 @@ "import logging\n", "import os\n", "import pathlib\n", - "import sys\n", "import warnings\n", - "from pathlib import Path\n", "\n", "import pandas as pd\n", + "import peilbeheerst_model.ribasim_parametrization as ribasim_param\n", "import ribasim\n", "import ribasim.nodes\n", - "\n", - "# load ribasim_nl\n", - "module_path = Path.cwd() / \"../../ribasim_nl/\"\n", - "sys.path.append(str(module_path))\n", - "\n", - "current_dir = os.getcwd()\n", - "parent_dir = os.path.dirname(current_dir)\n", - "if parent_dir not in sys.path:\n", - " sys.path.append(parent_dir)\n", - "\n", - "%reload_ext autoreload\n", - "%autoreload 2\n", - "warnings.filterwarnings(\"ignore\")\n", - "\n", - "import peilbeheerst_model.ribasim_parametrization as ribasim_param\n", "from peilbeheerst_model.add_storage_basins import AddStorageBasin\n", - "from peilbeheerst_model.controle_output import *\n", - "from peilbeheerst_model.ribasim_feedback_processor import RibasimFeedbackProcessor" + "from peilbeheerst_model.ribasim_feedback_processor import RibasimFeedbackProcessor\n", + "\n", + "warnings.filterwarnings(\"ignore\")" ] }, { @@ -464,15 +449,6 @@ " logging.error(f\"Could not read the log file: {log_exception}\")" ] }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "stop" - ] - }, { "cell_type": "markdown", "metadata": {}, diff --git a/src/peilbeheerst_model/Parametrize/Delfland_parametrize.ipynb b/src/peilbeheerst_model/Parametrize/Delfland_parametrize.ipynb index 206c18e..80a7cc4 100644 --- a/src/peilbeheerst_model/Parametrize/Delfland_parametrize.ipynb +++ b/src/peilbeheerst_model/Parametrize/Delfland_parametrize.ipynb @@ -10,31 +10,16 @@ "import logging\n", "import os\n", "import pathlib\n", - "import sys\n", "import warnings\n", - "from pathlib import Path\n", "\n", "import pandas as pd\n", + "import peilbeheerst_model.ribasim_parametrization as ribasim_param\n", "import ribasim\n", "import ribasim.nodes\n", - "\n", - "# load ribasim_nl\n", - "module_path = Path.cwd() / \"../../ribasim_nl/\"\n", - "sys.path.append(str(module_path))\n", - "\n", - "current_dir = os.getcwd()\n", - "parent_dir = os.path.dirname(current_dir)\n", - "if parent_dir not in sys.path:\n", - " sys.path.append(parent_dir)\n", - "\n", - "%reload_ext autoreload\n", - "%autoreload 2\n", - "warnings.filterwarnings(\"ignore\")\n", - "\n", - "import peilbeheerst_model.ribasim_parametrization as ribasim_param\n", "from peilbeheerst_model.add_storage_basins import AddStorageBasin\n", - "from peilbeheerst_model.controle_output import *\n", - "from peilbeheerst_model.ribasim_feedback_processor import RibasimFeedbackProcessor" + "from peilbeheerst_model.ribasim_feedback_processor import RibasimFeedbackProcessor\n", + "\n", + "warnings.filterwarnings(\"ignore\")" ] }, { @@ -389,15 +374,6 @@ " logging.error(f\"Could not read the log file: {log_exception}\")" ] }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "stop" - ] - }, { "cell_type": "markdown", "metadata": {}, diff --git a/src/peilbeheerst_model/Parametrize/HollandsNoorderkwartier_parametrize.ipynb b/src/peilbeheerst_model/Parametrize/HollandsNoorderkwartier_parametrize.ipynb index a8fa381..817200b 100644 --- a/src/peilbeheerst_model/Parametrize/HollandsNoorderkwartier_parametrize.ipynb +++ b/src/peilbeheerst_model/Parametrize/HollandsNoorderkwartier_parametrize.ipynb @@ -10,29 +10,14 @@ "import logging\n", "import os\n", "import pathlib\n", - "import sys\n", "import warnings\n", - "from pathlib import Path\n", "\n", "import pandas as pd\n", + "import peilbeheerst_model.ribasim_parametrization as ribasim_param\n", "import ribasim\n", "import ribasim.nodes\n", "\n", - "# load ribasim_nl\n", - "module_path = Path.cwd() / \"../../ribasim_nl/\"\n", - "sys.path.append(str(module_path))\n", - "\n", - "current_dir = os.getcwd()\n", - "parent_dir = os.path.dirname(current_dir)\n", - "if parent_dir not in sys.path:\n", - " sys.path.append(parent_dir)\n", - "\n", - "%reload_ext autoreload\n", - "%autoreload 2\n", - "warnings.filterwarnings(\"ignore\")\n", - "\n", - "import peilbeheerst_model.ribasim_parametrization as ribasim_param\n", - "from peilbeheerst_model.controle_output import *" + "warnings.filterwarnings(\"ignore\")" ] }, { @@ -377,15 +362,6 @@ " logging.error(f\"Could not read the log file: {log_exception}\")" ] }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "stop" - ] - }, { "cell_type": "markdown", "metadata": {}, diff --git a/src/peilbeheerst_model/Parametrize/HollandseDelta_parametrize.ipynb b/src/peilbeheerst_model/Parametrize/HollandseDelta_parametrize.ipynb index dd4c4ea..03911b0 100644 --- a/src/peilbeheerst_model/Parametrize/HollandseDelta_parametrize.ipynb +++ b/src/peilbeheerst_model/Parametrize/HollandseDelta_parametrize.ipynb @@ -10,35 +10,20 @@ "import logging\n", "import os\n", "import pathlib\n", - "import sys\n", "import warnings\n", - "from pathlib import Path\n", "\n", "import pandas as pd\n", + "import peilbeheerst_model.ribasim_parametrization as ribasim_param\n", "import ribasim\n", "import ribasim.nodes\n", - "from shapely.geometry import Point\n", - "\n", - "# load ribasim_nl\n", - "module_path = Path.cwd() / \"../../ribasim_nl/\"\n", - "sys.path.append(str(module_path))\n", - "\n", - "current_dir = os.getcwd()\n", - "parent_dir = os.path.dirname(current_dir)\n", - "if parent_dir not in sys.path:\n", - " sys.path.append(parent_dir)\n", - "\n", - "%reload_ext autoreload\n", - "%autoreload 2\n", - "warnings.filterwarnings(\"ignore\")\n", - "\n", - "import peilbeheerst_model.ribasim_parametrization as ribasim_param\n", - "from peilbeheerst_model.controle_output import *\n", "from peilbeheerst_model.ribasim_feedback_processor import RibasimFeedbackProcessor\n", "from ribasim import Node\n", "from ribasim.nodes import (\n", " tabulated_rating_curve,\n", - ")" + ")\n", + "from shapely.geometry import Point\n", + "\n", + "warnings.filterwarnings(\"ignore\")" ] }, { @@ -434,15 +419,6 @@ " logging.error(f\"Could not read the log file: {log_exception}\")" ] }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "stop" - ] - }, { "cell_type": "markdown", "metadata": {}, diff --git a/src/peilbeheerst_model/Parametrize/Rijnland_nieuw.ipynb b/src/peilbeheerst_model/Parametrize/Rijnland_nieuw.ipynb index 7bfbf78..fedcaf5 100644 --- a/src/peilbeheerst_model/Parametrize/Rijnland_nieuw.ipynb +++ b/src/peilbeheerst_model/Parametrize/Rijnland_nieuw.ipynb @@ -10,30 +10,15 @@ "import logging\n", "import os\n", "import pathlib\n", - "import sys\n", "import warnings\n", - "from pathlib import Path\n", "\n", "import pandas as pd\n", + "import peilbeheerst_model.ribasim_parametrization as ribasim_param\n", "import ribasim\n", "import ribasim.nodes\n", + "from peilbeheerst_model.ribasim_feedback_processor import RibasimFeedbackProcessor\n", "\n", - "# load ribasim_nl\n", - "module_path = Path.cwd() / \"../../ribasim_nl/\"\n", - "sys.path.append(str(module_path))\n", - "\n", - "current_dir = os.getcwd()\n", - "parent_dir = os.path.dirname(current_dir)\n", - "if parent_dir not in sys.path:\n", - " sys.path.append(parent_dir)\n", - "\n", - "%reload_ext autoreload\n", - "%autoreload 2\n", - "warnings.filterwarnings(\"ignore\")\n", - "\n", - "import peilbeheerst_model.ribasim_parametrization as ribasim_param\n", - "from peilbeheerst_model.controle_output import *\n", - "from peilbeheerst_model.ribasim_feedback_processor import RibasimFeedbackProcessor" + "warnings.filterwarnings(\"ignore\")" ] }, { @@ -386,15 +371,6 @@ " logging.error(f\"Could not read the log file: {log_exception}\")" ] }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "stop" - ] - }, { "cell_type": "markdown", "metadata": {}, diff --git a/src/peilbeheerst_model/Parametrize/Rijnland_parametrize.ipynb b/src/peilbeheerst_model/Parametrize/Rijnland_parametrize.ipynb index 44d7bf3..c399854 100644 --- a/src/peilbeheerst_model/Parametrize/Rijnland_parametrize.ipynb +++ b/src/peilbeheerst_model/Parametrize/Rijnland_parametrize.ipynb @@ -9,28 +9,14 @@ "import datetime\n", "import os\n", "import pathlib\n", - "import sys\n", "import warnings\n", - "from pathlib import Path\n", "\n", + "import matplotlib.pyplot as plt\n", "import pandas as pd\n", + "import peilbeheerst_model.ribasim_parametrization as ribasim_param\n", "import ribasim\n", "import ribasim.nodes\n", "\n", - "# load ribasim_nl\n", - "module_path = Path.cwd() / \"../../ribasim_nl/\"\n", - "sys.path.append(str(module_path))\n", - "\n", - "current_dir = os.getcwd()\n", - "parent_dir = os.path.dirname(current_dir)\n", - "if parent_dir not in sys.path:\n", - " sys.path.append(parent_dir)\n", - "\n", - "import peilbeheerst_model.ribasim_parametrization as ribasim_param\n", - "from peilbeheerst_model.controle_output import *\n", - "\n", - "%reload_ext autoreload\n", - "%autoreload 2\n", "warnings.filterwarnings(\"ignore\")" ] }, diff --git a/src/peilbeheerst_model/Parametrize/Rivierenland_parametrize.ipynb b/src/peilbeheerst_model/Parametrize/Rivierenland_parametrize.ipynb index 680853a..a60cb92 100644 --- a/src/peilbeheerst_model/Parametrize/Rivierenland_parametrize.ipynb +++ b/src/peilbeheerst_model/Parametrize/Rivierenland_parametrize.ipynb @@ -9,28 +9,13 @@ "import datetime\n", "import os\n", "import pathlib\n", - "import sys\n", "import warnings\n", - "from pathlib import Path\n", "\n", "import pandas as pd\n", + "import peilbeheerst_model.ribasim_parametrization as ribasim_param\n", "import ribasim\n", "import ribasim.nodes\n", "\n", - "# load ribasim_nl\n", - "module_path = Path.cwd() / \"../../ribasim_nl/\"\n", - "sys.path.append(str(module_path))\n", - "\n", - "current_dir = os.getcwd()\n", - "parent_dir = os.path.dirname(current_dir)\n", - "if parent_dir not in sys.path:\n", - " sys.path.append(parent_dir)\n", - "\n", - "import peilbeheerst_model.ribasim_parametrization as ribasim_param\n", - "from peilbeheerst_model.controle_output import *\n", - "\n", - "%reload_ext autoreload\n", - "%autoreload 2\n", "warnings.filterwarnings(\"ignore\")" ] }, diff --git a/src/peilbeheerst_model/Parametrize/Scheldestromen_parametrize.ipynb b/src/peilbeheerst_model/Parametrize/Scheldestromen_parametrize.ipynb index 98d9aeb..f7f49cc 100644 --- a/src/peilbeheerst_model/Parametrize/Scheldestromen_parametrize.ipynb +++ b/src/peilbeheerst_model/Parametrize/Scheldestromen_parametrize.ipynb @@ -10,31 +10,16 @@ "import logging\n", "import os\n", "import pathlib\n", - "import sys\n", "import warnings\n", - "from pathlib import Path\n", "\n", "import pandas as pd\n", + "import peilbeheerst_model.ribasim_parametrization as ribasim_param\n", "import ribasim\n", "import ribasim.nodes\n", - "\n", - "# load ribasim_nl\n", - "module_path = Path.cwd() / \"../../ribasim_nl/\"\n", - "sys.path.append(str(module_path))\n", - "\n", - "current_dir = os.getcwd()\n", - "parent_dir = os.path.dirname(current_dir)\n", - "if parent_dir not in sys.path:\n", - " sys.path.append(parent_dir)\n", - "\n", - "%reload_ext autoreload\n", - "%autoreload 2\n", - "warnings.filterwarnings(\"ignore\")\n", - "\n", - "import peilbeheerst_model.ribasim_parametrization as ribasim_param\n", "from peilbeheerst_model.add_storage_basins import AddStorageBasin\n", - "from peilbeheerst_model.controle_output import *\n", - "from peilbeheerst_model.ribasim_feedback_processor import RibasimFeedbackProcessor" + "from peilbeheerst_model.ribasim_feedback_processor import RibasimFeedbackProcessor\n", + "\n", + "warnings.filterwarnings(\"ignore\")" ] }, { diff --git a/src/peilbeheerst_model/Parametrize/SchielandendeKrimpenerwaard_parametrize.ipynb b/src/peilbeheerst_model/Parametrize/SchielandendeKrimpenerwaard_parametrize.ipynb index 3c45f7f..5478e2f 100644 --- a/src/peilbeheerst_model/Parametrize/SchielandendeKrimpenerwaard_parametrize.ipynb +++ b/src/peilbeheerst_model/Parametrize/SchielandendeKrimpenerwaard_parametrize.ipynb @@ -10,31 +10,16 @@ "import logging\n", "import os\n", "import pathlib\n", - "import sys\n", "import warnings\n", - "from pathlib import Path\n", "\n", "import pandas as pd\n", + "import peilbeheerst_model.ribasim_parametrization as ribasim_param\n", "import ribasim\n", "import ribasim.nodes\n", - "\n", - "# load ribasim_nl\n", - "module_path = Path.cwd() / \"../../ribasim_nl/\"\n", - "sys.path.append(str(module_path))\n", - "\n", - "current_dir = os.getcwd()\n", - "parent_dir = os.path.dirname(current_dir)\n", - "if parent_dir not in sys.path:\n", - " sys.path.append(parent_dir)\n", - "\n", - "%reload_ext autoreload\n", - "%autoreload 2\n", - "warnings.filterwarnings(\"ignore\")\n", - "\n", - "import peilbeheerst_model.ribasim_parametrization as ribasim_param\n", "from peilbeheerst_model.add_storage_basins import AddStorageBasin\n", - "from peilbeheerst_model.controle_output import *\n", - "from peilbeheerst_model.ribasim_feedback_processor import RibasimFeedbackProcessor" + "from peilbeheerst_model.ribasim_feedback_processor import RibasimFeedbackProcessor\n", + "\n", + "warnings.filterwarnings(\"ignore\")" ] }, { @@ -409,15 +394,6 @@ " logging.error(f\"Could not read the log file: {log_exception}\")" ] }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "stop" - ] - }, { "cell_type": "markdown", "metadata": {}, diff --git a/src/peilbeheerst_model/Parametrize/WetterskipFryslan_parametrize.ipynb b/src/peilbeheerst_model/Parametrize/WetterskipFryslan_parametrize.ipynb index 7abf60b..9bac655 100644 --- a/src/peilbeheerst_model/Parametrize/WetterskipFryslan_parametrize.ipynb +++ b/src/peilbeheerst_model/Parametrize/WetterskipFryslan_parametrize.ipynb @@ -10,34 +10,20 @@ "import logging\n", "import os\n", "import pathlib\n", - "import sys\n", "import warnings\n", - "from pathlib import Path\n", "\n", "import pandas as pd\n", + "import peilbeheerst_model.ribasim_parametrization as ribasim_param\n", "import ribasim\n", "import ribasim.nodes\n", - "from shapely.geometry import Point\n", - "\n", - "# load ribasim_nl\n", - "module_path = Path.cwd() / \"../../ribasim_nl/\"\n", - "sys.path.append(str(module_path))\n", - "\n", - "current_dir = os.getcwd()\n", - "parent_dir = os.path.dirname(current_dir)\n", - "if parent_dir not in sys.path:\n", - " sys.path.append(parent_dir)\n", - "\n", - "%reload_ext autoreload\n", - "%autoreload 2\n", - "warnings.filterwarnings(\"ignore\")\n", - "\n", - "import peilbeheerst_model.ribasim_parametrization as ribasim_param\n", - "from peilbeheerst_model.controle_output import *\n", + "from peilbeheerst_model.add_storage_basins import AddStorageBasin\n", "from ribasim import Node\n", "from ribasim.nodes import (\n", " pump,\n", - ")" + ")\n", + "from shapely.geometry import Point\n", + "\n", + "warnings.filterwarnings(\"ignore\")" ] }, { diff --git a/src/peilbeheerst_model/Parametrize/Zuiderzeeland_parametrize.ipynb b/src/peilbeheerst_model/Parametrize/Zuiderzeeland_parametrize.ipynb index 7690df6..62f0146 100644 --- a/src/peilbeheerst_model/Parametrize/Zuiderzeeland_parametrize.ipynb +++ b/src/peilbeheerst_model/Parametrize/Zuiderzeeland_parametrize.ipynb @@ -10,29 +10,15 @@ "import logging\n", "import os\n", "import pathlib\n", - "import sys\n", "import warnings\n", - "from pathlib import Path\n", "\n", "import pandas as pd\n", + "import peilbeheerst_model.ribasim_parametrization as ribasim_param\n", "import ribasim\n", "import ribasim.nodes\n", + "from peilbeheerst_model.add_storage_basins import AddStorageBasin\n", "\n", - "# load ribasim_nl\n", - "module_path = Path.cwd() / \"../../ribasim_nl/\"\n", - "sys.path.append(str(module_path))\n", - "\n", - "current_dir = os.getcwd()\n", - "parent_dir = os.path.dirname(current_dir)\n", - "if parent_dir not in sys.path:\n", - " sys.path.append(parent_dir)\n", - "\n", - "%reload_ext autoreload\n", - "%autoreload 2\n", - "warnings.filterwarnings(\"ignore\")\n", - "\n", - "import peilbeheerst_model.ribasim_parametrization as ribasim_param\n", - "from peilbeheerst_model.controle_output import *" + "warnings.filterwarnings(\"ignore\")" ] }, { diff --git a/src/peilbeheerst_model/peilbeheerst_model/add_storage_basins.py b/src/peilbeheerst_model/peilbeheerst_model/add_storage_basins.py index 37d887e..db3cd94 100644 --- a/src/peilbeheerst_model/peilbeheerst_model/add_storage_basins.py +++ b/src/peilbeheerst_model/peilbeheerst_model/add_storage_basins.py @@ -40,7 +40,6 @@ def __init__(self, ribasim_toml, model_name, output_folder, include_hoofdwater=F def setup_logging(self): """Set up logging to file and console.""" - # Clear any existing handlers for handler in logging.root.handlers[:]: logging.root.removeHandler(handler) @@ -92,7 +91,6 @@ def get_current_max_nodeid(self): def add_basin_nodes_with_manning_resistance(self): """Add basin nodes with Manning resistance based on meta_categorie.""" - # Get the meta_categorie column from the state DataFrame state_df = self.model.basin.state.df @@ -261,7 +259,6 @@ def connect_nodes(self, new_basin_node_id, manning_node_id, original_node_id): def run(self): """Run the process of adding basin nodes with Manning resistance and writing the updated model""" - self.add_basin_nodes_with_manning_resistance() # self.write_ribasim_model() logging.shutdown() @@ -270,7 +267,6 @@ def run(self): def write_ribasim_model(self): """Write the updated ribasim model to the output directory""" - outputdir = Path(self.output_folder) modelcase_dir = Path(f"updated_{self.model_name.lower()}") diff --git a/src/peilbeheerst_model/peilbeheerst_model/crossings_to_ribasim.py b/src/peilbeheerst_model/peilbeheerst_model/crossings_to_ribasim.py index 0211bf6..a4ea5d8 100644 --- a/src/peilbeheerst_model/peilbeheerst_model/crossings_to_ribasim.py +++ b/src/peilbeheerst_model/peilbeheerst_model/crossings_to_ribasim.py @@ -870,7 +870,6 @@ def edge(self): _type_ _description_ """ - edge = gpd.GeoDataFrame() # fix the from nodes @@ -901,7 +900,6 @@ def basin(self): _type_ _description_ """ - basin_nodes = self.nodes.loc[self.nodes["type"] == "Basin"][ ["node_id", "streefpeil", "geometry", "basins_area_geom"] ] @@ -1056,7 +1054,6 @@ def flow_boundary(self): _type_ _description_ """ - flow_boundary_nodes = self.nodes.loc[self.nodes["type"] == "FlowBoundary"][ ["node_id", "geometry"] ] # .node_id.to_numpy() @@ -1156,7 +1153,6 @@ def outlet(self, model): _type_ _description_ """ - outlet = ribasim.Outlet(static=pd.DataFrame(data={"node_id": [], "flow_rate": []})) return outlet diff --git a/src/peilbeheerst_model/peilbeheerst_model/parse_crossings.py b/src/peilbeheerst_model/peilbeheerst_model/parse_crossings.py index cd3aa3c..33a36b2 100644 --- a/src/peilbeheerst_model/peilbeheerst_model/parse_crossings.py +++ b/src/peilbeheerst_model/peilbeheerst_model/parse_crossings.py @@ -364,7 +364,6 @@ def add_krw_to_peilgebieden( gpd.GeoDataFrame _description_ """ - # Add columns to peilgebieden dataframe pgb_krw_id = "owmident" pgb_krw_name = "owmnaam" @@ -453,7 +452,6 @@ def find_crossings_with_peilgebieden( gpd.GeoDataFrame _description_ """ - # Check uniqueness of globalid for lyr in ["peilgebied", layer, filterlayer]: if lyr is None: @@ -845,7 +843,6 @@ def _make_merged_line_stacked( LineString _description_ """ - # Find the line(s) on which the current crossing lies and the directly # connected lines. nrec = 10 @@ -909,7 +906,6 @@ def _add_potential_crossing( dict[tuple[str | None, str | None, float, float], Point] _description_ """ - for crossing in crossing_points.geometry: # Find crossing line with potentially added connections merged_crossing_line, merged_ids = self._make_merged_line( @@ -1016,7 +1012,6 @@ def _find_stacked_crossings( TypeError _description_ """ - dfs = dfc.copy() dfs.insert(len(dfs.columns) - 1, "match_group", 0) dfs.insert(len(dfs.columns) - 1, "match_stacked", 0) @@ -1827,7 +1822,6 @@ def _assign_structure( tuple[gpd.GeoDataFrame, list] _description_ """ - # Find the line objects nearest to the structure _, idxs = self._find_closest_lines( structure_geom, @@ -2097,7 +2091,6 @@ def _aggregate_identical_links(self, dfc: gpd.GeoDataFrame, agg_links: bool) -> gpd.GeoDataFrame _description_ """ - group_col = "agg_links_group" old_use_col = "in_use" new_use_col = "agg_links_in_use" diff --git a/src/peilbeheerst_model/peilbeheerst_model/postprocess_data/general_functions.py b/src/peilbeheerst_model/peilbeheerst_model/postprocess_data/general_functions.py index 40b038f..0e40153 100644 --- a/src/peilbeheerst_model/peilbeheerst_model/postprocess_data/general_functions.py +++ b/src/peilbeheerst_model/peilbeheerst_model/postprocess_data/general_functions.py @@ -22,7 +22,6 @@ def read_gpkg_layers(gpkg_path, variables, engine="fiona", print_var=False): This function reads specified layers from a GeoPackage (GPKG) file and returns them as a dictionary. You can choose to print the names of variables as they are read by setting `print_var` to True. """ - data = {} for variable in variables: if print_var: @@ -49,7 +48,6 @@ def show_layers_and_columns(waterschap): in a dictionary. """ - for key in waterschap.keys(): print(key) print(waterschap[str(key)].columns.values) @@ -78,7 +76,6 @@ def store_data(waterschap, output_gpkg_path): - waterschap: A dictionary where the keys represent layer names, and the values are GeoDataFrames. - output_gpkg_path: The file path for the output GPKG file. The '.gpkg' extension is added automatically. """ - for key in waterschap.keys(): waterschap[str(key)].to_file(output_gpkg_path + ".gpkg", layer=str(key), driver="GPKG") @@ -103,7 +100,6 @@ def overlapping_peilgebieden(waterschap_peilgebieden): ---------- - waterschap_peilgebieden: A GeoDataFrame containing the peilgebieden polygons. """ - peilgebied = waterschap_peilgebieden peilgebied.geometry = peilgebied.buffer(distance=0) # make invalid geometries valid peilgebied.set_crs(crs="EPSG:28992", inplace=True) diff --git a/src/peilbeheerst_model/peilbeheerst_model/postprocess_data/post-process_WSRL.ipynb b/src/peilbeheerst_model/peilbeheerst_model/postprocess_data/post-process_WSRL.ipynb index 65dd880..e0569be 100644 --- a/src/peilbeheerst_model/peilbeheerst_model/postprocess_data/post-process_WSRL.ipynb +++ b/src/peilbeheerst_model/peilbeheerst_model/postprocess_data/post-process_WSRL.ipynb @@ -28,11 +28,7 @@ "source": [ "import geopandas as gpd\n", "import numpy as np\n", - "\n", - "%load_ext autoreload\n", - "%autoreload 2\n", - "\n", - "from general_functions import *" + "from general_functions import read_gpkg_layers" ] }, { diff --git a/src/peilbeheerst_model/peilbeheerst_model/postprocess_data/post-process_agv.ipynb b/src/peilbeheerst_model/peilbeheerst_model/postprocess_data/post-process_agv.ipynb index 374b6fa..97993ba 100644 --- a/src/peilbeheerst_model/peilbeheerst_model/postprocess_data/post-process_agv.ipynb +++ b/src/peilbeheerst_model/peilbeheerst_model/postprocess_data/post-process_agv.ipynb @@ -28,11 +28,8 @@ "source": [ "import geopandas as gpd\n", "import numpy as np\n", - "\n", - "%load_ext autoreload\n", - "%autoreload 2\n", - "\n", - "from general_functions import *" + "import pandas as pd\n", + "from general_functions import read_gpkg_layers" ] }, { diff --git a/src/peilbeheerst_model/peilbeheerst_model/postprocess_data/post-process_delfland.ipynb b/src/peilbeheerst_model/peilbeheerst_model/postprocess_data/post-process_delfland.ipynb index 7c6b28a..8bd09ed 100644 --- a/src/peilbeheerst_model/peilbeheerst_model/postprocess_data/post-process_delfland.ipynb +++ b/src/peilbeheerst_model/peilbeheerst_model/postprocess_data/post-process_delfland.ipynb @@ -28,11 +28,7 @@ "source": [ "import geopandas as gpd\n", "import numpy as np\n", - "\n", - "%load_ext autoreload\n", - "%autoreload 2\n", - "\n", - "from general_functions import *" + "from general_functions import read_gpkg_layers" ] }, { diff --git a/src/peilbeheerst_model/peilbeheerst_model/postprocess_data/post-process_rijnland.ipynb b/src/peilbeheerst_model/peilbeheerst_model/postprocess_data/post-process_rijnland.ipynb index 262c75a..bbd7459 100644 --- a/src/peilbeheerst_model/peilbeheerst_model/postprocess_data/post-process_rijnland.ipynb +++ b/src/peilbeheerst_model/peilbeheerst_model/postprocess_data/post-process_rijnland.ipynb @@ -28,11 +28,8 @@ "source": [ "import geopandas as gpd\n", "import numpy as np\n", - "\n", - "%load_ext autoreload\n", - "%autoreload 2\n", - "\n", - "from general_functions import *" + "import pandas as pd\n", + "from general_functions import read_gpkg_layers" ] }, { diff --git a/src/peilbeheerst_model/peilbeheerst_model/postprocess_data/post-process_wetterskip.ipynb b/src/peilbeheerst_model/peilbeheerst_model/postprocess_data/post-process_wetterskip.ipynb index a07b862..490f844 100644 --- a/src/peilbeheerst_model/peilbeheerst_model/postprocess_data/post-process_wetterskip.ipynb +++ b/src/peilbeheerst_model/peilbeheerst_model/postprocess_data/post-process_wetterskip.ipynb @@ -28,11 +28,9 @@ "source": [ "import geopandas as gpd\n", "import numpy as np\n", - "\n", - "%load_ext autoreload\n", - "%autoreload 2\n", - "\n", - "from general_functions import *" + "import pandas as pd\n", + "import shapely\n", + "from general_functions import read_gpkg_layers" ] }, { @@ -353,7 +351,6 @@ "from itertools import combinations\n", "\n", "gdf = Wetterskip[\"peilgebied\"]\n", - "gdf = test\n", "gdf = gdf[6:]\n", "# Initialize a list to store index pairs with more than 90% overlap\n", "overlapping_pairs = []\n", diff --git a/src/peilbeheerst_model/peilbeheerst_model/postprocess_data/post-process_zuiderzeeland.ipynb b/src/peilbeheerst_model/peilbeheerst_model/postprocess_data/post-process_zuiderzeeland.ipynb index 80ee686..ae1a321 100644 --- a/src/peilbeheerst_model/peilbeheerst_model/postprocess_data/post-process_zuiderzeeland.ipynb +++ b/src/peilbeheerst_model/peilbeheerst_model/postprocess_data/post-process_zuiderzeeland.ipynb @@ -30,11 +30,9 @@ "source": [ "import geopandas as gpd\n", "import numpy as np\n", - "\n", - "%load_ext autoreload\n", - "%autoreload 2\n", - "\n", - "from general_functions import *" + "import pandas as pd\n", + "import shapely\n", + "from general_functions import read_gpkg_layers" ] }, { @@ -54,6 +52,7 @@ "source": [ "# define relative paths\n", "waterschap = \"Zuiderzeeland\"\n", + "waterschap2 = \"Zuiderzeeland\"\n", "\n", "data_path = f\"../projects/4750_20/Data_postprocessed/Waterschappen/{waterschap}/{waterschap}.gpkg\"\n", "\n", diff --git a/src/peilbeheerst_model/peilbeheerst_model/postprocess_data/post-processing_HD.ipynb b/src/peilbeheerst_model/peilbeheerst_model/postprocess_data/post-processing_HD.ipynb index 0dc2b03..da0aa3f 100644 --- a/src/peilbeheerst_model/peilbeheerst_model/postprocess_data/post-processing_HD.ipynb +++ b/src/peilbeheerst_model/peilbeheerst_model/postprocess_data/post-processing_HD.ipynb @@ -28,11 +28,8 @@ "source": [ "import geopandas as gpd\n", "import numpy as np\n", - "\n", - "%load_ext autoreload\n", - "%autoreload 2\n", - "\n", - "from general_functions import *" + "import pandas as pd\n", + "from general_functions import read_gpkg_layers" ] }, { diff --git a/src/peilbeheerst_model/peilbeheerst_model/postprocess_data/post-processing_HHNK.ipynb b/src/peilbeheerst_model/peilbeheerst_model/postprocess_data/post-processing_HHNK.ipynb index 2414f41..d21b4c7 100644 --- a/src/peilbeheerst_model/peilbeheerst_model/postprocess_data/post-processing_HHNK.ipynb +++ b/src/peilbeheerst_model/peilbeheerst_model/postprocess_data/post-processing_HHNK.ipynb @@ -28,11 +28,8 @@ "source": [ "import geopandas as gpd\n", "import numpy as np\n", - "\n", - "%load_ext autoreload\n", - "%autoreload 2\n", - "\n", - "from general_functions import *" + "import pandas as pd\n", + "from general_functions import read_gpkg_layers" ] }, { diff --git a/src/peilbeheerst_model/peilbeheerst_model/postprocess_data/post-processing_HHSK.ipynb b/src/peilbeheerst_model/peilbeheerst_model/postprocess_data/post-processing_HHSK.ipynb index 7cd347c..2904edf 100644 --- a/src/peilbeheerst_model/peilbeheerst_model/postprocess_data/post-processing_HHSK.ipynb +++ b/src/peilbeheerst_model/peilbeheerst_model/postprocess_data/post-processing_HHSK.ipynb @@ -28,11 +28,9 @@ "source": [ "import geopandas as gpd\n", "import numpy as np\n", - "\n", - "%load_ext autoreload\n", - "%autoreload 2\n", - "\n", - "from general_functions import *" + "import pandas as pd\n", + "import shapely\n", + "from general_functions import read_gpkg_layers" ] }, { diff --git a/src/peilbeheerst_model/peilbeheerst_model/postprocess_data/post-processing_scheldestromen.ipynb b/src/peilbeheerst_model/peilbeheerst_model/postprocess_data/post-processing_scheldestromen.ipynb index 5d1ba16..5d7841f 100644 --- a/src/peilbeheerst_model/peilbeheerst_model/postprocess_data/post-processing_scheldestromen.ipynb +++ b/src/peilbeheerst_model/peilbeheerst_model/postprocess_data/post-processing_scheldestromen.ipynb @@ -28,11 +28,8 @@ "source": [ "import geopandas as gpd\n", "import numpy as np\n", - "\n", - "%load_ext autoreload\n", - "%autoreload 2\n", - "\n", - "from general_functions import *" + "import pandas as pd\n", + "from general_functions import read_gpkg_layers" ] }, { diff --git a/src/peilbeheerst_model/peilbeheerst_model/preprocess_data/AmstelGooienVecht.ipynb b/src/peilbeheerst_model/peilbeheerst_model/preprocess_data/AmstelGooienVecht.ipynb index 12145a6..8e478a8 100644 --- a/src/peilbeheerst_model/peilbeheerst_model/preprocess_data/AmstelGooienVecht.ipynb +++ b/src/peilbeheerst_model/peilbeheerst_model/preprocess_data/AmstelGooienVecht.ipynb @@ -7,7 +7,6 @@ "metadata": {}, "outputs": [], "source": [ - "# import packages and functions\n", "import os\n", "\n", "import geopandas as gpd\n", @@ -24,10 +23,8 @@ "metadata": {}, "outputs": [], "source": [ - "from general_functions import *\n", + "from general_functions import show_layers_and_columns, store_data\n", "\n", - "%load_ext autoreload\n", - "%autoreload 2\n", "pd.set_option(\"display.max_columns\", None)" ] }, @@ -193,9 +190,7 @@ "AVG[\"gemaal\"].loc[AVG[\"gemaal\"].functiegemaal.str.contains(\"anvoergemaal|pmaling|an-|p-|pvoer\"), \"func_aanvoer\"] = True\n", "AVG[\"gemaal\"].loc[AVG[\"gemaal\"].functiegemaal.str.contains(\"irculatie\"), \"func_circulatie\"] = True\n", "AVG[\"gemaal\"].loc[\n", - " (AVG[\"gemaal\"].func_afvoer == False)\n", - " & (AVG[\"gemaal\"].func_aanvoer == False)\n", - " & (AVG[\"gemaal\"].func_circulatie == False),\n", + " ~AVG[\"gemaal\"].func_afvoer & ~AVG[\"gemaal\"].func_aanvoer & ~AVG[\"gemaal\"].func_circulatie,\n", " \"func_afvoer\",\n", "] = True # set to afvoergemaal is there the function is unknown" ] diff --git a/src/peilbeheerst_model/peilbeheerst_model/preprocess_data/Delfland.ipynb b/src/peilbeheerst_model/peilbeheerst_model/preprocess_data/Delfland.ipynb index b558ddf..6de7b81 100644 --- a/src/peilbeheerst_model/peilbeheerst_model/preprocess_data/Delfland.ipynb +++ b/src/peilbeheerst_model/peilbeheerst_model/preprocess_data/Delfland.ipynb @@ -7,7 +7,6 @@ "metadata": {}, "outputs": [], "source": [ - "# import packages and functions\n", "import os\n", "\n", "import geopandas as gpd\n", @@ -21,7 +20,7 @@ "metadata": {}, "outputs": [], "source": [ - "from general_functions import *" + "from general_functions import read_gpkg_layers, show_layers_and_columns, store_data" ] }, { @@ -108,9 +107,7 @@ " Delfland[\"gemaal\"].FUNCTIEGEMAAL_resolved.str.contains(\"Overig|circulatie\"), \"func_circulatie\"\n", "] = True\n", "Delfland[\"gemaal\"].loc[\n", - " (Delfland[\"gemaal\"].func_afvoer == False)\n", - " & (Delfland[\"gemaal\"].func_aanvoer == False)\n", - " & (Delfland[\"gemaal\"].func_circulatie == False),\n", + " ~Delfland[\"gemaal\"].func_afvoer & ~Delfland[\"gemaal\"].func_aanvoer & ~Delfland[\"gemaal\"].func_circulatie,\n", " \"func_afvoer\",\n", "] = True # set to afvoergemaal is there the function is unknown\n", "\n", diff --git a/src/peilbeheerst_model/peilbeheerst_model/preprocess_data/HHNK.ipynb b/src/peilbeheerst_model/peilbeheerst_model/preprocess_data/HHNK.ipynb index a18b8df..5a77de3 100644 --- a/src/peilbeheerst_model/peilbeheerst_model/preprocess_data/HHNK.ipynb +++ b/src/peilbeheerst_model/peilbeheerst_model/preprocess_data/HHNK.ipynb @@ -21,10 +21,7 @@ "metadata": {}, "outputs": [], "source": [ - "%load_ext autoreload\n", - "%autoreload 2\n", - "\n", - "from general_functions import *" + "from general_functions import read_gpkg_layers, show_layers_and_columns, store_data" ] }, { @@ -133,9 +130,7 @@ "HHNK[\"gemaal\"].loc[HHNK[\"gemaal\"][\"functiegemaal\"].isin(circulatie_values), \"func_circulatie\"] = True\n", "\n", "HHNK[\"gemaal\"].loc[\n", - " (HHNK[\"gemaal\"].func_afvoer == False)\n", - " & (HHNK[\"gemaal\"].func_aanvoer == False)\n", - " & (HHNK[\"gemaal\"].func_circulatie == False),\n", + " ~HHNK[\"gemaal\"].func_afvoer & ~HHNK[\"gemaal\"].func_aanvoer & ~HHNK[\"gemaal\"].func_circulatie,\n", " \"func_afvoer\",\n", "] = True # set to afvoergemaal is there the function is unknown" ] diff --git a/src/peilbeheerst_model/peilbeheerst_model/preprocess_data/HHSK.ipynb b/src/peilbeheerst_model/peilbeheerst_model/preprocess_data/HHSK.ipynb index 60fb39b..4ec315b 100644 --- a/src/peilbeheerst_model/peilbeheerst_model/preprocess_data/HHSK.ipynb +++ b/src/peilbeheerst_model/peilbeheerst_model/preprocess_data/HHSK.ipynb @@ -26,7 +26,7 @@ }, "outputs": [], "source": [ - "from general_functions import *" + "from general_functions import read_gpkg_layers, show_layers_and_columns, store_data" ] }, { @@ -187,9 +187,7 @@ "HHSK[\"gemaal\"].loc[HHSK[\"gemaal\"].functiegemaal.str.contains(\"1|3|5|\"), \"func_aanvoer\"] = True\n", "HHSK[\"gemaal\"].loc[HHSK[\"gemaal\"].functiegemaal.str.contains(\"8\"), \"func_circulatie\"] = True\n", "HHSK[\"gemaal\"].loc[\n", - " (HHSK[\"gemaal\"].func_afvoer == False)\n", - " & (HHSK[\"gemaal\"].func_aanvoer == False)\n", - " & (HHSK[\"gemaal\"].func_circulatie == False),\n", + " ~HHSK[\"gemaal\"].func_afvoer & ~HHSK[\"gemaal\"].func_aanvoer & ~HHSK[\"gemaal\"].func_circulatie,\n", " \"func_afvoer\",\n", "] = True # set to afvoergemaal is there the function is unknown" ] diff --git a/src/peilbeheerst_model/peilbeheerst_model/preprocess_data/Hollandse_Delta.ipynb b/src/peilbeheerst_model/peilbeheerst_model/preprocess_data/Hollandse_Delta.ipynb index 9cf2c1a..213ab49 100644 --- a/src/peilbeheerst_model/peilbeheerst_model/preprocess_data/Hollandse_Delta.ipynb +++ b/src/peilbeheerst_model/peilbeheerst_model/preprocess_data/Hollandse_Delta.ipynb @@ -22,7 +22,7 @@ "metadata": {}, "outputs": [], "source": [ - "from general_functions import *" + "from general_functions import read_gpkg_layers, show_layers_and_columns, store_data" ] }, { @@ -136,9 +136,7 @@ "HD[\"gemaal\"].loc[HD[\"gemaal\"].functiegemaal.str.contains(\"anvoergemaal|pmaling\"), \"func_aanvoer\"] = True\n", "HD[\"gemaal\"].loc[HD[\"gemaal\"].functiegemaal.str.contains(\"Doorspoel\"), \"func_circulatie\"] = True\n", "HD[\"gemaal\"].loc[\n", - " (HD[\"gemaal\"].func_afvoer == False)\n", - " & (HD[\"gemaal\"].func_aanvoer == False)\n", - " & (HD[\"gemaal\"].func_circulatie == False),\n", + " ~HD[\"gemaal\"].func_afvoer & ~HD[\"gemaal\"].func_aanvoer & ~HD[\"gemaal\"].func_circulatie,\n", " \"func_afvoer\",\n", "] = True # set to afvoergemaal is there the function is unknown" ] diff --git a/src/peilbeheerst_model/peilbeheerst_model/preprocess_data/Rijnland.ipynb b/src/peilbeheerst_model/peilbeheerst_model/preprocess_data/Rijnland.ipynb index 67cc146..164d8ff 100644 --- a/src/peilbeheerst_model/peilbeheerst_model/preprocess_data/Rijnland.ipynb +++ b/src/peilbeheerst_model/peilbeheerst_model/preprocess_data/Rijnland.ipynb @@ -23,7 +23,7 @@ "metadata": {}, "outputs": [], "source": [ - "from general_functions import *" + "from general_functions import burn_in_peilgebieden, read_gpkg_layers, show_layers_and_columns, store_data" ] }, { diff --git a/src/peilbeheerst_model/peilbeheerst_model/preprocess_data/Rivierenland.ipynb b/src/peilbeheerst_model/peilbeheerst_model/preprocess_data/Rivierenland.ipynb index e2b5001..8de4cf1 100644 --- a/src/peilbeheerst_model/peilbeheerst_model/preprocess_data/Rivierenland.ipynb +++ b/src/peilbeheerst_model/peilbeheerst_model/preprocess_data/Rivierenland.ipynb @@ -23,7 +23,7 @@ "metadata": {}, "outputs": [], "source": [ - "from general_functions import *" + "from general_functions import read_gpkg_layers, show_layers_and_columns, store_data" ] }, { @@ -186,9 +186,7 @@ "WSRL[\"gemaal\"].loc[WSRL[\"gemaal\"].functiegemaal.str.contains(\"Aanvoer|Opmaling\"), \"func_aanvoer\"] = True\n", "WSRL[\"gemaal\"].loc[WSRL[\"gemaal\"].functiegemaal.str.contains(\"Doorspoelgemaal\"), \"func_circulatie\"] = True\n", "WSRL[\"gemaal\"].loc[\n", - " (WSRL[\"gemaal\"].func_afvoer == False)\n", - " & (WSRL[\"gemaal\"].func_aanvoer == False)\n", - " & (WSRL[\"gemaal\"].func_circulatie == False),\n", + " ~WSRL[\"gemaal\"].func_afvoer & ~WSRL[\"gemaal\"].func_aanvoer & ~WSRL[\"gemaal\"].func_circulatie,\n", " \"func_afvoer\",\n", "] = True # set to afvoergemaal is there the function is unknown" ] @@ -245,6 +243,7 @@ "def intersect_using_spatial_index(peilgebied_praktijk, peilgebied_afwijking, check):\n", " \"\"\"\n", " Conduct spatial intersection using spatial index for candidates GeoDataFrame to make queries faster.\n", + "\n", " Note, with this function, you can have multiple Polygons in the 'intersecting_gdf' and it will return all the points\n", " intersect with ANY of those geometries.\n", " \"\"\"\n", diff --git a/src/peilbeheerst_model/peilbeheerst_model/preprocess_data/Scheldestromen.ipynb b/src/peilbeheerst_model/peilbeheerst_model/preprocess_data/Scheldestromen.ipynb index 520e3bd..63c2ab8 100644 --- a/src/peilbeheerst_model/peilbeheerst_model/preprocess_data/Scheldestromen.ipynb +++ b/src/peilbeheerst_model/peilbeheerst_model/preprocess_data/Scheldestromen.ipynb @@ -12,7 +12,8 @@ "\n", "import geopandas as gpd\n", "import numpy as np\n", - "import pandas as pd" + "import pandas as pd\n", + "from shapely.geometry import Polygon" ] }, { @@ -22,7 +23,7 @@ "metadata": {}, "outputs": [], "source": [ - "from general_functions import *" + "from general_functions import read_gpkg_layers, show_layers_and_columns, store_data" ] }, { @@ -258,7 +259,7 @@ "outputs": [], "source": [ "for i in range(len(Scheldestromen[\"peilgebied\"])):\n", - " if type(Scheldestromen[\"peilgebied\"].loc[i, \"geometry\"]) == Polygon:\n", + " if isinstance(Scheldestromen[\"peilgebied\"].loc[i, \"geometry\"], Polygon):\n", " Scheldestromen[\"peilgebied\"].loc[i, \"geometry\"].plot()" ] }, diff --git a/src/peilbeheerst_model/peilbeheerst_model/preprocess_data/Wetterskip.ipynb b/src/peilbeheerst_model/peilbeheerst_model/preprocess_data/Wetterskip.ipynb index b5ea972..2fbe295 100644 --- a/src/peilbeheerst_model/peilbeheerst_model/preprocess_data/Wetterskip.ipynb +++ b/src/peilbeheerst_model/peilbeheerst_model/preprocess_data/Wetterskip.ipynb @@ -11,7 +11,7 @@ "\n", "import geopandas as gpd\n", "import pandas as pd\n", - "from general_functions import *\n", + "from general_functions import read_gpkg_layers, show_layers_and_columns, store_data\n", "\n", "pd.set_option(\"display.max_columns\", None)" ] @@ -160,9 +160,7 @@ "Wetterskip[\"gemaal\"].loc[Wetterskip[\"gemaal\"].functiegemaal.str.contains(\"Opmaling|Aanvoer\"), \"func_aanvoer\"] = True\n", "Wetterskip[\"gemaal\"].loc[Wetterskip[\"gemaal\"].functiegemaal.str.contains(\"Overig|circulatie\"), \"func_circulatie\"] = True\n", "Wetterskip[\"gemaal\"].loc[\n", - " (Wetterskip[\"gemaal\"].func_afvoer == False)\n", - " & (Wetterskip[\"gemaal\"].func_aanvoer == False)\n", - " & (Wetterskip[\"gemaal\"].func_circulatie == False),\n", + " ~Wetterskip[\"gemaal\"].func_afvoer & ~Wetterskip[\"gemaal\"].func_aanvoer & ~Wetterskip[\"gemaal\"].func_circulatie,\n", " \"func_afvoer\",\n", "] = True # set to afvoergemaal is there the function is unknown" ] diff --git a/src/peilbeheerst_model/peilbeheerst_model/preprocess_data/Zuiderzeeland.ipynb b/src/peilbeheerst_model/peilbeheerst_model/preprocess_data/Zuiderzeeland.ipynb index 9389c1f..92722a7 100644 --- a/src/peilbeheerst_model/peilbeheerst_model/preprocess_data/Zuiderzeeland.ipynb +++ b/src/peilbeheerst_model/peilbeheerst_model/preprocess_data/Zuiderzeeland.ipynb @@ -23,7 +23,7 @@ "metadata": {}, "outputs": [], "source": [ - "from general_functions import *" + "from general_functions import show_layers_and_columns, store_data" ] }, { @@ -163,9 +163,9 @@ "] = True\n", "Zuiderzeeland[\"gemaal\"].loc[Zuiderzeeland[\"gemaal\"].functiegemaal.str.contains(\"circulatie\"), \"func_circulatie\"] = True\n", "Zuiderzeeland[\"gemaal\"].loc[\n", - " (Zuiderzeeland[\"gemaal\"].func_afvoer == False)\n", - " & (Zuiderzeeland[\"gemaal\"].func_aanvoer == False)\n", - " & (Zuiderzeeland[\"gemaal\"].func_circulatie == False),\n", + " ~Zuiderzeeland[\"gemaal\"].func_afvoer\n", + " & ~Zuiderzeeland[\"gemaal\"].func_aanvoer\n", + " & ~Zuiderzeeland[\"gemaal\"].func_circulatie,\n", " \"func_afvoer\",\n", "] = True # set to afvoergemaal is there the function is unknown" ] diff --git a/src/peilbeheerst_model/peilbeheerst_model/preprocess_data/general_functions.py b/src/peilbeheerst_model/peilbeheerst_model/preprocess_data/general_functions.py index 40b038f..0e40153 100644 --- a/src/peilbeheerst_model/peilbeheerst_model/preprocess_data/general_functions.py +++ b/src/peilbeheerst_model/peilbeheerst_model/preprocess_data/general_functions.py @@ -22,7 +22,6 @@ def read_gpkg_layers(gpkg_path, variables, engine="fiona", print_var=False): This function reads specified layers from a GeoPackage (GPKG) file and returns them as a dictionary. You can choose to print the names of variables as they are read by setting `print_var` to True. """ - data = {} for variable in variables: if print_var: @@ -49,7 +48,6 @@ def show_layers_and_columns(waterschap): in a dictionary. """ - for key in waterschap.keys(): print(key) print(waterschap[str(key)].columns.values) @@ -78,7 +76,6 @@ def store_data(waterschap, output_gpkg_path): - waterschap: A dictionary where the keys represent layer names, and the values are GeoDataFrames. - output_gpkg_path: The file path for the output GPKG file. The '.gpkg' extension is added automatically. """ - for key in waterschap.keys(): waterschap[str(key)].to_file(output_gpkg_path + ".gpkg", layer=str(key), driver="GPKG") @@ -103,7 +100,6 @@ def overlapping_peilgebieden(waterschap_peilgebieden): ---------- - waterschap_peilgebieden: A GeoDataFrame containing the peilgebieden polygons. """ - peilgebied = waterschap_peilgebieden peilgebied.geometry = peilgebied.buffer(distance=0) # make invalid geometries valid peilgebied.set_crs(crs="EPSG:28992", inplace=True) diff --git a/src/peilbeheerst_model/peilbeheerst_model/ribasim_parametrization.py b/src/peilbeheerst_model/peilbeheerst_model/ribasim_parametrization.py index 5fa46b3..c4cf884 100644 --- a/src/peilbeheerst_model/peilbeheerst_model/ribasim_parametrization.py +++ b/src/peilbeheerst_model/peilbeheerst_model/ribasim_parametrization.py @@ -126,7 +126,6 @@ def set_static_forcing(timesteps: int, timestep_size: str, start_time: str, forc ribasim_model : object A model object containing the basin node data for assigning forcing inputs. """ - """_summary_ Parameters diff --git a/src/ribasim_nl/ribasim_nl/case_conversions.py b/src/ribasim_nl/ribasim_nl/case_conversions.py index 2d9aca3..5ba26cd 100644 --- a/src/ribasim_nl/ribasim_nl/case_conversions.py +++ b/src/ribasim_nl/ribasim_nl/case_conversions.py @@ -1,11 +1,9 @@ def snake_to_pascal_case(snake_case: str) -> str: """Convert snake_case to PascalCase""" - words = snake_case.split("_") return "".join(i.title() for i in words) def pascal_to_snake_case(pascal_case: str) -> str: """Convert PascalCase to snake_case""" - return "".join(["_" + i.lower() if i.isupper() else i for i in pascal_case]).lstrip("_") diff --git a/src/ribasim_nl/ribasim_nl/cloud.py b/src/ribasim_nl/ribasim_nl/cloud.py index fb7c5d6..aa40905 100644 --- a/src/ribasim_nl/ribasim_nl/cloud.py +++ b/src/ribasim_nl/ribasim_nl/cloud.py @@ -189,7 +189,6 @@ def content(self, url) -> list[str] | None: list[str] List of all content directories in a specified path """ - headers = {"Depth": "1", "Content-Type": "application/xml"} xml_data = """ @@ -234,7 +233,6 @@ def dirs(self, *args) -> list[str]: list[str] List of directories in a specified path """ - content = self.content(*args) return [item for item in content if is_dir(item)] @@ -253,7 +251,6 @@ def create_dir(self, *args): def download_content(self, url, overwrite: bool = False): """Download content of a directory recursively.""" - # get all content (files and directories from url) content = self.content(url) @@ -278,7 +275,6 @@ def download_content(self, url, overwrite: bool = False): def upload_content(self, dir_path: Path, overwrite: bool = False): """Upload content of a directory recursively.""" - # get all remote content content = self.content(self.joinurl(self.relative_path(dir_path).as_posix())) @@ -377,7 +373,6 @@ def upload_model(self, authority: str, model: str, include_results=False, includ ValueError If model does not exist locally """ - # get today, so we can later derive a version today = date.today() diff --git a/src/ribasim_nl/ribasim_nl/concat.py b/src/ribasim_nl/ribasim_nl/concat.py index 91f49c5..f08a6f9 100644 --- a/src/ribasim_nl/ribasim_nl/concat.py +++ b/src/ribasim_nl/ribasim_nl/concat.py @@ -19,7 +19,6 @@ def concat(models: list[Model]) -> Model: Model concatenated ribasim.Model """ - # models will be concatenated to first model. model = reset_index(models[0]) # determine node_start of next model diff --git a/src/ribasim_nl/ribasim_nl/geometry.py b/src/ribasim_nl/ribasim_nl/geometry.py index f703823..95de8fb 100644 --- a/src/ribasim_nl/ribasim_nl/geometry.py +++ b/src/ribasim_nl/ribasim_nl/geometry.py @@ -21,7 +21,6 @@ def basin_to_point(basin_polygon: Polygon | MultiPolygon) -> Point: Point Representative point for the basin """ - point = basin_polygon.centroid # if point not within basin, we return polylabel @@ -80,7 +79,6 @@ def split_basin(basin_polygon: Polygon, line: LineString) -> MultiPolygon: MultiPolygon Multipolygon with two polygons """ - _validate_inputs(split_basin, polygon=basin_polygon, line=line) unioned = basin_polygon.boundary.union(line) @@ -114,7 +112,6 @@ def drop_z(geometry: LineString | MultiPolygon | Point | Polygon) -> Point | Pol Point | Polygon | MultiPolygon Output geometry """ - # MultiPolygon if isinstance(geometry, MultiPolygon): geometry = MultiPolygon([drop_z(poly) for poly in geometry.geoms]) diff --git a/src/ribasim_nl/ribasim_nl/geoseries.py b/src/ribasim_nl/ribasim_nl/geoseries.py index 2239414..ff20451 100644 --- a/src/ribasim_nl/ribasim_nl/geoseries.py +++ b/src/ribasim_nl/ribasim_nl/geoseries.py @@ -16,5 +16,4 @@ def basins_to_points(basin_series: GeoSeries) -> GeoSeries: GeoSeries Basin points """ - return basin_series.apply(basin_to_point) diff --git a/src/ribasim_nl/ribasim_nl/model.py b/src/ribasim_nl/ribasim_nl/model.py index 14422ba..0bea2f8 100644 --- a/src/ribasim_nl/ribasim_nl/model.py +++ b/src/ribasim_nl/ribasim_nl/model.py @@ -54,7 +54,6 @@ def next_node_id(self): def find_node_id(self, ds_node_id=None, us_node_id=None, **kwargs) -> int: """Find a node_id by it's properties""" - # get node table df = self.node_table().df @@ -95,7 +94,6 @@ def get_node(self, node_id: int): def update_node(self, node_id, node_type, data, node_properties: dict = {}): """Update a node type and/or data""" - # get existing network node_type existing_node_type = self.node_table().df.set_index("node_id").at[node_id, "node_type"] @@ -157,7 +155,6 @@ def add_control_node( extra properties to add to the control node id. """ - # define node if node_geom is None: if isinstance(to_node_id, list): @@ -183,7 +180,6 @@ def add_control_node( def find_closest_basin(self, geometry: BaseGeometry, max_distance: float | None) -> NodeData: """Find the closest basin_node.""" - # only works when basin area are defined if self.basin.area.df is None: raise ValueError("No basin.area table defined for model") diff --git a/src/ribasim_nl/ribasim_nl/model_old.py b/src/ribasim_nl/ribasim_nl/model_old.py index 68d32c9..f885887 100644 --- a/src/ribasim_nl/ribasim_nl/model_old.py +++ b/src/ribasim_nl/ribasim_nl/model_old.py @@ -73,7 +73,6 @@ def add_control_node_to_network( network, int updated network and node_id of the control-node """ - # see if we have one node-id to offset ctrl-node from if offset_node_id is not None: node_id = offset_node_id diff --git a/src/ribasim_nl/ribasim_nl/raster.py b/src/ribasim_nl/ribasim_nl/raster.py index 87c3ad8..f244756 100644 --- a/src/ribasim_nl/ribasim_nl/raster.py +++ b/src/ribasim_nl/ribasim_nl/raster.py @@ -44,7 +44,6 @@ def build_vrt(raster_dir: Path): raster_dir : Path _description_ """ - rasters_vrt = raster_dir / f"{raster_dir.name}.vrt" if rasters_vrt.exists(): rasters_vrt.unlink() @@ -154,7 +153,6 @@ def sample_elevation_distance(raster_path: Path, line: LineString) -> gpd.GeoDat gpd.GeoDataFrame GeoDataFrame with Point-geometry, distance along the line and elevation value """ - with rasterio.open(raster_path) as src: sample_dist = abs(src.res[0]) gdf = line_to_samples(line, sample_dist) diff --git a/src/ribasim_nl/ribasim_nl/styles.py b/src/ribasim_nl/ribasim_nl/styles.py index f8d12fe..85c01b5 100644 --- a/src/ribasim_nl/ribasim_nl/styles.py +++ b/src/ribasim_nl/ribasim_nl/styles.py @@ -61,6 +61,7 @@ def read_style(style_path: Path) -> str: """ To make style-text sql-compatible, we need to replace single ' to ''. + Example 'http://mrcc.com/qgis.dtd -> ''http://mrcc.com/qgis.dtd'' Parameters @@ -96,7 +97,6 @@ def add_styles_to_geopackage(gpkg_path: Path): None. """ - with sqlite3.connect(gpkg_path) as conn: # create table conn.execute(DROP_TABLE_SQL) diff --git a/src/ribasim_nl/ribasim_nl/tables.py b/src/ribasim_nl/ribasim_nl/tables.py index ff9643c..a81aa7a 100644 --- a/src/ribasim_nl/ribasim_nl/tables.py +++ b/src/ribasim_nl/ribasim_nl/tables.py @@ -51,7 +51,6 @@ def cumulative_area(df: pd.DataFrame) -> pd.Series: pd.Series Series with cumulative area """ - df.reset_index(drop=True, inplace=True) df.sort_values("level", inplace=True) @@ -77,7 +76,6 @@ def manning_profile(df: pd.DataFrame) -> tuple[float, float]: Tuple[int, int] Tuple with (profile_width, slope) values """ - dz = df["level"].max() - df["level"].min() tw = df["width"].max() diff --git a/src/ribasim_nl/tests/test_cloud.py b/src/ribasim_nl/tests/test_cloud.py index 36f5e35..ed9b24f 100644 --- a/src/ribasim_nl/tests/test_cloud.py +++ b/src/ribasim_nl/tests/test_cloud.py @@ -10,7 +10,6 @@ def cloud(tmp_path): def test_initialize(cloud): """Test if cloud still has same structure""" - assert cloud.data_dir.exists() # check if we have the correct directories