Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

AGV reproducible parse_crossings #173

Merged
merged 3 commits into from
Oct 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 9 additions & 9 deletions docs/workflow/level-controlled.qmd
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,17 @@ Workflow for deriving level controlled (peilbeheerst) regional models.
All code can be found under [`src/peilbeheerst_model`](https://github.com/Deltares/Ribasim-NL/tree/main/src/peilbeheerst_model).
The paths below are relative to this path.

1. Run the preprocessing notebooks. One notebook per water board, path: `peilbeheerst_model/preprocess_data/`
2. Run the postprocessing notebook. One notebook per water board, path: `peilbeheerst_model/postprocess_data/`
3. Run the crossings notebook. One notebook, path: `01_parse_crossings.ipynb`
4. Run shortest paths notebooks. One notebook per water board, path: `Shortest_path/`
5. Run crossings to Ribasim notebook. One notebook, all water boards are below each other, path: `02_crossings_to_ribasim_notebook.ipynb`
6. Run parametrize notebooks. One notebook per water board, for now only Amstel, Gooi en Vecht (AGV), path: `Parametrize/AmstelGooienVecht_parametrize.ipynb`
1. Run the preprocessing scripts. One script per water board, path: `peilbeheerst_model/preprocess_data/`
2. Run the postprocessing script. One script per water board, path: `peilbeheerst_model/postprocess_data/`
3. Run the crossings script. One script, path: `01_parse_crossings.ipynb`. Moving to one script per water board under `peilbeheerst_model/parse_crossings/`.
4. Run shortest paths scripts. One script per water board, path: `Shortest_path/`
5. Run crossings to Ribasim script. One script, all water boards are below each other, path: `02_crossings_to_ribasim_notebook.ipynb`. Moving to one script per water board under `peilbeheerst_model/crossings_to_ribasim/`.
6. Run parametrize scripts. One script per water board, for now only Amstel, Gooi en Vecht (AGV), path: `Parametrize/AmstelGooienVecht_parametrize.ipynb`

We originally had more parametrize notebooks, but because so much has changed I have now saved these in our backup.
We originally had more parametrize scripts, but because so much has changed I have now saved these in our backup.
We will only use these to see if there were any additional manual adjustments.
For the rest, it follows the same workflow as `AmstelGooienVecht_parametrize.ipynb`.

Finally: step 1 started with a clear notebook per water board.
During the process of 1.5 years, these notebooks have become increasingly larger and more confusing, whereby not every line is needed anymore.
Finally: step 1 started with a clear script per water board.
During the process of 1.5 years, these scripts have become increasingly larger and more confusing, whereby not every line is needed anymore.
For now, there is no priority to clean this up, partly because this is a major risk that the data will (unintentionally) change, which will change the networks and the feedback forms can no longer be used.
5 changes: 3 additions & 2 deletions src/peilbeheerst_model/01_parse_crossings.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,9 @@
for waterschap, waterschap_struct in waterschap_data.items():
print(f"\n{waterschap}...")

init_settings, crossing_settings = waterschap_struct.values()
init_settings["logfile"] = pathlib.Path(init_settings["output_path"]).with_suffix("").with_suffix(".log")
crossing_settings = waterschap_struct["find_crossings_with_peilgebieden"]
init_settings = waterschap_struct["init"]
init_settings["logfile"] = pathlib.Path(init_settings["output_path"]).with_suffix(".log")
Comment on lines -28 to +30
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The order of the waterschap_struct.values() changed, so this was no longer correct.
And with_suffix replaces any existing suffix, so a single call is sufficient.


if waterschap not in ["HHNK"]:
continue
Expand Down
4 changes: 3 additions & 1 deletion src/peilbeheerst_model/01b_ad_krw_to_peilgebieden.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,9 @@
for waterschap, waterschap_struct in waterschap_data.items():
print(f"\n{waterschap}...")

init_settings, crossing_settings = waterschap_struct.values()
crossing_settings = waterschap_struct["find_crossings_with_peilgebieden"]
init_settings = waterschap_struct["init"]

gpkg = pathlib.Path(init_settings["output_path"])
if not gpkg.exists():
raise ValueError(gpkg)
Expand Down
38 changes: 38 additions & 0 deletions src/peilbeheerst_model/parse_crossings/AmstelGooienVecht.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
# %%

from peilbeheerst_model import ParseCrossings, waterschap_data
from ribasim_nl import CloudStorage

# %%
waterschap = "AmstelGooienVecht"
waterschap_struct = waterschap_data[waterschap]

cloud = CloudStorage()
verwerkt_dir = cloud.joinpath(waterschap, "verwerkt")
cloud.download_verwerkt(waterschap)
cloud.download_basisgegevens()

# %%

crossing_settings = waterschap_struct["find_crossings_with_peilgebieden"]
init_settings = waterschap_struct["init"]

init_settings["gpkg_path"] = verwerkt_dir / "postprocessed.gpkg"
init_settings["krw_path"] = cloud.joinpath("Basisgegevens/KRW/KRW_lichamen_per_waterschap.gpkg")
init_settings["output_path"] = verwerkt_dir / "crossings.gpkg"
Comment on lines +20 to +22
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This overwrites the waterschappen.py for now to avoid breaking other code.

init_settings["logfile"] = verwerkt_dir / "crossings.log"

# Crossings class initializeren
cross = ParseCrossings(**init_settings)

# Crossings bepalen en wegschrijven
if crossing_settings["filterlayer"] is None:
df_hydro = cross.find_crossings_with_peilgebieden("hydroobject", **crossing_settings)
cross.write_crossings(df_hydro)
else:
df_hydro, df_dsf, df_hydro_dsf = cross.find_crossings_with_peilgebieden("hydroobject", **crossing_settings)
cross.write_crossings(df_hydro, crossing_settings["filterlayer"], df_dsf, df_hydro_dsf)

# %%

cloud.upload_verwerkt(waterschap)
Loading