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

Move sim.py to separate submodule #104

Merged
merged 4 commits into from
Oct 27, 2022
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
143 changes: 81 additions & 62 deletions docs/examples/01_basic_model.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,13 @@
"metadata": {},
"outputs": [],
"source": [
"import matplotlib.pyplot as plt\n",
"import flopy\n",
"import logging\n",
"import os\n",
"import geopandas as gpd\n",
"\n",
"import nlmod\n",
"\n",
"import logging"
"import flopy\n",
"import geopandas as gpd\n",
"import matplotlib.pyplot as plt\n",
"import nlmod\n"
]
},
{
Expand All @@ -45,17 +44,17 @@
"metadata": {},
"outputs": [],
"source": [
"print(f'nlmod version: {nlmod.__version__}')\n",
"print(f\"nlmod version: {nlmod.__version__}\")\n",
"\n",
"# toon informatie bij het aanroepen van functies\n",
"logging.basicConfig(level=logging.INFO)"
"logging.basicConfig(level=logging.INFO)\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### [0. Download MODFLOW-binariesl](#TOC)<a name=\"binaries\"></a>\n",
"### [0. Download MODFLOW-binaries](#TOC)<a name=\"binaries\"></a>\n",
"To run MODFLOW, we need to download the MODFLOW-excecutables. We do this with the following code:"
]
},
Expand All @@ -66,7 +65,7 @@
"outputs": [],
"source": [
"if not nlmod.util.check_presence_mfbinaries():\n",
" nlmod.util.download_mfbinaries()"
" nlmod.util.download_mfbinaries()\n"
]
},
{
Expand Down Expand Up @@ -97,19 +96,19 @@
"outputs": [],
"source": [
"# model settings\n",
"model_ws = 'model1'\n",
"model_name = 'IJmuiden'\n",
"model_ws = \"model1\"\n",
"model_name = \"IJmuiden\"\n",
"figdir, cachedir = nlmod.util.get_model_dirs(model_ws)\n",
"extent = [95000., 105000., 494000., 500000.]\n",
"delr = 100.\n",
"delc = 100.\n",
"extent = [95000.0, 105000.0, 494000.0, 500000.0]\n",
"delr = 100.0\n",
"delc = 100.0\n",
"steady_state = True\n",
"start_time = '2015-1-1'\n",
"start_time = \"2015-1-1\"\n",
"use_regis = True\n",
"regis_botm_layer = 'MSz1'\n",
"regis_botm_layer = \"MSz1\"\n",
"use_geotop = True\n",
"add_northsea = True\n",
"starting_head = 1.0"
"starting_head = 1.0\n"
]
},
{
Expand All @@ -118,21 +117,27 @@
"metadata": {},
"outputs": [],
"source": [
"layer_model = nlmod.read.regis.get_combined_layer_models(extent,\n",
" use_regis=use_regis,\n",
" regis_botm_layer=regis_botm_layer,\n",
" use_geotop=use_geotop,\n",
" cachedir=cachedir,\n",
" cachename='combined_layer_ds.nc')\n",
"layer_model = nlmod.read.regis.get_combined_layer_models(\n",
" extent,\n",
" use_regis=use_regis,\n",
" regis_botm_layer=regis_botm_layer,\n",
" use_geotop=use_geotop,\n",
" cachedir=cachedir,\n",
" cachename=\"combined_layer_ds.nc\",\n",
")\n",
"\n",
"# create a model ds by changing grid of layer_model\n",
"ds = nlmod.mdims.to_model_ds(layer_model, model_name, model_ws, delr=delr, delc=delc)\n",
"ds = nlmod.mdims.to_model_ds(\n",
" layer_model, model_name, model_ws, delr=delr, delc=delc\n",
")\n",
"\n",
"# add time discretisation\n",
"ds = nlmod.mdims.set_ds_time(ds, start_time=start_time, steady_state=steady_state, perlen=365*5)\n",
"ds = nlmod.mdims.set_ds_time(\n",
" ds, start_time=start_time, steady_state=steady_state, perlen=365 * 5\n",
")\n",
"\n",
"if add_northsea:\n",
" ds = nlmod.mdims.add_northsea(ds)"
" ds = nlmod.mdims.add_northsea(ds)\n"
]
},
{
Expand All @@ -141,11 +146,11 @@
"metadata": {},
"outputs": [],
"source": [
"# create simulation \n",
"sim = nlmod.gwf.sim(ds)\n",
"# create simulation\n",
"sim = nlmod.sim.sim(ds)\n",
"\n",
"# create time discretisation\n",
"tdis = nlmod.gwf.tdis(ds, sim)\n",
"tdis = nlmod.sim.tdis(ds, sim)\n",
"\n",
"# create groundwater flow model\n",
"gwf = nlmod.gwf.gwf(ds, sim)\n",
Expand All @@ -154,16 +159,16 @@
"ims = nlmod.gwf.ims(sim)\n",
"\n",
"# Create discretization\n",
"nlmod.gwf.dis(ds, gwf)\n",
"dis = nlmod.gwf.dis(ds, gwf)\n",
"\n",
"# create node property flow\n",
"nlmod.gwf.npf(ds, gwf)\n",
"npf = nlmod.gwf.npf(ds, gwf)\n",
"\n",
"# Create the initial conditions package\n",
"nlmod.gwf.ic(ds, gwf, starting_head=starting_head)\n",
"ic = nlmod.gwf.ic(ds, gwf, starting_head=starting_head)\n",
"\n",
"# Create the output control package\n",
"nlmod.gwf.oc(ds, gwf);"
"oc = nlmod.gwf.oc(ds, gwf)\n"
]
},
{
Expand All @@ -173,13 +178,12 @@
"outputs": [],
"source": [
"# voeg grote oppervlaktewaterlichamen toe o.b.v. rws shape\n",
"da_name = 'rws_oppwater'\n",
"rws_ds = nlmod.read.rws.get_surface_water(ds,\n",
" da_name,\n",
" cachedir=ds.cachedir,\n",
" cachename=da_name)\n",
"da_name = \"rws_oppwater\"\n",
"rws_ds = nlmod.read.rws.get_surface_water(\n",
" ds, da_name, cachedir=ds.cachedir, cachename=da_name\n",
")\n",
"ds.update(rws_ds)\n",
"ghb = nlmod.gwf.ghb(ds, gwf, da_name)"
"ghb = nlmod.gwf.ghb(ds, gwf, da_name)\n"
]
},
{
Expand All @@ -189,15 +193,15 @@
"outputs": [],
"source": [
"# surface level drain\n",
"ahn_ds = nlmod.read.ahn.get_ahn(ds, cachedir=ds.cachedir, cachename='ahn')\n",
"ahn_ds = nlmod.read.ahn.get_ahn(ds, cachedir=ds.cachedir, cachename=\"ahn\")\n",
"ds.update(ahn_ds)\n",
"\n",
"drn = nlmod.gwf.surface_drain_from_ds(ds, gwf)\n",
"\n",
"\n",
"# add constant head cells at model boundaries\n",
"ds.update(nlmod.gwf.constant_head.chd_at_model_edge(ds, ds['idomain'])) \n",
"chd = nlmod.gwf.chd(ds, gwf, head='starting_head')"
"ds.update(nlmod.gwf.constant_head.chd_at_model_edge(ds, ds[\"idomain\"]))\n",
"chd = nlmod.gwf.chd(ds, gwf, head=\"starting_head\")\n"
]
},
{
Expand All @@ -207,11 +211,13 @@
"outputs": [],
"source": [
"# add knmi recharge to the model datasets\n",
"knmi_ds = nlmod.read.knmi.get_recharge(ds, cachedir=ds.cachedir, cachename='recharge')\n",
"knmi_ds = nlmod.read.knmi.get_recharge(\n",
" ds, cachedir=ds.cachedir, cachename=\"recharge\"\n",
")\n",
"ds.update(knmi_ds)\n",
"\n",
"# create recharge package\n",
"rch = nlmod.gwf.rch(ds, gwf)"
"rch = nlmod.gwf.rch(ds, gwf)\n"
]
},
{
Expand All @@ -235,7 +241,7 @@
"metadata": {},
"source": [
"### [2. Write and Run](#TOC)<a name=\"run\"></a>\n",
"Now that we've created all the modflow packages we need to write them to modflow files. You always have to write the modflow data to the model workspace before you can run the model. You can write the model files and run the model using the function `nlmod.util.write_and_run_model()` as shown below. This function has two additional options:\n",
"Now that we've created all the modflow packages we need to write them to modflow files. You always have to write the modflow data to the model workspace before you can run the model. You can write the model files and run the model using the function `nlmod.sim.write_and_run)` as shown below. This function has two additional options:\n",
"1. Write the model dataset to the disk if `write_ds` is `True`. This makes it easier and faster to load model data if you ever need it. \n",
"2. Write a copy of this Jupyter Notebook to the same directory as the modflow files if `nb_path` is the name of this Jupyter Notebook. It can be useful to have a copy of the script that created the modflow files, together with the files. "
]
Expand All @@ -246,7 +252,9 @@
"metadata": {},
"outputs": [],
"source": [
"nlmod.gwf.write_and_run_model(gwf, ds, write_ds=True, nb_path='01_basic_model.ipynb')"
"nlmod.sim.write_and_run(\n",
" sim, ds, write_ds=True, nb_path=\"01_basic_model.ipynb\"\n",
")\n"
]
},
{
Expand All @@ -265,7 +273,9 @@
"outputs": [],
"source": [
"ax = nlmod.visualise.plots.plot_modelgrid(ds, gwf)\n",
"ax.figure.savefig(os.path.join(ds.figdir, 'mgrid_swater.png'), bbox_inches='tight')"
"ax.figure.savefig(\n",
" os.path.join(ds.figdir, \"mgrid_swater.png\"), bbox_inches=\"tight\"\n",
")\n"
]
},
{
Expand All @@ -282,26 +292,30 @@
"outputs": [],
"source": [
"fig, axes = plt.subplots(nrows=2, ncols=2, figsize=(14, 11))\n",
"ds['ahn'].plot(ax=axes[0][0])\n",
"ds['botm'][0].plot(ax=axes[0][1])\n",
"ds['idomain'][0].plot(ax=axes[1][0])\n",
"ds['chd'][0].plot(ax=axes[1][1])\n",
"ds[\"ahn\"].plot(ax=axes[0][0])\n",
"ds[\"botm\"][0].plot(ax=axes[0][1])\n",
"ds[\"idomain\"][0].plot(ax=axes[1][0])\n",
"ds[\"chd\"][0].plot(ax=axes[1][1])\n",
"for axes1 in axes:\n",
" for ax in axes1:\n",
" ax.axis('scaled')\n",
" ax.axis(\"scaled\")\n",
"\n",
"fig.savefig(os.path.join(ds.figdir, 'ahn_bot_idom_chd.png'), bbox_inches='tight')\n",
"fig.savefig(\n",
" os.path.join(ds.figdir, \"ahn_bot_idom_chd.png\"), bbox_inches=\"tight\"\n",
")\n",
"\n",
"fig, axes = plt.subplots(nrows=2, ncols=2, figsize=(14, 11))\n",
"ds['bathymetry'].plot(ax=axes[0][0])\n",
"ds['northsea'].plot(ax=axes[0][1])\n",
"ds['kh'][1].plot(ax=axes[1][0])\n",
"ds['recharge'].plot(ax=axes[1][1])\n",
"ds[\"bathymetry\"].plot(ax=axes[0][0])\n",
"ds[\"northsea\"].plot(ax=axes[0][1])\n",
"ds[\"kh\"][1].plot(ax=axes[1][0])\n",
"ds[\"recharge\"].plot(ax=axes[1][1])\n",
"\n",
"for axes1 in axes:\n",
" for ax in axes1:\n",
" ax.axis('scaled')\n",
"fig.savefig(os.path.join(ds.figdir, 'bath_nsea_kh_top.png'), bbox_inches='tight')"
" ax.axis(\"scaled\")\n",
"fig.savefig(\n",
" os.path.join(ds.figdir, \"bath_nsea_kh_top.png\"), bbox_inches=\"tight\"\n",
")\n"
]
},
{
Expand All @@ -325,7 +339,7 @@
},
"anaconda-cloud": {},
"kernelspec": {
"display_name": "Python 3 (ipykernel)",
"display_name": "Python 3.9.7 ('artesia')",
"language": "python",
"name": "python3"
},
Expand All @@ -339,7 +353,12 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.9.4"
"version": "3.9.7"
},
"vscode": {
"interpreter": {
"hash": "dace5e1b41a98a8e52d2a8eebc3b981caf2c12e7a76736ebfb89a489e3b62e79"
}
},
"widgets": {
"state": {},
Expand Down
Loading