-
Notifications
You must be signed in to change notification settings - Fork 95
/
matpower_grids.py
82 lines (68 loc) · 2.42 KB
/
matpower_grids.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
import os
import pandas as pd
import multiprocessing as mp
import GridCalEngine as gce
folder = "/home/santi/matpower8.0b1/data"
def run_grid(fname):
"""
Run individual grid
:param fname: file name
:return: information about the run
"""
grid = gce.open_file(fname)
name = os.path.basename(fname)
if grid.get_bus_number() > 0:
res = gce.power_flow(
grid=grid,
options=gce.PowerFlowOptions(solver_type=gce.SolverType.NR,
retry_with_other_methods=False,
use_stored_guess=False)
)
flat_start = True
if not res.converged:
# if it does not converge, retry with the provided solution
res = gce.power_flow(
grid=grid,
options=gce.PowerFlowOptions(solver_type=gce.SolverType.NR,
retry_with_other_methods=False,
use_stored_guess=True)
)
flat_start = False
info = {
"name": name,
"n_buses": grid.get_bus_number(),
"n_branches": grid.get_branch_number(),
"P imbalance (%)": grid.get_imbalance() * 100.0,
"Flat start": flat_start,
"converged": res.converged,
"error (p.u.)": res.error,
"iterations": res.iterations,
"time (s)": res.elapsed,
}
else:
info = {
"name": name,
"n_buses": grid.get_bus_number(),
"n_branches": grid.get_branch_number(),
"P imbalance (%)": 0.0,
"Flat start": True,
"converged": True,
"error (p.u.)": 0,
"iterations": 0,
"time (s)": 0,
}
return info
# run this one to compile the stuff
# gce.power_flow(gce.open_file(os.path.join(folder, "/home/santi/matpower8.0b1/data/case5.m")))
gce.power_flow(gce.open_file(os.path.join(folder, "case_ieee30.m")))
data = list()
files_list = list()
for root, dirs, files in os.walk(folder):
for file in files:
if file.endswith(".m"):
path = os.path.join(root, file)
files_list.append(path)
with mp.Pool(mp.cpu_count()) as p:
data = p.map(run_grid, files_list)
df = pd.DataFrame(data).sort_values(by='n_buses', ascending=False)
df.to_excel("All matpower grids.xlsx", index=False)