In [1]:
import os
In [15]:
from psst.case import read_matpower
import pandas as pd
from psst.model import build_model
mpc_files = []
root= './../../../matpower/'
for mpc in os.listdir(root):
if mpc.startswith('case') and mpc.endswith('.m'):
mpc_files.append(os.path.abspath(os.path.join(root, mpc)))
import getpass
USER = getpass.getuser()
In [16]:
mpc_files = [ '/Users/{}/Documents/GitRepos/matpower/case5.m'.format(USER),
'/Users/{}/Documents/GitRepos/matpower/case30.m'.format(USER),
'/Users/{}/Documents/GitRepos/matpower/case6ww.m'.format(USER),
'/Users/{}/Documents/GitRepos/matpower/case9.m'.format(USER),
'/Users/{}/Documents/GitRepos/matpower/case9target.m'.format(USER),
]
In [17]:
mpc_case = dict()
mpc_results = dict()
for mpc in mpc_files:
try:
case = read_matpower(mpc)
model = build_model(case)
model.solve(solver='xpress', verbose=False)
s1 = (model.results.angles / 2 / pd.np.pi * 360).T[0]
case_name = mpc.split('/')[-1].replace('.m', '')
mpc_case[case_name] = [v for v in model.results.power_generated.values[0]]
mpc_results[case_name] = dict()
mpc_results[case_name]['line_power'] = model.results.line_power.values
mpc_results[case_name]['angles'] = model.results.angles.values * 360 / 2 / pd.np.pi
except Exception as e:
print('Unable to solve {}\n{}'.format(mpc, e))
In [18]:
for k in mpc_case:
print(k)
mpc_case
In [19]:
from scipy.io import loadmat
In [20]:
matpower = loadmat('/Users/{}/Documents/GitRepos/matpower/results.mat'.format(USER))
In [21]:
def rmse(predictions, targets):
predictions = pd.DataFrame(predictions).T[0]
targets = pd.DataFrame(targets)[0]
return np.sqrt(((predictions - targets) ** 2).mean())
In [22]:
import numpy as np
In [23]:
print('case30', rmse(mpc_results['case30']['angles'], matpower['a30']))
print('case9', rmse(mpc_results['case9']['angles'], matpower['a9']))
print('case6ww', rmse(mpc_results['case6ww']['angles'], matpower['a6ww']))
print('case5', rmse(mpc_results['case5']['angles'], matpower['a5']))
print('case9target', rmse(mpc_results['case9target']['angles'], matpower['a9target']))
In [24]:
print('case30', rmse(mpc_results['case30']['line_power'], matpower['lp30']))
print('case9', rmse(mpc_results['case9']['line_power'], matpower['lp9']))
print('case6ww', rmse(mpc_results['case6ww']['line_power'], matpower['lp6ww']))
print('case5', rmse(mpc_results['case5']['line_power'], matpower['lp5']))
print('case9target', rmse(mpc_results['case9target']['line_power'], matpower['lp9target']))
In [ ]:
In [ ]:
In [ ]: