diff --git a/notebooks/split_branch.ipynb b/notebooks/split_branch.ipynb new file mode 100644 index 0000000..c17e3e1 --- /dev/null +++ b/notebooks/split_branch.ipynb @@ -0,0 +1,272 @@ +{ + "cells": [ + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "# install octave\n", + "!sudo apt-get -qq update\n", + "!sudo apt-get -qq install octave octave-signal liboctave-dev\n", + "\n", + "# install oct2py that compatible with colab\n", + "import os\n", + "\n", + "from pkg_resources import get_distribution\n", + "\n", + "os.system(\n", + " f\"pip install -qq\"\n", + " f\" ipykernel=={get_distribution('ipykernel').version}\"\n", + " f\" ipython=={get_distribution('ipython').version}\"\n", + " f\" tornado=={get_distribution('tornado').version}\"\n", + " f\" oct2py\"\n", + ")\n", + "\n", + "# install packages\n", + "!pip install -qq matpower matpowercaseframes" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "# Impedance Refactor for Parallel Lines\n", + "\n", + "## Objective\n", + "To model a single impedance $ Z $ as $ N $ parallel lines in a power system data file.\n", + "\n", + "## Formula\n", + "\n", + "### Impedance\n", + "\n", + "For $ N $ parallel lines with equal impedance:\n", + "\n", + "$$\n", + "\\frac{1}{Z_{\\text{total}}} = \\frac{1}{Z_1} + \\frac{1}{Z_2} + \\dots + \\frac{1}{Z_n} = \\frac{N}{Z_1} \\quad \\Rightarrow \\quad Z_{\\text{total}} = \\frac{Z_1}{N}\n", + "$$\n", + "\n", + "To refactor the impedance for each line, multiply the original impedance $ Z $ by $ N $:\n", + "\n", + "$$\n", + "Z_n = Z \\times N\n", + "$$\n", + "\n", + "Where $ Z = R + jX $ (resistance and reactance).\n", + "\n", + "### Susceptance\n", + "\n", + "For $ N $ parallel lines with equal susceptance:\n", + "\n", + "$$\n", + "B_{\\text{total}} = B_1 + B_2 + \\dots + B_n = N \\times B_1\n", + "$$\n", + "\n", + "To refactor the susceptance for each line, divide the original susceptance $ B $ by $ N $:\n", + "\n", + "$$\n", + "B_{\\text{new}} = \\frac{B}{N}\n", + "$$\n", + "\n", + "### Rate\n", + "\n", + "For $ N $ parallel lines with equal rate $ C $:\n", + "\n", + "$$\n", + "C_{\\text{total}} = C_{1} + C_{2} + \\dots + C_{n} = N \\times C_1\n", + "$$\n", + "\n", + "To refactor the rate for each line, divide the original rate $ C $ by $ N $:\n", + "\n", + "$$\n", + "C_n = \\frac{C}{N}\n", + "$$\n", + "\n", + "Where $ C $ long term, short term and emergency rating in MVA.\n", + "\n", + "## Example\n", + "Original impedance $ Z = 0.01 + j0.02 $ with line capacity $ C = 75 $ and total line charging susceptance $ B = 0.15$ , splitted into three parallel lines $ N = 3 $:\n", + "\n", + "$$\n", + "Z_{\\text{new}} = Z \\times N = (0.01 + j0.02) \\times 3 = 0.03 + j0.06\n", + "$$\n", + "\n", + "$$\n", + "B_{\\text{new}} = B / N = 0.15 / 3 = 0.05\n", + "$$\n", + "\n", + "$$\n", + "C_{\\text{new}} = C / N = 75 / 3 = 25\n", + "$$\n", + "\n", + "We then have N row in branch data, with each using $ Z_{\\text{new}} $, $ B_{\\text{new}} $, and $ C_{\\text{new}} $." + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "import matpowercaseframes\n", + "import oct2py\n", + "\n", + "import matpower\n", + "\n", + "print(f\"matpowercaseframes version: {matpowercaseframes.__version__}\")\n", + "print(f\"oct2py version: {oct2py.__version__}\")\n", + "\n", + "print(f\"matpower version: {matpower.__version__}\")" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "import os\n", + "\n", + "import pandas as pd\n", + "from matpowercaseframes import CaseFrames\n", + "from matpowercaseframes.constants import COLUMNS\n", + "\n", + "from matpower import path_matpower, start_instance" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Inspect data" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "m = start_instance()" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "path = os.path.join(path_matpower, \"data/case9.m\")\n", + "cf = CaseFrames(path, load_case_engine=m)\n", + "cf.infer_numpy()\n", + "cf.branch" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Run base" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "mpc_org = cf.to_mpc()\n", + "sol = m.runpf(mpc_org, verbose=True)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "pd.DataFrame(sol[\"branch\"], columns=COLUMNS[\"branch\"][:17])" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Edit branch to became N parallel lines" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "N = 2\n", + "cf.branch = pd.concat([cf.branch] * N, ignore_index=True)\n", + "cf.branch.loc[:, [\"BR_R\", \"BR_X\"]] = cf.branch.loc[:, [\"BR_R\", \"BR_X\"]] * N\n", + "cf.branch.loc[:, [\"BR_B\", \"RATE_A\", \"RATE_B\", \"RATE_C\"]] = (\n", + " cf.branch.loc[:, [\"BR_B\", \"RATE_A\", \"RATE_B\", \"RATE_C\"]] / N\n", + ")\n", + "cf.branch" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "mpc_new = cf.to_mpc()\n", + "sol = m.runpf(mpc_new, verbose=True)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "pd.DataFrame(sol[\"branch\"], columns=COLUMNS[\"branch\"][:17])" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## TODO: Show the new branch resiliency when there is branch contingency N - 1" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [] + } + ], + "metadata": { + "kernelspec": { + "display_name": "env", + "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" + } + }, + "nbformat": 4, + "nbformat_minor": 2 +}