{ "cells": [ { "attachments": {}, "cell_type": "markdown", "metadata": {}, "source": [ "# Output Simulation Results" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "In AMS, the results can be output in different formats.\n", "\n", "One is the plain-text format, where it lists all solved dispatch requests.\n", "Another is the CSV format, where the dispatch results are exported to a CSV file." ] }, { "cell_type": "code", "execution_count": 1, "metadata": {}, "outputs": [], "source": [ "import os\n", "\n", "import ams\n", "\n", "import datetime\n", "\n", "import pandas as pd" ] }, { "cell_type": "code", "execution_count": 2, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Last run time: 2024-06-18 20:17:35\n", "ams:0.9.8\n" ] } ], "source": [ "print(\"Last run time:\", datetime.datetime.now().strftime(\"%Y-%m-%d %H:%M:%S\"))\n", "\n", "print(f'ams:{ams.__version__}')" ] }, { "cell_type": "code", "execution_count": 3, "metadata": {}, "outputs": [], "source": [ "ams.config_logger(stream_level=20)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Import case and run simulation" ] }, { "cell_type": "code", "execution_count": 4, "metadata": {}, "outputs": [ { "name": "stderr", "output_type": "stream", "text": [ "Parsing input file \"/Users/jinningwang/Documents/work/mambaforge/envs/amsre/lib/python3.9/site-packages/ams/cases/5bus/pjm5bus_demo.xlsx\"...\n", "Input file parsed in 0.0926 seconds.\n", "Zero line rates detacted in rate_b, rate_c, adjusted to 999.\n", "System set up in 0.0027 seconds.\n" ] } ], "source": [ "sp = ams.load(ams.get_case('5bus/pjm5bus_demo.xlsx'),\n", " setup=True,\n", " no_output=False,)" ] }, { "cell_type": "code", "execution_count": 5, "metadata": {}, "outputs": [ { "name": "stderr", "output_type": "stream", "text": [ " initialized in 0.0073 seconds.\n", " solved as optimal in 0.0112 seconds, converged in 8 iterations with CLARABEL.\n" ] }, { "data": { "text/plain": [ "True" ] }, "execution_count": 5, "metadata": {}, "output_type": "execute_result" } ], "source": [ "sp.DCOPF.run(solver='CLARABEL')" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Report to plain text" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Then, the system method ``report()`` can generated a plain-text report of the simulation results.\n", "\n", "If multiple simulation runs are performed, the report will contain all of them." ] }, { "cell_type": "code", "execution_count": 6, "metadata": {}, "outputs": [ { "name": "stderr", "output_type": "stream", "text": [ "Report saved to \"pjm5bus_demo_out.txt\" in 0.0011 seconds.\n" ] }, { "data": { "text/plain": [ "True" ] }, "execution_count": 6, "metadata": {}, "output_type": "execute_result" } ], "source": [ "sp.report()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "The report is like:" ] }, { "cell_type": "code", "execution_count": 7, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "AMS 0.9.8\n", "Copyright (C) 2023-2024 Jinning Wang\n", "\n", "AMS comes with ABSOLUTELY NO WARRANTY\n", "Case file: /Users/jinningwang/Documents/work/mambaforge/envs/amsre/lib/python3.9/site-packages/ams/cases/5bus/pjm5bus_demo.xlsx\n", "Report time: 06/18/2024 08:17:36 PM\n", "\n", "\n", "========== System Statistics ==========\n", "Buses 5\n", "Generators 4\n", "Loads 3\n", "Shunts 0\n", "Lines 7\n", "Transformers 0\n", "Areas 3\n", "Regions 2\n", "\n", "============================== DCOPF ==============================\n", " P (p.u.)\n", "\n", "Generation 10\n", "Load 10\n", "\n", "Bus DATA:\n", " Name aBus (rad) pi ($/p.u.)\n", "\n", "Bus_1 A 0.02086 0.4\n", "Bus_2 B 0.001022 0.4\n", "Bus_3 C 0.018174 0.4\n", "Bus_4 D -0 0.4\n", "Bus_5 E 0.020847 0.4\n", "\n", "Line DATA:\n", " Name plf (p.u.)\n", "\n", "Line_0 Line AB 0.70595\n", "Line_1 Line AD 0.68617\n", "Line_2 Line AE 0.001925\n", "Line_3 Line BC -1.5881\n", "Line_4 Line CD 0.61191\n", "Line_5 Line DE -0.70193\n", "Line_6 Line AB2 0.70595\n", "\n", "StaticGen DATA:\n", " Name pg (p.u.)\n", "\n", "Slack_4 Sundance 2\n", "PV_1 Alta 2.1\n", "PV_3 Solitude 5.2\n", "PV_5 Brighton 0.7\n", "\n", "\n" ] } ], "source": [ "report_file = \"pjm5bus_demo_out.txt\"\n", "\n", "with open(report_file, 'r') as file:\n", " report_content = file.read()\n", "\n", "print(report_content)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Export to CSV" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "The dispatch simulation can also be exported to a CSV file." ] }, { "cell_type": "code", "execution_count": 8, "metadata": {}, "outputs": [ { "name": "stderr", "output_type": "stream", "text": [ " initialized in 0.0608 seconds.\n", " solved as optimal in 0.0182 seconds, converged in 10 iterations with CLARABEL.\n" ] }, { "data": { "text/plain": [ "True" ] }, "execution_count": 8, "metadata": {}, "output_type": "execute_result" } ], "source": [ "sp.ED.run(solver='CLARABEL')" ] }, { "cell_type": "code", "execution_count": 9, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "'pjm5bus_demo_ED.csv'" ] }, "execution_count": 9, "metadata": {}, "output_type": "execute_result" } ], "source": [ "sp.ED.export_csv()" ] }, { "cell_type": "code", "execution_count": 10, "metadata": {}, "outputs": [], "source": [ "df = pd.read_csv('pjm5bus_demo_ED.csv')" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "In the exported CSV file, each row represents a timeslot, and each column represents a variable." ] }, { "cell_type": "code", "execution_count": 11, "metadata": {}, "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", "
Timepg Slack_4pg PV_1pg PV_3pg PV_5aBus Bus_1aBus Bus_2aBus Bus_3aBus Bus_4aBus Bus_5
0EDT12.02.13.230.60.016353-0.0061650.002219-0.00.016613
1EDT22.02.12.860.60.015611-0.007540-0.000840-0.00.016002
2EDT32.02.12.530.60.014948-0.008766-0.003569-0.00.015457
3EDT42.02.12.380.60.014647-0.009323-0.004809-0.00.015210
4EDT52.02.12.300.60.014487-0.009620-0.005471-0.00.015078
5EDT62.02.12.360.60.014607-0.009397-0.004975-0.00.015177
\n", "
" ], "text/plain": [ " Time pg Slack_4 pg PV_1 pg PV_3 pg PV_5 aBus Bus_1 aBus Bus_2 \\\n", "0 EDT1 2.0 2.1 3.23 0.6 0.016353 -0.006165 \n", "1 EDT2 2.0 2.1 2.86 0.6 0.015611 -0.007540 \n", "2 EDT3 2.0 2.1 2.53 0.6 0.014948 -0.008766 \n", "3 EDT4 2.0 2.1 2.38 0.6 0.014647 -0.009323 \n", "4 EDT5 2.0 2.1 2.30 0.6 0.014487 -0.009620 \n", "5 EDT6 2.0 2.1 2.36 0.6 0.014607 -0.009397 \n", "\n", " aBus Bus_3 aBus Bus_4 aBus Bus_5 \n", "0 0.002219 -0.0 0.016613 \n", "1 -0.000840 -0.0 0.016002 \n", "2 -0.003569 -0.0 0.015457 \n", "3 -0.004809 -0.0 0.015210 \n", "4 -0.005471 -0.0 0.015078 \n", "5 -0.004975 -0.0 0.015177 " ] }, "execution_count": 11, "metadata": {}, "output_type": "execute_result" } ], "source": [ "df.iloc[:, :10]" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Cleanup" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Remove the output files." ] }, { "cell_type": "code", "execution_count": 12, "metadata": {}, "outputs": [], "source": [ "os.remove('pjm5bus_demo_out.txt')\n", "os.remove('pjm5bus_demo_ED.csv')" ] } ], "metadata": { "kernelspec": { "display_name": "ams", "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.9.18" }, "orig_nbformat": 4, "vscode": { "interpreter": { "hash": "d2b3bf80176349caa68dc4a3c77bd06eaade8abc678330f7d1c813c53380e5d2" } } }, "nbformat": 4, "nbformat_minor": 2 }