diff --git a/doc/eTraGo_tutorial_release0.9.0.ipynb b/doc/eTraGo_tutorial_release0.9.0.ipynb new file mode 100644 index 00000000..bde00d78 --- /dev/null +++ b/doc/eTraGo_tutorial_release0.9.0.ipynb @@ -0,0 +1,469 @@ +{ + "cells": [ + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "\"HSF\"\n" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "\n", + "#
Abschlussworkshop eGon 2023
\n", + "\n", + "##
Session eTraGo: electric Transmission Grid optimization
\n" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "\n", + "# Agenda \n", + "\n", + "\n", + "* [Important links](#links)\n", + "* [Installation](#install)\n", + "* [General procedure](#general)\n", + "* [Use case: eGon2035 scenario optimization](#useCase)\n", + "* [Outputs](#outputs)\n" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "# Important links \n", + "\n", + "* __[eTraGo Source Code](https://github.com/openego/eTraGo)__\n", + "* __[eTraGo Documentation](http://etrago.readthedocs.io/)__\n" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "# Installation \n", + "The current eTraGo version and the python package jupyter are required to use this notebook. Install these with\n", + "\n", + "`pip install eTraGo`\n", + "\n", + "`pip install jupyterlab`" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "# General procedure\n", + "\n", + "1. Choose parameter settings (args) in appl.py.\n", + "2. Run appl.py or etrago(args).\n", + "3. Evaluate results.\n", + "\n", + "\n", + "# Use case: eGon2035 scenario optimization\n", + "\n", + "\n", + "## Minimal example\n", + "\n", + "1. Where and how much AC/DC network transmission capacity is required?\n", + "2. Optimal distribution of different storage technologies\n", + "3. System costs" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "tags": [] + }, + "outputs": [], + "source": [ + "%%capture\n", + "# enable jupyter interactive plotting\n", + "%matplotlib notebook\n", + "from ipywidgets import *\n", + "%matplotlib inline\n", + "\n", + "#import plotting function\n", + "from etrago.tools.plot import plot_carrier" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "tags": [] + }, + "source": [ + "### Import required general and eTraGo specific python packages" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "tags": [] + }, + "outputs": [], + "source": [ + "%%capture\n", + "import datetime\n", + "import os\n", + "import os.path\n", + "\n", + "import numpy as np\n", + "\n", + "__copyright__ = (\n", + " \"Flensburg University of Applied Sciences, \"\n", + " \"Europa-Universität Flensburg, Centre for Sustainable Energy Systems, \"\n", + " \"DLR-Institute for Networked Energy Systems\"\n", + ")\n", + "__license__ = \"GNU Affero General Public License Version 3 (AGPL-3.0)\"\n", + "__author__ = (\n", + " \"ulfmueller, lukasol, wolfbunke, mariusves, s3pp, ClaraBuettner, \"\n", + " \"CarlosEpia, KathiEsterl, fwitte, gnn, pieterhexen, AmeliaNadal\"\n", + ")\n", + "\n", + "if \"READTHEDOCS\" not in os.environ:\n", + " # Sphinx does not run this code.\n", + " # Do not import internal packages directly\n", + "\n", + " from etrago import Etrago\n" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "### Define parameters to run eTraGo" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "tags": [] + }, + "outputs": [], + "source": [ + "args = {\n", + " # Setup and Configuration:\n", + " \"db\": \"egon-data\", # database session\n", + " \"gridversion\": None, # None for model_draft or Version number\n", + " \"method\": { # Choose method and settings for optimization\n", + " \"type\": \"lopf\", # type of optimization, currently only 'lopf'\n", + " \"n_iter\": 1, # abort criterion of iterative optimization, 'n_iter' or 'threshold'\n", + " \"pyomo\": True, # set if pyomo is used for model building\n", + " },\n", + " \"pf_post_lopf\": {\n", + " \"active\": True, # choose if perform a pf after lopf\n", + " \"add_foreign_lopf\": True, # keep results of lopf for foreign DC-links\n", + " \"q_allocation\": \"p_nom\", # allocate reactive power via 'p_nom' or 'p'\n", + " },\n", + " \"start_snapshot\": 1,\n", + " \"end_snapshot\": 15,\n", + " \"solver\": \"gurobi\", # glpk, cplex or gurobi\n", + " \"solver_options\": {\n", + " \"BarConvTol\": 1.0e-5,\n", + " \"FeasibilityTol\": 1.0e-5,\n", + " \"method\": 2,\n", + " \"crossover\": 0,\n", + " \"logFile\": \"solver_etrago.log\",\n", + " \"threads\": 7,\n", + " },\n", + " \"model_formulation\": \"kirchhoff\", # angles or kirchhoff\n", + " \"scn_name\": \"eGon2035\", # scenario: eGon2035 or eGon100RE\n", + " # Scenario variations:\n", + " \"scn_extension\": None, # None or array of extension scenarios\n", + " \"scn_decommissioning\": None, # None or decommissioning scenario\n", + " # Export options:\n", + " \"lpfile\": False, # save pyomo's lp file: False or /path/to/lpfile.lp\n", + " \"csv_export\": \"results\", # save results as csv: False or /path/tofolder\n", + " # Settings:\n", + " \"extendable\": {\n", + " \"extendable_components\": [\n", + " \"as_in_db\"\n", + " ], # Array of components to optimize\n", + " \"upper_bounds_grid\": { # Set upper bounds for grid expansion\n", + " # lines in Germany\n", + " \"grid_max_D\": None, # relative to existing capacity\n", + " \"grid_max_abs_D\": { # absolute capacity per voltage level\n", + " \"380\": {\"i\": 1020, \"wires\": 4, \"circuits\": 4},\n", + " \"220\": {\"i\": 1020, \"wires\": 4, \"circuits\": 4},\n", + " \"110\": {\"i\": 1020, \"wires\": 4, \"circuits\": 2},\n", + " \"dc\": 0,\n", + " },\n", + " # border crossing lines\n", + " \"grid_max_foreign\": 4, # relative to existing capacity\n", + " \"grid_max_abs_foreign\": None, # absolute capacity per voltage level\n", + " },\n", + " },\n", + " \"generator_noise\": 789456, # apply generator noise, False or seed number\n", + " \"extra_functionality\": {}, # Choose function name or {}\n", + " # Spatial Complexity:\n", + " \"network_clustering_ehv\": False, # clustering of HV buses to EHV buses\n", + " \"network_clustering\": {\n", + " \"active\": True, # choose if clustering is activated\n", + " \"method\": \"kmedoids-dijkstra\", # choose clustering method: kmeans or kmedoids-dijkstra\n", + " \"n_clusters_AC\": 60, # total number of resulting AC nodes (DE+foreign)\n", + " \"cluster_foreign_AC\": False, # take foreign AC buses into account, True or False\n", + " \"method_gas\": \"kmedoids-dijkstra\", # choose clustering method: kmeans or kmedoids-dijkstra\n", + " \"n_clusters_gas\": 17, # total number of resulting CH4 nodes (DE+foreign)\n", + " \"cluster_foreign_gas\": False, # take foreign CH4 buses into account, True or False\n", + " \"k_elec_busmap\": False, # False or path/to/busmap.csv\n", + " \"k_gas_busmap\": False, # False or path/to/ch4_busmap.csv\n", + " \"bus_weight_tocsv\": None, # None or path/to/bus_weight.csv\n", + " \"bus_weight_fromcsv\": None, # None or path/to/bus_weight.csv\n", + " \"gas_weight_tocsv\": None, # None or path/to/gas_bus_weight.csv\n", + " \"gas_weight_fromcsv\": None, # None or path/to/gas_bus_weight.csv\n", + " \"line_length_factor\": 1, # Factor to multiply distance between new buses for new line lengths\n", + " \"remove_stubs\": False, # remove stubs bevore kmeans clustering\n", + " \"use_reduced_coordinates\": False, # If True, do not average cluster coordinates\n", + " \"random_state\": 42, # random state for replicability of clustering results\n", + " \"n_init\": 10, # affects clustering algorithm, only change when neccesary\n", + " \"max_iter\": 100, # affects clustering algorithm, only change when neccesary\n", + " \"tol\": 1e-6, # affects clustering algorithm, only change when neccesary\n", + " \"CPU_cores\": 7, # number of cores used during clustering, \"max\" for all cores available.\n", + " },\n", + " \"sector_coupled_clustering\": {\n", + " \"active\": True, # choose if clustering is activated\n", + " \"carrier_data\": { # select carriers affected by sector coupling\n", + " \"central_heat\": {\n", + " \"base\": [\"CH4\", \"AC\"],\n", + " \"strategy\": \"simultaneous\", # select strategy to cluster other sectors\n", + " },\n", + " },\n", + " },\n", + " \"disaggregation\": None, # None, 'mini' or 'uniform'\n", + " # Temporal Complexity:\n", + " \"snapshot_clustering\": {\n", + " \"active\": False, # choose if clustering is activated\n", + " \"method\": \"segmentation\", # 'typical_periods' or 'segmentation'\n", + " \"extreme_periods\": None, # consideration of extreme timesteps; e.g. 'append'\n", + " \"how\": \"daily\", # type of period - only relevant for 'typical_periods'\n", + " \"storage_constraints\": \"soc_constraints\", # additional constraints for storages - only relevant for 'typical_periods'\n", + " \"n_clusters\": 5, # number of periods - only relevant for 'typical_periods'\n", + " \"n_segments\": 5, # number of segments - only relevant for segmentation\n", + " },\n", + " \"skip_snapshots\": 5, # False or number of snapshots to skip\n", + " \"temporal_disaggregation\": {\n", + " \"active\": False, # choose if temporally full complex dispatch optimization should be conducted\n", + " \"no_slices\": 8, # number of subproblems optimization is divided into\n", + " },\n", + " # Simplifications:\n", + " \"branch_capacity_factor\": {\"HV\": 0.5, \"eHV\": 0.7}, # p.u. branch derating\n", + " \"load_shedding\": True, # meet the demand at value of loss load cost\n", + " \"foreign_lines\": {\n", + " \"carrier\": \"AC\", # 'DC' for modeling foreign lines as links\n", + " \"capacity\": \"osmTGmod\", # 'osmTGmod', 'tyndp2020', 'ntc_acer' or 'thermal_acer'\n", + " },\n", + " \"comments\": None,\n", + "}" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "### Import the network" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "tags": [] + }, + "outputs": [], + "source": [ + "#etrago = Etrago(args, json_path=None)\n", + "#etrago.build_network_from_db()\n", + "\n", + "etrago.network.buses.carrier.value_counts()" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "tags": [] + }, + "outputs": [], + "source": [ + "plot_carrier(etrago.network, carrier_links=[\"AC\", \"DC\"])" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "tags": [] + }, + "outputs": [], + "source": [ + "plot_carrier(etrago.network, carrier_links=[\"CH4\"], carrier_buses=[\"CH4\"])" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "tags": [] + }, + "source": [ + "### Cluster electrical network and attached technologies" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "tags": [] + }, + "outputs": [], + "source": [ + "%%capture\n", + "#etrago.adjust_network()\n", + "#etrago.spatial_clustering()\n", + "#etrago.spatial_clustering_gas()\n", + "etrago2 = Etrago(csv_folder_name = \"/home/carlos/Documents/Ego-n/etrago_presentation/before_lopf_60\")" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "tags": [] + }, + "outputs": [], + "source": [ + "plot_carrier(etrago2.network, carrier_links=[\"AC\", \"DC\"])" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "### Cluster gas network and attached technologies" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "tags": [] + }, + "outputs": [], + "source": [ + "plot_carrier(etrago2.network, carrier_links=[\"CH4\"], carrier_buses=[\"CH4\"])" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "### Reduce temporal complexity" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "tags": [] + }, + "outputs": [], + "source": [ + "etrago2.network.snapshots" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "tags": [] + }, + "outputs": [], + "source": [ + "etrago2.skip_snapshots()\n", + "etrago2.network.snapshots" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "### Run linear optimal power flow" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "etrago2.lopf()" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "### Results" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "tags": [] + }, + "outputs": [], + "source": [ + "etrago2.plot_grid(line_colors= \"expansion_abs\", bus_colors= \"storage_expansion\", bus_sizes= 0.000001)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "tags": [] + }, + "outputs": [], + "source": [ + "etrago2.calc_results()\n", + "etrago2.results" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [] + } + ], + "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.10.11" + } + }, + "nbformat": 4, + "nbformat_minor": 4 +}