Skip to content

Commit

Permalink
Merge pull request #8 from eWaterCycle/cleanUpRolf
Browse files Browse the repository at this point in the history
Clean up rolf
  • Loading branch information
RolfHut authored Oct 28, 2024
2 parents fd4ca79 + 785f3ee commit 975da4a
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 42 deletions.
1 change: 0 additions & 1 deletion book/_toc.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,3 @@ parts:
- file: oneModel/additional/example_model_run_HBV_CMIP_forcing.ipynb
- file: oneModel/additional/calibration_HBV/example_calibrate_HBV.ipynb
- file: oneModel/additional/pcrglobwb/example_model_run_pcrglobwb.ipynb
- file: references.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,11 @@
"\n",
"# PCRGlobWB example use case\n",
"\n",
"This example shows how the [PCRGlobWB model](https://globalhydrology.nl/research/models/pcr-globwb-2-0/) can be used within the eWaterCycle system. It is based on the example use case from https://github.com/UU-Hydro/PCR-GLOBWB_input_example.\n",
"This example shows how the [PCRGlobWB model](https://globalhydrology.nl/research/models/pcr-globwb-2-0/) can be used within the eWaterCycle system. It is assumed you have already seen [this tutorial notebook](../../example_model_run_HBV.ipynb) explaining how to run the simple HBV model for the River Leven at Newby Bridge. \n",
"\n",
"This example use case assumes that the ewatercycle platform has been installed and configured on your system. See our [system setup documentation](https://ewatercycle.readthedocs.io/en/latest/system_setup.html) for instructions if this is not the case."
"The PCRGlobWB model is an example of a distributed model where fluxes and stores in the balance are calculated for grid cells (often also called pixels). This requires both the forcing data as well as any parameters to also be spatially distributed. Depending on the complexity of the model, these datasets can be quite large in memory size.\n",
"\n",
"Here we will be running PCRGLobWB for Great Brittain and will extract discharge data at the location of the River Leven again, to compare with the HBV model run. We will also demonstrate how to interact with the state of the model, during runtime, showcasing the benefit of using the BMI interface when building experiments using models."
]
},
{
Expand Down Expand Up @@ -46,6 +48,17 @@
"import ewatercycle.parameter_sets"
]
},
{
"cell_type": "code",
"execution_count": 13,
"id": "3f186494-1f05-445d-8663-306591c87320",
"metadata": {},
"outputs": [],
"source": [
"station_latitude = 54.26935849558577 #Newby Bridge location from Google Maps\n",
"station_longitude = -2.9710855713537745 "
]
},
{
"cell_type": "markdown",
"id": "194f357f",
Expand All @@ -59,7 +72,9 @@
"id": "1cdf38a2",
"metadata": {},
"source": [
"A set of (example) parameter sets come pre-installed on the eWaterCycle system (see [system setup](https://ewatercycle.readthedocs.io/en/latest/system_setup.html) if this is not the case)."
"For this example we have prepared and hosted a global parameter set made by Utrecht University. For each model run, what needs to be specified to delinaite the region of interest is a \"clone map\". The config file has many options, one of which is the location of this clone map.\n",
"\n",
"Note that this is very specific to PCRGlobWB. For complex (and legacy) models like PCRGlobWB one needs to know quite detailed information about the model before being able to run it. However, using eWaterCycle does reduce the time for seting up the model and getting it to run."
]
},
{
Expand All @@ -78,14 +93,6 @@
")"
]
},
{
"cell_type": "markdown",
"id": "d9bfc9ac",
"metadata": {},
"source": [
"Existing parametersets can easily be loaded:"
]
},
{
"cell_type": "code",
"execution_count": 4,
Expand Down Expand Up @@ -119,7 +126,9 @@
"source": [
"## Load forcing data\n",
"\n",
"For this example case, the forcing is already included in the parameter set and configured correctly. Therefore in principle this step can be skipped. However, for the purpose of illustration, we show how the forcing would be loaded using the `ewatercycle.forcing` module, as if it came from another source. To learn about forcing generation, see our [preprocessing examples](https://ewatercycle.readthedocs.io/en/latest/examples/generate_forcing.html)."
"For this example case, the forcing is generated in [this seperate notebook](generate_forcing.ipynb). This is a common practice when generating forcing takes considerable (CPU, memory, disk) resources. \n",
"\n",
"In the cell below, we load the pre-generated forcing. Note that in contrast with HBV, PCRGlobWB only needs temperature and precipitation as forcing inputs. HBV also needs potential evaporation. PCRGlobWB calculated potential and actual evaporation as part of its update step."
]
},
{
Expand Down Expand Up @@ -227,7 +236,7 @@
"id": "2a27869b",
"metadata": {},
"source": [
"Calling `setup()` will start up a container. Be careful with calling it multiple times!"
"Calling `setup()` will start up the model container. Be careful with calling it multiple times!"
]
},
{
Expand Down Expand Up @@ -292,6 +301,14 @@
"pcrglob.initialize(cfg_file)"
]
},
{
"cell_type": "markdown",
"id": "f16e18c7-88b1-4019-9281-44a4a51d21d0",
"metadata": {},
"source": [
"We prepare a small dataframe where we can store the discharge output from the model"
]
},
{
"cell_type": "code",
"execution_count": 12,
Expand Down Expand Up @@ -367,30 +384,13 @@
}
],
"source": [
"# time = pd.date_range(reference.start_time_as_isostr, reference.end_time_as_isostr)\n",
"# timeseries = pd.DataFrame(\n",
"# index=pd.Index(time, name=\"time\"), columns=[\"reference\", \"experiment\"]\n",
"# )\n",
"# timeseries.head()\n",
"\n",
"time = pd.date_range(pcrglob.start_time_as_isostr, pcrglob.end_time_as_isostr)\n",
"timeseries = pd.DataFrame(\n",
" index=pd.Index(time, name=\"time\"), columns=[\"PCRGlobWB\"]\n",
" index=pd.Index(time, name=\"time\"), columns=[\"PCRGlobWB: Leven\"]\n",
")\n",
"timeseries.head()"
]
},
{
"cell_type": "code",
"execution_count": 13,
"id": "3f186494-1f05-445d-8663-306591c87320",
"metadata": {},
"outputs": [],
"source": [
"station_latitude = 54.26935849558577 #Newby Bridge location from Google Maps\n",
"station_longitude = -2.9710855713537745 "
]
},
{
"cell_type": "markdown",
"id": "f0f4987f",
Expand Down Expand Up @@ -426,7 +426,7 @@
" \"discharge\", lat=[station_latitude], lon=[station_longitude]\n",
" )\n",
" time = pcrglob.time_as_isostr\n",
" timeseries[\"PCRGlobWB\"][time] = discharge_at_station[0]\n",
" timeseries[\"PCRGlobWB: Leven\"][time] = discharge_at_station[0]\n",
"\n",
" # Show progress\n",
" print(time,end='\\r') # \"\\r\" clears the output before printing the next timestamp\n"
Expand Down Expand Up @@ -1033,7 +1033,7 @@
"id": "b68de73f",
"metadata": {},
"source": [
"Xarray makes it very easy to plot the data. In the figure below, we add three points that we will use to illustrate that we can also access individual grid cells."
"Xarray makes it very easy to plot the data. In the figure below, we add a cross at the location where we collected the discharge every timestep: Leven at Newby bridge."
]
},
{
Expand Down
12 changes: 4 additions & 8 deletions book/oneModel/additional/pcrglobwb/generate_forcing.ipynb
Original file line number Diff line number Diff line change
@@ -1,12 +1,5 @@
{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"![image](https://github.com/eWaterCycle/ewatercycle/raw/main/docs/examples/logo.png)"
]
},
{
"cell_type": "markdown",
"metadata": {},
Expand Down Expand Up @@ -47,7 +40,10 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"Forcing for PCRGlobWB is created using the ESMValTool recipe. It produces one file per each variable: temperature, and precipitation. You can set the start and end date, and the region. See [eWaterCycle documentation](https://ewatercycle.readthedocs.io/en/latest/apidocs/ewatercycle.forcing.html#submodules) for more information. "
"Forcing for PCRGlobWB is created using the ESMValTool recipe. It produces one file per each variable: temperature, and precipitation. You can set the start and end date, and the region. See [eWaterCycle documentation](https://ewatercycle.readthedocs.io/en/latest/apidocs/ewatercycle.forcing.html#submodules) for more information. \n",
"\n",
"#### Bug:\n",
"A shape file needs to be provided to delineate the area of interest. However, the forcing generated in this way will fill a bounding box that is \"tight\" around the shapefile. PCRGlobWB needs forcing files to be (slightly) larger than the extend of the clonemap. We fix this with \"esmavaltool_padding below. Furhtermore, the number of pixels in the lat and lon directions need to be even for the interpolation algorithm that converts forcing data to the grid of the model. Therefore, we use the extract region and hard-code the extend of Great Brittain."
]
},
{
Expand Down

0 comments on commit 975da4a

Please sign in to comment.