|
| 1 | +{ |
| 2 | + "cells": [ |
| 3 | + { |
| 4 | + "cell_type": "markdown", |
| 5 | + "id": "02a37d9a", |
| 6 | + "metadata": {}, |
| 7 | + "source": [ |
| 8 | + "# Estimating Hydropower with the Reservoir Module\n", |
| 9 | + "\n", |
| 10 | + "This notebook shows an example of estimating daily hydropower time series given a water system. Here, we will work with a system called \"complex_river\", comprising four reservoirs: Atay, Kamchay, Kirirom1, and Kirirom2. These reservoirs are situated in a cascade. Water flow from Kamchay are diverted 25% to Kirirom1 and 75% to Kirirom2. Hydropower capacities are shown in the figure below.\n", |
| 11 | + "\n", |
| 12 | + "The following code imports necessary libraries and displays a diagram of the 'complex_river' water system, illustrating reservoir connections and hydropower capacities." |
| 13 | + ] |
| 14 | + }, |
| 15 | + { |
| 16 | + "cell_type": "code", |
| 17 | + "execution_count": null, |
| 18 | + "id": "67d99308", |
| 19 | + "metadata": {}, |
| 20 | + "outputs": [], |
| 21 | + "source": [ |
| 22 | + "import os\n", |
| 23 | + "from IPython.display import Image, display\n", |
| 24 | + "from pownet.folder_utils import get_pownet_dir\n", |
| 25 | + "\n", |
| 26 | + "project_root = get_pownet_dir()\n", |
| 27 | + "image_path = os.path.join(project_root, \"images\", \"complex_river.png\")\n", |
| 28 | + "display(Image(filename=image_path))" |
| 29 | + ] |
| 30 | + }, |
| 31 | + { |
| 32 | + "cell_type": "markdown", |
| 33 | + "id": "3e7f3d1e", |
| 34 | + "metadata": {}, |
| 35 | + "source": [ |
| 36 | + "## Setup: Input/Output Folders\n", |
| 37 | + "\n", |
| 38 | + "First, we specify the directory containing the input data using `input_folder`. If simulation results need to be saved, we also define the `output_folder`. PowNet requires the following CSV files:\n", |
| 39 | + "\n", |
| 40 | + "- `reservoir_unit.csv` contains information on the characteristics of reservoirs\n", |
| 41 | + "- `inflow.csv` contains the daily inflow to each reservoirs\n", |
| 42 | + "- `minimum_flow.csv` contains the daily minimum flow from each reservoirs\n", |
| 43 | + "- `flow_paths.csv` contains the system topology -- the water flow paths\n", |
| 44 | + "\n", |
| 45 | + "This code block imports the ReservoirManager and defines essential paths. It sets up the input_folder where PowNet will look for model data (e.g., CSV files for the 'complex_river' model) and an output_folder for saving simulation results. Note: If PowNet was installed via pip, or if your data resides in a different location, you may need to adjust the input_folder path accordingly." |
| 46 | + ] |
| 47 | + }, |
| 48 | + { |
| 49 | + "cell_type": "code", |
| 50 | + "execution_count": null, |
| 51 | + "id": "ab379af5", |
| 52 | + "metadata": {}, |
| 53 | + "outputs": [], |
| 54 | + "source": [ |
| 55 | + "import os\n", |
| 56 | + "from pownet.reservoir import ReservoirManager\n", |
| 57 | + "\n", |
| 58 | + "input_folder = os.path.join(project_root, \"model_library\")\n", |
| 59 | + "output_folder = os.path.join(project_root, \"outputs\")\n", |
| 60 | + "\n", |
| 61 | + "# Define the specific model name\n", |
| 62 | + "model_name = \"complex_river\"\n", |
| 63 | + "input_folder = os.path.join(input_folder, model_name)" |
| 64 | + ] |
| 65 | + }, |
| 66 | + { |
| 67 | + "cell_type": "markdown", |
| 68 | + "id": "25e9671b", |
| 69 | + "metadata": {}, |
| 70 | + "source": [ |
| 71 | + "## Reservoir simulation\n", |
| 72 | + "\n", |
| 73 | + "The operation of downstream reservoirs is influenced by the operations of those upstream. The `ReservoirManager` class orchestrates the simulation sequence, commencing with the most upstream reservoirs and progressing downstream. The subsequent code block demonstrates loading reservoir parameters from the previously defined CSV files and executing a simulation to generate time-series data of reservoir dynamics (e.g., water levels, flow, hydropower generation).\n", |
| 74 | + "\n", |
| 75 | + "Here, we initialize the `ReservoirManager`, load the reservoir characteristics and system topology from CSV files located in the `input_folder`, and then run the reservoir simulation based on the loaded data and predefined operational rules." |
| 76 | + ] |
| 77 | + }, |
| 78 | + { |
| 79 | + "cell_type": "code", |
| 80 | + "execution_count": null, |
| 81 | + "id": "49059702", |
| 82 | + "metadata": {}, |
| 83 | + "outputs": [], |
| 84 | + "source": [ |
| 85 | + "reservoir_manager = ReservoirManager()\n", |
| 86 | + "reservoir_manager.load_reservoirs_from_csv(input_folder)\n", |
| 87 | + "reservoir_manager.simulate()" |
| 88 | + ] |
| 89 | + }, |
| 90 | + { |
| 91 | + "cell_type": "markdown", |
| 92 | + "id": "4da626dd", |
| 93 | + "metadata": {}, |
| 94 | + "source": [ |
| 95 | + "After the simulation, we retrieve the simulated daily hydropower generation time series for all reservoirs as a pandas DataFrame. We then display the first 5 days of this data, rounded to the nearest whole number, for a quick review." |
| 96 | + ] |
| 97 | + }, |
| 98 | + { |
| 99 | + "cell_type": "code", |
| 100 | + "execution_count": null, |
| 101 | + "id": "ec2b2151", |
| 102 | + "metadata": {}, |
| 103 | + "outputs": [], |
| 104 | + "source": [ |
| 105 | + "hydropower_df = reservoir_manager.get_hydropower_ts()\n", |
| 106 | + "hydropower_df.round(0).head()" |
| 107 | + ] |
| 108 | + }, |
| 109 | + { |
| 110 | + "cell_type": "markdown", |
| 111 | + "id": "2b37cd6d", |
| 112 | + "metadata": {}, |
| 113 | + "source": [ |
| 114 | + "Finally, to visualize the results for a specific reservoir, we access the 'atay' reservoir object from the ReservoirManager and then generate and display a plot summarizing its state variables (e.g., water level, inflow, outflow, generation) over the simulation period. Of course, we can do this for the other three reservoirs as well." |
| 115 | + ] |
| 116 | + }, |
| 117 | + { |
| 118 | + "cell_type": "code", |
| 119 | + "execution_count": null, |
| 120 | + "id": "946be6d6", |
| 121 | + "metadata": {}, |
| 122 | + "outputs": [], |
| 123 | + "source": [ |
| 124 | + "atay_reservoir = reservoir_manager.reservoirs[\"atay\"]\n", |
| 125 | + "atay_reservoir.plot_state() # Include the output_folder argument if you want to save the plot" |
| 126 | + ] |
| 127 | + } |
| 128 | + ], |
| 129 | + "metadata": { |
| 130 | + "kernelspec": { |
| 131 | + "display_name": "pownet", |
| 132 | + "language": "python", |
| 133 | + "name": "python3" |
| 134 | + }, |
| 135 | + "language_info": { |
| 136 | + "codemirror_mode": { |
| 137 | + "name": "ipython", |
| 138 | + "version": 3 |
| 139 | + }, |
| 140 | + "file_extension": ".py", |
| 141 | + "mimetype": "text/x-python", |
| 142 | + "name": "python", |
| 143 | + "nbconvert_exporter": "python", |
| 144 | + "pygments_lexer": "ipython3", |
| 145 | + "version": "3.12.10" |
| 146 | + } |
| 147 | + }, |
| 148 | + "nbformat": 4, |
| 149 | + "nbformat_minor": 5 |
| 150 | +} |
0 commit comments