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.

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-01-29 20:45:39
ams:0.8.1.post37.dev0+gf76a132
ams.config_logger(stream_level=20)

Import case and run simulation#

sp = ams.load(ams.get_case('5bus/pjm5bus_demo.xlsx'),
                  setup=True,
                  no_output=False,)
Parsing input file "/Users/jinningwang/Documents/work/ams/ams/cases/5bus/pjm5bus_demo.xlsx"...
Input file parsed in 0.1613 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.0020 seconds.
sp.DCOPF.run(solver='ECOS')
Routine <DCOPF> initialized in 0.0075 seconds.
DCOPF solved as optimal in 0.0092 seconds, converged after 9 iterations using solver ECOS.
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.

sp.report()
Report saved to "pjm5bus_demo_out.txt" in 0.0008 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.8.1.post37.dev0+gf76a132
Copyright (C) 2023-2024 Jinning Wang

AMS comes with ABSOLUTELY NO WARRANTY
Case file: /Users/jinningwang/Documents/work/ams/ams/cases/5bus/pjm5bus_demo.xlsx
Report time: 01/29/2024 08:45:40 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.0141
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

Export to CSV#

The dispatch simulation can also be exported to a CSV file.

sp.ED.run(solver='ECOS')
Routine <ED> initialized in 0.0167 seconds.
ED solved as optimal in 0.0222 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.008402 -0.014116 -0.005732 -0.007951 0.008662
1 EDT2 2.1 2.86 0.6 2.0 0.008755 -0.014395 -0.007696 -0.006855 0.009147
2 EDT3 2.1 2.53 0.6 2.0 0.009070 -0.014644 -0.009447 -0.005878 0.009580
3 EDT4 2.1 2.38 0.6 2.0 0.009214 -0.014757 -0.010243 -0.005434 0.009776
4 EDT5 2.1 2.30 0.6 2.0 0.009290 -0.014817 -0.010668 -0.005197 0.009881
5 EDT6 2.1 2.36 0.6 2.0 0.009232 -0.014772 -0.010350 -0.005375 0.009802

Cleanup#

Remove the output files.

os.remove('pjm5bus_demo_out.txt')
os.remove('pjm5bus_demo_ED.csv')