{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# Inspecting Data\n", "\n", "This example shows how to inspect the data of a loaded test system." ] }, { "cell_type": "code", "execution_count": 1, "metadata": { "ExecuteTime": { "end_time": "2021-03-19T01:57:43.135158Z", "start_time": "2021-03-19T01:57:42.407900Z" } }, "outputs": [], "source": [ "import andes\n", "from andes.utils.paths import get_case\n", "\n", "andes.main.config_logger()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "To show all the rows and columns, change the pandas configuration with" ] }, { "cell_type": "code", "execution_count": 2, "metadata": { "ExecuteTime": { "end_time": "2021-03-19T01:57:43.381726Z", "start_time": "2021-03-19T01:57:43.140307Z" } }, "outputs": [], "source": [ "import pandas as pd\n", "\n", "pd.options.display.max_columns = None\n", "pd.options.display.max_rows = None" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Let's load the Kundur's system." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Load System from an ANDES XLSX File\n", "\n", "The ANDES xlsx file is the best supported format. Other formats can be converted to the xlsx format.\n", "\n", "See the link below for more about format conversion.\n", "https://github.com/cuihantao/andes/blob/master/README.md#format-converter" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "As previously shown, test cases can be loaded with ``andes.run()``:" ] }, { "cell_type": "code", "execution_count": 3, "metadata": { "ExecuteTime": { "end_time": "2021-03-19T01:57:43.965479Z", "start_time": "2021-03-19T01:57:43.383941Z" } }, "outputs": [ { "name": "stderr", "output_type": "stream", "text": [ "Working directory: \"/home/hcui7/repos/andes/examples\"\n", "Loaded config from file \"/home/hcui7/.andes/andes.rc\"\n", "Using generated Python code.\n", "Parsing input file \"/home/hcui7/repos/andes/andes/cases/kundur/kundur_full.xlsx\"...\n", "Input file parsed in 0.2894 seconds.\n", "System internal structure set up in 0.0295 seconds.\n", "-> System connectivity check results:\n", " No islanded bus detected.\n", " No islanded areas detected.\n", " Each island has a slack bus correctly defined and enabled.\n", "\n", "-> Power flow calculation\n", " Sparse solver: KLU\n", " Solution method: NR method\n", " Sparse addition: Fast in-place (kvxopt)\n", "Power flow initialized.\n", "0: |F(x)| = 14.9282832\n", "1: |F(x)| = 3.608627841\n", "2: |F(x)| = 0.1701107882\n", "3: |F(x)| = 0.002038626956\n", "4: |F(x)| = 3.745103977e-07\n", "Converged in 5 iterations in 0.0172 seconds.\n", "Report saved to \"kundur_full_out.txt\" in 0.0014 seconds.\n" ] }, { "name": "stdout", "output_type": "stream", "text": [ "-> Single process finished in 0.5743 seconds.\n" ] } ], "source": [ "ss = andes.run(get_case('kundur/kundur_full.xlsx'))" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Alternatively, one can load a test case _without setting up_ using `andes.load(..., setup=False)`. Note that `setup=False` option.\n", "It is useful to apply parameter changes to an existing test case." ] }, { "cell_type": "code", "execution_count": 4, "metadata": { "ExecuteTime": { "end_time": "2021-03-19T01:57:44.168248Z", "start_time": "2021-03-19T01:57:43.970545Z" } }, "outputs": [ { "name": "stderr", "output_type": "stream", "text": [ "Working directory: \"/home/hcui7/repos/andes/examples\"\n", "Loaded config from file \"/home/hcui7/.andes/andes.rc\"\n", "Using generated Python code.\n", "Parsing input file \"/home/hcui7/repos/andes/andes/cases/kundur/kundur_full.xlsx\"...\n", "Input file parsed in 0.1064 seconds.\n" ] } ], "source": [ "ss = andes.load(get_case('kundur/kundur_full.xlsx'), setup=False)" ] }, { "cell_type": "markdown", "metadata": { "ExecuteTime": { "end_time": "2021-03-18T00:25:32.261166Z", "start_time": "2021-03-18T00:25:32.256088Z" } }, "source": [ "For example, we can toggle the connectivity status `u` of `Line_1` to `0` using" ] }, { "cell_type": "code", "execution_count": 5, "metadata": { "ExecuteTime": { "end_time": "2021-03-19T01:57:44.176858Z", "start_time": "2021-03-19T01:57:44.173846Z" } }, "outputs": [], "source": [ "ss.Line.alter('u', 'Line_1', 0)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "When done, remember to set up the system before running calculation routines:" ] }, { "cell_type": "code", "execution_count": 6, "metadata": { "ExecuteTime": { "end_time": "2021-03-19T01:57:44.266523Z", "start_time": "2021-03-19T01:57:44.181450Z" } }, "outputs": [ { "name": "stderr", "output_type": "stream", "text": [ "System internal structure set up in 0.0308 seconds.\n", "-> System connectivity check results:\n", " No islanded bus detected.\n", " No islanded areas detected.\n", " Each island has a slack bus correctly defined and enabled.\n", "\n", "-> Power flow calculation\n", " Sparse solver: KLU\n", " Solution method: NR method\n", " Sparse addition: Fast in-place (kvxopt)\n", "Power flow initialized.\n", "0: |F(x)| = 14.9282832\n", "1: |F(x)| = 3.601770103\n", "2: |F(x)| = 0.1535494157\n", "3: |F(x)| = 0.001799769945\n", "4: |F(x)| = 3.667672734e-07\n", "Converged in 5 iterations in 0.0161 seconds.\n", "Report saved to \"kundur_full_out.txt\" in 0.0031 seconds.\n" ] }, { "data": { "text/plain": [ "True" ] }, "execution_count": 6, "metadata": {}, "output_type": "execute_result" } ], "source": [ "ss.setup()\n", "\n", "ss.PFlow.run()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "After setting up the system, adding or removing devices are not yet allowed." ] }, { "cell_type": "markdown", "metadata": { "ExecuteTime": { "end_time": "2021-03-18T00:28:42.135119Z", "start_time": "2021-03-18T00:28:42.128972Z" } }, "source": [ "## Load System from PSS/E RAW and DYR Files\n", "\n", "ANDES supports loading systems from PSS/E RAW and DYR files.\n", "\n", "The PSS/E v32 raw format is best supported.\n", "\n", "Note that this feature is experimental. We try out best to support this format, but the compatibility is not guaranteed." ] }, { "cell_type": "code", "execution_count": 7, "metadata": { "ExecuteTime": { "end_time": "2021-03-19T01:57:44.274794Z", "start_time": "2021-03-19T01:57:44.271077Z" } }, "outputs": [], "source": [ "raw_path = get_case('kundur/kundur.raw')\n", "dyr_path = get_case('kundur/kundur_full.dyr')" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "The raw file is passed to the positional argument, whereas the dyr file is passed to `addfile`." ] }, { "cell_type": "code", "execution_count": 8, "metadata": { "ExecuteTime": { "end_time": "2021-03-19T01:57:44.606632Z", "start_time": "2021-03-19T01:57:44.277112Z" } }, "outputs": [ { "name": "stderr", "output_type": "stream", "text": [ "Working directory: \"/home/hcui7/repos/andes/examples\"\n", "Loaded config from file \"/home/hcui7/.andes/andes.rc\"\n", "Using generated Python code.\n", "Parsing input file \"/home/hcui7/repos/andes/andes/cases/kundur/kundur.raw\"...\n", " MODIFIED KUNDUR'S TWO-AREA TEST SYSTEM, DISTRIBUTED WITH ANDES\n", " SEE THE BOOK \"POWER SYSTEM STABILITY AND CONTROL\" FOR ORIGINAL DATA\n", "Input file parsed in 0.0046 seconds.\n", "Parsing additional file \"/home/hcui7/repos/andes/andes/cases/kundur/kundur_full.dyr\"...\n", "Addfile parsed in 0.1473 seconds.\n", "System internal structure set up in 0.0283 seconds.\n", "-> System connectivity check results:\n", " No islanded bus detected.\n", " No islanded areas detected.\n", " Each island has a slack bus correctly defined and enabled.\n", "\n", "-> Power flow calculation\n", " Sparse solver: KLU\n", " Solution method: NR method\n", " Sparse addition: Fast in-place (kvxopt)\n", "Power flow initialized.\n", "0: |F(x)| = 3.175850023\n", "1: |F(x)| = 3.176155228e-08\n", "Converged in 2 iterations in 0.0067 seconds.\n", "Report saved to \"kundur_out.txt\" in 0.0038 seconds.\n" ] }, { "name": "stdout", "output_type": "stream", "text": [ "-> Single process finished in 0.3241 seconds.\n" ] } ], "source": [ "ss = andes.run(raw_path, addfile=dyr_path)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Attributes for storing values" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Parameters are stored as attributes of the model. For example, `ss.GENROU.M`, the machine starting time constant (`2H`), is stored in `ss.GENROU.M`." ] }, { "cell_type": "code", "execution_count": 9, "metadata": { "ExecuteTime": { "end_time": "2021-03-19T01:57:44.618529Z", "start_time": "2021-03-19T01:57:44.611845Z" } }, "outputs": [ { "data": { "text/plain": [ "NumParam: GENROU.M, v=[117. 117. 111.15 111.15], vin=[13. 13. 12.35 12.35]" ] }, "execution_count": 9, "metadata": {}, "output_type": "execute_result" } ], "source": [ "ss.GENROU.M" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "It is an instance of `NumParam`, which contains fields `v` for the values after converting to system-base per unit values." ] }, { "cell_type": "code", "execution_count": 10, "metadata": { "ExecuteTime": { "end_time": "2021-03-19T01:57:44.629108Z", "start_time": "2021-03-19T01:57:44.623058Z" } }, "outputs": [ { "data": { "text/plain": [ "array([117. , 117. , 111.15, 111.15])" ] }, "execution_count": 10, "metadata": {}, "output_type": "execute_result" } ], "source": [ "ss.GENROU.M.v" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "And field `vin` is for the original input data." ] }, { "cell_type": "code", "execution_count": 11, "metadata": { "ExecuteTime": { "end_time": "2021-03-19T01:57:44.639730Z", "start_time": "2021-03-19T01:57:44.633864Z" } }, "outputs": [ { "data": { "text/plain": [ "array([13. , 13. , 12.35, 12.35])" ] }, "execution_count": 11, "metadata": {}, "output_type": "execute_result" } ], "source": [ "ss.GENROU.M.vin" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Tabulated view" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "ANDES provides tabulated **view** of model parameters by using DataFrame. Each model object has an attribute called `cache` for caching the parameter dataframes." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "The original parameters from the input file are stored in `cache.df_in` of the model object. For `GENROU`, do" ] }, { "cell_type": "code", "execution_count": 12, "metadata": { "ExecuteTime": { "end_time": "2021-03-19T01:57:44.681593Z", "start_time": "2021-03-19T01:57:44.644323Z" } }, "outputs": [ { "data": { "text/html": [ "
\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
idxunamebusgencoiSnVnfnDMraxlxd1kpkwS10S12gammapgammaqxdxqxd2xq1xq2Td10Td20Tq10Tq20
uid
0GENROU_11.0GENROU_111None900.020.060.00.013.000.00.060.30.00.00.00.01.01.01.81.70.250.550.258.00.030.40.05
1GENROU_21.0GENROU_222None900.020.060.00.013.000.00.060.30.00.00.00.01.01.01.81.70.250.550.258.00.030.40.05
2GENROU_31.0GENROU_333None900.020.060.00.012.350.00.060.30.00.00.00.01.01.01.81.70.250.550.258.00.030.40.05
3GENROU_41.0GENROU_444None900.020.060.00.012.350.00.060.30.00.00.00.01.01.01.81.70.250.550.258.00.030.40.05
\n", "
" ], "text/plain": [ " idx u name bus gen coi Sn Vn fn D M \\\n", "uid \n", "0 GENROU_1 1.0 GENROU_1 1 1 None 900.0 20.0 60.0 0.0 13.00 \n", "1 GENROU_2 1.0 GENROU_2 2 2 None 900.0 20.0 60.0 0.0 13.00 \n", "2 GENROU_3 1.0 GENROU_3 3 3 None 900.0 20.0 60.0 0.0 12.35 \n", "3 GENROU_4 1.0 GENROU_4 4 4 None 900.0 20.0 60.0 0.0 12.35 \n", "\n", " ra xl xd1 kp kw S10 S12 gammap gammaq xd xq xd2 xq1 \\\n", "uid \n", "0 0.0 0.06 0.3 0.0 0.0 0.0 0.0 1.0 1.0 1.8 1.7 0.25 0.55 \n", "1 0.0 0.06 0.3 0.0 0.0 0.0 0.0 1.0 1.0 1.8 1.7 0.25 0.55 \n", "2 0.0 0.06 0.3 0.0 0.0 0.0 0.0 1.0 1.0 1.8 1.7 0.25 0.55 \n", "3 0.0 0.06 0.3 0.0 0.0 0.0 0.0 1.0 1.0 1.8 1.7 0.25 0.55 \n", "\n", " xq2 Td10 Td20 Tq10 Tq20 \n", "uid \n", "0 0.25 8.0 0.03 0.4 0.05 \n", "1 0.25 8.0 0.03 0.4 0.05 \n", "2 0.25 8.0 0.03 0.4 0.05 \n", "3 0.25 8.0 0.03 0.4 0.05 " ] }, "execution_count": 12, "metadata": {}, "output_type": "execute_result" } ], "source": [ "ss.GENROU.cache.df_in" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Parameters will be **converted** to per-unit in the system base after loading. This process have been done if `andes.run` is used for loading the data file.\n", "\n", "To inspect the converted parameters, check the `cache.df` parameter." ] }, { "cell_type": "code", "execution_count": 13, "metadata": { "ExecuteTime": { "end_time": "2021-03-19T01:57:44.721712Z", "start_time": "2021-03-19T01:57:44.686492Z" }, "scrolled": true }, "outputs": [ { "data": { "text/html": [ "
\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
idxunamebusgencoiSnVnfnDMraxlxd1kpkwS10S12gammapgammaqxdxqxd2xq1xq2Td10Td20Tq10Tq20
uid
0GENROU_11.0GENROU_111None900.020.060.00.0117.000.00.0066670.0333330.00.00.00.01.01.00.20.1888890.0277780.0611110.0277788.00.030.40.05
1GENROU_21.0GENROU_222None900.020.060.00.0117.000.00.0066670.0333330.00.00.00.01.01.00.20.1888890.0277780.0611110.0277788.00.030.40.05
2GENROU_31.0GENROU_333None900.020.060.00.0111.150.00.0066670.0333330.00.00.00.01.01.00.20.1888890.0277780.0611110.0277788.00.030.40.05
3GENROU_41.0GENROU_444None900.020.060.00.0111.150.00.0066670.0333330.00.00.00.01.01.00.20.1888890.0277780.0611110.0277788.00.030.40.05
\n", "
" ], "text/plain": [ " idx u name bus gen coi Sn Vn fn D M \\\n", "uid \n", "0 GENROU_1 1.0 GENROU_1 1 1 None 900.0 20.0 60.0 0.0 117.00 \n", "1 GENROU_2 1.0 GENROU_2 2 2 None 900.0 20.0 60.0 0.0 117.00 \n", "2 GENROU_3 1.0 GENROU_3 3 3 None 900.0 20.0 60.0 0.0 111.15 \n", "3 GENROU_4 1.0 GENROU_4 4 4 None 900.0 20.0 60.0 0.0 111.15 \n", "\n", " ra xl xd1 kp kw S10 S12 gammap gammaq xd \\\n", "uid \n", "0 0.0 0.006667 0.033333 0.0 0.0 0.0 0.0 1.0 1.0 0.2 \n", "1 0.0 0.006667 0.033333 0.0 0.0 0.0 0.0 1.0 1.0 0.2 \n", "2 0.0 0.006667 0.033333 0.0 0.0 0.0 0.0 1.0 1.0 0.2 \n", "3 0.0 0.006667 0.033333 0.0 0.0 0.0 0.0 1.0 1.0 0.2 \n", "\n", " xq xd2 xq1 xq2 Td10 Td20 Tq10 Tq20 \n", "uid \n", "0 0.188889 0.027778 0.061111 0.027778 8.0 0.03 0.4 0.05 \n", "1 0.188889 0.027778 0.061111 0.027778 8.0 0.03 0.4 0.05 \n", "2 0.188889 0.027778 0.061111 0.027778 8.0 0.03 0.4 0.05 \n", "3 0.188889 0.027778 0.061111 0.027778 8.0 0.03 0.4 0.05 " ] }, "execution_count": 13, "metadata": {}, "output_type": "execute_result" } ], "source": [ "ss.GENROU.cache.df" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "One will notice the converted parameters such as `M`, `xl`, and all other impedances." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "**It is very important to notice that `cache.df` and `cache.df_in` are both views. Altering data in these views will NOT alter the underlying parameter values.**\n", "\n", "To alter values, see the example below." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Altering parameters" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Parameters can be altered by calling the `alter` method on a model instance. \n", "\n", "We first look up the original value through `get`. \n", "\n", "Either `v` or `vin` can be passed to argument `attr` to retrieve the converted or the original data. Here we are retrieving the original input data. If `attr` is not provided, `get` returns the value after per-unit conversion, which is the value used for calculation, by default. " ] }, { "cell_type": "code", "execution_count": 14, "metadata": { "ExecuteTime": { "end_time": "2021-03-19T01:57:44.732256Z", "start_time": "2021-03-19T01:57:44.726208Z" } }, "outputs": [ { "data": { "text/plain": [ "13.0" ] }, "execution_count": 14, "metadata": {}, "output_type": "execute_result" } ], "source": [ "ss.GENROU.get(\"M\", \"GENROU_1\", attr='vin')" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "To change the `M` of `GENROU_1` to `10`, do" ] }, { "cell_type": "code", "execution_count": 15, "metadata": { "ExecuteTime": { "end_time": "2021-03-19T01:57:44.740180Z", "start_time": "2021-03-19T01:57:44.736736Z" }, "pycharm": { "name": "#%%\n" } }, "outputs": [], "source": [ "ss.GENROU.alter(\"M\", \"GENROU_1\", 10)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "The value set through `alter` is always the data before per-unit conversion - just like it should have been in an input file. ANDES will perform the conversion and set `vin` and `v` correctly." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Parameters altered through `Model.alter()` can be saved as a new system using" ] }, { "cell_type": "code", "execution_count": 16, "metadata": { "ExecuteTime": { "end_time": "2021-03-19T01:57:46.442430Z", "start_time": "2021-03-19T01:57:44.741232Z" } }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "File \"new_system.xlsx\" already exist. Overwrite? [y/N]y\n" ] }, { "name": "stderr", "output_type": "stream", "text": [ "xlsx file written to \"new_system.xlsx\"\n" ] }, { "data": { "text/plain": [ "True" ] }, "execution_count": 16, "metadata": {}, "output_type": "execute_result" } ], "source": [ "andes.io.xlsx.write(ss, 'new_system.xlsx')" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Refreshing the view" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "As mentioned, `cache.df` and `cache.df_in` are *cached* views and will not be automatically updated for inspection.\n", "\n", "This is generally not an issue if one performs the simulation after altering data. However, if one needs to inspect the data again, `cache.refresh()` needs to be called manually.\n" ] }, { "cell_type": "code", "execution_count": 17, "metadata": { "ExecuteTime": { "end_time": "2021-03-19T01:57:46.458001Z", "start_time": "2021-03-19T01:57:46.447362Z" }, "pycharm": { "name": "#%%\n" } }, "outputs": [], "source": [ "ss.GENROU.cache.refresh()" ] }, { "cell_type": "code", "execution_count": 18, "metadata": { "ExecuteTime": { "end_time": "2021-03-19T01:57:46.492578Z", "start_time": "2021-03-19T01:57:46.462694Z" }, "pycharm": { "name": "#%%\n" } }, "outputs": [ { "data": { "text/html": [ "
\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
idxunamebusgencoiSnVnfnDMraxlxd1kpkwS10S12gammapgammaqxdxqxd2xq1xq2Td10Td20Tq10Tq20
uid
0GENROU_11.0GENROU_111None900.020.060.00.010.000.00.060.30.00.00.00.01.01.01.81.70.250.550.258.00.030.40.05
1GENROU_21.0GENROU_222None900.020.060.00.013.000.00.060.30.00.00.00.01.01.01.81.70.250.550.258.00.030.40.05
2GENROU_31.0GENROU_333None900.020.060.00.012.350.00.060.30.00.00.00.01.01.01.81.70.250.550.258.00.030.40.05
3GENROU_41.0GENROU_444None900.020.060.00.012.350.00.060.30.00.00.00.01.01.01.81.70.250.550.258.00.030.40.05
\n", "
" ], "text/plain": [ " idx u name bus gen coi Sn Vn fn D M \\\n", "uid \n", "0 GENROU_1 1.0 GENROU_1 1 1 None 900.0 20.0 60.0 0.0 10.00 \n", "1 GENROU_2 1.0 GENROU_2 2 2 None 900.0 20.0 60.0 0.0 13.00 \n", "2 GENROU_3 1.0 GENROU_3 3 3 None 900.0 20.0 60.0 0.0 12.35 \n", "3 GENROU_4 1.0 GENROU_4 4 4 None 900.0 20.0 60.0 0.0 12.35 \n", "\n", " ra xl xd1 kp kw S10 S12 gammap gammaq xd xq xd2 xq1 \\\n", "uid \n", "0 0.0 0.06 0.3 0.0 0.0 0.0 0.0 1.0 1.0 1.8 1.7 0.25 0.55 \n", "1 0.0 0.06 0.3 0.0 0.0 0.0 0.0 1.0 1.0 1.8 1.7 0.25 0.55 \n", "2 0.0 0.06 0.3 0.0 0.0 0.0 0.0 1.0 1.0 1.8 1.7 0.25 0.55 \n", "3 0.0 0.06 0.3 0.0 0.0 0.0 0.0 1.0 1.0 1.8 1.7 0.25 0.55 \n", "\n", " xq2 Td10 Td20 Tq10 Tq20 \n", "uid \n", "0 0.25 8.0 0.03 0.4 0.05 \n", "1 0.25 8.0 0.03 0.4 0.05 \n", "2 0.25 8.0 0.03 0.4 0.05 \n", "3 0.25 8.0 0.03 0.4 0.05 " ] }, "execution_count": 18, "metadata": {}, "output_type": "execute_result" } ], "source": [ "ss.GENROU.cache.df_in" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Variables" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Snapshots" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "One might also want to check the variable values in a similar way to that for a parameter. Certainly, a variable has a `v` attribute which stores values. \n", "\n", "**It is important to note that `v` only holds the values at the last program state.** Such program state could be the solution of power flow, the initialization of time-domain simulation, or the end of a simulation disturbances. " ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Since we have only ran power flow for ``ss``, ``ss.Bus.v.v`` are the voltage magnitude solutions, where the first `v` is for \"voltage\", and the second `v` is the first `v`'s value attribute." ] }, { "cell_type": "code", "execution_count": 19, "metadata": { "ExecuteTime": { "end_time": "2021-03-19T01:57:46.497826Z", "start_time": "2021-03-19T01:57:46.494209Z" } }, "outputs": [ { "data": { "text/plain": [ "array([1. , 1. , 1. , 1. , 0.98337472,\n", " 0.96908585, 0.9562181 , 0.95400018, 0.96856366, 0.98377143])" ] }, "execution_count": 19, "metadata": {}, "output_type": "execute_result" } ], "source": [ "ss.Bus.v.v" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Variables hold more than values. They have an attribute `a` for the addresses indexing into the corresponding type of array." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "There are two system-level arrays, `ss.dae.x` and `ss.dae.y` for the right-hand-side of the differential and algebraic equations, respectively. " ] }, { "cell_type": "code", "execution_count": 20, "metadata": { "ExecuteTime": { "end_time": "2021-03-19T01:57:46.502680Z", "start_time": "2021-03-19T01:57:46.499574Z" } }, "outputs": [ { "data": { "text/plain": [ "andes.core.var.Algeb" ] }, "execution_count": 20, "metadata": {}, "output_type": "execute_result" } ], "source": [ "type(ss.Bus.v)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "`ss.Bus.v` is an algebraic variable, thus `ss.Bus.v.a` holds the indices into ``ss.dae.g``." ] }, { "cell_type": "code", "execution_count": 21, "metadata": { "ExecuteTime": { "end_time": "2021-03-19T01:57:46.508151Z", "start_time": "2021-03-19T01:57:46.504486Z" } }, "outputs": [ { "data": { "text/plain": [ "array([1. , 1. , 1. , 1. , 0.98337472,\n", " 0.96908585, 0.9562181 , 0.95400018, 0.96856366, 0.98377143])" ] }, "execution_count": 21, "metadata": {}, "output_type": "execute_result" } ], "source": [ "ss.dae.y[ss.Bus.v.a]" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "We can see that these two values are the same." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Time series" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "After a time-domain simulation, the time series of the variables can be retrieved through `ss.dae.ts`. Let's first run a simulation." ] }, { "cell_type": "code", "execution_count": 22, "metadata": { "ExecuteTime": { "end_time": "2021-03-19T01:57:48.088224Z", "start_time": "2021-03-19T01:57:46.510076Z" } }, "outputs": [ { "name": "stderr", "output_type": "stream", "text": [ "\n", "-> Time Domain Simulation Summary:\n", "Sparse Solver: KLU\n", "Simulation time: 0-20.0 s.\n", "Fixed step size: h=33.33 ms. Shrink if not converged.\n", "Suspect initialization issue! Simulation may crash!\n", "\n", " Name | Var. Value | Eqn. Mismatch\n", "----------------+------------+--------------\n", " delta GENROU 1 | 2.840 | 753.982 \n", " delta GENROU 2 | 2.248 | 753.982 \n", " delta GENROU 3 | 1.878 | 753.982 \n", " delta GENROU 4 | 2.423 | 753.982 \n", " a Bus 1 | 0.570 | -21.804 \n", " a Bus 2 | 0.378 | -21.000 \n", " a Bus 3 | 0.196 | -21.000 \n", " a Bus 4 | 0.378 | -21 \n", " v Bus 1 | 1.000 | -3.284 \n", " v Bus 2 | 1.000 | -6.841 \n", " v Bus 3 | 1.000 | -6.972 \n", " v Bus 4 | 1.000 | -3.183 \n", " vd GENROU 1 | 1.502 | -1.473 \n", " vd GENROU 2 | 1.357 | -0.804 \n", " vd GENROU 3 | 1.353 | -0.719 \n", " vd GENROU 4 | 1.481 | -1.182 \n", " vq GENROU 1 | 1.320 | -3.928 \n", " vq GENROU 2 | 1.469 | -3.527 \n", " vq GENROU 3 | 1.473 | -3.167 \n", " vq GENROU 4 | 1.344 | -3.602 \n", " tm GENROU 1 | 14.536 | -14.536 \n", " tm GENROU 2 | 14 | -14 \n", " tm GENROU 3 | 14.000 | -14.000 \n", " tm GENROU 4 | 14.000 | -14.000 \n", " te GENROU 1 | 14.536 | 29.072 \n", " te GENROU 2 | 14 | 28 \n", " te GENROU 3 | 14.000 | 28.000 \n", " te GENROU 4 | 14.000 | 28.000 \n", " vf GENROU 1 | 3.793 | -3.793 \n", " vf GENROU 2 | 4.039 | -4.039 \n", " vf GENROU 3 | 4.052 | -4.052 \n", " vf GENROU 4 | 3.703 | -3.703 \n", " wd TGOV1 1 | 0 | -1 \n", " wd TGOV1 2 | 0 | -1 \n", " wd TGOV1 3 | 0 | -1 \n", " wd TGOV1 4 | 0 | -1 \n", " vout EXDC2 1 | 3.793 | 3.793 \n", " vout EXDC2 2 | 4.039 | 4.039 \n", " vout EXDC2 3 | 4.052 | 4.052 \n", " vout EXDC2 4 | 3.703 | 3.703 \n", "\n", "\n", "Initialization for dynamics failed in 0.0418 seconds.\n" ] }, { "name": "stdout", "output_type": "stream", "text": [ " 0%| | 0/100 [00:01" ] }, "execution_count": 23, "metadata": {}, "output_type": "execute_result" } ], "source": [ "ss.dae.ts" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "`ss.dae.ts` has four commonly used attributes: `t` for time stamps, `xy` for variables (differential and then algebraic), `z` for discontinuous states, and `df` for the dataframe of all.\n", "\n", "- Each point in `ss.dae.ts.t` correspond to a row in `ss.dae.ts.xy`.\n", "- Each column in `ss.dae.ts.xy` correspond to a variable, whose name can be located in `ss.dae.xy_name`, for all timestamps.\n", "- `z` is not stored by default unless one enables it before simulation by setting `ss.TDS.config.store_z = 1`. \n", "- `df` is not built by default but can be manually triggered after simulation by calling `ss.dae.ts.unpack(df=True)`" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "The following are some statistics of the shapes of arrays:" ] }, { "cell_type": "code", "execution_count": 24, "metadata": { "ExecuteTime": { "end_time": "2021-03-19T01:57:48.107524Z", "start_time": "2021-03-19T01:57:48.103549Z" } }, "outputs": [ { "data": { "text/plain": [ "(0,)" ] }, "execution_count": 24, "metadata": {}, "output_type": "execute_result" } ], "source": [ "ss.dae.ts.t.shape" ] }, { "cell_type": "code", "execution_count": 25, "metadata": { "ExecuteTime": { "end_time": "2021-03-19T01:57:48.116573Z", "start_time": "2021-03-19T01:57:48.110379Z" } }, "outputs": [ { "data": { "text/plain": [ "(0, 0)" ] }, "execution_count": 25, "metadata": {}, "output_type": "execute_result" } ], "source": [ "ss.dae.ts.xy.shape" ] }, { "cell_type": "code", "execution_count": 26, "metadata": { "ExecuteTime": { "end_time": "2021-03-19T01:57:48.125081Z", "start_time": "2021-03-19T01:57:48.119155Z" } }, "outputs": [ { "data": { "text/plain": [ "192" ] }, "execution_count": 26, "metadata": {}, "output_type": "execute_result" } ], "source": [ "len(ss.dae.xy_name)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Cleanup" ] }, { "cell_type": "code", "execution_count": 27, "metadata": { "ExecuteTime": { "end_time": "2021-03-19T01:57:49.038948Z", "start_time": "2021-03-19T01:57:48.127782Z" } }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "\r\n", " _ _ | Version 1.3.4.post6.dev0+g1cc8c20\r\n", " /_\\ _ _ __| |___ ___ | Python 3.8.6 on Linux, 03/18/2021 09:57:48 PM\r\n", " / _ \\| ' \\/ _` / -_|_-< | \r\n", " /_/ \\_\\_||_\\__,_\\___/__/ | This program comes with ABSOLUTELY NO WARRANTY.\r\n", "\r\n", "\"/home/hcui7/repos/andes/examples/kundur_full_out.npz\" removed.\r\n", "\"/home/hcui7/repos/andes/examples/kundur_full_out.lst\" removed.\r\n", "\"/home/hcui7/repos/andes/examples/kundur_full_out.txt\" removed.\r\n", "\"/home/hcui7/repos/andes/examples/kundur_out.lst\" removed.\r\n", "\"/home/hcui7/repos/andes/examples/kundur_out.npz\" removed.\r\n", "\"/home/hcui7/repos/andes/examples/kundur_out.txt\" removed.\r\n" ] } ], "source": [ "!andes misc -C" ] } ], "metadata": { "kernelspec": { "display_name": "Python 3", "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.6" }, "pycharm": { "stem_cell": { "cell_type": "raw", "metadata": { "collapsed": false }, "source": [] } }, "varInspector": { "cols": { "lenName": 16, "lenType": 16, "lenVar": 40 }, "kernels_config": { "python": { "delete_cmd_postfix": "", "delete_cmd_prefix": "del ", "library": "var_list.py", "varRefreshCmd": "print(var_dic_list())" }, "r": { "delete_cmd_postfix": ") ", "delete_cmd_prefix": "rm(", "library": "var_list.r", "varRefreshCmd": "cat(var_dic_list()) " } }, "types_to_exclude": [ "module", "function", "builtin_function_or_method", "instance", "_Feature" ], "window_display": false } }, "nbformat": 4, "nbformat_minor": 4 }