{ "cells": [ { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "__copyright__ = \"Reiner Lemoine Institut gGmbH\"\n", "__license__ = \"GNU Affero General Public License Version 3 (AGPL-3.0)\"\n", "__url__ = \"https://github.com/openego/eDisGo/blob/master/LICENSE\"\n", "__author__ = \"mltja\"" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "# eDisGo plot example with plotly" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Setup" ] }, { "cell_type": "markdown", "metadata": { "tags": [] }, "source": [ "### Import packages" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "tags": [] }, "outputs": [], "source": [ "import logging\n", "\n", "logging.basicConfig(level=logging.CRITICAL)" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "tags": [] }, "outputs": [], "source": [ "import copy\n", "import os\n", "import time\n", "\n", "import requests\n", "\n", "from edisgo import EDisGo\n", "from edisgo.tools.plots import plot_dash, plot_plotly" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Download example grid" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "tags": [] }, "outputs": [], "source": [ "def download_ding0_example_grid():\n", "\n", " # create directories to save ding0 example grid into\n", " ding0_example_grid_path = os.path.join(\n", " os.path.expanduser(\"~\"), \".edisgo\", \"ding0_test_network\"\n", " )\n", " os.makedirs(ding0_example_grid_path, exist_ok=True)\n", "\n", " # download files\n", " filenames = [\n", " \"buses\",\n", " \"generators\",\n", " \"lines\",\n", " \"loads\",\n", " \"network\",\n", " \"switches\",\n", " \"transformers\",\n", " \"transformers_hvmv\",\n", " ]\n", "\n", " for file in filenames:\n", " req = requests.get(\n", " f\"https://raw.githubusercontent.com/openego/eDisGo/dev/tests/data/ding0_test_network_1/{file}.csv\"\n", " )\n", " filename = os.path.join(ding0_example_grid_path, f\"{file}.csv\")\n", " with open(filename, \"wb\") as fout:\n", " fout.write(req.content)\n", "\n", "\n", "download_ding0_example_grid()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Create edisgo objects" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "tags": [] }, "outputs": [], "source": [ "ding0_grid = os.path.join(os.path.expanduser(\"~\"), \".edisgo\", \"ding0_test_network\")" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "tags": [] }, "outputs": [], "source": [ "edisgo_root = EDisGo(ding0_grid=ding0_grid)\n", "edisgo_root.set_time_series_worst_case_analysis()" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "tags": [] }, "outputs": [], "source": [ "edisgo_analyzed = copy.deepcopy(edisgo_root)\n", "edisgo_analyzed.analyze();" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "tags": [] }, "outputs": [], "source": [ "edisgo_reinforced = copy.deepcopy(edisgo_root)\n", "edisgo_reinforced.reinforce();" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Plots" ] }, { "cell_type": "markdown", "metadata": { "tags": [] }, "source": [ "### plot_plotly function" ] }, { "cell_type": "markdown", "metadata": { "tags": [] }, "source": [ "In the following different plotting options are shown. For more information on different plotting options see [API docstring](https://edisgo.readthedocs.io/en/dev/autoapi/edisgo/tools/plots/index.html#edisgo.tools.plots.plot_plotly).\n", "\n", "\n", "Hovering over nodes and lines shows some information on them." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "#### Plotting relative loading and voltage deviation, with map in the background. \n", "\n", "Be aware that the used grid is a test grid with random geolocations. To see the plotting on a map with a ding0 grid with actual geolocations you can change the downloaded grid in the function `download_ding0_example_grid` above to 'ding0_test_network_3' and import the grid as follows:\n", "\n", "```\n", "edisgo_root = EDisGo(ding0_grid=ding0_grid, legacy_ding0_grids=False)\n", "```" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "fig = plot_plotly(\n", " edisgo_obj=edisgo_analyzed,\n", " grid=None,\n", " line_color=\"relative_loading\",\n", " node_color=\"voltage_deviation\",\n", " line_result_selection=\"max\",\n", " node_result_selection=\"max\",\n", " selected_timesteps=None,\n", " pseudo_coordinates=False,\n", " plot_map=True,\n", " node_selection=False,\n", ")\n", "\n", "fig.show()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "#### Plotting relative loading and voltage deviation, with time step selection" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "plot_plotly(\n", " edisgo_obj=edisgo_analyzed,\n", " grid=None,\n", " line_color=\"relative_loading\",\n", " node_color=\"voltage_deviation\",\n", " line_result_selection=\"max\",\n", " node_result_selection=\"max\",\n", " selected_timesteps=[\n", " \"1970-01-01 00:00:00\",\n", " \"1970-01-01 01:00:00\",\n", " ],\n", " pseudo_coordinates=False,\n", " node_selection=False,\n", ")" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "#### Plotting loading and voltage deviation, with pseudo coordinates" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "plot_plotly(\n", " edisgo_obj=edisgo_analyzed,\n", " grid=None,\n", " line_color=\"loading\",\n", " node_color=\"voltage_deviation\",\n", " line_result_selection=\"max\",\n", " node_result_selection=\"max\",\n", " selected_timesteps=\"1970-01-01 03:00:00\",\n", " pseudo_coordinates=True,\n", " node_selection=False,\n", ")" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "#### Plotting reinforced lines, node adjacencies and a node selection" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "plot_plotly(\n", " edisgo_obj=edisgo_reinforced,\n", " grid=None,\n", " line_color=\"reinforce\",\n", " node_color=\"adjacencies\",\n", " line_result_selection=\"max\",\n", " node_result_selection=\"max\",\n", " selected_timesteps=None,\n", " pseudo_coordinates=False,\n", " node_selection=[\n", " \"Bus_MVStation_1\",\n", " \"Bus_BranchTee_MVGrid_1_5\",\n", " \"Bus_BranchTee_MVGrid_1_10\",\n", " \"Bus_GeneratorFluctuating_4\",\n", " \"Bus_BranchTee_MVGrid_1_11\",\n", " \"Bus_GeneratorFluctuating_3\",\n", " \"BusBar_MVGrid_1_LVGrid_4_MV\",\n", " ],\n", ")" ] }, { "cell_type": "markdown", "metadata": { "tags": [] }, "source": [ "### Dash plot app which calls plot_plotly\n", "One edisgo object creates one large plot. Two or more edisgo objects create two adjacent plots, where the objects to be plotted are selected in the dropdown menu." ] }, { "cell_type": "markdown", "metadata": { "tags": [] }, "source": [ "#### One interactive plot" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "plot_dash(edisgo_objects=edisgo_analyzed)\n", "time.sleep(2)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "#### Two interactives plots side by side" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "plot_dash(\n", " edisgo_objects={\n", " \"edisgo_analyzed\": edisgo_analyzed,\n", " \"edisgo_reinforced\": edisgo_reinforced,\n", " }\n", ")\n", "time.sleep(2)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "#### Two interactives plots side by side with 3 EDisGo objects\n", "\n", "Choose your edisgo objects in the drop down menu." ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "plot_dash(\n", " edisgo_objects={\n", " \"edisgo_root\": edisgo_root,\n", " \"edisgo_analyzed\": edisgo_analyzed,\n", " \"edisgo_reinforced\": edisgo_reinforced,\n", " },\n", " height=1000,\n", ")" ] } ], "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.16" }, "toc": { "base_numbering": 1, "nav_menu": {}, "number_sections": true, "sideBar": true, "skip_h1_title": false, "title_cell": "Table of Contents", "title_sidebar": "Contents", "toc_cell": false, "toc_position": {}, "toc_section_display": true, "toc_window_display": true } }, "nbformat": 4, "nbformat_minor": 4 }