Output Simulation Results#
In AMS, the results can be output in different formats.
One is the plain-text format, where it lists all solved dispatch requests. Another is the CSV format, where the dispatch results are exported to a CSV file.
[1]:
import os
import ams
import datetime
import pandas as pd
[2]:
print("Last run time:", datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S"))
print(f'ams:{ams.__version__}')
Last run time: 2024-04-21 17:30:21
ams:0.9.6
[3]:
ams.config_logger(stream_level=20)
Import case and run simulation#
[4]:
sp = ams.load(ams.get_case('5bus/pjm5bus_demo.xlsx'),
setup=True,
no_output=False,)
Parsing input file "/Users/jinningwang/Documents/work/mambaforge/envs/amsre/lib/python3.9/site-packages/ams/cases/5bus/pjm5bus_demo.xlsx"...
Input file parsed in 0.0997 seconds.
Zero line rates detacted in rate_b, rate_c, adjusted to 999.
System set up in 0.0021 seconds.
[5]:
sp.DCOPF.run(solver='ECOS')
<DCOPF> initialized in 0.0089 seconds.
<DCOPF> solved as optimal in 0.0098 seconds, converged in 10 iterations with ECOS.
[5]:
True
Report to plain text#
Then, the system method report()
can generated a plain-text report of the simulation results.
If multiple simulation runs are performed, the report will contain all of them.
[6]:
sp.report()
Report saved to "pjm5bus_demo_out.txt" in 0.0050 seconds.
[6]:
True
The report is like:
[7]:
report_file = "pjm5bus_demo_out.txt"
with open(report_file, 'r') as file:
report_content = file.read()
print(report_content)
AMS 0.9.6
Copyright (C) 2023-2024 Jinning Wang
AMS comes with ABSOLUTELY NO WARRANTY
Case file: /Users/jinningwang/Documents/work/mambaforge/envs/amsre/lib/python3.9/site-packages/ams/cases/5bus/pjm5bus_demo.xlsx
Report time: 04/21/2024 05:30:21 PM
========== System Statistics ==========
Buses 5
Generators 4
Loads 3
Shunts 0
Lines 7
Transformers 0
Areas 3
Regions 2
============================== DCOPF ==============================
P (p.u.)
Generation 10
Load 10
Bus DATA:
Name aBus (rad) pi ($/p.u.)
Bus_1 A 0.02086 0.4
Bus_2 B 0.001022 0.4
Bus_3 C 0.018174 0.4
Bus_4 D -0 0.4
Bus_5 E 0.020847 0.4
Line DATA:
Name plf (p.u.)
Line_0 Line AB 0.70595
Line_1 Line AD 0.68617
Line_2 Line AE 0.001925
Line_3 Line BC -1.5881
Line_4 Line CD 0.61191
Line_5 Line DE -0.70193
Line_6 Line AB2 0.70595
StaticGen DATA:
Name pg (p.u.)
Slack_4 Sundance 2
PV_1 Alta 2.1
PV_3 Solitude 5.2
PV_5 Brighton 0.7
Export to CSV#
The dispatch simulation can also be exported to a CSV file.
[8]:
sp.ED.run(solver='ECOS')
<ED> initialized in 0.0187 seconds.
<ED> solved as optimal in 0.0216 seconds, converged in 11 iterations with ECOS.
[8]:
True
[9]:
sp.ED.export_csv()
[9]:
'pjm5bus_demo_ED.csv'
[10]:
df = pd.read_csv('pjm5bus_demo_ED.csv')
In the exported CSV file, each row represents a timeslot, and each column represents a variable.
[11]:
df.iloc[:, :10]
[11]:
Time | pg Slack_4 | pg PV_1 | pg PV_3 | pg PV_5 | aBus Bus_1 | aBus Bus_2 | aBus Bus_3 | aBus Bus_4 | aBus Bus_5 | |
---|---|---|---|---|---|---|---|---|---|---|
0 | EDT1 | 2.0 | 2.1 | 3.23 | 0.6 | 0.016353 | -0.006165 | 0.002219 | -0.0 | 0.016613 |
1 | EDT2 | 2.0 | 2.1 | 2.86 | 0.6 | 0.015611 | -0.007540 | -0.000840 | -0.0 | 0.016002 |
2 | EDT3 | 2.0 | 2.1 | 2.53 | 0.6 | 0.014948 | -0.008766 | -0.003569 | -0.0 | 0.015457 |
3 | EDT4 | 2.0 | 2.1 | 2.38 | 0.6 | 0.014647 | -0.009323 | -0.004809 | -0.0 | 0.015210 |
4 | EDT5 | 2.0 | 2.1 | 2.30 | 0.6 | 0.014487 | -0.009620 | -0.005471 | -0.0 | 0.015078 |
5 | EDT6 | 2.0 | 2.1 | 2.36 | 0.6 | 0.014607 | -0.009397 | -0.004975 | -0.0 | 0.015177 |
Cleanup#
Remove the output files.
[12]:
os.remove('pjm5bus_demo_out.txt')
os.remove('pjm5bus_demo_ED.csv')