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.
import os
import ams
import datetime
import pandas as pd
print("Last run time:", datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S"))
print(f'ams:{ams.__version__}')
Last run time: 2024-06-18 20:17:35 ams:0.9.8
ams.config_logger(stream_level=20)
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.0926 seconds. Zero line rates detacted in rate_b, rate_c, adjusted to 999. System set up in 0.0027 seconds.
sp.DCOPF.run(solver='CLARABEL')
<DCOPF> initialized in 0.0073 seconds. <DCOPF> solved as optimal in 0.0112 seconds, converged in 8 iterations with CLARABEL.
True
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.
sp.report()
Report saved to "pjm5bus_demo_out.txt" in 0.0011 seconds.
True
The report is like:
report_file = "pjm5bus_demo_out.txt"
with open(report_file, 'r') as file:
report_content = file.read()
print(report_content)
AMS 0.9.8 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: 06/18/2024 08:17:36 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
The dispatch simulation can also be exported to a CSV file.
sp.ED.run(solver='CLARABEL')
<ED> initialized in 0.0608 seconds. <ED> solved as optimal in 0.0182 seconds, converged in 10 iterations with CLARABEL.
True
sp.ED.export_csv()
'pjm5bus_demo_ED.csv'
df = pd.read_csv('pjm5bus_demo_ED.csv')
In the exported CSV file, each row represents a timeslot, and each column represents a variable.
df.iloc[:, :10]
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 |
Remove the output files.
os.remove('pjm5bus_demo_out.txt')
os.remove('pjm5bus_demo_ED.csv')