ConniKLu commited on
Commit
68e7402
·
verified ·
1 Parent(s): 7bd2a95

Upload 3 files

Browse files
Files changed (1) hide show
  1. app.py +32 -24
app.py CHANGED
@@ -17,6 +17,7 @@ import plotly.express as px
17
  import streamlit as st
18
  import sourced as src
19
  import numpy as np
 
20
 
21
  ## Setting
22
  write_pickle_from_standard_excel = True
@@ -59,11 +60,16 @@ if url_excel == None:
59
  with col4:
60
  st.write('Lauf mit Standarddaten')
61
  else:
62
- sets_dict, params_dict= src.load_data_from_excel(url_excel, load_from_pickle_flag = False)
63
-
 
64
  with col4:
65
  st.write('Lauf mit Nutzerdaten')
66
 
 
 
 
 
67
  # # %%
68
 
69
  def timstep_aggregate(time_steps_aggregate, xr ):
@@ -216,7 +222,7 @@ maxcapsto_iSto_t = m.add_constraints((l.sel(i = iSto) - K.sel(i = iSto) * e2p_iS
216
  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')
217
 
218
  ## CO2 limit
219
- # l_co2 = 180
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
@@ -294,7 +300,7 @@ df_combined = pd.DataFrame({
294
  })
295
 
296
  # Create the integrated plot using Plotly Express
297
- fig = px.line(df_combined, x='x', y='y', color='label', title='Lastdauerlinie [€/MW]',
298
  labels={"x": "Stunden im Jahr", "y": "Leistung [MW]"})
299
 
300
  # Specific updates for each trace
@@ -310,8 +316,30 @@ with colb2:
310
 
311
  # fig.show()
312
  # %%
 
313
  i_with_capacity = m.solution['K'].where( m.solution['K'] > 0).dropna(dim = 'i').get_index('i')
314
  df_production = m.solution['y'].sel(i = i_with_capacity).to_dataframe().reset_index()
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
315
  fig = px.area(m.solution['y'].sel(i = i_with_capacity).to_dataframe().reset_index(), y='y', x='t', title='Stromproduktion Lastgang [MW]', color='i', color_discrete_map=color_dict)
316
  fig.update_traces(line=dict(width=0))
317
  fig.for_each_trace(lambda trace: trace.update(fillcolor = trace.line.color))
@@ -334,26 +362,6 @@ fig = px.line(y=df_sorted_price, x=x_price, title='Preisdauerlinie [€/MWh]',
334
  with colb2:
335
  fig
336
 
337
- # %%
338
- # calculate full load hours
339
- df_capacity = m.solution['K'].sel(i = i_with_capacity).to_dataframe().reset_index()
340
- df_production_sum = (df_production.groupby('i')['y'].sum() * dt).round(0).reset_index()
341
- # reorder rows according to i_with_capacity
342
- df_production_sum = df_production_sum.set_index('i').loc[i_with_capacity].reset_index()
343
- # df_production_sum['i'] = pd.Categorical(df_production_sum['i'], categories=desired_order, ordered=True)
344
-
345
- df_fullload = df_production_sum['y']/df_capacity['K']
346
- # to dataframe
347
- df_fullload = df_fullload.to_frame()
348
- # rename column
349
- df_fullload.columns = ['fullload']
350
- df_fullload['i'] = df_production_sum['i']
351
- # change order of columns
352
- df_fullload = df_fullload[['i', 'fullload']]
353
- fig = px.bar(df_fullload, y='i', x=df_fullload['fullload'], orientation='h', title='Volllaststunden [h]', color='i', color_discrete_map=color_dict)
354
- with colb1:
355
- fig
356
- # fig.show()
357
 
358
  # %%
359
 
 
17
  import streamlit as st
18
  import sourced as src
19
  import numpy as np
20
+ import tempfile
21
 
22
  ## Setting
23
  write_pickle_from_standard_excel = True
 
60
  with col4:
61
  st.write('Lauf mit Standarddaten')
62
  else:
63
+ # sets_dict, params_dict= src.load_data_from_excel(url_excel, load_from_pickle_flag = False)
64
+ sets_dict, params_dict= src.load_data_from_excel(url_excel, write_to_pickle_flag = True)
65
+
66
  with col4:
67
  st.write('Lauf mit Nutzerdaten')
68
 
69
+ # Debugging output to verify that sets_dict is defined
70
+ # st.write(f"sets_dict: {sets_dict}")
71
+ # st.write(f"params_dict: {params_dict}")
72
+
73
  # # %%
74
 
75
  def timstep_aggregate(time_steps_aggregate, xr ):
 
222
  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')
223
 
224
  ## CO2 limit
225
+ # l_co2 = 50
226
  CO2_limit = m.add_constraints(((y / eff_i) * co2_factor_i * dt).sum() <= l_co2 * 1_000_000 , name = 'CO2_limit')
227
 
228
  ## set run-of-river power plants capacity limit to 5 GW
 
300
  })
301
 
302
  # Create the integrated plot using Plotly Express
303
+ fig = px.line(df_combined, x='x', y='y', color='label', title='Lastdauerlinie [MW]',
304
  labels={"x": "Stunden im Jahr", "y": "Leistung [MW]"})
305
 
306
  # Specific updates for each trace
 
316
 
317
  # fig.show()
318
  # %%
319
+ # calculate full load hours
320
  i_with_capacity = m.solution['K'].where( m.solution['K'] > 0).dropna(dim = 'i').get_index('i')
321
  df_production = m.solution['y'].sel(i = i_with_capacity).to_dataframe().reset_index()
322
+ df_capacity = m.solution['K'].sel(i = i_with_capacity).to_dataframe().reset_index()
323
+ df_production_sum = (df_production.groupby('i')['y'].sum() * dt).round(0).reset_index()
324
+ # reorder rows according to i_with_capacity
325
+ df_production_sum = df_production_sum.set_index('i').loc[i_with_capacity].reset_index()
326
+ # df_production_sum['i'] = pd.Categorical(df_production_sum['i'], categories=desired_order, ordered=True)
327
+
328
+ df_fullload = df_production_sum['y']/df_capacity['K']
329
+ # to dataframe
330
+ df_fullload = df_fullload.to_frame()
331
+ # rename column
332
+ df_fullload.columns = ['fullload']
333
+ df_fullload['i'] = df_production_sum['i']
334
+ # change order of columns
335
+ df_fullload = df_fullload[['i', 'fullload']]
336
+ fig = px.bar(df_fullload, y='i', x=df_fullload['fullload'], orientation='h', title='Volllaststunden [h]', color='i', color_discrete_map=color_dict)
337
+ with colb1:
338
+ fig
339
+ # fig.show()
340
+
341
+
342
+ # %%
343
  fig = px.area(m.solution['y'].sel(i = i_with_capacity).to_dataframe().reset_index(), y='y', x='t', title='Stromproduktion Lastgang [MW]', color='i', color_discrete_map=color_dict)
344
  fig.update_traces(line=dict(width=0))
345
  fig.for_each_trace(lambda trace: trace.update(fillcolor = trace.line.color))
 
362
  with colb2:
363
  fig
364
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
365
 
366
  # %%
367