{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# Grid from text Examples\n", "\n", "This document gives instructions for combining the graph drawing tool on [https://csacademy.com/app/graph_editor/](https://csacademy.com/app/graph_editor/) with pgm-ds. Please note that the graph drawing tool is not linked to the power-grid-model project. This example solely illustrates how to use their editor to create a simple graph which can be loaded into power-grid-model-ds using a .txt file.\n", "\n", "## Creating input data for pgm-ds\n", "\n", "### Drawing a grid\n", "\n", "The graph editor on [https://csacademy.com/app/graph_editor/](https://csacademy.com/app/graph_editor/) is a very intuitive and easy to use tool for quickly drawing a grid.\n", "A graph can be created by defining `branches` between `nodes`.\n", "\n", "\"graph_editor\"\n", "\n", "If you follow a specific syntax, you can use the input from the\n", "graph editor to transfer your drawing to pgm-ds:\n", "\n", "- A _source node_ should be prefixed with `S`\n", " - e.g: `S1`, `S2`\n", "- A _line_ is defined as ` `\n", " - From nodes can be both regular nodes and source nodes\n", " - e.g.: `S1 2`, `3 4`\n", "- A _transformer_ is defined as ` transformer`\n", " - e.g.: `8 9 transformer`\n", "- A _grid opening_ is defined by adding `open`\n", " - e.g.: `4 5 open` for _lines_ or `6 7 transformer,open` for _transformers_\n", "\n", "### Loading a drawn grid into pgm-ds\n", "\n", "Once you've created a grid, copy the _Graph Data_ of your grid to a text file (e.g. `my_grid.txt`).\n", "\n", "For example, your file could contain the following data:\n", "\n", "```text\n", "S1 2\n", "S1 3 open\n", "2 7\n", "3 5\n", "3 6 transformer\n", "5 7\n", "7 8\n", "8 9\n", "```\n", "\n", "Then, using python's `pathlib` module, navigate to your file and load your grid\n" ] }, { "cell_type": "code", "execution_count": 1, "metadata": {}, "outputs": [], "source": [ "from pathlib import Path\n", "\n", "from power_grid_model_ds import Grid\n", "\n", "txt_file_path = Path(\"../../_static/my_grid.txt\")\n", "grid = Grid.from_txt_file(txt_file_path)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "**You should now have a grid loaded from your drawn graph data!**\n" ] }, { "cell_type": "code", "execution_count": 2, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "3 6 14,transformer\n", "S1 2 10\n", "S1 3 11,open\n", "2 7 12\n", "3 5 13\n", "5 7 15\n", "7 8 16\n", "8 9 17\n", "\n" ] } ], "source": [ "print(grid)" ] } ], "metadata": { "kernelspec": { "display_name": ".venv", "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.12.3" } }, "nbformat": 4, "nbformat_minor": 2 }