{ "cells": [ { "attachments": {}, "cell_type": "markdown", "metadata": {}, "source": [ "# Case I/O" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "AMS supprots multiple case formats." ] }, { "attachments": {}, "cell_type": "markdown", "metadata": {}, "source": [ "Still, first import the `ams` library and configure the logger level." ] }, { "cell_type": "code", "execution_count": 1, "metadata": {}, "outputs": [], "source": [ "import os\n", "\n", "import ams\n", "\n", "import datetime" ] }, { "cell_type": "code", "execution_count": 2, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Last run time: 2024-02-24 17:29:23\n", "ams:0.8.5.post62.dev0+gf6ed683\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": [ "## Input" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### AMS Execel" ] }, { "cell_type": "code", "execution_count": 4, "metadata": {}, "outputs": [ { "name": "stderr", "output_type": "stream", "text": [ "Parsing input file \"/Users/jinningwang/Documents/work/ams/ams/cases/ieee14/ieee14_uced.xlsx\"...\n", "Input file parsed in 0.1440 seconds.\n", "Zero line rates detacted in rate_a, rate_b, rate_c, adjusted to 999.\n", "If expect a line outage, please set 'u' to 0.\n", "System set up in 0.0043 seconds.\n", "-> Systen size:\n", "Base: 100 MVA; Frequency: 60 Hz\n", "14 Buses; 20 Lines; 5 Static Generators\n", "Active load: 2.24 p.u.; Reactive load: 0.95 p.u.\n", "-> Data check results:\n", "ACED: ACOPF\n", "DCED: DCOPF, ED, RTED\n", "DCUC: UC\n", "DED: DOPF\n", "PF: DCPF, PFlow, CPF\n" ] } ], "source": [ "sp_xlsx = ams.load(ams.get_case('ieee14/ieee14_uced.xlsx'),\n", " setup=True,\n", " no_output=True,)\n", "\n", "sp_xlsx.summary()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### AMS JSON" ] }, { "cell_type": "code", "execution_count": 5, "metadata": {}, "outputs": [ { "name": "stderr", "output_type": "stream", "text": [ "Parsing input file \"/Users/jinningwang/Documents/work/ams/ams/cases/ieee14/ieee14.json\"...\n", "Input file parsed in 0.0021 seconds.\n", "Zero line rates detacted in rate_a, rate_b, rate_c, adjusted to 999.\n", "If expect a line outage, please set 'u' to 0.\n" ] }, { "name": "stderr", "output_type": "stream", "text": [ "System set up in 0.0040 seconds.\n", "-> Systen size:\n", "Base: 100 MVA; Frequency: 60 Hz\n", "14 Buses; 20 Lines; 5 Static Generators\n", "Active load: 2.24 p.u.; Reactive load: 0.95 p.u.\n", "-> Data check results:\n", "PF: DCPF, PFlow, CPF\n" ] } ], "source": [ "sp_json = ams.load(ams.get_case('ieee14/ieee14.json'),\n", " setup=True,\n", " no_output=True,)\n", "\n", "sp_json.summary()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### MATPOWER" ] }, { "cell_type": "code", "execution_count": 6, "metadata": {}, "outputs": [ { "name": "stderr", "output_type": "stream", "text": [ "Parsing input file \"/Users/jinningwang/Documents/work/ams/ams/cases/matpower/case14.m\"...\n", "Input file parsed in 0.0071 seconds.\n", "Zero line rates detacted in rate_a, rate_b, rate_c, adjusted to 999.\n", "If expect a line outage, please set 'u' to 0.\n", "System set up in 0.0028 seconds.\n", "-> Systen size:\n", "Base: 100.0 MVA; Frequency: 60 Hz\n", "14 Buses; 20 Lines; 5 Static Generators\n", "Active load: 2.59 p.u.; Reactive load: 0.74 p.u.\n", "-> Data check results:\n", "ACED: ACOPF\n", "DCED: DCOPF\n", "DED: DOPF\n", "PF: DCPF, PFlow, CPF\n" ] } ], "source": [ "sp_mp = ams.load(ams.get_case('matpower/case14.m'),\n", " setup=True,\n", " no_output=True,)\n", "\n", "sp_mp.summary()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Note that AMS also supports PYPOWER format py-file." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### PSS/E RAW" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "AMS also supports PSS/E RAW format for power flow analysis." ] }, { "cell_type": "code", "execution_count": 7, "metadata": {}, "outputs": [ { "name": "stderr", "output_type": "stream", "text": [ "Parsing input file \"/Users/jinningwang/Documents/work/ams/ams/cases/ieee14/ieee14.raw\"...\n", "Input file parsed in 0.0102 seconds.\n", "Zero line rates detacted in rate_a, rate_b, rate_c, adjusted to 999.\n", "If expect a line outage, please set 'u' to 0.\n", "System set up in 0.0030 seconds.\n", "-> Systen size:\n", "Base: 100.0 MVA; Frequency: 60.0 Hz\n", "14 Buses; 20 Lines; 5 Static Generators\n", "Active load: 2.24 p.u.; Reactive load: 0.95 p.u.\n", "-> Data check results:\n", "PF: DCPF, PFlow, CPF\n" ] } ], "source": [ "sp_raw = ams.load(ams.get_case('ieee14/ieee14.raw'),\n", " setup=True,\n", " no_output=True,)\n", "\n", "sp_raw.summary()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Output" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Vice versa, AMS supports multiple output formats." ] }, { "cell_type": "code", "execution_count": 8, "metadata": {}, "outputs": [ { "name": "stderr", "output_type": "stream", "text": [ "xlsx file written to \"out.xlsx\"\n" ] }, { "data": { "text/plain": [ "True" ] }, "execution_count": 8, "metadata": {}, "output_type": "execute_result" } ], "source": [ "ams.io.xlsx.write(system=sp_xlsx,\n", " outfile='out.xlsx',)" ] }, { "cell_type": "code", "execution_count": 9, "metadata": {}, "outputs": [], "source": [ "os.remove('out.xlsx')" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Similarly, JSON output formats can be achieved by using `ams.io.json.write`." ] } ], "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 }