Skip to content

Commit

Permalink
docs: update example notebooks (#679)
Browse files Browse the repository at this point in the history
fixes: #677
  • Loading branch information
veenstrajelmer authored Jul 9, 2024
1 parent e8b5262 commit 2d5dcdc
Show file tree
Hide file tree
Showing 8 changed files with 2,741 additions and 2,327 deletions.
2,082 changes: 1,041 additions & 1,041 deletions docs/tutorials/Tutorial_1d2d_fluvial_flood_model_for_Magdalena.ipynb

Large diffs are not rendered by default.

2,293 changes: 1,231 additions & 1,062 deletions docs/tutorials/Tutorial_1d2d_fluvial_flood_model_for_Magdalena_with_answers.ipynb

Large diffs are not rendered by default.

317 changes: 170 additions & 147 deletions docs/tutorials/build_basic_model.ipynb
Original file line number Diff line number Diff line change
@@ -1,148 +1,171 @@
{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Build a basic model\n",
"\n",
"This _Build a basic model_ tutorial illustrates how to build a simple D-Flow FM model from scratch using [HYDROLIB-core](https://github.com/Deltares/HYDROLIB-core). "
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### Import HYDROLIB-core functionalities and setup D-Flow FM model\n",
"The commands below import all needed packages and will prepare a model that will be saved in a subdir `testmodel/` within the current working dir."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"from hydrolib.core.structure.models import FlowDirection, StructureModel, Weir\n",
"from hydrolib.core.mdu.models import FMModel\n",
"from pathlib import Path\n",
"\n",
"print(\"Package import successful!\")"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"workdir = Path(\"testmodel\")\n",
"mdufile = \"test.mdu\"\n",
"\n",
"fm = FMModel()\n",
"fm.filepath = workdir / mdufile"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Add a hydraulic structure; note that this is invalid because the model does not \n",
"have a 1D network with branches and coordinates yet, but it will work for demo purposes \n",
"and the network may be added later."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"# Add weir to the structure set/model and add this structure set to D-Flow FM model \n",
"struc = Weir(branchId='someBranch', chainage = 123.0, allowedflowdir=FlowDirection.none, crestlevel=0.0)\n",
"struc.comments.crestlevel = \"This is a comment\"\n",
"fm.geometry.structurefile = [StructureModel(structure=[struc])]"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Note that the creation of a `Weir` and other model objects requires several input arguments.\n",
"A `ValidationError` will be raised when the model is invalid or incomplete.\n",
"For instance, in the above example, if the `StructureModel` had been assigned directly to `structurefile` instead of as a list, that would have triggered a `ValidationError`.\n",
"\n",
"### Setup a DIMR model\n",
"Now let's add this model to an integrated model (DIMR config) and save it."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"from hydrolib.core.dimr.models import DIMR, FMComponent\n",
"\n",
"dimr = DIMR()\n",
"dimr.component.append(\n",
" FMComponent(name=\"test\", workingDir=workdir, inputfile=mdufile, model=fm)\n",
")\n",
"\n",
"dimr_config = Path(\"dimr_config.xml\")\n",
"dimr.save(filepath=dimr_config, recurse=True)\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### The model files on disk\n",
"Now, let's see which model input files were saved:"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"dimr.show_tree()"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"The save call on the highest-level DIMR object will result in recursive saves of all child models in the model hierarchy, so this results in four files (`dimr_config.xml`, `network.nc`, `structures.ini`,`test.mdu`) in the working directory.\n",
"Some more in-depth background about recursive saving of a model tree is given in another tutorial: [Loading and saving](loading_and_saving_a_model.md)."
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3 (ipykernel)",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.8.8"
},
"vscode": {
"interpreter": {
"hash": "82e465d5440b391da8d43d2f583b852925fd7bed0ed0d752c9688c1fce589220"
}
}
},
"nbformat": 4,
"nbformat_minor": 2
}
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Build a basic model\n",
"\n",
"This _Build a basic model_ tutorial illustrates how to build a simple D-Flow FM model from scratch using [HYDROLIB-core](https://github.com/Deltares/HYDROLIB-core). "
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### Import HYDROLIB-core functionalities and setup D-Flow FM model\n",
"The commands below import all needed packages and will prepare a model that will be saved in a subdir `testmodel/` within the current working dir."
]
},
{
"cell_type": "code",
"execution_count": 1,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Package import successful!\n"
]
}
],
"source": [
"from hydrolib.core.dflowfm.structure.models import FlowDirection, StructureModel, Weir\n",
"from hydrolib.core.dflowfm.mdu.models import FMModel\n",
"from pathlib import Path\n",
"\n",
"print(\"Package import successful!\")"
]
},
{
"cell_type": "code",
"execution_count": 2,
"metadata": {},
"outputs": [],
"source": [
"workdir = Path(\"testmodel\")\n",
"mdufile = \"test.mdu\"\n",
"\n",
"fm = FMModel()\n",
"fm.filepath = workdir / mdufile"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Add a hydraulic structure; note that this is invalid because the model does not \n",
"have a 1D network with branches and coordinates yet, but it will work for demo purposes \n",
"and the network may be added later."
]
},
{
"cell_type": "code",
"execution_count": 3,
"metadata": {},
"outputs": [],
"source": [
"# Add weir to the structure set/model and add this structure set to D-Flow FM model \n",
"struc = Weir(branchId='someBranch', chainage = 123.0, allowedflowdir=FlowDirection.none, crestlevel=0.0)\n",
"struc.comments.crestlevel = \"This is a comment\"\n",
"fm.geometry.structurefile = [StructureModel(structure=[struc])]"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Note that the creation of a `Weir` and other model objects requires several input arguments.\n",
"A `ValidationError` will be raised when the model is invalid or incomplete.\n",
"For instance, in the above example, if the `StructureModel` had been assigned directly to `structurefile` instead of as a list, that would have triggered a `ValidationError`.\n",
"\n",
"### Setup a DIMR model\n",
"Now let's add this model to an integrated model (DIMR config) and save it."
]
},
{
"cell_type": "code",
"execution_count": 4,
"metadata": {},
"outputs": [],
"source": [
"from hydrolib.core.dimr.models import DIMR, FMComponent\n",
"\n",
"dimr = DIMR()\n",
"dimr.component.append(\n",
" FMComponent(name=\"test\", workingDir=workdir, inputfile=mdufile, model=fm)\n",
")\n",
"\n",
"dimr_config = Path(\"dimr_config.xml\")\n",
"dimr.save(filepath=dimr_config, recurse=True)\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### The model files on disk\n",
"Now, let's see which model input files were saved:"
]
},
{
"cell_type": "code",
"execution_count": 5,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
" dimr_config.xml\n",
" FMComponent\n",
" ∟ testmodel\\test.mdu\n",
" ∟ Geometry\n",
" ∟ network.nc\n",
" ∟ structures.ini\n",
" ∟ ExternalForcing\n",
" ∟ Output\n"
]
}
],
"source": [
"dimr.show_tree()"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"The save call on the highest-level DIMR object will result in recursive saves of all child models in the model hierarchy, so this results in four files (`dimr_config.xml`, `network.nc`, `structures.ini`,`test.mdu`) in the working directory.\n",
"Some more in-depth background about recursive saving of a model tree is given in another tutorial: [Loading and saving](loading_and_saving_a_model.md)."
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3 (ipykernel)",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.11.6"
},
"vscode": {
"interpreter": {
"hash": "82e465d5440b391da8d43d2f583b852925fd7bed0ed0d752c9688c1fce589220"
}
}
},
"nbformat": 4,
"nbformat_minor": 4
}
Loading

0 comments on commit 2d5dcdc

Please sign in to comment.