Skip to content

Commit

Permalink
Merge pull request #7 from eWaterCycle/add_jpuyterhub_and_specific_bu…
Browse files Browse the repository at this point in the history
…ttons_per_notebook

Add jpuyterhub and specific buttons per notebook
  • Loading branch information
RolfHut authored Dec 11, 2024
2 parents 8aad90f + baa8d43 commit 07946fb
Show file tree
Hide file tree
Showing 3 changed files with 505 additions and 248 deletions.
191 changes: 156 additions & 35 deletions book/1_modelling_intro_HBV/Exercise1.ipynb
Original file line number Diff line number Diff line change
@@ -1,10 +1,66 @@
{
"cells": [
{
"cell_type": "code",
"execution_count": 2,
"metadata": {
"editable": true,
"slideshow": {
"slide_type": ""
},
"tags": [
"thebe-remove-input-init",
"thebe-init"
]
},
"outputs": [],
"source": [
"import numpy as np\n",
"import pandas as pd\n",
"import matplotlib.pyplot as plt"
]
},
{
"cell_type": "markdown",
"metadata": {
"editable": true,
"slideshow": {
"slide_type": ""
},
"tags": []
},
"source": [
"`````{admonition} Interactive Python Page\n",
":class: tip, dropdown\n",
"\n",
"The code on this page can be used interactively: click {fa}`rocket` --> {guilabel}`Live Code` in the top right corner, then wait until the message {guilabel}`Python interaction ready!` appears.\n",
"\n",
"When this page is activated:\n",
"- Several packages will be imported automatically\n",
"- Code cells will **not** be executed automatically (you do it!)\n",
"\n",
"````{admonition} Which packages are imported when this page is activated?\n",
":class: note, dropdown\n",
"```\n",
"import numpy as np\n",
"import pandas as pd\n",
"import matplotlib.pyplot as plt\n",
"```\n",
"````\n",
"`````"
]
},
{
"cell_type": "markdown",
"metadata": {},
"metadata": {
"editable": true,
"slideshow": {
"slide_type": ""
},
"tags": []
},
"source": [
"# Exercise 1\n",
"# Modelling exercise 1: Linear Reservoir\n",
"\n",
"## Introduction\n",
"\n",
Expand All @@ -31,15 +87,23 @@
},
{
"cell_type": "markdown",
"metadata": {},
"metadata": {
"editable": true,
"slideshow": {
"slide_type": ""
},
"tags": []
},
"source": [
"## 1. Linear Reservoir without External Drivers\n",
"\n",
"At first we will consider the reservoir without the external drivers ```P``` and ```E``` and we assume that Q is equal to:\n",
"\n",
"$$\n",
"\\begin{equation}\n",
"Q = k S ^\\alpha\n",
"\\end{equation}\n",
"$$\n",
"\n",
"Next to this, we also assmume a linear reservoir, so $\\alpha$ is equal to 1.\n",
"\n",
Expand All @@ -53,33 +117,48 @@
"\n",
"An simple example of a numerical solution is the explicit forward Euler method. This method calculates the state of a system at each time step considering the state of the system at the previous time step and rate of changes:\n",
"\n",
"$$\n",
"\\begin{equation}\n",
"S(t + \\Delta t) = F(S(t))\n",
"\\end{equation}\n",
"$$\n",
"\n",
"If we consider the linear reservoir problem without the external drivers, we obtain:\n",
"\n",
"$$\n",
"\\begin{equation}\n",
"\\frac{dS(t)}{dt} = -k S(t) ^\\alpha\n",
"\\end{equation}\n",
"$$\n",
"\n",
"The forward Euler method yields:\n",
"\n",
"$$\n",
"\\begin{equation}\n",
"\\frac{S(t + \\Delta t) - S(t)}{\\Delta t} = -kS(t)^\\alpha\n",
"\\end{equation}\n",
"$$\n",
"\n",
"This results in the numerical solution:\n",
"\n",
"$$\n",
"\\begin{equation}\n",
"S(t + \\Delta t) = S(t) + - k \\Delta t k S(t) ^\\alpha\n",
"\\end{equation}\n",
"$$\n",
"\n",
"Hence, if $ S(t) $ is known, $ S(t + \\Delta t) $ can be calculated in one iteration. The big assumption in the forward Euler model is that $ S\\left(t\\right) $ is relatively constant during the timestep. This may not always be true. If $S\\left(t\\right)$ changes fast smaller timesteps need to be used to not make too big of an error. Other, more complicated methods to numerically solve differential equations exist such as Runga-Kutta. See the material of the MUDE course for more information on those. In hydrology it is always important to weigh if the error introduced by your numerical scheme is significant compared to the error introduced by the fact that the model is not perfect to begin with."
]
},
{
"cell_type": "markdown",
"metadata": {},
"metadata": {
"editable": true,
"slideshow": {
"slide_type": ""
},
"tags": []
},
"source": [
"Write the functions in the code cells below to calculate the analytical and numerical solution of the linear reservoir problem without external drivers. Return for both the storage array ```S```and the time array ```t```. \n",
"\n",
Expand All @@ -99,28 +178,16 @@
"5. How can you use a function for this exercise?"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"First import the relevant packages "
]
},
{
"cell_type": "code",
"execution_count": 1,
"metadata": {},
"outputs": [],
"source": [
"import numpy as np\n",
"import pandas as pd\n",
"import matplotlib.pyplot as plt"
]
},
{
"cell_type": "code",
"execution_count": 2,
"metadata": {},
"execution_count": 3,
"metadata": {
"editable": true,
"slideshow": {
"slide_type": ""
},
"tags": []
},
"outputs": [],
"source": [
"S0 = 75 #mm\n",
Expand All @@ -133,8 +200,14 @@
},
{
"cell_type": "code",
"execution_count": 3,
"metadata": {},
"execution_count": 4,
"metadata": {
"editable": true,
"slideshow": {
"slide_type": ""
},
"tags": []
},
"outputs": [],
"source": [
"def analytical_solve():\n",
Expand All @@ -145,8 +218,14 @@
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"execution_count": 5,
"metadata": {
"editable": true,
"slideshow": {
"slide_type": ""
},
"tags": []
},
"outputs": [],
"source": [
"def numerical_solve():\n",
Expand All @@ -158,7 +237,13 @@
},
{
"cell_type": "markdown",
"metadata": {},
"metadata": {
"editable": true,
"slideshow": {
"slide_type": ""
},
"tags": []
},
"source": [
"### Part 3\n",
"\n",
Expand All @@ -170,13 +255,25 @@
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"metadata": {
"editable": true,
"slideshow": {
"slide_type": ""
},
"tags": []
},
"outputs": [],
"source": []
},
{
"cell_type": "markdown",
"metadata": {},
"metadata": {
"editable": true,
"slideshow": {
"slide_type": ""
},
"tags": []
},
"source": [
"## 2. Linear Reservoir with External Drivers\n",
"\n",
Expand All @@ -187,7 +284,13 @@
},
{
"cell_type": "markdown",
"metadata": {},
"metadata": {
"editable": true,
"slideshow": {
"slide_type": ""
},
"tags": []
},
"source": [
"### Part 4\n",
"\n",
Expand All @@ -199,13 +302,25 @@
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"metadata": {
"editable": true,
"slideshow": {
"slide_type": ""
},
"tags": []
},
"outputs": [],
"source": []
},
{
"cell_type": "markdown",
"metadata": {},
"metadata": {
"editable": true,
"slideshow": {
"slide_type": ""
},
"tags": []
},
"source": [
"### Bonus Question\n",
"\n",
Expand All @@ -215,7 +330,13 @@
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"metadata": {
"editable": true,
"slideshow": {
"slide_type": ""
},
"tags": []
},
"outputs": [],
"source": []
}
Expand Down
Loading

0 comments on commit 07946fb

Please sign in to comment.