{ "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-11-24 17:46:50\n", "ams:0.9.12\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": [ "Working directory: \"/Users/jinningwang/work/ams/examples\"\n", "Parsing input file \"/Users/jinningwang/work/miniconda3/envs/amsre/lib/python3.12/site-packages/ams/cases/ieee14/ieee14_uced.xlsx\"...\n", "Input file parsed in 0.0259 seconds.\n", "System set up in 0.0016 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, PFlow0, DCPF0\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": [ "Working directory: \"/Users/jinningwang/work/ams/examples\"\n", "Parsing input file \"/Users/jinningwang/work/miniconda3/envs/amsre/lib/python3.12/site-packages/ams/cases/ieee14/ieee14.json\"...\n", "Input file parsed in 0.0013 seconds.\n", "Zero line rates detacted in rate_c, adjusted to 999.\n", "System set up in 0.0018 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, PFlow0, DCPF0\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": [ "Working directory: \"/Users/jinningwang/work/ams/examples\"\n", "Parsing input file \"/Users/jinningwang/work/miniconda3/envs/amsre/lib/python3.12/site-packages/ams/cases/matpower/case14.m\"...\n", "CASE14 Power flow data for IEEE 14 bus test case.\n", "Input file parsed in 0.0028 seconds.\n", "Zero line rates detacted in rate_a, rate_b, rate_c, adjusted to 999.\n", "System set up in 0.0016 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, PFlow0, DCPF0\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": [ "Working directory: \"/Users/jinningwang/work/ams/examples\"\n", "Parsing input file \"/Users/jinningwang/work/miniconda3/envs/amsre/lib/python3.12/site-packages/ams/cases/ieee14/ieee14.raw\"...\n", " IEEE 14 BUS TEST CASE\n", " 03/06/14 CONTO 100.0 1962 W\n", "Input file parsed in 0.0047 seconds.\n", "Zero line rates detacted in rate_c, adjusted to 999.\n", "System set up in 0.0017 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, PFlow0, DCPF0\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": "amsre", "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.0" }, "orig_nbformat": 4 }, "nbformat": 4, "nbformat_minor": 2 }