-
Notifications
You must be signed in to change notification settings - Fork 0
/
scs_demo.py
135 lines (114 loc) · 3.74 KB
/
scs_demo.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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
import itertools
import random
from mosaik.util import connect_randomly, connect_many_to_one
import mosaik
sim_config = {
'CSV': {
'python': 'mosaik_csv:CSV',
},
'DB': {
'cmd': 'mosaik-hdf5 %(addr)s',
},
'HouseholdSim': {
'python': 'householdsim.mosaik:HouseholdSim',
# 'cmd': 'mosaik-householdsim %(addr)s',
},
'PyPower': {
'python': 'mosaik_pypower.mosaik:PyPower',
# 'cmd': 'mosaik-pypower %(addr)s',
},
'WebVis': {
'cmd': 'mosaik-web -s 0.0.0.0:8000 %(addr)s',
},
}
START = '2014-01-01 00:00:00'
END = 31 * 24 * 3600 # 1 day
PV_DATA = 'data/pv_10kw.csv'
PROFILE_FILE = 'data/profiles.data.gz'
GRID_NAME = 'demo_lv_grid'
GRID_FILE = 'data/%s.json' % GRID_NAME
def main():
random.seed(23)
world = mosaik.World(sim_config)
create_scenario(world)
world.run(until=END) # As fast as possilbe
# world.run(until=END, rt_factor=1/60) # Real-time 1min -> 1sec
def create_scenario(world):
# Start simulators
pypower = world.start('PyPower', step_size=15*60)
hhsim = world.start('HouseholdSim')
pvsim = world.start('CSV', sim_start=START, datafile=PV_DATA)
# Instantiate models
grid = pypower.Grid(gridfile=GRID_FILE).children
houses = hhsim.ResidentialLoads(sim_start=START,
profile_file=PROFILE_FILE,
grid_name=GRID_NAME).children
pvs = pvsim.PV.create(20)
# Connect entities
connect_buildings_to_grid(world, houses, grid)
connect_randomly(world, pvs, [e for e in grid if 'node' in e.eid], 'P')
# Database
db = world.start('DB', step_size=60, duration=END)
hdf5 = db.Database(filename='demo.hdf5')
connect_many_to_one(world, houses, hdf5, 'P_out')
connect_many_to_one(world, pvs, hdf5, 'P')
nodes = [e for e in grid if e.type in ('RefBus, PQBus')]
connect_many_to_one(world, nodes, hdf5, 'P', 'Q', 'Vl', 'Vm', 'Va')
branches = [e for e in grid if e.type in ('Transformer', 'Branch')]
connect_many_to_one(world, branches, hdf5,
'P_from', 'Q_from', 'P_to', 'P_from')
# Web visualization
webvis = world.start('WebVis', start_date=START, step_size=60)
webvis.set_config(ignore_types=['Topology', 'ResidentialLoads', 'Grid',
'Database'])
vis_topo = webvis.Topology()
connect_many_to_one(world, nodes, vis_topo, 'P', 'Vm')
webvis.set_etypes({
'RefBus': {
'cls': 'refbus',
'attr': 'P',
'unit': 'P [W]',
'default': 0,
'min': 0,
'max': 30000,
},
'PQBus': {
'cls': 'pqbus',
'attr': 'Vm',
'unit': 'U [V]',
'default': 230,
'min': 0.99 * 230,
'max': 1.01 * 230,
},
})
connect_many_to_one(world, houses, vis_topo, 'P_out')
webvis.set_etypes({
'House': {
'cls': 'load',
'attr': 'P_out',
'unit': 'P [W]',
'default': 0,
'min': 0,
'max': 3000,
},
})
connect_many_to_one(world, pvs, vis_topo, 'P')
webvis.set_etypes({
'PV': {
'cls': 'gen',
'attr': 'P',
'unit': 'P [W]',
'default': 0,
'min': -10000,
'max': 0,
},
})
def connect_buildings_to_grid(world, houses, grid):
buses = filter(lambda e: e.type == 'PQBus', grid)
buses = {b.eid.split('-')[1]: b for b in buses}
house_data = world.get_data(houses, 'node_id')
for house in houses:
node_id = house_data[house]['node_id']
world.connect(house, buses[node_id], ('P_out', 'P'))
if __name__ == '__main__':
main()