#!/usr/bin/env python # coding: utf-8 # # 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. # In[1]: import os import ams import datetime import pandas as pd # In[2]: print("Last run time:", datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S")) print(f'ams:{ams.__version__}') # In[3]: ams.config_logger(stream_level=20) # ## Import case and run simulation # In[4]: sp = ams.load(ams.get_case('5bus/pjm5bus_demo.xlsx'), setup=True, no_output=False,) # In[5]: sp.DCOPF.run(solver='CLARABEL') # ## 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. # In[6]: sp.report() # The report is like: # In[7]: report_file = "pjm5bus_demo_out.txt" with open(report_file, 'r') as file: report_content = file.read() print(report_content) # ## Export to CSV # The dispatch simulation can also be exported to a CSV file. # In[8]: sp.ED.run(solver='CLARABEL') # In[9]: sp.ED.export_csv() # In[10]: df = pd.read_csv('pjm5bus_demo_ED.csv') # In the exported CSV file, each row represents a timeslot, and each column represents a variable. # In[11]: df.iloc[:, :10] # ## Cleanup # Remove the output files. # In[12]: os.remove('pjm5bus_demo_out.txt') os.remove('pjm5bus_demo_ED.csv')