-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcap_comb.py
More file actions
220 lines (189 loc) · 7.31 KB
/
cap_comb.py
File metadata and controls
220 lines (189 loc) · 7.31 KB
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
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
from cap import pfa
from cap import viz
import simbench as sb
import pandas as pd
# for Dash import (might change Dash into a single function)
import dash # (version 1.12.0) pip install dash
import dash_core_components as dcc
import dash_html_components as html
from dash.dependencies import Input, Output
#import dash_bootstrap_components as dbc
import plotly.graph_objs as go
### Input Grid
'''
Input grid for developing code is sb_code1
sb_code2 is the larger grid to test the code
Initial values of the loads and generation are stored
Maximum voltage limits are relaxed for testing sample code since the limit gets violated for the test grid without adding any capacity
'''
sb_code1 = "1-MV-rural--1-sw" # rural MV grid of scenario 0 with full switchs
sb_code2 = "1-HVMV-urban-all-0-sw" # urban hv grid with one connected mv grid which has the subnet 2.202
net = sb.get_simbench_net(sb_code1)
net.bus.max_vm_pu = net.bus.max_vm_pu * 1.05
### Other parameters
ow = pfa.define_log(net, time_steps=range(96)) # For logging variables
## Get Map / PFA
'''
loadorgen: eg. 'load' , 'sgen'
prof: eg. 'L0-A' , 'WP4'
all_cap_map function takes lot of time to calculate capacities of an entire map. So they will be stored in an external file and read again in next section. Try using other inner functions to check if they work
Functions for finding maximum capacities
The all_cap_map function is max_cap looped for all busses so try below functions for quick results.
sing_res function is for checking individual case analysis
'''
net = pfa.resample_profiles_months(net, month=6)
#sgen_allcap=pfa.all_cap_map(net,ow=ow, loadorgen='sgen', ul_p=ul_p, ll_p=ll_p, prof='WP4')
# load_allcap=pfa.all_cap_map(net,ow=ow, loadorgen='load', ul_p=ul_p, ll_p=ll_p, prof='L0-A')
# One sample run is needed to initiate visualisation
pfa.sing_res(net,ow=ow,conn_at_bus=95, loadorgen='load',size_p=10,size_q=0.1, prof='L0-A')
# Uncomment for Mapbox scatter plot
#viz.cap_map_scatter(net)
## Visualisation
#Load data from all cap here. Calculated and stored earlier for saving time
net.bus['max_load']=pd.read_csv("sampdata/samp_load_allcap.csv")['max_add_cap']
net.bus['max_sgen'] = pd.read_csv("sampdata/samp_sgen_allcap.csv")['max_add_cap']
#####################################################################
######################################################################
# Following section requires executing any one timeseries case (to be used with pfa.sing_res later) above to generate the graph. (Already done)
# extract time-series values
networks_eng, figures_eng = viz.generate_graph_data_eng(net)
figures_gen = viz.generate_graph_data_gen(networks_eng, 40)
# take the correct order for slider
list_length = len(networks_eng) - 1
# activate Dash
app = dash.Dash(external_stylesheets=[dbc.themes.BOOTSTRAP])
# Dash component
controls = dbc.Card(
[
dbc.FormGroup(
[
dbc.Label("Step1: Input capacity"),
html.Br(),
dcc.Input(
id="capacity",
type="number",
placeholder="Enter a capacity (MW)",
),
]
),
dbc.FormGroup(
[
dbc.Label("Step2: Select location"),
dcc.Dropdown(
id="location",
placeholder="Select a location",
options=[
{"label": "Stockholm", "value": "col"},
{"label": "Uppsala", "value": "col2"},
{"label": "Öland", "value": "col3"},
],
value="sepal width (cm)",
),
]
),
dbc.FormGroup(
[
dbc.Label("Cluster count"),
dbc.Input(id="cluster-count", type="number", value=0),
]
),
dbc.FormGroup(
[
dbc.Label("Check the capacity in different time"),
dbc.Row(
[
dbc.Col(
dbc.Button("Summer", id="summer_button", active=True, color="success", className="mr-1"),
width={"size": 5},
),
dbc.Col(
dbc.Button("Winter", id="winter_button", color="primary", className="mr-1"),
width={"size": 5},
),
]
),
]
),
],
body=True,
)
# the enginner part of the graph
engineer_part = html.Div(
[
html.H1("Capacity Map with Dash component, for Time-series usage", style={'text-align': 'center'}),
html.Br(),
dcc.Graph(id='my_powerFlow_graph',
style={
"margin-left": "auto",
"margin-right": "auto",
},
figure={}),
html.Div(id='output_container_slider', children=[]),
html.Br(),
dcc.Slider(
id='my-slider',
min=0,
max=list_length,
step=1,
value=0,
),
]
)
# the place to set up layout
app.layout = dbc.Container(
[
html.H1("Capacity Map with Dash component, for general usage", style={'text-align': 'center'}),
html.Br(),
dbc.Row(
[
dbc.Col(controls, md=4, align="start"),
dbc.Col(dcc.Graph(id="cluster-graph", figure={}), md=8),
],
align="center",
),
# this is part is the engineer par
engineer_part,
],
# fluid=True,
)
# callback functions can be align with multiple callbacks
@app.callback(
Output("cluster-graph", "figure"),
[
Input("capacity", "value"),
Input("location", "value"),
#Input("cluster-count", "value"),
Input("summer_button", "n_clicks"),
Input("winter_button", "n_clicks"),
],
)
# Here insert the graph from pandapower, for beginner part
def change_graph_input(x, y, summer_click, winter_click):
container = "The year chosen by user was: {}".format(x)
container_slider = "The time interval chosen by user was: {}".format(y)
ctx = dash.callback_context
count = ctx.triggered[0]['prop_id'].split('.')[0]
if count == 'summer_button':
return figures_gen[0]
elif count == 'winter_button':
return figures_eng[1]
return figures_gen[0]
# From the following, the code is used for the second graph
# Connect the Plotly graphs with Dash Components, Fro expert part
@app.callback(
[Output(component_id='output_container_slider', component_property='children'),
Output(component_id='my_powerFlow_graph', component_property='figure')],
[
# Input(component_id='slct_year', component_property='value'),
Input(component_id='my-slider', component_property='value')
]
)
def update_graph(slider_slctd):
#container = "The year chosen by user was: {}".format(option_slctd)
container_slider = "The time interval chosen by user was: {}".format(slider_slctd)
fig_power = figures_eng[slider_slctd]
# 上面的output對應到這邊的return,是按照順序的
# The output is correspoding to the return value below, by order
return container_slider, fig_power
if __name__ == "__main__":
app.run_server(debug=False, port=3004)