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 pandas as pd
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/work/miniconda3/envs/amsre/lib/python3.12/site-packages/ams/cases/5bus/pjm5bus_demo.xlsx"... Input file parsed in 0.0605 seconds. Zero line rates detacted in rate_b, rate_c, adjusted to 999. System set up in 0.0016 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.0071 seconds, converged in 8 iterations with CLARABEL. Report saved to "pjm5bus_demo_out.txt" in 0.0008 seconds.
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.0013 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 1.0.5 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: 04/10/2025 09:30:37 AM ========== System Statistics ========== Buses 5 Generators 5 Loads 3 Shunts 0 Lines 7 Transformers 0 Areas 3 Zones 2 ============================== DCOPF ============================== P (p.u.) Generation 10 Load 10 Bus DATA: Name vBus (p.u.) aBus (rad) pi ($/p.u.) 0 A 0 0.023989 0.077623 1 B 0 0.034668 0.01 2 C 0 0.013068 0.3 3 D 0 -0 0.15705 4 E 0 0.022896 0.091705 Line DATA: Name plf (p.u.) Line_1 Line AB -0.38001 Line_2 Line AD 0.78912 Line_3 Line AE 0.17089 Line_4 Line BC 2 Line_5 Line CD 0.43998 Line_6 Line DE -0.77089 Line_7 Line AB2 -0.38001 StaticGen DATA: Name pg (p.u.) pmaxe (p.u.) pmine (p.u.) PV_1 Alta 0.2 2.1 0.2 PV_3 Solitude 1.44 5.2 0.5 PV_5 Brighton 0.6 6 0.6 PV_2 PV 2 5.76 99 -99 Slack_4 Sundance 2 2 0.2
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.0129 seconds. <ED> solved as optimal in 0.0145 seconds, converged in 11 iterations with CLARABEL. Report saved to "pjm5bus_demo_out.txt" in 0.0024 seconds.
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 PV_2 | pg Slack_4 | vBus 0 | vBus 1 | vBus 2 | vBus 3 | |
---|---|---|---|---|---|---|---|---|---|---|
0 | EDT1 | 0.2 | 0.500000 | 0.6 | 4.829523 | 1.870477 | 0.0 | 0.0 | 0.0 | 0.0 |
1 | EDT2 | 0.2 | 0.937153 | 0.6 | 5.262847 | 2.000000 | 0.0 | 0.0 | 0.0 | 0.0 |
2 | EDT3 | 0.2 | 1.439984 | 0.6 | 5.760016 | 2.000000 | 0.0 | 0.0 | 0.0 | 0.0 |
3 | EDT4 | 0.2 | 0.937153 | 0.6 | 5.262847 | 2.000000 | 0.0 | 0.0 | 0.0 | 0.0 |
4 | EDT5 | 0.2 | 0.500000 | 0.6 | 4.829523 | 1.870477 | 0.0 | 0.0 | 0.0 | 0.0 |
Remove the output files.
os.remove('pjm5bus_demo_out.txt')
os.remove('pjm5bus_demo_ED.csv')