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-02-28 12:15:03 ams:0.9.0
ams.config_logger(stream_level=20)
sp = ams.load(ams.get_case('5bus/pjm5bus_demo.xlsx'),
setup=True,
no_output=False,)
Parsing input file "/home/jwang175/miniconda3/envs/amsre/lib/python3.9/site-packages/ams/cases/5bus/pjm5bus_demo.xlsx"... Input file parsed in 0.2256 seconds. Zero line rates detacted in rate_a, rate_b, rate_c, adjusted to 999. If expect a line outage, please set 'u' to 0. System set up in 0.0144 seconds.
sp.DCOPF.run(solver='ECOS')
Routine <DCOPF> initialized in 0.0266 seconds. DCOPF solved as optimal in 0.0259 seconds, converged after 9 iterations using solver ECOS.
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.0022 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.0 Copyright (C) 2023-2024 Jinning Wang AMS comes with ABSOLUTELY NO WARRANTY Case file: /home/jwang175/miniconda3/envs/amsre/lib/python3.9/site-packages/ams/cases/5bus/pjm5bus_demo.xlsx Report time: 02/28/2024 12:15:03 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) Bus_1 A 0.006759 Bus_2 B -0.013078 Bus_3 C 0.004073 Bus_4 D -0.014101 Bus_5 E 0.006747 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.) PV_1 Alta 2.1 PV_3 Solitude 5.2 PV_5 Brighton 0.7 Slack_4 Sundance 2
The dispatch simulation can also be exported to a CSV file.
sp.ED.run(solver='ECOS')
Routine <ED> initialized in 0.0541 seconds. ED solved as optimal in 0.0516 seconds, converged after 9 iterations using solver ECOS.
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 PV_1 | pg PV_3 | pg PV_5 | pg Slack_4 | aBus Bus_1 | aBus Bus_2 | aBus Bus_3 | aBus Bus_4 | aBus Bus_5 | |
---|---|---|---|---|---|---|---|---|---|---|
0 | EDT1 | 2.1 | 3.23 | 0.6 | 2.0 | 0.008403 | -0.014115 | -0.005731 | -0.007950 | 0.008663 |
1 | EDT2 | 2.1 | 2.86 | 0.6 | 2.0 | 0.008755 | -0.014395 | -0.007696 | -0.006856 | 0.009146 |
2 | EDT3 | 2.1 | 2.53 | 0.6 | 2.0 | 0.009069 | -0.014645 | -0.009448 | -0.005879 | 0.009578 |
3 | EDT4 | 2.1 | 2.38 | 0.6 | 2.0 | 0.009213 | -0.014758 | -0.010244 | -0.005435 | 0.009775 |
4 | EDT5 | 2.1 | 2.30 | 0.6 | 2.0 | 0.009290 | -0.014817 | -0.010667 | -0.005197 | 0.009881 |
5 | EDT6 | 2.1 | 2.36 | 0.6 | 2.0 | 0.009233 | -0.014772 | -0.010349 | -0.005375 | 0.009802 |
Remove the output files.
os.remove('pjm5bus_demo_out.txt')
os.remove('pjm5bus_demo_ED.csv')