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

Add lake package + example to nlmod #154

Merged
merged 12 commits into from
Mar 27, 2023
136 changes: 115 additions & 21 deletions docs/examples/09_schoonhoven.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
"import matplotlib.pyplot as plt\n",
"import nlmod\n",
"import numpy as np\n",
"import xarray as xr\n",
"import pandas as pd\n",
"import hydropandas as hpd\n",
"import geopandas as gpd\n",
Expand Down Expand Up @@ -287,9 +288,6 @@
"# Create the output control package\n",
"oc = nlmod.gwf.oc(ds, gwf)\n",
"\n",
"# create recharge package\n",
"rch = nlmod.gwf.rch(ds, gwf)\n",
"\n",
"# create storagee package\n",
"sto = nlmod.gwf.sto(ds, gwf)"
]
Expand All @@ -303,6 +301,24 @@
"We cut the surface water bodies with the grid, set a default resistance of 1 day, and seperate the large river 'Lek' form the other surface water bodies."
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "d7ee4e0f-0409-4edb-8670-1528d970d161",
"metadata": {},
"outputs": [],
"source": [
"# remove grote gracht and oude haven to model as a lake\n",
"ids_grote_gracht = ['W0656.774b12049d9a4252bd61c4ea442b5158', 'W0656.59ab56cf0b2d4f15894c24369f0748df']\n",
"ids_oude_haven = ['W0656.a6013e26cd9442de86eac2295eb0012b', 'W0656.2053970c192b4fe48bba882842e53eb5', 'W0656.540780b5c9944b51b53d8a98445b315a', 'W0656.a7c39fcaabe149c3b9eb4823f76db024', 'W0656.cb3c3a25de4141d18c573b561f02e84a']\n",
"lakes = bgt.loc[bgt['identificatie'].isin(ids_grote_gracht) | bgt['identificatie'].isin(ids_oude_haven)]\n",
"\n",
"lakes.loc[lakes['identificatie'].isin(ids_grote_gracht), 'name'] = 'grote gracht'\n",
"lakes.loc[lakes['identificatie'].isin(ids_oude_haven), 'name'] = 'oude haven'\n",
"\n",
"bgt.drop(lakes.index, inplace=True)"
]
},
{
"cell_type": "code",
"execution_count": null,
Expand Down Expand Up @@ -363,6 +379,70 @@
"drn = nlmod.gwf.surface_water.gdf_to_seasonal_pkg(bgt_grid, gwf, ds);"
]
},
{
"cell_type": "markdown",
"id": "e894b678-42b7-469a-9b2f-675417d2168e",
"metadata": {},
"source": [
"### Add lake\n",
"\n",
"Model de \"grote gracht\" and \"Oude Haven\" as lakes. Let the grote gracht overflow in to de oude Haven."
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "66f8c218-35da-4084-a569-013ab59aa686",
"metadata": {},
"outputs": [],
"source": [
"lake_grid = nlmod.grid.gdf_to_grid(lakes, ix=gi)\n",
"lake_grid.set_index('cellid', inplace=True)"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "1240a110-b71e-4afd-9c8f-0a1d868e8c2f",
"metadata": {},
"outputs": [],
"source": [
"# add specific properties to the lake gdf\n",
"lake_grid.loc[lake_grid['identificatie'].isin(ids_grote_gracht), 'lakeno'] = 0\n",
"lake_grid.loc[lake_grid['identificatie'].isin(ids_oude_haven),'lakeno'] = 1\n",
"\n",
"# add general properties to the lake gdf\n",
"lake_grid['elev'] = lake_grid['ahn_min'] - 0.5\n",
"summer_months=(4, 5, 6, 7, 8, 9)\n",
"if pd.to_datetime(ds.time.start).month in summer_months:\n",
" lake_grid['strt'] = lake_grid['summer_stage']\n",
"else:\n",
" lake_grid['strt'] = lake_grid['winter_stage']\n",
"lake_grid['clake'] = 100\n",
"\n",
"#add inflow to Oude Haven\n",
"# ds['inflow_lake'] = xr.DataArray(100, dims=[\"time\"], coords=dict(time=ds.time))\n",
"# lake_grid.loc[lake_grid['identificatie'].isin(ids_oude_haven), 'INFLOW'] = 'inflow_lake'\n",
"\n",
"#add outlet to Oude Haven, water flows from Oude Haven to Grote Gracht.\n",
"lake_grid.loc[lake_grid['identificatie'].isin(ids_oude_haven), 'lakeout'] = 0\n",
"lake_grid.loc[lake_grid['identificatie'].isin(ids_oude_haven), \"outlet_invert\"] = 1.0 # overstort hoogte\n",
"\n",
"# add lake to groundwaterflow model\n",
"nlmod.gwf.lake_from_gdf(gwf, lake_grid, ds, boundname_column='name');"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "f4cc10d1-d14c-4ddf-b32c-0444269ee38c",
"metadata": {},
"outputs": [],
"source": [
"# create recharge package\n",
"rch = nlmod.gwf.rch(ds, gwf)"
]
},
{
"cell_type": "markdown",
"id": "1a7f416e",
Expand Down Expand Up @@ -479,6 +559,26 @@
"head_point.plot.line(hue=\"layer\", size=10);"
]
},
{
"cell_type": "markdown",
"id": "a429d806-cf6d-4b3f-9d59-77f46fa66759",
"metadata": {},
"source": [
"### plot the lake stages"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "0d9f3bd7-a0c2-4aec-a52b-6278053f4fef",
"metadata": {},
"outputs": [],
"source": [
"df = pd.read_csv(os.path.join(model_ws, 'lak_STAGE.csv'), index_col=0)\n",
"df.index = ds.time.values\n",
"ax = df.plot(figsize=(10,3));"
]
},
{
"cell_type": "markdown",
"id": "37179636-e410-4e82-9efa-62e14140a161",
Expand All @@ -489,10 +589,8 @@
},
{
"cell_type": "raw",
OnnoEbbens marked this conversation as resolved.
Show resolved Hide resolved
"id": "550791d6",
"metadata": {
"raw_mimetype": "text/x-python"
},
"id": "9faabb6c-728a-477d-a659-2941ee684bbc",
"metadata": {"raw_mimetype": "text/x-python"},
"source": [
"fname_pklz = os.path.join(ds.cachedir, 'oc_bro.pklz')\n",
"if os.path.exists(fname_pklz):\n",
Expand All @@ -504,22 +602,17 @@
},
{
"cell_type": "raw",
"id": "24a1ea6e",
"metadata": {
"raw_mimetype": "text/x-python",
"tags": []
},
"id": "06fdd4cc-a15e-485e-b12e-fda9a464d30c",
"metadata": {"raw_mimetype": "text/x-python"},
"source": [
"# get modellayers\n",
"oc['modellayer'] = oc.gwobs.get_modellayers(ds=ds)"
]
},
{
"cell_type": "raw",
"id": "94e6af4b",
"metadata": {
"raw_mimetype": "text/x-python"
},
"id": "7831eddc-3b69-4cc5-b1c0-7ee09732a2f9",
"metadata": {"raw_mimetype": "text/x-python"},
"source": [
"# get modelled head at measurement points\n",
"ds['heads'] = nlmod.gwf.get_heads_da(ds)\n",
Expand All @@ -528,11 +621,8 @@
},
{
"cell_type": "raw",
"id": "ab1db83d",
"metadata": {
"raw_mimetype": "text/x-python",
"tags": []
},
"id": "1c736d07-5623-4df3-97be-b5ed14d301e1",
"metadata": {"raw_mimetype": "text/x-python"},
"source": [
"# add modelled head to measured heads\n",
"obs_list_map = []\n",
Expand Down Expand Up @@ -727,6 +817,10 @@
}
],
"metadata": {
"kernelspec": {
"display_name": "",
"name": ""
},
"language_info": {
"name": "python"
}
Expand Down
1 change: 1 addition & 0 deletions nlmod/gwf/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@
from .output import *
from .recharge import *
from .surface_water import *
from .lake import *
Loading