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-11-24 17:47:25 ams:0.9.12
ams.config_logger(stream_level=20)
sp = ams.load(ams.get_case('5bus/pjm5bus_demo.xlsx'),
setup=True,
no_output=False,)
Working directory: "/Users/jinningwang/work/ams/examples" Parsing input file "/Users/jinningwang/work/miniconda3/envs/amsre/lib/python3.12/site-packages/ams/cases/5bus/pjm5bus_demo.xlsx"... Input file parsed in 0.0218 seconds. Zero line rates detacted in rate_b, rate_c, adjusted to 999. System set up in 0.0019 seconds.
sp.DCOPF.run(solver='CLARABEL')
Building system matrices Parsing OModel for <DCOPF> Evaluating OModel for <DCOPF> Finalizing OModel for <DCOPF> <DCOPF> initialized in 0.0081 seconds. <DCOPF> solved as optimal in 0.0064 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.0012 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.12 Copyright (C) 2023-2024 Jinning Wang AMS comes with ABSOLUTELY NO WARRANTY Case file: /Users/jinningwang/work/miniconda3/envs/amsre/lib/python3.12/site-packages/ams/cases/5bus/pjm5bus_demo.xlsx Report time: 11/24/2024 05:47:25 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.02086 Bus_2 B 0.001022 Bus_3 C 0.018174 Bus_4 D -0 Bus_5 E 0.020847 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')
Parsing OModel for <ED> Evaluating OModel for <ED> Finalizing OModel for <ED> <ED> initialized in 0.0281 seconds. <ED> solved as optimal in 0.0136 seconds, converged in 9 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')