-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgmd_ts_results.py
92 lines (68 loc) · 2.19 KB
/
gmd_ts_results.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
#!/usr/bin/env python
# coding: utf-8
import json, gzip, os
from glob import glob
import numpy as np
import pandas as pd
#%%
os.getcwd()
#%%
with open("data/epri21_ots_gmd_opf_ts.json") as h:
output = json.load(h);
net = output['case']
result = output['result']
#%%
def merge_multinetwork_results(output, table_names=None):
networks = output['case']['nw']
solutions = output['result']['solution']['nw']
times = sorted([int(x) for x in networks.keys()])
n = len(times)
solved_networks = []
for t in times:
print(f'processing time {t}/{n}')
net = networks[f'{t}']
soln = solutions[f'{t}']
merge_results(net, soln, table_names=table_names)
solved_networks.append(net)
return solved_networks
#%%
def merge_results(output, table_names=None):
net = output['case']
soln = output['result']['solution']
return merge_results(net, soln, table_names=table_names)
#%%
def merge_results(net, soln, table_names=None):
if table_names is None:
table_names = 'bus branch gen dcline storage shunt load gmd_bus gmd_branch'.split()
for tname in table_names:
# print(f'Table {tname}')
for oid, obj in net[tname].items():
if tname not in soln:
continue
soln_obj = soln[tname][oid]
for fieldname, val in soln_obj.items():
if fieldname in obj:
soln_fieldname = fieldname + '_soln'
obj[soln_fieldname] = val
else:
obj[fieldname] = val
return net
#%%
tnames = 'bus branch gen dcline storage shunt load gmd_bus gmd_branch'.split()
#merge_results(result, solution, table_names=tnames)
solved = merge_multinetwork_results(output, table_names=tnames)
#%%
n = len(solved)
#%%
tables = {}
for tname in tnames:
tables[tname] = []
for i in range(n):
t = pd.DataFrame(list(solved[i][tname].values()))
tables[tname].append(t)
buses = tables['bus']
branches = tables['branch']
gens = tables['gen']
loads = tables['load']
gmd_buses = tables['gmd_bus']
gmd_branches = tables['gmd_branch']