Spaces:
Sleeping
Sleeping
Upload 4 files
Browse filesimplementing light model
- Input_Jahr_2021.xlsx +2 -2
- app.py +93 -45
- model_data.pkl +2 -2
- sourced.py +26 -27
Input_Jahr_2021.xlsx
CHANGED
@@ -1,3 +1,3 @@
|
|
1 |
version https://git-lfs.github.com/spec/v1
|
2 |
-
oid sha256:
|
3 |
-
size
|
|
|
1 |
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:127195ebc8ff48f366fb9a4c0d32a6e4c33a8bba916f4685523f6ef396374f73
|
3 |
+
size 1126639
|
app.py
CHANGED
@@ -30,21 +30,16 @@ col1.header("Data Input")
|
|
30 |
col4.header("Download Results")
|
31 |
|
32 |
# Color dictionary for figures
|
33 |
-
color_dict = {'
|
34 |
-
'Braunkohle': '
|
35 |
'Erdgas': 'grey',
|
36 |
'Steinkohle': 'darkgrey',
|
37 |
-
'Erdöl': '
|
38 |
-
'
|
39 |
-
'
|
40 |
-
'Nuclear': 'orange',
|
41 |
'PV': 'yellow',
|
42 |
'WindOff': 'darkblue',
|
43 |
-
'WindOn': '
|
44 |
-
'H2': 'crimson',
|
45 |
-
'Laufwasser': 'lightblue',
|
46 |
-
'Batteriespeicher': 'red',
|
47 |
-
'Electrolyzer': 'olive'}
|
48 |
|
49 |
# %%
|
50 |
with col1:
|
@@ -91,14 +86,15 @@ def timstep_aggregate(time_steps_aggregate, xr ):
|
|
91 |
t = sets_dict['t']
|
92 |
t_original = sets_dict['t']
|
93 |
i = sets_dict['i']
|
94 |
-
iSto = sets_dict['iSto']
|
95 |
iConv = sets_dict['iConv']
|
96 |
-
iPtG = sets_dict['iPtG']
|
97 |
iRes = sets_dict['iRes']
|
98 |
-
iHyRes = sets_dict['iHyRes']
|
99 |
|
100 |
# Unpack params_dict into the workspace
|
101 |
-
l_co2 = params_dict['l_co2']
|
|
|
102 |
p_co2 = params_dict['p_co2']
|
103 |
|
104 |
eff_i = params_dict['eff_i']
|
@@ -107,17 +103,17 @@ c_fuel_i = params_dict['c_fuel_i']
|
|
107 |
c_other_i = params_dict['c_other_i']
|
108 |
c_inv_i = params_dict['c_inv_i']
|
109 |
co2_factor_i = params_dict['co2_factor_i']
|
110 |
-
|
111 |
K_0_i = params_dict['K_0_i']
|
112 |
-
e2p_iSto = params_dict['e2p_iSto']
|
113 |
|
114 |
# Sliders and input boxes for parameters
|
115 |
with col2:
|
116 |
# Slider for CO2 limit [mio. t]
|
117 |
l_co2 = st.slider(value=int(params_dict['l_co2']), min_value=0, max_value=750, label="CO2 Limit [Mio. t]", step=10)
|
118 |
|
119 |
-
# Slider for H2 price / usevalue [€/MWH_th]
|
120 |
-
price_h2 = st.slider(value=100, min_value=0, max_value=300, label="Wasserstoffpreis [€/MWh]", step=10)
|
121 |
|
122 |
for i_idx in c_fuel_i.get_index('i'):
|
123 |
if i_idx in ['Braunkohle']:
|
@@ -131,13 +127,15 @@ with col3:
|
|
131 |
if i_idx in ['Steinkohle', 'Erdöl','Erdgas']:
|
132 |
c_fuel_i.loc[i_idx] = st.slider(value=int(c_fuel_i.loc[i_idx]), min_value=0, max_value=300, label=i_idx + ' Preis [€/MWh]' , step=10)
|
133 |
|
134 |
-
technologies_invest = st.multiselect(label='Technologien für Investitionen', options=i, default=['Braunkohle','Erdgas','Steinkohle','Erdöl','PV','WindOff','WindOn','
|
135 |
technologies_no_invest = [x for x in i if x not in technologies_invest]
|
136 |
|
137 |
# Aggregate time series
|
138 |
D_t = timstep_aggregate(dt,params_dict['D_t'])
|
|
|
|
|
139 |
s_t_r_iRes = timstep_aggregate(dt,params_dict['s_t_r_iRes'])
|
140 |
-
h_t = timstep_aggregate(dt,params_dict['h_t'])
|
141 |
t = D_t.get_index('t')
|
142 |
partial_year_factor = (8760/len(t))/dt
|
143 |
|
@@ -166,25 +164,27 @@ C_inv = m.add_variables(name = 'C_inv', lower = 0) # Investment costs
|
|
166 |
|
167 |
K = m.add_variables(coords = [i], name = 'K', lower = 0) # Endogenous capacity
|
168 |
y = m.add_variables(coords = [t,i], name = 'y', lower = 0) # Electricity production --> für Elektrolyseure ausschließen
|
169 |
-
y_ch = m.add_variables(coords = [t,i], name = 'y_ch', lower = 0) # Electricity consumption --> für alles außer Elektrolyseure und Speicher ausschließen
|
170 |
-
l = m.add_variables(coords = [t,i], name = 'l', lower = 0) # Storage filling level
|
171 |
-
w = m.add_variables(coords = [t], name = 'w', lower = 0)
|
172 |
-
y_curt = m.add_variables(coords = [t,i], name = 'y_curt', lower = 0)
|
173 |
-
y_h2 = m.add_variables(coords = [t,i], name = 'y_h2', lower = 0)
|
174 |
|
175 |
## Objective function
|
176 |
C_tot = C_op + C_inv
|
177 |
m.add_objective(C_tot)
|
178 |
|
179 |
## Costs terms for objective function
|
180 |
-
# Operational costs minus revenue for produced hydrogen
|
181 |
-
C_op_sum = m.add_constraints((y * c_fuel_i/eff_i).sum() * dt - (y_h2.sel(i = iPtG) * price_h2).sum() * dt == C_op, name = 'C_op_sum')
|
|
|
182 |
|
183 |
# Investment costs
|
184 |
C_inv_sum = m.add_constraints((K * c_inv_i).sum() == C_inv, name = 'C_inv_sum')
|
185 |
|
186 |
## Load serving
|
187 |
-
loadserve_t = m.add_constraints((((y ).sum(dims = 'i') - y_ch.sum(dims = 'i')) * dt == D_t.sel(t = t) * dt), name = 'load')
|
|
|
188 |
|
189 |
## Maximum capacity limit
|
190 |
maxcap_i_t = m.add_constraints((y - K <= K_0_i), name = 'max_cap')
|
@@ -193,34 +193,35 @@ maxcap_i_t = m.add_constraints((y - K <= K_0_i), name = 'max_cap')
|
|
193 |
maxcap_invest_i = m.add_constraints((K.sel(i = technologies_no_invest) <= 0), name = 'max_cap_invest')
|
194 |
|
195 |
## Prevent power production by PtG
|
196 |
-
no_power_prod_iPtG_t = m.add_constraints((y.sel(i = iPtG) <= 0), name = 'prevent_ptg_prod')
|
197 |
|
198 |
## Maximum storage charging and discharging
|
199 |
-
maxcha_iSto_t = m.add_constraints((y.sel(i = iSto) - y_ch.sel(i = iSto) - K.sel(i = iSto) <= K_0_i.sel(i = iSto)), name = 'max_cha')
|
200 |
|
201 |
## Maximum electrolyzer capacity
|
202 |
-
ptg_prod_iPtG_t = m.add_constraints((y_ch.sel(i = iPtG) - K.sel(i = iPtG) <= K_0_i.sel(i = iPtG)), name = 'max_cha_ptg')
|
203 |
|
204 |
## PtG H2 production
|
205 |
-
h2_prod_iPtG_t = m.add_constraints(y_ch.sel(i = iPtG) * eff_i.sel(i = iPtG) == y_h2.sel(i = iPtG), name = 'ptg_h2_prod')
|
206 |
|
207 |
## Infeed of renewables
|
208 |
infeed_iRes_t = m.add_constraints((y.sel(i = iRes) - s_t_r_iRes.sel(i = iRes).sel(t = t) * K.sel(i = iRes) + y_curt.sel(i = iRes) == s_t_r_iRes.sel(i = iRes).sel(t = t) * K_0_i.sel(i = iRes)), name = 'infeed')
|
209 |
|
210 |
## Maximum filling level restriction storage power plant
|
211 |
-
maxcapsto_iSto_t = m.add_constraints((l.sel(i = iSto) - K.sel(i = iSto) * e2p_iSto.sel(i = iSto) <= K_0_i.sel(i = iSto) * e2p_iSto.sel(i = iSto)), name = 'max_sto_filling')
|
212 |
|
213 |
## Filling level restriction hydro reservoir
|
214 |
-
filling_iHydro_t = m.add_constraints(l.sel(i = iHyRes) - l.sel(i = iHyRes).roll(t = -1) + y.sel(i = iHyRes) * dt == h_t.sel(t = t) * dt, name = 'filling_level_hydro')
|
215 |
|
216 |
## Filling level restriction other storages
|
217 |
-
filling_iSto_t = m.add_constraints(l.sel(i = iSto) - (l.sel(i = iSto).roll(t = -1) + (y.sel(i = iSto) / eff_i.sel(i = iSto)) * dt - y_ch.sel(i = iSto) * eff_i.sel(i = iSto) * dt) == 0, name = 'filling_level')
|
218 |
|
219 |
## CO2 limit
|
220 |
CO2_limit = m.add_constraints(((y / eff_i) * co2_factor_i * dt).sum() <= l_co2 * 1_000_000 , name = 'CO2_limit')
|
221 |
|
222 |
## set run-of-river power plants capacity limit to 5 GW
|
223 |
RoR_cap = m.add_constraints(K.sel(i = 'Laufwasser') <= 5000, name = 'RoR_cap')
|
|
|
224 |
|
225 |
|
226 |
# %%
|
@@ -346,23 +347,70 @@ with colb1:
|
|
346 |
fig
|
347 |
|
348 |
# %%
|
349 |
-
|
350 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
351 |
fig.update_traces(line=dict(width=0))
|
352 |
fig.for_each_trace(lambda trace: trace.update(fillcolor = trace.line.color))
|
353 |
-
|
|
|
|
|
354 |
with colb2:
|
355 |
-
fig
|
|
|
356 |
|
357 |
# %%
|
358 |
-
|
359 |
-
|
|
|
360 |
fig.update_traces(line=dict(width=0))
|
361 |
fig.for_each_trace(lambda trace: trace.update(fillcolor = trace.line.color))
|
362 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
363 |
with colb2:
|
364 |
fig
|
365 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
366 |
# %%
|
367 |
((m.solution['y'] / eff_i) * co2_factor_i * dt).sum()
|
368 |
# %%
|
@@ -388,7 +436,7 @@ def disaggregate_df(df):
|
|
388 |
#df_repeated = df.iloc[idx_repeat,:].reset_index(drop = True).drop('t', axis = 1)
|
389 |
df_t_all = pd.DataFrame({"t_all": t_original.to_series(), 't': t.repeat(dt)}).reset_index(drop=True)
|
390 |
|
391 |
-
|
392 |
df_output = df.merge(df_t_all,on = 't').drop('t',axis = 1).rename({'t_all':'t'}, axis = 1)
|
393 |
# last column to first column
|
394 |
cols = list(df_output.columns)
|
@@ -408,10 +456,10 @@ with pd.ExcelWriter(output, engine='xlsxwriter') as writer:
|
|
408 |
disaggregate_df(df_contr_marg).to_excel(writer, sheet_name='Deckungsbeiträge', index=False)
|
409 |
disaggregate_df(df_new_capacities).to_excel(writer, sheet_name='Kapazitäten', index=False)
|
410 |
disaggregate_df(df_production).to_excel(writer, sheet_name='Produktion', index=False)
|
411 |
-
disaggregate_df(df_charging).to_excel(writer, sheet_name='Ladevorgänge', index=False)
|
412 |
disaggregate_df(D_t.to_dataframe().reset_index()).to_excel(writer, sheet_name='Nachfrage', index=False)
|
413 |
disaggregate_df(df_curtailment).to_excel(writer, sheet_name='Abregelung', index=False)
|
414 |
-
disaggregate_df(df_h2_prod).to_excel(writer, sheet_name='H2 produktion', index=False)
|
415 |
|
416 |
with col4:
|
417 |
st.download_button(
|
|
|
30 |
col4.header("Download Results")
|
31 |
|
32 |
# Color dictionary for figures
|
33 |
+
color_dict = {'Biomasse': 'lightgreen',
|
34 |
+
'Braunkohle': 'red',
|
35 |
'Erdgas': 'grey',
|
36 |
'Steinkohle': 'darkgrey',
|
37 |
+
'Erdöl': 'brown',
|
38 |
+
'Laufwasser': 'aquamarine',
|
39 |
+
'Kernenergie': 'orange',
|
|
|
40 |
'PV': 'yellow',
|
41 |
'WindOff': 'darkblue',
|
42 |
+
'WindOn': 'blue'}
|
|
|
|
|
|
|
|
|
43 |
|
44 |
# %%
|
45 |
with col1:
|
|
|
86 |
t = sets_dict['t']
|
87 |
t_original = sets_dict['t']
|
88 |
i = sets_dict['i']
|
89 |
+
# iSto = sets_dict['iSto']
|
90 |
iConv = sets_dict['iConv']
|
91 |
+
# iPtG = sets_dict['iPtG']
|
92 |
iRes = sets_dict['iRes']
|
93 |
+
# iHyRes = sets_dict['iHyRes']
|
94 |
|
95 |
# Unpack params_dict into the workspace
|
96 |
+
# l_co2 = params_dict['l_co2']
|
97 |
+
l_co2 = 90
|
98 |
p_co2 = params_dict['p_co2']
|
99 |
|
100 |
eff_i = params_dict['eff_i']
|
|
|
103 |
c_other_i = params_dict['c_other_i']
|
104 |
c_inv_i = params_dict['c_inv_i']
|
105 |
co2_factor_i = params_dict['co2_factor_i']
|
106 |
+
c_var_i = params_dict['c_var_i']
|
107 |
K_0_i = params_dict['K_0_i']
|
108 |
+
# e2p_iSto = params_dict['e2p_iSto']
|
109 |
|
110 |
# Sliders and input boxes for parameters
|
111 |
with col2:
|
112 |
# Slider for CO2 limit [mio. t]
|
113 |
l_co2 = st.slider(value=int(params_dict['l_co2']), min_value=0, max_value=750, label="CO2 Limit [Mio. t]", step=10)
|
114 |
|
115 |
+
# # Slider for H2 price / usevalue [€/MWH_th]
|
116 |
+
# price_h2 = st.slider(value=100, min_value=0, max_value=300, label="Wasserstoffpreis [€/MWh]", step=10)
|
117 |
|
118 |
for i_idx in c_fuel_i.get_index('i'):
|
119 |
if i_idx in ['Braunkohle']:
|
|
|
127 |
if i_idx in ['Steinkohle', 'Erdöl','Erdgas']:
|
128 |
c_fuel_i.loc[i_idx] = st.slider(value=int(c_fuel_i.loc[i_idx]), min_value=0, max_value=300, label=i_idx + ' Preis [€/MWh]' , step=10)
|
129 |
|
130 |
+
technologies_invest = st.multiselect(label='Technologien für Investitionen', options=i, default=['Braunkohle','Erdgas','Steinkohle','Erdöl','PV','WindOff','WindOn','Laufwasser','Kernenergie','Biomasse'])
|
131 |
technologies_no_invest = [x for x in i if x not in technologies_invest]
|
132 |
|
133 |
# Aggregate time series
|
134 |
D_t = timstep_aggregate(dt,params_dict['D_t'])
|
135 |
+
# D_t sorted descending
|
136 |
+
D_t_sorted = D_t.sortby(D_t, ascending = False)
|
137 |
s_t_r_iRes = timstep_aggregate(dt,params_dict['s_t_r_iRes'])
|
138 |
+
# h_t = timstep_aggregate(dt,params_dict['h_t'])
|
139 |
t = D_t.get_index('t')
|
140 |
partial_year_factor = (8760/len(t))/dt
|
141 |
|
|
|
164 |
|
165 |
K = m.add_variables(coords = [i], name = 'K', lower = 0) # Endogenous capacity
|
166 |
y = m.add_variables(coords = [t,i], name = 'y', lower = 0) # Electricity production --> für Elektrolyseure ausschließen
|
167 |
+
# y_ch = m.add_variables(coords = [t,i], name = 'y_ch', lower = 0) # Electricity consumption --> für alles außer Elektrolyseure und Speicher ausschließen
|
168 |
+
# l = m.add_variables(coords = [t,i], name = 'l', lower = 0) # Storage filling level
|
169 |
+
w = m.add_variables(coords = [t], name = 'w', lower = 0)
|
170 |
+
y_curt = m.add_variables(coords = [t,i], name = 'y_curt', lower = 0) # RES curtailment
|
171 |
+
# y_h2 = m.add_variables(coords = [t,i], name = 'y_h2', lower = 0)
|
172 |
|
173 |
## Objective function
|
174 |
C_tot = C_op + C_inv
|
175 |
m.add_objective(C_tot)
|
176 |
|
177 |
## Costs terms for objective function
|
178 |
+
# Operational costs (minus revenue for produced hydrogen)
|
179 |
+
# C_op_sum = m.add_constraints((y * c_fuel_i/eff_i).sum() * dt - (y_h2.sel(i = iPtG) * price_h2).sum() * dt == C_op, name = 'C_op_sum')
|
180 |
+
C_op_sum = m.add_constraints((y * c_fuel_i/eff_i).sum() * dt == C_op, name = 'C_op_sum')
|
181 |
|
182 |
# Investment costs
|
183 |
C_inv_sum = m.add_constraints((K * c_inv_i).sum() == C_inv, name = 'C_inv_sum')
|
184 |
|
185 |
## Load serving
|
186 |
+
# loadserve_t = m.add_constraints((((y ).sum(dims = 'i') - y_ch.sum(dims = 'i')) * dt == D_t.sel(t = t) * dt), name = 'load')
|
187 |
+
loadserve_t = m.add_constraints((((y ).sum(dims = 'i') ) * dt == D_t.sel(t = t) * dt), name = 'load')
|
188 |
|
189 |
## Maximum capacity limit
|
190 |
maxcap_i_t = m.add_constraints((y - K <= K_0_i), name = 'max_cap')
|
|
|
193 |
maxcap_invest_i = m.add_constraints((K.sel(i = technologies_no_invest) <= 0), name = 'max_cap_invest')
|
194 |
|
195 |
## Prevent power production by PtG
|
196 |
+
# no_power_prod_iPtG_t = m.add_constraints((y.sel(i = iPtG) <= 0), name = 'prevent_ptg_prod')
|
197 |
|
198 |
## Maximum storage charging and discharging
|
199 |
+
# maxcha_iSto_t = m.add_constraints((y.sel(i = iSto) - y_ch.sel(i = iSto) - K.sel(i = iSto) <= K_0_i.sel(i = iSto)), name = 'max_cha')
|
200 |
|
201 |
## Maximum electrolyzer capacity
|
202 |
+
# ptg_prod_iPtG_t = m.add_constraints((y_ch.sel(i = iPtG) - K.sel(i = iPtG) <= K_0_i.sel(i = iPtG)), name = 'max_cha_ptg')
|
203 |
|
204 |
## PtG H2 production
|
205 |
+
# h2_prod_iPtG_t = m.add_constraints(y_ch.sel(i = iPtG) * eff_i.sel(i = iPtG) == y_h2.sel(i = iPtG), name = 'ptg_h2_prod')
|
206 |
|
207 |
## Infeed of renewables
|
208 |
infeed_iRes_t = m.add_constraints((y.sel(i = iRes) - s_t_r_iRes.sel(i = iRes).sel(t = t) * K.sel(i = iRes) + y_curt.sel(i = iRes) == s_t_r_iRes.sel(i = iRes).sel(t = t) * K_0_i.sel(i = iRes)), name = 'infeed')
|
209 |
|
210 |
## Maximum filling level restriction storage power plant
|
211 |
+
# maxcapsto_iSto_t = m.add_constraints((l.sel(i = iSto) - K.sel(i = iSto) * e2p_iSto.sel(i = iSto) <= K_0_i.sel(i = iSto) * e2p_iSto.sel(i = iSto)), name = 'max_sto_filling')
|
212 |
|
213 |
## Filling level restriction hydro reservoir
|
214 |
+
# filling_iHydro_t = m.add_constraints(l.sel(i = iHyRes) - l.sel(i = iHyRes).roll(t = -1) + y.sel(i = iHyRes) * dt == h_t.sel(t = t) * dt, name = 'filling_level_hydro')
|
215 |
|
216 |
## Filling level restriction other storages
|
217 |
+
# filling_iSto_t = m.add_constraints(l.sel(i = iSto) - (l.sel(i = iSto).roll(t = -1) + (y.sel(i = iSto) / eff_i.sel(i = iSto)) * dt - y_ch.sel(i = iSto) * eff_i.sel(i = iSto) * dt) == 0, name = 'filling_level')
|
218 |
|
219 |
## CO2 limit
|
220 |
CO2_limit = m.add_constraints(((y / eff_i) * co2_factor_i * dt).sum() <= l_co2 * 1_000_000 , name = 'CO2_limit')
|
221 |
|
222 |
## set run-of-river power plants capacity limit to 5 GW
|
223 |
RoR_cap = m.add_constraints(K.sel(i = 'Laufwasser') <= 5000, name = 'RoR_cap')
|
224 |
+
Biomass_cap = m.add_constraints(K.sel(i = 'Biomasse') <= 9000, name = 'Biomass_cap')
|
225 |
|
226 |
|
227 |
# %%
|
|
|
347 |
fig
|
348 |
|
349 |
# %%
|
350 |
+
df_production_pivot = df_production.pivot(index='t', columns='i', values='y')
|
351 |
+
# sort columns according to i_with_capacity
|
352 |
+
df_production_pivot = df_production_pivot[i_with_capacity]
|
353 |
+
co2_factor_i_with_capacity = co2_factor_i.sel(i = i_with_capacity)
|
354 |
+
# colour_dict = {i: color_dict[i] for i in i_with_capacity}
|
355 |
+
color_dict_with_capacity = {i: color_dict[i] for i in i_with_capacity}
|
356 |
+
|
357 |
+
# multiply df_production with co2 factor
|
358 |
+
df_production_emissions = df_production_pivot * co2_factor_i_with_capacity
|
359 |
+
# unpivot df_production_emissions, sorting by datetime
|
360 |
+
df_production_emissions_unpivot = df_production_emissions.reset_index().melt(id_vars='t', var_name='i', value_name='y')
|
361 |
+
df_production_emissions_unpivot = df_production_emissions_unpivot.sort_values(by='t')
|
362 |
+
# sum up y column in total
|
363 |
+
df_production_emissions_total = df_production_emissions_unpivot['y'].sum()
|
364 |
+
df_production_emissions_sorted = df_production_emissions_unpivot.sort_values(by='y', ascending=True)
|
365 |
+
# sum up cumulated emissions
|
366 |
+
df_production_emissions_sorted['cumsum'] = df_production_emissions_sorted['y'].cumsum()
|
367 |
+
|
368 |
+
# generate area plot of df_production_emissions_unpivot over t
|
369 |
+
fig = px.area(df_production_emissions_unpivot, y='y', x='t', title='Co2-Emissionen [t]', color='i', color_discrete_map=color_dict_with_capacity)
|
370 |
fig.update_traces(line=dict(width=0))
|
371 |
fig.for_each_trace(lambda trace: trace.update(fillcolor = trace.line.color))
|
372 |
+
# fig = px.area(df_production_emissions_unpivot.sel(i = i_with_capacity).to_dataframe().reset_index(), y='y', x='t', title='Stromproduktion Lastgang [MW]', color='i', color_discrete_map=color_dict)
|
373 |
+
# fig.update_traces(line=dict(width=0))
|
374 |
+
# fig.for_each_trace(lambda trace: trace.update(fillcolor = trace.line.color))
|
375 |
with colb2:
|
376 |
+
fig
|
377 |
+
|
378 |
|
379 |
# %%
|
380 |
+
# generate area plot of df_production_emissions_sorted['cumsum] over t
|
381 |
+
x_emissions = np.arange(1, df_production_emissions_sorted['t'].size + 1)
|
382 |
+
fig = px.area(df_production_emissions_sorted, y='cumsum', x=x_emissions, title='Kumulierte Co2-Emissionen [t]', color='i', color_discrete_map=color_dict_with_capacity)
|
383 |
fig.update_traces(line=dict(width=0))
|
384 |
fig.for_each_trace(lambda trace: trace.update(fillcolor = trace.line.color))
|
385 |
|
386 |
+
with colb2:
|
387 |
+
fig
|
388 |
+
|
389 |
+
# %%
|
390 |
+
# df_charging = m.solution['y_ch'].sel(i = iSto).to_dataframe().reset_index()
|
391 |
+
# fig = px.area(m.solution['y_ch'].sel(i = iSto).to_dataframe().reset_index(), y='y_ch', x='t', title='Speicherbeladung [MWh]', color='i', color_discrete_map=color_dict)
|
392 |
+
# fig.update_traces(line=dict(width=0))
|
393 |
+
# fig.for_each_trace(lambda trace: trace.update(fillcolor = trace.line.color))
|
394 |
+
|
395 |
+
# with colb2:
|
396 |
+
# fig
|
397 |
+
|
398 |
+
# %%
|
399 |
+
# define vector x with size (1,size D_t_sorted)
|
400 |
+
x = np.arange(1, D_t_sorted.size + 1)
|
401 |
+
fig = px.line(y=D_t_sorted, x=x, title='Lastdauerlinie [€/MWh]', labels={"x": "Stunden im Jahr"})
|
402 |
with colb2:
|
403 |
fig
|
404 |
|
405 |
+
# # %%
|
406 |
+
# df_h2_prod = m.solution['y_h2'].sel(i = iPtG).to_dataframe().reset_index()
|
407 |
+
# fig = px.area(m.solution['y_h2'].sel(i = iPtG).to_dataframe().reset_index(), y='y_h2', x='t', title='Produktion Wasserstoff [MWh_th]', color='i', color_discrete_map=color_dict)
|
408 |
+
# fig.update_traces(line=dict(width=0))
|
409 |
+
# fig.for_each_trace(lambda trace: trace.update(fillcolor = trace.line.color))
|
410 |
+
|
411 |
+
# with colb2:
|
412 |
+
# fig
|
413 |
+
|
414 |
# %%
|
415 |
((m.solution['y'] / eff_i) * co2_factor_i * dt).sum()
|
416 |
# %%
|
|
|
436 |
#df_repeated = df.iloc[idx_repeat,:].reset_index(drop = True).drop('t', axis = 1)
|
437 |
df_t_all = pd.DataFrame({"t_all": t_original.to_series(), 't': t.repeat(dt)}).reset_index(drop=True)
|
438 |
|
439 |
+
## %%
|
440 |
df_output = df.merge(df_t_all,on = 't').drop('t',axis = 1).rename({'t_all':'t'}, axis = 1)
|
441 |
# last column to first column
|
442 |
cols = list(df_output.columns)
|
|
|
456 |
disaggregate_df(df_contr_marg).to_excel(writer, sheet_name='Deckungsbeiträge', index=False)
|
457 |
disaggregate_df(df_new_capacities).to_excel(writer, sheet_name='Kapazitäten', index=False)
|
458 |
disaggregate_df(df_production).to_excel(writer, sheet_name='Produktion', index=False)
|
459 |
+
# disaggregate_df(df_charging).to_excel(writer, sheet_name='Ladevorgänge', index=False)
|
460 |
disaggregate_df(D_t.to_dataframe().reset_index()).to_excel(writer, sheet_name='Nachfrage', index=False)
|
461 |
disaggregate_df(df_curtailment).to_excel(writer, sheet_name='Abregelung', index=False)
|
462 |
+
# disaggregate_df(df_h2_prod).to_excel(writer, sheet_name='H2 produktion', index=False)
|
463 |
|
464 |
with col4:
|
465 |
st.download_button(
|
model_data.pkl
CHANGED
@@ -1,3 +1,3 @@
|
|
1 |
version https://git-lfs.github.com/spec/v1
|
2 |
-
oid sha256:
|
3 |
-
size
|
|
|
1 |
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:3454912d7cfa9b850e8d7651b73c143a7e177d02261d6671a9a8e2d3bc6b81cc
|
3 |
+
size 1065854
|
sourced.py
CHANGED
@@ -34,19 +34,19 @@ def load_data_from_excel(url_excel, write_to_pickle_flag = True):
|
|
34 |
i = pd.Index(df_excel.iloc[:, 0], name='i')
|
35 |
|
36 |
df_excel = pd.read_excel(url_excel, sheet_name='Technologies')
|
37 |
-
iConv = pd.Index(df_excel.iloc[0:
|
38 |
|
39 |
df_excel = pd.read_excel(url_excel, sheet_name='Technologies')
|
40 |
iRes = pd.Index(df_excel.iloc[0:4, 4], name='iRes')
|
41 |
|
42 |
-
df_excel = pd.read_excel(url_excel, sheet_name='Technologies')
|
43 |
-
iSto = pd.Index(df_excel.iloc[0:2, 6], name='iSto')
|
44 |
|
45 |
-
df_excel = pd.read_excel(url_excel, sheet_name='Technologies')
|
46 |
-
iPtG = pd.Index(df_excel.iloc[0:1, 8], name='iPtG')
|
47 |
|
48 |
-
df_excel = pd.read_excel(url_excel, sheet_name='Technologies')
|
49 |
-
iHyRes = pd.Index(df_excel.iloc[0:1, 10], name='iHyRes')
|
50 |
|
51 |
# Parameters
|
52 |
l_co2 = pd.read_excel(url_excel, sheet_name='CO2_Cap').iloc[0,0]
|
@@ -145,21 +145,20 @@ def load_data_from_excel(url_excel, write_to_pickle_flag = True):
|
|
145 |
df_excel = df_excel.set_index('i')
|
146 |
K_0_i = df_excel.iloc[:,0].to_xarray()
|
147 |
|
148 |
-
# Energy-to-power ratio storages
|
149 |
-
df_excel = pd.read_excel(url_excel, sheet_name = 'E2P')
|
150 |
-
df_excel = df_excel.rename(columns = {'Speicher':'i', 'Unnamed: 1':'E2P-Ratio'})
|
151 |
-
#df_excel = i.to_frame().reset_index(drop=True).merge(df_excel, how = 'left')
|
152 |
-
df_excel = df_excel.fillna(0)
|
153 |
-
df_excel = df_excel.set_index('i')
|
154 |
-
e2p_iSto = df_excel.iloc[:,0].to_xarray()
|
155 |
-
|
156 |
-
# Inflow for hydro reservoir
|
157 |
-
df_excel = pd.read_excel(url_excel, sheet_name = 'HydroInflow')
|
158 |
-
df_excel = df_excel.rename(columns = {'Zeitschritte':'t', 'Staudamm':'Zufluss'})
|
159 |
-
df_excel = df_excel.fillna(0)
|
160 |
-
df_excel = df_excel.set_index('t')
|
161 |
-
h_t = df_excel.iloc[:,0].to_xarray()
|
162 |
-
|
163 |
|
164 |
|
165 |
sets_dict = {}
|
@@ -167,11 +166,11 @@ def load_data_from_excel(url_excel, write_to_pickle_flag = True):
|
|
167 |
# Append parameters to the dictionary
|
168 |
sets_dict['t'] = t
|
169 |
sets_dict['i'] = i
|
170 |
-
sets_dict['iSto'] = iSto
|
171 |
sets_dict['iConv'] = iConv
|
172 |
-
sets_dict['iPtG'] = iPtG
|
173 |
sets_dict['iRes'] = iRes
|
174 |
-
sets_dict['iHyRes'] = iHyRes
|
175 |
# Append parameters to the dictionary
|
176 |
params_dict['l_co2'] = l_co2
|
177 |
params_dict['p_co2'] = p_co2
|
@@ -186,8 +185,8 @@ def load_data_from_excel(url_excel, write_to_pickle_flag = True):
|
|
186 |
params_dict['c_var_i'] = c_var_i
|
187 |
params_dict['s_t_r_iRes'] = s_t_r_iRes
|
188 |
params_dict['K_0_i'] = K_0_i
|
189 |
-
params_dict['e2p_iSto'] = e2p_iSto
|
190 |
-
params_dict['h_t'] = h_t
|
191 |
|
192 |
if write_to_pickle_flag:
|
193 |
save_to_pickle(sets_dict, params_dict)
|
|
|
34 |
i = pd.Index(df_excel.iloc[:, 0], name='i')
|
35 |
|
36 |
df_excel = pd.read_excel(url_excel, sheet_name='Technologies')
|
37 |
+
iConv = pd.Index(df_excel.iloc[0:6, 2], name='iConv') # changed to 6 from 7
|
38 |
|
39 |
df_excel = pd.read_excel(url_excel, sheet_name='Technologies')
|
40 |
iRes = pd.Index(df_excel.iloc[0:4, 4], name='iRes')
|
41 |
|
42 |
+
# df_excel = pd.read_excel(url_excel, sheet_name='Technologies')
|
43 |
+
# iSto = pd.Index(df_excel.iloc[0:2, 6], name='iSto')
|
44 |
|
45 |
+
# df_excel = pd.read_excel(url_excel, sheet_name='Technologies')
|
46 |
+
# iPtG = pd.Index(df_excel.iloc[0:1, 8], name='iPtG')
|
47 |
|
48 |
+
# df_excel = pd.read_excel(url_excel, sheet_name='Technologies')
|
49 |
+
# iHyRes = pd.Index(df_excel.iloc[0:1, 10], name='iHyRes')
|
50 |
|
51 |
# Parameters
|
52 |
l_co2 = pd.read_excel(url_excel, sheet_name='CO2_Cap').iloc[0,0]
|
|
|
145 |
df_excel = df_excel.set_index('i')
|
146 |
K_0_i = df_excel.iloc[:,0].to_xarray()
|
147 |
|
148 |
+
# # Energy-to-power ratio storages
|
149 |
+
# df_excel = pd.read_excel(url_excel, sheet_name = 'E2P')
|
150 |
+
# df_excel = df_excel.rename(columns = {'Speicher':'i', 'Unnamed: 1':'E2P-Ratio'})
|
151 |
+
# #df_excel = i.to_frame().reset_index(drop=True).merge(df_excel, how = 'left')
|
152 |
+
# df_excel = df_excel.fillna(0)
|
153 |
+
# df_excel = df_excel.set_index('i')
|
154 |
+
# e2p_iSto = df_excel.iloc[:,0].to_xarray()
|
155 |
+
|
156 |
+
# # Inflow for hydro reservoir
|
157 |
+
# df_excel = pd.read_excel(url_excel, sheet_name = 'HydroInflow')
|
158 |
+
# df_excel = df_excel.rename(columns = {'Zeitschritte':'t', 'Staudamm':'Zufluss'})
|
159 |
+
# df_excel = df_excel.fillna(0)
|
160 |
+
# df_excel = df_excel.set_index('t')
|
161 |
+
# h_t = df_excel.iloc[:,0].to_xarray()
|
|
|
162 |
|
163 |
|
164 |
sets_dict = {}
|
|
|
166 |
# Append parameters to the dictionary
|
167 |
sets_dict['t'] = t
|
168 |
sets_dict['i'] = i
|
169 |
+
# sets_dict['iSto'] = iSto
|
170 |
sets_dict['iConv'] = iConv
|
171 |
+
# sets_dict['iPtG'] = iPtG
|
172 |
sets_dict['iRes'] = iRes
|
173 |
+
# sets_dict['iHyRes'] = iHyRes
|
174 |
# Append parameters to the dictionary
|
175 |
params_dict['l_co2'] = l_co2
|
176 |
params_dict['p_co2'] = p_co2
|
|
|
185 |
params_dict['c_var_i'] = c_var_i
|
186 |
params_dict['s_t_r_iRes'] = s_t_r_iRes
|
187 |
params_dict['K_0_i'] = K_0_i
|
188 |
+
# params_dict['e2p_iSto'] = e2p_iSto
|
189 |
+
# params_dict['h_t'] = h_t
|
190 |
|
191 |
if write_to_pickle_flag:
|
192 |
save_to_pickle(sets_dict, params_dict)
|