Spaces:
Running
Running
Upload 11 files
Browse files- .gitattributes +2 -0
- Input_Jahr_2023.xlsx +3 -0
- app.py +1253 -0
- language.csv +138 -0
- media/Logo_HEMF.svg +45 -0
- media/Logo_UDE.svg +1 -0
- media/OPT____S.ttf +0 -0
- media/OPT____S.woff2 +0 -0
- media/favicon.ico +0 -0
- model_data.pkl +3 -0
- requirements.txt +9 -3
- sourced.py +215 -0
.gitattributes
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
|
|
|
|
|
|
|
| 1 |
+
Input_Jahr_2023.xlsx filter=lfs diff=lfs merge=lfs -text
|
| 2 |
+
model_data.pkl filter=lfs diff=lfs merge=lfs -text
|
Input_Jahr_2023.xlsx
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:071c0d7133608f15f5daf16663cd7cbd172113d50fc9ec6026fa40f9f7d91128
|
| 3 |
+
size 1050705
|
app.py
ADDED
|
@@ -0,0 +1,1253 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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Pflugfelder
|
| 6 |
+
"""
|
| 7 |
+
|
| 8 |
+
import numpy as np
|
| 9 |
+
import pandas as pd
|
| 10 |
+
import xarray as xr
|
| 11 |
+
import plotly.express as px
|
| 12 |
+
import plotly.graph_objects as go
|
| 13 |
+
import streamlit as st
|
| 14 |
+
from io import BytesIO
|
| 15 |
+
import xlsxwriter
|
| 16 |
+
from linopy import Model
|
| 17 |
+
import sourced as src
|
| 18 |
+
import time
|
| 19 |
+
|
| 20 |
+
|
| 21 |
+
# Main function to run the Streamlit app
|
| 22 |
+
def main():
|
| 23 |
+
"""
|
| 24 |
+
Main function to set up and solve the energy system optimization model, and handle user inputs and outputs.
|
| 25 |
+
"""
|
| 26 |
+
setup_page()
|
| 27 |
+
|
| 28 |
+
settings = load_settings()
|
| 29 |
+
|
| 30 |
+
# fill session space with variables that are needed on all pages
|
| 31 |
+
if 'settings' not in st.session_state:
|
| 32 |
+
st.session_state.df = load_settings()
|
| 33 |
+
st.session_state.settings = settings
|
| 34 |
+
|
| 35 |
+
if 'url_excel' not in st.session_state:
|
| 36 |
+
st.session_state.url_excel = None
|
| 37 |
+
|
| 38 |
+
if 'ui_model' not in st.session_state:
|
| 39 |
+
st.session_state.url_excel = None
|
| 40 |
+
|
| 41 |
+
if 'output' not in st.session_state:
|
| 42 |
+
st.session_state.output = BytesIO()
|
| 43 |
+
|
| 44 |
+
|
| 45 |
+
setup_sidebar(st.session_state.settings["df"])
|
| 46 |
+
|
| 47 |
+
|
| 48 |
+
|
| 49 |
+
# # Navigation
|
| 50 |
+
# pg = st.navigation([st.Page(page_model, title=st.session_state.settings["df"].loc['menu_modell',st.session_state.lang], icon="📊"),
|
| 51 |
+
# st.Page(page_documentation, title=st.session_state.settings["df"].loc['menu_doku',st.session_state.lang], icon="📓"),
|
| 52 |
+
# st.Page(page_about_us, title=st.session_state.settings["df"].loc['menu_impressum',st.session_state.lang], icon="💬")],
|
| 53 |
+
# expanded=True)
|
| 54 |
+
|
| 55 |
+
# # # Run the app
|
| 56 |
+
# pg.run()
|
| 57 |
+
|
| 58 |
+
# Create tabs for navigation
|
| 59 |
+
tabs = st.tabs([
|
| 60 |
+
st.session_state.settings["df"].loc['menu_modell', st.session_state.lang],
|
| 61 |
+
st.session_state.settings["df"].loc['menu_doku', st.session_state.lang],
|
| 62 |
+
st.session_state.settings["df"].loc['menu_impressum', st.session_state.lang]
|
| 63 |
+
])
|
| 64 |
+
|
| 65 |
+
# Load and display content based on the selected tab
|
| 66 |
+
with tabs[0]: # Model page
|
| 67 |
+
page_model()
|
| 68 |
+
with tabs[1]: # Documentation page
|
| 69 |
+
page_documentation()
|
| 70 |
+
with tabs[2]: # About Us page
|
| 71 |
+
page_about_us()
|
| 72 |
+
|
| 73 |
+
|
| 74 |
+
|
| 75 |
+
|
| 76 |
+
# Load settings and initial configurations
|
| 77 |
+
def load_settings():
|
| 78 |
+
"""
|
| 79 |
+
Load settings for the app, including colors and language information.
|
| 80 |
+
"""
|
| 81 |
+
settings = {
|
| 82 |
+
'write_pickle_from_standard_excel': True,
|
| 83 |
+
'df': pd.read_csv("language.csv", encoding="iso-8859-1", index_col="Label", sep=";"),
|
| 84 |
+
'color_dict': {
|
| 85 |
+
'Biomass': 'lightgreen',
|
| 86 |
+
'Lignite': 'saddlebrown',
|
| 87 |
+
'Fossil Hard coal': 'chocolate', # Ein Braunton ähnlich Lignite
|
| 88 |
+
'Fossil Oil': 'black',
|
| 89 |
+
'CCGT': 'lightgray', # Hellgrau
|
| 90 |
+
'OCGT': 'darkgray', # Dunkelgrau
|
| 91 |
+
'RoR': 'aquamarine',
|
| 92 |
+
'Hydro Water Reservoir': 'lightsteelblue',
|
| 93 |
+
'Nuclear': 'gold',
|
| 94 |
+
'PV': 'yellow',
|
| 95 |
+
'WindOff': 'darkblue',
|
| 96 |
+
'WindOn': 'green',
|
| 97 |
+
'H2': 'tomato',
|
| 98 |
+
'Pumped Hydro Storage': 'skyblue',
|
| 99 |
+
'Battery storages': 'firebrick',
|
| 100 |
+
'Electrolyzer': 'yellowgreen'
|
| 101 |
+
},
|
| 102 |
+
'colors': {
|
| 103 |
+
'hemf_blau_dunkel': "#00386c",
|
| 104 |
+
'hemf_blau_hell': "#00529f",
|
| 105 |
+
'hemf_rot_dunkel': "#8b310d",
|
| 106 |
+
'hemf_rot_hell': "#d04119",
|
| 107 |
+
'hemf_grau': "#dadada"
|
| 108 |
+
}
|
| 109 |
+
}
|
| 110 |
+
return settings
|
| 111 |
+
|
| 112 |
+
# Initialize Streamlit app
|
| 113 |
+
def setup_page():
|
| 114 |
+
"""
|
| 115 |
+
Set up the Streamlit page with a specific layout, title, and favicon.
|
| 116 |
+
"""
|
| 117 |
+
st.set_page_config(layout="wide", page_title="Investment tool", page_icon="media/favicon.ico", initial_sidebar_state="expanded")
|
| 118 |
+
|
| 119 |
+
|
| 120 |
+
# Sidebar for language and links
|
| 121 |
+
def setup_sidebar(df):
|
| 122 |
+
"""
|
| 123 |
+
Set up the sidebar with language options and external links.
|
| 124 |
+
"""
|
| 125 |
+
st.session_state.lang = st.sidebar.selectbox("Language", ["🇬🇧 EN", "🇩🇪 DE"], key="foo", label_visibility="collapsed")[-2:]
|
| 126 |
+
|
| 127 |
+
st.sidebar.markdown("""
|
| 128 |
+
<style>
|
| 129 |
+
text-align: center;
|
| 130 |
+
display: block;
|
| 131 |
+
margin-left: auto;
|
| 132 |
+
margin-right: auto;
|
| 133 |
+
width: 100%;
|
| 134 |
+
</style>
|
| 135 |
+
""", unsafe_allow_html=True)
|
| 136 |
+
|
| 137 |
+
with st.sidebar:
|
| 138 |
+
left_co, cent_co, last_co = st.columns([0.1, 0.8, 0.1])
|
| 139 |
+
with cent_co:
|
| 140 |
+
st.text(" ") # add vertical empty space
|
| 141 |
+
""+df.loc['menu_text', st.session_state.lang]
|
| 142 |
+
st.text(" ") # add vertical empty space
|
| 143 |
+
|
| 144 |
+
if st.session_state.lang == "DE":
|
| 145 |
+
st.write("Schaue vorbei beim")
|
| 146 |
+
st.markdown(r'[Lehrstuhl für Energiewirtschaft](https://www.ewl.wiwi.uni-due.de)', unsafe_allow_html=True)
|
| 147 |
+
elif st.session_state.lang == "EN":
|
| 148 |
+
st.write("Get in touch with the")
|
| 149 |
+
st.markdown(r'[Chair of Management Science and Energy Economics](https://www.ewl.wiwi.uni-due.de/en)', unsafe_allow_html=True)
|
| 150 |
+
|
| 151 |
+
st.text(" ") # add vertical empty space
|
| 152 |
+
st.image("media/Logo_HEMF.svg", width=200)
|
| 153 |
+
st.image("media/Logo_UDE.svg", width=200)
|
| 154 |
+
|
| 155 |
+
|
| 156 |
+
# Load model input data
|
| 157 |
+
def load_model_input(df, write_pickle_from_standard_excel):
|
| 158 |
+
"""
|
| 159 |
+
Load model input data from Excel or Pickle based on user input.
|
| 160 |
+
"""
|
| 161 |
+
if st.session_state.url_excel is None:
|
| 162 |
+
if write_pickle_from_standard_excel:
|
| 163 |
+
url_excel = r'Input_Jahr_2023.xlsx'
|
| 164 |
+
sets_dict, params_dict = src.load_data_from_excel(url_excel, write_to_pickle_flag=True)
|
| 165 |
+
sets_dict, params_dict = src.load_from_pickle()
|
| 166 |
+
#st.write(df.loc['model_title1.1', st.session_state.lang])
|
| 167 |
+
# st.write('Running with standard data')
|
| 168 |
+
else:
|
| 169 |
+
url_excel = st.session_state.url_excel
|
| 170 |
+
sets_dict, params_dict = src.load_data_from_excel(url_excel, load_from_pickle_flag=False)
|
| 171 |
+
st.write(df.loc['model_title1.2', st.session_state.lang])
|
| 172 |
+
|
| 173 |
+
return sets_dict, params_dict
|
| 174 |
+
|
| 175 |
+
|
| 176 |
+
|
| 177 |
+
def page_documentation():
|
| 178 |
+
"""
|
| 179 |
+
Display documentation and mathematical model details.
|
| 180 |
+
"""
|
| 181 |
+
|
| 182 |
+
df = st.session_state.settings["df"]
|
| 183 |
+
|
| 184 |
+
st.header(df.loc['constr_header1', st.session_state.lang])
|
| 185 |
+
st.write(df.loc['constr_header2', st.session_state.lang])
|
| 186 |
+
|
| 187 |
+
col1, col2 = st.columns([6, 4])
|
| 188 |
+
|
| 189 |
+
with col1:
|
| 190 |
+
st.header(df.loc['constr_header3', st.session_state.lang])
|
| 191 |
+
|
| 192 |
+
with st.container():
|
| 193 |
+
|
| 194 |
+
# Objective function
|
| 195 |
+
st.subheader(df.loc['constr_subheader_obj_func', st.session_state.lang])
|
| 196 |
+
st.write(df.loc['constr_subheader_obj_func_descr', st.session_state.lang])
|
| 197 |
+
st.latex(r''' \text{min } C^{tot} = C^{op} + C^{inv}''')
|
| 198 |
+
|
| 199 |
+
# Operational costs minus revenue for produced hydrogen
|
| 200 |
+
st.write(df.loc['constr_c_op', st.session_state.lang])
|
| 201 |
+
st.latex(r''' C^{op} = \sum_{i} y_{t,i} \cdot \left( \frac{c^{fuel}_{i}}{\eta_i} + c_{i}^{other} \right) \cdot \Delta t - \sum_{i \in \mathcal{I}^{PtG}} y^{h2}_{t,i} \cdot p^{h2} \cdot \Delta t''')
|
| 202 |
+
|
| 203 |
+
# Investment costs
|
| 204 |
+
st.write(df.loc['constr_c_inv', st.session_state.lang])
|
| 205 |
+
st.latex(r''' C^{inv} = \sum_{i} a_{i} \cdot K_{i} \cdot c^{inv}_{i}''')
|
| 206 |
+
|
| 207 |
+
# Constraints
|
| 208 |
+
st.subheader(df.loc['subheader_constr', st.session_state.lang])
|
| 209 |
+
|
| 210 |
+
# Load-serving constraint
|
| 211 |
+
st.write(df.loc['constr_load_serve', st.session_state.lang])
|
| 212 |
+
st.latex(r''' \left( \sum_{i} y_{t,i} - \sum_{i} y_{t,i}^{ch} \right) \cdot \Delta t = D_t \cdot \Delta t, \quad \forall t \in \mathcal{T}''')
|
| 213 |
+
|
| 214 |
+
# Maximum capacity limit
|
| 215 |
+
st.write(df.loc['constr_max_cap', st.session_state.lang])
|
| 216 |
+
st.latex(r''' y_{t,i} - K_{i} \leq K_{0,i}, \quad \forall i \in \mathcal{I}''')
|
| 217 |
+
|
| 218 |
+
# Capacity limits for investment
|
| 219 |
+
st.write(df.loc['constr_inv_cap', st.session_state.lang])
|
| 220 |
+
st.latex(r''' K_{i} \leq 0, \quad \forall i \in \mathcal{I}^{no\_invest}''')
|
| 221 |
+
|
| 222 |
+
# Prevent power production by PtG
|
| 223 |
+
st.write(df.loc['constr_prevent_ptg', st.session_state.lang])
|
| 224 |
+
st.latex(r''' y_{t,i} = 0, \quad \forall i \in \mathcal{I}^{PtG}''')
|
| 225 |
+
|
| 226 |
+
# Prevent charging for non-storage technologies
|
| 227 |
+
st.write(df.loc['constr_prevent_chg', st.session_state.lang])
|
| 228 |
+
st.latex(r''' y_{t,i}^{ch} = 0, \quad \forall i \in \mathcal{I} \setminus \{ \mathcal{I}^{PtG} \cup \mathcal{I}^{Sto} \}''')
|
| 229 |
+
|
| 230 |
+
# Maximum storage charging and discharging
|
| 231 |
+
st.write(df.loc['constr_max_chg', st.session_state.lang])
|
| 232 |
+
st.latex(r''' y_{t,i} + y_{t,i}^{ch} - K_{i} \leq K_{0,i}, \quad \forall i \in \mathcal{I}^{Sto}''')
|
| 233 |
+
|
| 234 |
+
# Maximum electrolyzer capacity
|
| 235 |
+
st.write(df.loc['constr_max_cap_electrolyzer', st.session_state.lang])
|
| 236 |
+
st.latex(r''' y_{t,i}^{ch} - K_{i} \leq K_{0,i}, \quad \forall i \in \mathcal{I}^{PtG}''')
|
| 237 |
+
|
| 238 |
+
# PtG H2 production
|
| 239 |
+
st.write(df.loc['constr_prod_ptg', st.session_state.lang])
|
| 240 |
+
st.latex(r''' y_{t,i}^{ch} \cdot \eta_i = y_{t,i}^{h2}, \quad \forall i \in \mathcal{I}^{PtG}''')
|
| 241 |
+
|
| 242 |
+
# Infeed of renewables
|
| 243 |
+
st.write(df.loc['constr_inf_res', st.session_state.lang])
|
| 244 |
+
st.latex(r''' y_{t,i} + y_{t,i}^{curt} = s_{t,r,i} \cdot (K_{0,i} + K_i), \quad \forall i \in \mathcal{I}^{Res}''')
|
| 245 |
+
|
| 246 |
+
# Maximum filling level restriction for storage power plants
|
| 247 |
+
st.write(df.loc['constr_max_fil_sto', st.session_state.lang])
|
| 248 |
+
# st.latex(r''' l_{t,i} \leq K_{0,i} \cdot e2p_i, \quad \forall i \in \mathcal{I}^{Sto}''')
|
| 249 |
+
st.latex(r''' l_{t,i} \leq (K_{0,i} + K_{i}) \cdot \gamma_i^{Sto}, \quad \forall i \in \mathcal{I}^{Sto}''')
|
| 250 |
+
|
| 251 |
+
# Filling level restriction for hydro reservoir
|
| 252 |
+
st.write(df.loc['constr_fil_hyres', st.session_state.lang])
|
| 253 |
+
st.latex(r''' l_{t+1,i} = l_{t,i} + ( h_{t,i} - y_{t,i}) \cdot \Delta t, \quad \forall i \in \mathcal{I}^{HyRes}''')
|
| 254 |
+
|
| 255 |
+
# Filling level restriction for other storages
|
| 256 |
+
st.write(df.loc['constr_fil_sto', st.session_state.lang])
|
| 257 |
+
st.latex(r''' l_{t+1,i} = l_{t,i} - \left(\frac{y_{t,i}}{\eta_i} - y_{t,i}^{ch} \cdot \eta_i \right) \cdot \Delta t, \quad \forall i \in \mathcal{I}^{Sto}''')
|
| 258 |
+
|
| 259 |
+
# CO2 emission constraint
|
| 260 |
+
st.write(df.loc['constr_co2_lim', st.session_state.lang])
|
| 261 |
+
st.latex(r''' \sum_{t} \sum_{i} \frac{y_{t,i}}{\eta_i} \cdot \chi^{CO2}_i \cdot \Delta t \leq L^{CO2}''')
|
| 262 |
+
|
| 263 |
+
|
| 264 |
+
with col2:
|
| 265 |
+
|
| 266 |
+
symbols_container = st.container()
|
| 267 |
+
with symbols_container:
|
| 268 |
+
st.header(df.loc['symb_header1', st.session_state.lang])
|
| 269 |
+
st.write(df.loc['symb_header2', st.session_state.lang])
|
| 270 |
+
|
| 271 |
+
st.subheader(df.loc['symb_header_sets', st.session_state.lang])
|
| 272 |
+
st.write(f"$\mathcal{{T}}$: {df.loc['symb_time_steps', st.session_state.lang]}")
|
| 273 |
+
st.write(f"$\mathcal{{I}}$: {df.loc['symb_tech', st.session_state.lang]}")
|
| 274 |
+
st.write(f"$\mathcal{{I}}^{{\\text{{Sto}}}}$: {df.loc['symb_sto_tech', st.session_state.lang]}")
|
| 275 |
+
st.write(f"$\mathcal{{I}}^{{\\text{{Conv}}}}$: {df.loc['symb_conv_tech', st.session_state.lang]}")
|
| 276 |
+
st.write(f"$\mathcal{{I}}^{{\\text{{PtG}}}}$: {df.loc['symb_ptg', st.session_state.lang]}")
|
| 277 |
+
st.write(f"$\mathcal{{I}}^{{\\text{{Res}}}}$: {df.loc['symb_res', st.session_state.lang]}")
|
| 278 |
+
st.write(f"$\mathcal{{I}}^{{\\text{{HyRes}}}}$: {df.loc['symb_hyres', st.session_state.lang]}")
|
| 279 |
+
st.write(f"$\mathcal{{I}}^{{\\text{{no\_invest}}}}$: {df.loc['symb_no_inv', st.session_state.lang]}")
|
| 280 |
+
|
| 281 |
+
|
| 282 |
+
|
| 283 |
+
# Variables section
|
| 284 |
+
st.subheader(df.loc['symb_header_variables', st.session_state.lang])
|
| 285 |
+
st.write(f"$C^{{tot}}$: {df.loc['symb_tot_costs', st.session_state.lang]}")
|
| 286 |
+
st.write(f"$C^{{op}}$: {df.loc['symb_c_op', st.session_state.lang]}")
|
| 287 |
+
st.write(f"$C^{{inv}}$: {df.loc['symb_c_inv', st.session_state.lang]}")
|
| 288 |
+
st.write(f"$K_i$: {df.loc['symb_inst_cap', st.session_state.lang]}")
|
| 289 |
+
st.write(f"$y_{{t,i}}$: {df.loc['symb_el_prod', st.session_state.lang]}")
|
| 290 |
+
st.write(f"$y_{{t, i}}^{{ch}}$: {df.loc['symb_el_ch', st.session_state.lang]}")
|
| 291 |
+
st.write(f"$l_{{t,i}}$: {df.loc['symb_sto_fil', st.session_state.lang]}")
|
| 292 |
+
st.write(f"$y_{{t, i}}^{{curt}}$: {df.loc['symb_curt', st.session_state.lang]}")
|
| 293 |
+
st.write(f"$y_{{t, i}}^{{h2}}$: {df.loc['symb_h2_ptg', st.session_state.lang]}")
|
| 294 |
+
|
| 295 |
+
|
| 296 |
+
# Parameters section
|
| 297 |
+
st.subheader(df.loc['symb_header_parameters', st.session_state.lang])
|
| 298 |
+
st.write(f"$D_t$: {df.loc['symb_energy_demand', st.session_state.lang]}")
|
| 299 |
+
st.write(f"$p^{{h2}}$: {df.loc['symb_price_h2', st.session_state.lang]}")
|
| 300 |
+
st.write(f"$c^{{fuel}}_{{i}}$: {df.loc['symb_fuel_costs', st.session_state.lang]}")
|
| 301 |
+
st.write(f"$c_{{i}}^{{other}}$: {df.loc['symb_c_op_other', st.session_state.lang]}")
|
| 302 |
+
st.write(f"$c^{{inv}}_{{i}}$: {df.loc['symb_c_inv_tech', st.session_state.lang]}")
|
| 303 |
+
st.write(f"$a_{{i}}$: {df.loc['symb_annuity', st.session_state.lang]}")
|
| 304 |
+
st.write(f"$\eta_i$: {df.loc['symb_eff_fac', st.session_state.lang]}")
|
| 305 |
+
st.write(f"$K_{{0,i}}$: {df.loc['symb_max_cap_tech', st.session_state.lang]}")
|
| 306 |
+
st.write(f"$\chi^{{CO2}}_i$: {df.loc['symb_co2_fac', st.session_state.lang]}")
|
| 307 |
+
st.write(f"$L^{{CO2}}$: {df.loc['symb_co2_limit', st.session_state.lang]}")
|
| 308 |
+
# st.write(f"$e2p_{{\\text{{Sto}}, i}}$: {df.loc['symb_etp', st.session_state.lang]}")
|
| 309 |
+
st.write(f"$\gamma^{{\\text{{Sto}}}}_{{i}}$: {df.loc['symb_etp', st.session_state.lang]}")
|
| 310 |
+
st.write(f"$s_{{t, r, i}}$: {df.loc['symb_res_supply', st.session_state.lang]}")
|
| 311 |
+
st.write(f"$h_{{t, i}}$: {df.loc['symb_hyRes_inflow', st.session_state.lang]}")
|
| 312 |
+
|
| 313 |
+
# css = float_css_helper(top="50")
|
| 314 |
+
# symbols_container.float(css)
|
| 315 |
+
|
| 316 |
+
|
| 317 |
+
def page_about_us():
|
| 318 |
+
"""
|
| 319 |
+
Display information about the team and the project.
|
| 320 |
+
"""
|
| 321 |
+
st.write("About Us/Impressum")
|
| 322 |
+
|
| 323 |
+
|
| 324 |
+
def page_model(): #, write_pickle_from_standard_excel, color_dict):
|
| 325 |
+
"""
|
| 326 |
+
Display the main model page for energy system optimization.
|
| 327 |
+
|
| 328 |
+
This function sets up the user interface for the model input parameters, loads data, and configures the
|
| 329 |
+
optimization model before solving it and presenting the results.
|
| 330 |
+
"""
|
| 331 |
+
|
| 332 |
+
df = st.session_state.settings["df"]
|
| 333 |
+
color_dict = st.session_state.settings["color_dict"]
|
| 334 |
+
write_pickle_from_standard_excel = st.session_state.settings["write_pickle_from_standard_excel"]
|
| 335 |
+
|
| 336 |
+
|
| 337 |
+
|
| 338 |
+
|
| 339 |
+
# Load data from Excel or Pickle
|
| 340 |
+
sets_dict, params_dict = load_model_input(df, write_pickle_from_standard_excel)
|
| 341 |
+
|
| 342 |
+
# Unpack sets_dict into the workspace
|
| 343 |
+
t = sets_dict['t']
|
| 344 |
+
t_original = sets_dict['t']
|
| 345 |
+
i = sets_dict['i']
|
| 346 |
+
iSto = sets_dict['iSto']
|
| 347 |
+
iConv = sets_dict['iConv']
|
| 348 |
+
iPtG = sets_dict['iPtG']
|
| 349 |
+
iRes = sets_dict['iRes']
|
| 350 |
+
iHyRes = sets_dict['iHyRes']
|
| 351 |
+
|
| 352 |
+
# Unpack params_dict into the workspace
|
| 353 |
+
l_co2 = params_dict['l_co2']
|
| 354 |
+
p_co2 = params_dict['p_co2']
|
| 355 |
+
eff_i = params_dict['eff_i']
|
| 356 |
+
life_i = params_dict['life_i']
|
| 357 |
+
c_fuel_i = params_dict['c_fuel_i']
|
| 358 |
+
c_other_i = params_dict['c_other_i']
|
| 359 |
+
c_inv_i = params_dict['c_inv_i']
|
| 360 |
+
co2_factor_i = params_dict['co2_factor_i']
|
| 361 |
+
K_0_i = params_dict['K_0_i']
|
| 362 |
+
e2p_iSto = params_dict['e2p_iSto']
|
| 363 |
+
|
| 364 |
+
# Adjust efficiency for storage technologies
|
| 365 |
+
eff_i.loc[iSto] = np.sqrt(eff_i.loc[iSto]) # Apply square root to cycle efficiency for storage technologies
|
| 366 |
+
|
| 367 |
+
# Create columns for UI layout
|
| 368 |
+
col1, col2 = st.columns([0.30, 0.70], gap="large")
|
| 369 |
+
|
| 370 |
+
# Load input data
|
| 371 |
+
with col1:
|
| 372 |
+
|
| 373 |
+
st.title(df.loc['model_title1', st.session_state.lang])
|
| 374 |
+
|
| 375 |
+
with open('Input_Jahr_2023.xlsx', 'rb') as f:
|
| 376 |
+
st.download_button(df.loc['model_title1.3',st.session_state.lang], f, file_name='Input_Jahr_2023.xlsx') # Download button for Excel template
|
| 377 |
+
|
| 378 |
+
with st.form("input_file"):
|
| 379 |
+
|
| 380 |
+
|
| 381 |
+
st.session_state.url_excel = st.file_uploader(label=df.loc['model_title1.4',st.session_state.lang]) # File uploader for user Excel file
|
| 382 |
+
|
| 383 |
+
#st.title(df.loc['model_title4', st.session_state.lang])
|
| 384 |
+
|
| 385 |
+
run_model_excel = st.form_submit_button(df.loc['model_run_info_excel', st.session_state.lang]) #, key="run_model_button", help=df.loc['run_model_button_info',st.session_state.lang])
|
| 386 |
+
#else:
|
| 387 |
+
# run_model = st.button(df.loc['model_run_info_gui', st.session_state.lang], key="run_model_button", help=df.loc['run_model_button_info',st.session_state.lang])
|
| 388 |
+
|
| 389 |
+
|
| 390 |
+
|
| 391 |
+
|
| 392 |
+
|
| 393 |
+
# Set up user interface for parameters
|
| 394 |
+
with col2:
|
| 395 |
+
|
| 396 |
+
st.title(df.loc['model_title3', st.session_state.lang])
|
| 397 |
+
|
| 398 |
+
|
| 399 |
+
|
| 400 |
+
with st.form("input_custom"):
|
| 401 |
+
|
| 402 |
+
col1form, col2form, col3form = st.columns([0.25, 0.25, 0.50])
|
| 403 |
+
|
| 404 |
+
# colum 1 form
|
| 405 |
+
l_co2 = col1form.slider(value=int(params_dict['l_co2']), min_value=0, max_value=750, label=df.loc['model_label_co2',st.session_state.lang], step=50)
|
| 406 |
+
price_h2 = col1form.slider(value=100, min_value=0, max_value=300, label=df.loc['model_label_h2',st.session_state.lang], step=10)
|
| 407 |
+
for i_idx in params_dict['c_fuel_i'].get_index('i'):
|
| 408 |
+
if i_idx in ['Lignite']:
|
| 409 |
+
params_dict['c_fuel_i'].loc[i_idx] = col1form.slider(value=int(params_dict['c_fuel_i'].loc[i_idx]),
|
| 410 |
+
min_value=0, max_value=300, label=df.loc[f'model_label_{i_idx}',st.session_state.lang], step=10)
|
| 411 |
+
|
| 412 |
+
# colum 1 form
|
| 413 |
+
for i_idx in params_dict['c_fuel_i'].get_index('i'):
|
| 414 |
+
if i_idx in ['Fossil Hard coal', 'Fossil Oil', 'CCGT']:
|
| 415 |
+
params_dict['c_fuel_i'].loc[i_idx] = col2form.slider(value=int(params_dict['c_fuel_i'].loc[i_idx]),
|
| 416 |
+
min_value=0, max_value=300, label=df.loc[f'model_label_{i_idx}',st.session_state.lang], step=10)
|
| 417 |
+
params_dict['c_fuel_i'].loc['OCGT'] = params_dict['c_fuel_i'].loc['CCGT']
|
| 418 |
+
# Create a dictionary to map German names to English names
|
| 419 |
+
tech_mapping_de_to_en = {
|
| 420 |
+
df.loc[f'tech_{tech.lower()}', 'DE']: df.loc[f'tech_{tech.lower()}', 'EN']
|
| 421 |
+
for tech in sets_dict['i'] if f'tech_{tech.lower()}' in df.index
|
| 422 |
+
}
|
| 423 |
+
|
| 424 |
+
# Set options and default values based on the selected language
|
| 425 |
+
if st.session_state.lang == 'DE':
|
| 426 |
+
# German options for the user interface
|
| 427 |
+
options = [
|
| 428 |
+
df.loc[f'tech_{tech.lower()}', 'DE'] for tech in sets_dict['i'] if f'tech_{tech.lower()}' in df.index
|
| 429 |
+
]
|
| 430 |
+
default = [
|
| 431 |
+
df.loc[f'tech_{tech.lower()}', 'DE'] for tech in ['Lignite', 'CCGT', 'OCGT', 'Fossil Hard coal', 'Fossil Oil', 'PV', 'WindOff', 'WindOn', 'H2', 'Pumped Hydro Storage', 'Battery storages', 'Electrolyzer']
|
| 432 |
+
if f'tech_{tech.lower()}' in df.index
|
| 433 |
+
]
|
| 434 |
+
else:
|
| 435 |
+
# English options for the user interface
|
| 436 |
+
options = sets_dict['i']
|
| 437 |
+
default = ['Lignite', 'CCGT', 'OCGT', 'Fossil Hard coal', 'Fossil Oil', 'PV', 'WindOff', 'WindOn', 'H2', 'Pumped Hydro Storage', 'Battery storages', 'Electrolyzer']
|
| 438 |
+
|
| 439 |
+
# Multiselect for technology options in the user interface
|
| 440 |
+
selected_technologies = col3form.multiselect(
|
| 441 |
+
label=df.loc['model_label_tech', st.session_state.lang],
|
| 442 |
+
options=options,
|
| 443 |
+
default=[tech for tech in default if tech in options]
|
| 444 |
+
)
|
| 445 |
+
|
| 446 |
+
# If language is German, map selected German names back to their English equivalents
|
| 447 |
+
if st.session_state.lang == 'DE':
|
| 448 |
+
technologies_invest = [tech_mapping_de_to_en[tech] for tech in selected_technologies]
|
| 449 |
+
else:
|
| 450 |
+
technologies_invest = selected_technologies
|
| 451 |
+
|
| 452 |
+
# Technologies that will not be invested in (based on English names)
|
| 453 |
+
technologies_no_invest = [tech for tech in sets_dict['i'] if tech not in technologies_invest]
|
| 454 |
+
|
| 455 |
+
col4form, col5form = st.columns([0.25, 0.75])
|
| 456 |
+
dt = col4form.number_input(label=df.loc['model_label_t',st.session_state.lang], min_value=1, max_value=len(t), value=6,
|
| 457 |
+
help=df.loc['model_label_t_info',st.session_state.lang])
|
| 458 |
+
|
| 459 |
+
run_model_manual = col5form.form_submit_button(df.loc['model_run_info_gui', st.session_state.lang])
|
| 460 |
+
|
| 461 |
+
#run_model = st.button(df.loc['model_run_info_gui', st.session_state.lang], key="run_model_button", help=df.loc['run_model_button_info',st.session_state.lang])
|
| 462 |
+
|
| 463 |
+
st.markdown("-------")
|
| 464 |
+
|
| 465 |
+
# run_model_manual = True
|
| 466 |
+
|
| 467 |
+
if run_model_excel or run_model_manual:
|
| 468 |
+
# Model setup
|
| 469 |
+
|
| 470 |
+
info_yellow_build = st.info(df.loc['label_build_model', st.session_state.lang])
|
| 471 |
+
|
| 472 |
+
|
| 473 |
+
if run_model_excel: # overwrite with excel values
|
| 474 |
+
#sets_dict, params_dict = load_model_input(df, write_pickle_from_standard_excel)
|
| 475 |
+
sets_dict, params_dict = src.load_data_from_excel(st.session_state.url_excel, write_to_pickle_flag=True)
|
| 476 |
+
|
| 477 |
+
# Unpack sets_dict into the workspace
|
| 478 |
+
t = sets_dict['t']
|
| 479 |
+
t_original = sets_dict['t']
|
| 480 |
+
i = sets_dict['i']
|
| 481 |
+
iSto = sets_dict['iSto']
|
| 482 |
+
iConv = sets_dict['iConv']
|
| 483 |
+
iPtG = sets_dict['iPtG']
|
| 484 |
+
iRes = sets_dict['iRes']
|
| 485 |
+
iHyRes = sets_dict['iHyRes']
|
| 486 |
+
|
| 487 |
+
# Unpack params_dict into the workspace
|
| 488 |
+
l_co2 = params_dict['l_co2']
|
| 489 |
+
p_co2 = params_dict['p_co2']
|
| 490 |
+
eff_i = params_dict['eff_i']
|
| 491 |
+
# life_i = params_dict['life_i']
|
| 492 |
+
c_fuel_i = params_dict['c_fuel_i']
|
| 493 |
+
c_other_i = params_dict['c_other_i']
|
| 494 |
+
c_inv_i = params_dict['c_inv_i']
|
| 495 |
+
co2_factor_i = params_dict['co2_factor_i']
|
| 496 |
+
K_0_i = params_dict['K_0_i']
|
| 497 |
+
e2p_iSto = params_dict['e2p_iSto']
|
| 498 |
+
|
| 499 |
+
# Adjust efficiency for storage technologies
|
| 500 |
+
eff_i.loc[iSto] = np.sqrt(eff_i.loc[iSto]) # Apply square root to cycle efficiency for storage technologies
|
| 501 |
+
|
| 502 |
+
|
| 503 |
+
# Time series aggregation for various parameters
|
| 504 |
+
D_t = timstep_aggregate(dt, params_dict['D_t'], t)
|
| 505 |
+
s_t_r_iRes = timstep_aggregate(dt, params_dict['s_t_r_iRes'], t)
|
| 506 |
+
h_t = timstep_aggregate(dt, params_dict['h_t'], t)
|
| 507 |
+
t = D_t.get_index('t')
|
| 508 |
+
partial_year_factor = (8760 / len(t)) / dt
|
| 509 |
+
|
| 510 |
+
m = Model()
|
| 511 |
+
|
| 512 |
+
# Define Variables
|
| 513 |
+
C_tot = m.add_variables(name='C_tot') # Total costs
|
| 514 |
+
C_op = m.add_variables(name='C_op', lower=0) # Operational costs
|
| 515 |
+
C_inv = m.add_variables(name='C_inv', lower=0) # Investment costs
|
| 516 |
+
K = m.add_variables(coords=[i], name='K', lower=0) # Endogenous capacity
|
| 517 |
+
y = m.add_variables(coords=[t, i], name='y', lower=0) # Electricity production
|
| 518 |
+
y_ch = m.add_variables(coords=[t, i], name='y_ch', lower=0) # Electricity consumption
|
| 519 |
+
l = m.add_variables(coords=[t, i], name='l', lower=0) # Storage filling level
|
| 520 |
+
y_curt = m.add_variables(coords=[t, i], name='y_curt', lower=0) # RES curtailment
|
| 521 |
+
y_h2 = m.add_variables(coords=[t, i], name='y_h2', lower=0) # H2 production
|
| 522 |
+
|
| 523 |
+
# Define Objective function
|
| 524 |
+
C_tot = C_op + C_inv
|
| 525 |
+
m.add_objective(C_tot)
|
| 526 |
+
|
| 527 |
+
# Define Constraints
|
| 528 |
+
# Operational costs minus revenue for produced hydrogen
|
| 529 |
+
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')
|
| 530 |
+
|
| 531 |
+
# Investment costs
|
| 532 |
+
m.add_constraints((K * c_inv_i).sum() == C_inv, name='C_inv_sum')
|
| 533 |
+
|
| 534 |
+
# Load serving
|
| 535 |
+
m.add_constraints((((y).sum(dims='i') - y_ch.sum(dims='i')) * dt == D_t.sel(t=t) * dt), name='load')
|
| 536 |
+
|
| 537 |
+
# Maximum capacity limit
|
| 538 |
+
m.add_constraints((y - K <= K_0_i), name='max_cap')
|
| 539 |
+
|
| 540 |
+
# Capacity limits for investment
|
| 541 |
+
m.add_constraints((K.sel(i=technologies_no_invest) <= 0), name='max_cap_invest')
|
| 542 |
+
|
| 543 |
+
# Prevent power production by PtG
|
| 544 |
+
m.add_constraints((y.sel(i=iPtG) <= 0), name='prevent_ptg_prod')
|
| 545 |
+
|
| 546 |
+
# Prevent charging for non-storage technologies
|
| 547 |
+
m.add_constraints((y_ch.sel(i=[x for x in i if x not in iPtG and x not in iSto]) <= 0), name='no_charging')
|
| 548 |
+
|
| 549 |
+
# Maximum storage charging and discharging
|
| 550 |
+
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')
|
| 551 |
+
|
| 552 |
+
# Maximum electrolyzer capacity
|
| 553 |
+
m.add_constraints((y_ch.sel(i=iPtG) - K.sel(i=iPtG) <= K_0_i.sel(i=iPtG)), name='max_cha_ptg')
|
| 554 |
+
|
| 555 |
+
# PtG H2 production
|
| 556 |
+
m.add_constraints(y_ch.sel(i=iPtG) * eff_i.sel(i=iPtG) == y_h2.sel(i=iPtG), name='ptg_h2_prod')
|
| 557 |
+
|
| 558 |
+
# Infeed of renewables
|
| 559 |
+
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')
|
| 560 |
+
|
| 561 |
+
# Maximum filling level restriction for storage power plants
|
| 562 |
+
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')
|
| 563 |
+
|
| 564 |
+
# Filling level restriction for hydro reservoir
|
| 565 |
+
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')
|
| 566 |
+
|
| 567 |
+
# Filling level restriction for other storages
|
| 568 |
+
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')
|
| 569 |
+
|
| 570 |
+
# CO2 limit
|
| 571 |
+
m.add_constraints(((y / eff_i) * co2_factor_i * dt).sum() <= l_co2 * 1_000_000, name='CO2_limit')
|
| 572 |
+
|
| 573 |
+
# Solve the model
|
| 574 |
+
info_yellow_build.empty()
|
| 575 |
+
info_green_build = st.success(df.loc['label_build_model', st.session_state.lang])
|
| 576 |
+
info_yellow_solve = st.info(df.loc['label_solve_model', st.session_state.lang])
|
| 577 |
+
|
| 578 |
+
|
| 579 |
+
m.solve(solver_name='highs')
|
| 580 |
+
|
| 581 |
+
info_yellow_solve.empty()
|
| 582 |
+
info_green_solve = st.success(df.loc['label_solve_model', st.session_state.lang])
|
| 583 |
+
info_yellow_plot = st.info(df.loc['label_generate_plots', st.session_state.lang])
|
| 584 |
+
|
| 585 |
+
|
| 586 |
+
|
| 587 |
+
# Prepare columns for figures
|
| 588 |
+
colb1, colb2 = st.columns(2)
|
| 589 |
+
|
| 590 |
+
# Generate and display figures
|
| 591 |
+
st.markdown("---")
|
| 592 |
+
|
| 593 |
+
df_total_costs = plot_total_costs(m, colb1, df)
|
| 594 |
+
df_CO2_price = plot_co2_price(m, colb2, df)
|
| 595 |
+
df_new_capacities = plot_new_capacities(m, color_dict, colb1, df)
|
| 596 |
+
|
| 597 |
+
# Only plot production for technologies with capacity
|
| 598 |
+
i_with_capacity = m.solution['K'].where((m.solution['K'] > 0) & (m.solution['i'] != 'Electrolyzer')).dropna(dim='i').get_index('i')
|
| 599 |
+
df_production = plot_production(m, i_with_capacity, dt, color_dict, colb2, df)
|
| 600 |
+
# df_price = plot_electricity_prices(m, dt, colb2, df)
|
| 601 |
+
df_curtailment = plot_curtailment(m, iRes, color_dict, colb1, df)
|
| 602 |
+
df_residual_load_duration = plot_residual_load_duration(m, dt, colb1, df, D_t, i_with_capacity, iRes, color_dict, df_curtailment, iConv)
|
| 603 |
+
df_price = plot_electricity_prices(m, dt, colb2, df, df_residual_load_duration)
|
| 604 |
+
|
| 605 |
+
df_contr_marg = plot_contribution_margin(m, dt, i_with_capacity, color_dict, colb1, df)
|
| 606 |
+
# df_curtailment = plot_curtailment(m, iRes, color_dict, colb1, df)
|
| 607 |
+
df_charging = plot_storage_charging(m, iSto, color_dict, colb2, df)
|
| 608 |
+
df_h2_prod = plot_hydrogen_production(m, iPtG, color_dict, colb1, df)
|
| 609 |
+
|
| 610 |
+
# df_stackplot = plot_stackplot(m)
|
| 611 |
+
|
| 612 |
+
# Export results
|
| 613 |
+
|
| 614 |
+
st.session_state.output = BytesIO()
|
| 615 |
+
|
| 616 |
+
|
| 617 |
+
with pd.ExcelWriter(st.session_state.output, engine='xlsxwriter') as writer:
|
| 618 |
+
disaggregate_df(df_total_costs, t, t_original, dt).to_excel(writer, sheet_name=df.loc['sheet_name_total_costs', st.session_state.lang], index=False)
|
| 619 |
+
disaggregate_df(df_CO2_price, t, t_original, dt).to_excel(writer, sheet_name=df.loc['sheet_name_co2_price', st.session_state.lang], index=False)
|
| 620 |
+
disaggregate_df(df_price, t, t_original, dt).to_excel(writer, sheet_name=df.loc['sheet_name_prices', st.session_state.lang], index=False)
|
| 621 |
+
disaggregate_df(df_contr_marg, t, t_original, dt).to_excel(writer, sheet_name=df.loc['sheet_name_contribution_margin', st.session_state.lang], index=False)
|
| 622 |
+
disaggregate_df(df_new_capacities, t, t_original, dt).to_excel(writer, sheet_name=df.loc['sheet_name_capacities', st.session_state.lang], index=False)
|
| 623 |
+
disaggregate_df(df_production, t, t_original, dt).to_excel(writer, sheet_name=df.loc['sheet_name_production', st.session_state.lang], index=False)
|
| 624 |
+
disaggregate_df(df_charging, t, t_original, dt).to_excel(writer, sheet_name=df.loc['sheet_name_charging', st.session_state.lang], index=False)
|
| 625 |
+
disaggregate_df(D_t.to_dataframe().reset_index(), t, t_original, dt).to_excel(writer, sheet_name=df.loc['sheet_name_demand', st.session_state.lang], index=False)
|
| 626 |
+
disaggregate_df(df_curtailment, t, t_original, dt).to_excel(writer, sheet_name=df.loc['sheet_name_curtailment', st.session_state.lang], index=False)
|
| 627 |
+
disaggregate_df(df_h2_prod, t, t_original, dt).to_excel(writer, sheet_name=df.loc['sheet_name_h2_production', st.session_state.lang], index=False)
|
| 628 |
+
|
| 629 |
+
with col1:
|
| 630 |
+
st.title(df.loc['model_title2', st.session_state.lang])
|
| 631 |
+
|
| 632 |
+
st.download_button(label=df.loc['model_title2.1',st.session_state.lang], disabled=(st.session_state.output.getbuffer().nbytes==0), data=st.session_state.output.getvalue(), file_name="workbook.xlsx", mime="application/vnd.ms-excel")
|
| 633 |
+
|
| 634 |
+
info_yellow_plot.empty()
|
| 635 |
+
info_green_plot = st.success(df.loc['label_generate_plots', st.session_state.lang])
|
| 636 |
+
|
| 637 |
+
time.sleep(1)
|
| 638 |
+
|
| 639 |
+
info_green_build.empty()
|
| 640 |
+
info_green_solve.empty()
|
| 641 |
+
info_green_plot.empty()
|
| 642 |
+
|
| 643 |
+
st.stop()
|
| 644 |
+
|
| 645 |
+
|
| 646 |
+
|
| 647 |
+
# st.rerun()
|
| 648 |
+
|
| 649 |
+
|
| 650 |
+
def timstep_aggregate(time_steps_aggregate, xr_data, t):
|
| 651 |
+
"""
|
| 652 |
+
Aggregates time steps in the data using rolling mean and selects based on step size.
|
| 653 |
+
"""
|
| 654 |
+
return xr_data.rolling(t=time_steps_aggregate).mean().sel(t=t[0::time_steps_aggregate])
|
| 655 |
+
|
| 656 |
+
# Visualization functions
|
| 657 |
+
|
| 658 |
+
def plot_total_costs(m, col, df):
|
| 659 |
+
"""
|
| 660 |
+
Displays the total costs.
|
| 661 |
+
"""
|
| 662 |
+
total_costs = float(m.solution['C_inv'].values) + float(m.solution['C_op'].values)
|
| 663 |
+
total_costs_rounded = round(total_costs / 1e9, 2)
|
| 664 |
+
with col:
|
| 665 |
+
st.markdown(
|
| 666 |
+
f"<h3><b>{df.loc['plot_label_total_costs', st.session_state.lang]} {total_costs_rounded}</b></h3>",
|
| 667 |
+
unsafe_allow_html=True
|
| 668 |
+
)
|
| 669 |
+
|
| 670 |
+
df_total_costs = pd.DataFrame({'Total costs':[total_costs]})
|
| 671 |
+
return df_total_costs
|
| 672 |
+
|
| 673 |
+
def plot_co2_price(m, col, df):
|
| 674 |
+
"""
|
| 675 |
+
Displays the CO2 price based on the CO2 constraint dual values.
|
| 676 |
+
"""
|
| 677 |
+
CO2_price = float(m.constraints['CO2_limit'].dual.values) * (-1)
|
| 678 |
+
CO2_price_rounded = round(CO2_price, 2)
|
| 679 |
+
df_CO2_price = pd.DataFrame({'CO2 price': [CO2_price]})
|
| 680 |
+
with col:
|
| 681 |
+
st.markdown(
|
| 682 |
+
f"<h3><b>{df.loc['plot_label_co2_price', st.session_state.lang]} {CO2_price_rounded}</b></h3>",
|
| 683 |
+
unsafe_allow_html=True
|
| 684 |
+
)
|
| 685 |
+
|
| 686 |
+
return df_CO2_price
|
| 687 |
+
|
| 688 |
+
|
| 689 |
+
def plot_new_capacities(m, color_dict, col, df):
|
| 690 |
+
"""
|
| 691 |
+
Plots the new capacities installed in MW as a bar chart and pie chart.
|
| 692 |
+
Includes technologies with 0 MW capacity in the bar chart.
|
| 693 |
+
Supports both German and English labels for technologies while ensuring color consistency.
|
| 694 |
+
"""
|
| 695 |
+
# Convert the solution for new capacities to a DataFrame
|
| 696 |
+
df_new_capacities = m.solution['K'].round(0).to_dataframe().reset_index()
|
| 697 |
+
|
| 698 |
+
# Store the English technology names in a separate column to maintain color consistency
|
| 699 |
+
df_new_capacities['i_en'] = df_new_capacities['i']
|
| 700 |
+
|
| 701 |
+
# Check if the language is German and map English names to German for display
|
| 702 |
+
if st.session_state.lang == 'DE':
|
| 703 |
+
tech_mapping_en_to_de = {
|
| 704 |
+
df.loc[f'tech_{tech.lower()}', 'EN']: df.loc[f'tech_{tech.lower()}', 'DE']
|
| 705 |
+
for tech in df_new_capacities['i_en'] if f'tech_{tech.lower()}' in df.index
|
| 706 |
+
}
|
| 707 |
+
# Replace the English technology names with German ones for display
|
| 708 |
+
df_new_capacities['i'] = df_new_capacities['i_en'].replace(tech_mapping_en_to_de)
|
| 709 |
+
|
| 710 |
+
# Bar plot for new capacities (including technologies with 0 MW)
|
| 711 |
+
fig_bar = px.bar(df_new_capacities, y='i', x='K', orientation='h',
|
| 712 |
+
title=df.loc['plot_label_new_capacities', st.session_state.lang],
|
| 713 |
+
color='i_en', # Use the English names for consistent coloring
|
| 714 |
+
color_discrete_map=color_dict,
|
| 715 |
+
labels={'K': '', 'i': ''} # Delete double labeling
|
| 716 |
+
)
|
| 717 |
+
|
| 718 |
+
# Hide the legend completely since the labels are already next to the bars
|
| 719 |
+
fig_bar.update_layout(showlegend=False)
|
| 720 |
+
|
| 721 |
+
with col:
|
| 722 |
+
st.plotly_chart(fig_bar)
|
| 723 |
+
|
| 724 |
+
# Pie chart for new capacities (only show technologies with K > 0 in pie chart)
|
| 725 |
+
df_new_capacities_filtered = df_new_capacities[df_new_capacities["K"] > 0]
|
| 726 |
+
fig_pie = px.pie(df_new_capacities_filtered, names='i', values='K',
|
| 727 |
+
title=df.loc['plot_label_new_capacities_pie', st.session_state.lang],
|
| 728 |
+
color='i_en', color_discrete_map=color_dict)
|
| 729 |
+
|
| 730 |
+
# Remove English labels (i_en) from the pie chart legend
|
| 731 |
+
fig_pie.update_layout(legend_title_text=df.loc['label_technology', st.session_state.lang])
|
| 732 |
+
fig_pie.for_each_trace(lambda t: t.update(name=df_new_capacities_filtered['i'].iloc[0] if st.session_state.lang == 'DE' else t.name))
|
| 733 |
+
|
| 734 |
+
with col:
|
| 735 |
+
st.plotly_chart(fig_pie)
|
| 736 |
+
|
| 737 |
+
return df_new_capacities
|
| 738 |
+
|
| 739 |
+
|
| 740 |
+
def plot_production(m, i_with_capacity, dt, color_dict, col, df):
|
| 741 |
+
"""
|
| 742 |
+
Plots the energy production for technologies with capacity as an area chart.
|
| 743 |
+
Supports both German and English labels for technologies while ensuring color consistency.
|
| 744 |
+
"""
|
| 745 |
+
# Convert the production data to a DataFrame
|
| 746 |
+
df_production = m.solution['y'].sel(i=i_with_capacity).to_dataframe().reset_index()
|
| 747 |
+
|
| 748 |
+
# Store the English technology names in a separate column to maintain color consistency
|
| 749 |
+
df_production['i_en'] = df_production['i']
|
| 750 |
+
|
| 751 |
+
# Convert 't'-column in a datetime format
|
| 752 |
+
df_production['t'] = df_production['t'].str.strip("'")
|
| 753 |
+
df_production['t'] = pd.to_datetime(df_production['t'], format='%Y-%m-%d %H:%M %z')
|
| 754 |
+
|
| 755 |
+
# Check if the language is German and map English names to German for display
|
| 756 |
+
if st.session_state.lang == 'DE':
|
| 757 |
+
tech_mapping_en_to_de = {
|
| 758 |
+
df.loc[f'tech_{tech.lower()}', 'EN']: df.loc[f'tech_{tech.lower()}', 'DE']
|
| 759 |
+
for tech in df_production['i_en'] if f'tech_{tech.lower()}' in df.index
|
| 760 |
+
}
|
| 761 |
+
# Replace the English technology names with German ones for display
|
| 762 |
+
df_production['i'] = df_production['i_en'].replace(tech_mapping_en_to_de)
|
| 763 |
+
|
| 764 |
+
# Area plot for energy production
|
| 765 |
+
fig = px.area(df_production, y='y', x='t',
|
| 766 |
+
title=df.loc['plot_label_production', st.session_state.lang],
|
| 767 |
+
color='i_en', # Use the English names for consistent coloring
|
| 768 |
+
color_discrete_map=color_dict,
|
| 769 |
+
labels={'y': '', 't': '', 'i_en': df.loc['label_technology', st.session_state.lang]} # Delete double labeling
|
| 770 |
+
)
|
| 771 |
+
|
| 772 |
+
# Update legend labels to display German names instead of English
|
| 773 |
+
if st.session_state.lang == 'DE':
|
| 774 |
+
fig.for_each_trace(lambda trace: trace.update(name=tech_mapping_en_to_de[trace.name]))
|
| 775 |
+
|
| 776 |
+
fig.update_traces(line=dict(width=0))
|
| 777 |
+
fig.for_each_trace(lambda trace: trace.update(fillcolor=trace.line.color))
|
| 778 |
+
|
| 779 |
+
# # Customize x-axis for better date formatting
|
| 780 |
+
# fig.update_layout(
|
| 781 |
+
# xaxis=dict(
|
| 782 |
+
# tickformat="%d/%m/%Y", # Display months and years in MM/YYYY format
|
| 783 |
+
# title='', # No title for the x-axis
|
| 784 |
+
# type="date" # Ensure x-axis is treated as a date axis
|
| 785 |
+
# ),
|
| 786 |
+
# xaxis_tickangle=-45 # Tilt the ticks for better readability
|
| 787 |
+
# )
|
| 788 |
+
|
| 789 |
+
with col:
|
| 790 |
+
st.plotly_chart(fig)
|
| 791 |
+
|
| 792 |
+
# Pie chart for total production
|
| 793 |
+
df_production_sum = (df_production.groupby(['i', 'i_en'])['y'].sum() * dt / 1000).round(0).reset_index()
|
| 794 |
+
|
| 795 |
+
# If the language is set to German, display German labels, otherwise use English
|
| 796 |
+
pie_column = 'i' if st.session_state.lang == 'DE' else 'i_en'
|
| 797 |
+
|
| 798 |
+
# Pie chart for total production
|
| 799 |
+
fig_pie = px.pie(df_production_sum, names=pie_column, values='y',
|
| 800 |
+
title=df.loc['plot_label_total_production_pie', st.session_state.lang],
|
| 801 |
+
color='i_en', # Ensure the coloring stays consistent using the 'i_en' column
|
| 802 |
+
color_discrete_map=color_dict)
|
| 803 |
+
|
| 804 |
+
# Update legend title to reflect the correct language
|
| 805 |
+
fig_pie.update_layout(legend_title_text=df.loc['label_technology', st.session_state.lang])
|
| 806 |
+
|
| 807 |
+
with col:
|
| 808 |
+
st.plotly_chart(fig_pie)
|
| 809 |
+
|
| 810 |
+
return df_production
|
| 811 |
+
|
| 812 |
+
|
| 813 |
+
def plot_electricity_prices(m, dt, col, df, df_residual_load_duration):
|
| 814 |
+
"""
|
| 815 |
+
Plots the electricity price and the price duration curve.
|
| 816 |
+
Supports both German and English labels for the plot titles and axis labels.
|
| 817 |
+
"""
|
| 818 |
+
# Convert the dual constraints to a DataFrame
|
| 819 |
+
df_price = m.constraints['load'].dual.to_dataframe().reset_index()
|
| 820 |
+
|
| 821 |
+
# Convert 't'-column in a datetime format
|
| 822 |
+
df_price['t'] = df_price['t'].str.strip("'")
|
| 823 |
+
df_price['t'] = pd.to_datetime(df_price['t'], format='%Y-%m-%d %H:%M %z')
|
| 824 |
+
|
| 825 |
+
# Line plot for electricity prices
|
| 826 |
+
fig_price = px.line(df_price, y='dual', x='t',
|
| 827 |
+
title=df.loc['plot_label_electricity_prices', st.session_state.lang],
|
| 828 |
+
labels={'dual': '', 't': ''}
|
| 829 |
+
)
|
| 830 |
+
with col:
|
| 831 |
+
st.plotly_chart(fig_price)
|
| 832 |
+
|
| 833 |
+
# Create the price duration curve
|
| 834 |
+
df_sorted_price = df_price["dual"].repeat(dt).sort_values(ascending=False).reset_index(drop=True) / int(dt)
|
| 835 |
+
df_residual_load_sorted = df_residual_load_duration.sort_values(by='Residual_Load', ascending=False).reset_index(drop=True)
|
| 836 |
+
df_axis2 = df_residual_load_sorted['Residual_Load']
|
| 837 |
+
|
| 838 |
+
ax2_max = np.max(df_axis2)
|
| 839 |
+
ax2_min = np.min(df_axis2)
|
| 840 |
+
|
| 841 |
+
fig_duration = go.Figure()
|
| 842 |
+
|
| 843 |
+
# Add primary y-axis trace (Price duration curve)
|
| 844 |
+
fig_duration.add_trace(go.Scatter(
|
| 845 |
+
x=df_sorted_price.index,
|
| 846 |
+
y=df_sorted_price,
|
| 847 |
+
mode='lines',
|
| 848 |
+
name=df.loc['plot_label_price_duration_curve', st.session_state.lang],
|
| 849 |
+
line=dict(color='blue', width=2)
|
| 850 |
+
))
|
| 851 |
+
|
| 852 |
+
# Add secondary y-axis trace (Residual load)
|
| 853 |
+
fig_duration.add_trace(go.Scatter(
|
| 854 |
+
x=df_axis2.index,
|
| 855 |
+
y=df_axis2,
|
| 856 |
+
mode='lines',
|
| 857 |
+
name=df.loc['plot_label_residual_load', st.session_state.lang],
|
| 858 |
+
line=dict(color='red', width=2),
|
| 859 |
+
yaxis='y2'
|
| 860 |
+
))
|
| 861 |
+
|
| 862 |
+
# Layout mit neuen title-formaten (kein titlefont mehr!)
|
| 863 |
+
fig_duration.update_layout(
|
| 864 |
+
title=df.loc['plot_label_price_duration_curve', st.session_state.lang],
|
| 865 |
+
xaxis=dict(
|
| 866 |
+
title=df.loc['label_hours', st.session_state.lang]
|
| 867 |
+
),
|
| 868 |
+
yaxis=dict(
|
| 869 |
+
title=dict(
|
| 870 |
+
text=df.loc['plot_label_price_duration_curve', st.session_state.lang],
|
| 871 |
+
font=dict(color='blue')
|
| 872 |
+
),
|
| 873 |
+
range=[-(100/(ax2_max/(ax2_max-ax2_min))-100), 100],
|
| 874 |
+
tickfont=dict(color='blue')
|
| 875 |
+
),
|
| 876 |
+
yaxis2=dict(
|
| 877 |
+
title=dict(
|
| 878 |
+
text=df.loc['plot_label_residual_load', st.session_state.lang],
|
| 879 |
+
font=dict(color='red')
|
| 880 |
+
),
|
| 881 |
+
range=[ax2_min, ax2_max],
|
| 882 |
+
tickfont=dict(color='red'),
|
| 883 |
+
overlaying='y',
|
| 884 |
+
side='right'
|
| 885 |
+
),
|
| 886 |
+
legend=dict(
|
| 887 |
+
x=1,
|
| 888 |
+
y=1,
|
| 889 |
+
xanchor='right',
|
| 890 |
+
yanchor='top',
|
| 891 |
+
bgcolor='rgba(255, 255, 255, 0.5)',
|
| 892 |
+
bordercolor='black',
|
| 893 |
+
borderwidth=1
|
| 894 |
+
)
|
| 895 |
+
)
|
| 896 |
+
|
| 897 |
+
with col:
|
| 898 |
+
st.plotly_chart(fig_duration)
|
| 899 |
+
|
| 900 |
+
return df_price
|
| 901 |
+
|
| 902 |
+
def plot_residual_load_duration(m, dt, col, df, D_t, i_with_capacity, iRes, color_dict, df_curtailment, iConv):
|
| 903 |
+
"""
|
| 904 |
+
Plots the residual load and corresponding production as a stacked area chart.
|
| 905 |
+
Supports both German and English labels for the plot titles and axis labels.
|
| 906 |
+
Consistent color coding for technologies using a predefined color dictionary.
|
| 907 |
+
"""
|
| 908 |
+
|
| 909 |
+
# Extract load data and repeat each value to match the total number of hours in the year
|
| 910 |
+
df_load = D_t.values.flatten()
|
| 911 |
+
total_hours = len(df_load) * dt # Calculate the total number of hours dynamically
|
| 912 |
+
repeated_load = np.repeat(df_load, dt)[:total_hours] # Repeat values to represent each hour
|
| 913 |
+
|
| 914 |
+
# Convert production data to DataFrame
|
| 915 |
+
df_production = m.solution['y'].sel(i=i_with_capacity).to_dataframe().reset_index()
|
| 916 |
+
|
| 917 |
+
# Pivot production data to get technologies as columns and time 't' as index
|
| 918 |
+
df_production_pivot = df_production.pivot(index='t', columns='i', values='y')
|
| 919 |
+
|
| 920 |
+
# Repeat the pivoted production data to match the number of hours
|
| 921 |
+
repeated_index = np.repeat(df_production_pivot.index, dt)[:total_hours] # Create repeated index
|
| 922 |
+
df_production_repeated = df_production_pivot.loc[repeated_index].reset_index(drop=True)
|
| 923 |
+
|
| 924 |
+
# Create load series with the same index as the repeated production data
|
| 925 |
+
df_load_series = pd.Series(repeated_load, index=df_production_repeated.index, name='Load')
|
| 926 |
+
|
| 927 |
+
# Combine load with repeated production data
|
| 928 |
+
df_combined = df_production_repeated.copy()
|
| 929 |
+
df_combined['Load'] = df_load_series
|
| 930 |
+
|
| 931 |
+
# Identify renewable technologies from iRes
|
| 932 |
+
iRes_list = iRes.tolist() # Convert the Index to a list
|
| 933 |
+
|
| 934 |
+
# Calculate renewable generation (only include available technologies in df_combined)
|
| 935 |
+
renewable_columns = [col for col in iRes_list if col in df_combined.columns]
|
| 936 |
+
df_combined['Renewable_Generation'] = df_combined[renewable_columns].sum(axis=1) if renewable_columns else 0
|
| 937 |
+
|
| 938 |
+
# Create pivot table of curtailment
|
| 939 |
+
df_curtailment_pivot = df_curtailment.pivot(index='t', columns='i', values='y_curt')
|
| 940 |
+
repeated_index = np.repeat(df_curtailment_pivot.index, dt)[:total_hours] # Create repeated index
|
| 941 |
+
df_curtailment_repeated = df_curtailment_pivot.loc[repeated_index].reset_index(drop=True)
|
| 942 |
+
df_curtailment_repeated['Sum'] = df_curtailment_repeated.sum(axis=1)
|
| 943 |
+
df_combined['Sum_curtailment'] = -df_curtailment_repeated['Sum']
|
| 944 |
+
|
| 945 |
+
# Calculate residual load as the difference between total load and renewable generation
|
| 946 |
+
df_combined['Residual_Load'] = df_combined['Load'] - df_combined['Renewable_Generation'] + df_combined['Sum_curtailment']
|
| 947 |
+
|
| 948 |
+
# Sort DataFrame by residual load (descending order) to create the duration curve
|
| 949 |
+
df_sorted = df_combined.sort_values(by='Residual_Load', ascending=False).reset_index(drop=True)
|
| 950 |
+
|
| 951 |
+
# Identify all technology columns except 'Load', 'Residual_Load', 'Renewable_Generation'
|
| 952 |
+
technology_columns = [col for col in df_combined.columns if col not in ['Load', 'Residual_Load', 'Renewable_Generation', 'Sum_curtailment']]
|
| 953 |
+
|
| 954 |
+
# Mapping English technology names to German (if desired)
|
| 955 |
+
if st.session_state.lang == 'DE':
|
| 956 |
+
tech_mapping_en_to_de = {
|
| 957 |
+
df.loc[f'tech_{tech.lower()}', 'EN']: df.loc[f'tech_{tech.lower()}', 'DE']
|
| 958 |
+
for tech in technology_columns if f'tech_{tech.lower()}' in df.index
|
| 959 |
+
}
|
| 960 |
+
else:
|
| 961 |
+
tech_mapping_en_to_de = {tech: tech for tech in technology_columns} # Use the original names if not in German
|
| 962 |
+
|
| 963 |
+
|
| 964 |
+
# Plotting with Plotly - Creating stacked area chart
|
| 965 |
+
fig = go.Figure()
|
| 966 |
+
|
| 967 |
+
# Sort technology_columns based on the highest index in df_sorted (only for iConv); others are placed at the end
|
| 968 |
+
sorted_technology_columns = sorted(
|
| 969 |
+
technology_columns,
|
| 970 |
+
key=lambda tech: (
|
| 971 |
+
tech not in iConv, # Place non-iConv technologies at the end
|
| 972 |
+
-df_sorted[df_sorted[tech] != 0].index.max() if tech in iConv and not df_sorted[df_sorted[tech] != 0].empty else float('inf')
|
| 973 |
+
)
|
| 974 |
+
)
|
| 975 |
+
|
| 976 |
+
|
| 977 |
+
# Add stacked area traces for each production technology with consistent colors and language-specific names
|
| 978 |
+
for tech in sorted_technology_columns:
|
| 979 |
+
tech_name = tech_mapping_en_to_de.get(tech, tech) # Get the translated name or fallback to the original
|
| 980 |
+
fig.add_trace(go.Scatter(
|
| 981 |
+
x=df_sorted.index,
|
| 982 |
+
y=df_sorted[tech],
|
| 983 |
+
mode='lines',
|
| 984 |
+
stackgroup='one', # For stacking traces
|
| 985 |
+
name=tech_name,
|
| 986 |
+
line=dict(width=0.5, color=color_dict.get(tech))
|
| 987 |
+
))
|
| 988 |
+
|
| 989 |
+
# Add residual load trace as a red line
|
| 990 |
+
fig.add_trace(go.Scatter(
|
| 991 |
+
x=df_sorted.index,
|
| 992 |
+
y=df_sorted['Residual_Load'],
|
| 993 |
+
mode='lines',
|
| 994 |
+
name=df.loc['plot_label_residual_load', st.session_state.lang], # Residual load label in current language
|
| 995 |
+
line=dict(color='red', width=2)
|
| 996 |
+
))
|
| 997 |
+
|
| 998 |
+
|
| 999 |
+
# Add curtailment trace as a shaded area with a dark yellow tone
|
| 1000 |
+
fig.add_trace(go.Scatter(
|
| 1001 |
+
x=df_sorted.index,
|
| 1002 |
+
y=df_sorted['Sum_curtailment'],
|
| 1003 |
+
mode='lines', # Line mode for the boundary of the area
|
| 1004 |
+
name=df.loc['plot_label_sum_curtailment', st.session_state.lang], # Curtailment label in current language
|
| 1005 |
+
line=dict(color='rgba(204, 153, 0, 1)', width=1.5), # Dark yellow line
|
| 1006 |
+
fill='tozeroy', # Fill area down to the x-axis
|
| 1007 |
+
fillcolor='rgba(204, 153, 0, 0.3)' # Semi-transparent dark yellow for the fill
|
| 1008 |
+
))
|
| 1009 |
+
|
| 1010 |
+
# Layout settings for the plot
|
| 1011 |
+
fig.update_layout(
|
| 1012 |
+
title=df.loc['plot_label_residual_load_curve', st.session_state.lang],
|
| 1013 |
+
xaxis_title=df.loc['label_hours', st.session_state.lang],
|
| 1014 |
+
template="plotly_white",
|
| 1015 |
+
)
|
| 1016 |
+
|
| 1017 |
+
# Display the plot in Streamlit
|
| 1018 |
+
with col:
|
| 1019 |
+
st.plotly_chart(fig)
|
| 1020 |
+
|
| 1021 |
+
return df_combined
|
| 1022 |
+
|
| 1023 |
+
|
| 1024 |
+
|
| 1025 |
+
def plot_contribution_margin(m, dt, i_with_capacity, color_dict, col, df):
|
| 1026 |
+
"""
|
| 1027 |
+
Plots the contribution margin for each technology.
|
| 1028 |
+
Supports both German and English labels for titles and axes while ensuring color consistency.
|
| 1029 |
+
"""
|
| 1030 |
+
# Convert the dual constraints to a DataFrame
|
| 1031 |
+
df_contr_marg = m.constraints['max_cap'].dual.sel(i=i_with_capacity).to_dataframe().reset_index()
|
| 1032 |
+
|
| 1033 |
+
# Adjust the 'dual' values for the contribution margin calculation
|
| 1034 |
+
df_contr_marg['dual'] = df_contr_marg['dual'] / dt * (-1)
|
| 1035 |
+
|
| 1036 |
+
# Store the English technology names in a separate column to maintain color consistency
|
| 1037 |
+
df_contr_marg['i_en'] = df_contr_marg['i']
|
| 1038 |
+
|
| 1039 |
+
# Convert 't'-column in a datetime format
|
| 1040 |
+
df_contr_marg['t'] = pd.to_datetime(df_contr_marg['t'].str.strip("'"), format='%Y-%m-%d %H:%M %z')
|
| 1041 |
+
|
| 1042 |
+
# Check if the language is German and map English names to German for display
|
| 1043 |
+
if st.session_state.lang == 'DE':
|
| 1044 |
+
tech_mapping_en_to_de = {
|
| 1045 |
+
df.loc[f'tech_{tech.lower()}', 'EN']: df.loc[f'tech_{tech.lower()}', 'DE']
|
| 1046 |
+
for tech in df_contr_marg['i_en'] if f'tech_{tech.lower()}' in df.index
|
| 1047 |
+
}
|
| 1048 |
+
# Replace the English technology names with German ones for display
|
| 1049 |
+
df_contr_marg['i'] = df_contr_marg['i_en'].replace(tech_mapping_en_to_de)
|
| 1050 |
+
|
| 1051 |
+
# Plot contribution margin for each technology
|
| 1052 |
+
fig = px.line(df_contr_marg, y='dual', x='t',
|
| 1053 |
+
title=df.loc['plot_label_contribution_margin', st.session_state.lang],
|
| 1054 |
+
color='i_en', # Use the English names for consistent coloring
|
| 1055 |
+
range_y=[0, 250], color_discrete_map=color_dict,
|
| 1056 |
+
labels={'dual':'', 't':'', 'i_en':''}
|
| 1057 |
+
)
|
| 1058 |
+
|
| 1059 |
+
# Update legend to display the correct language
|
| 1060 |
+
fig.update_layout(legend_title_text=df.loc['label_technology', st.session_state.lang])
|
| 1061 |
+
|
| 1062 |
+
# For German language, update the legend to show German technology names
|
| 1063 |
+
if st.session_state.lang == 'DE':
|
| 1064 |
+
fig.for_each_trace(lambda t: t.update(name=df_contr_marg.loc[df_contr_marg['i_en'] == t.name, 'i'].values[0]))
|
| 1065 |
+
|
| 1066 |
+
# Display the plot
|
| 1067 |
+
with col:
|
| 1068 |
+
st.plotly_chart(fig)
|
| 1069 |
+
|
| 1070 |
+
return df_contr_marg
|
| 1071 |
+
|
| 1072 |
+
|
| 1073 |
+
|
| 1074 |
+
|
| 1075 |
+
def plot_curtailment(m, iRes, color_dict, col, df):
|
| 1076 |
+
"""
|
| 1077 |
+
Plots the curtailment of renewable energy.
|
| 1078 |
+
Supports both German and English labels for titles and axes while ensuring color consistency.
|
| 1079 |
+
"""
|
| 1080 |
+
# Convert the curtailment solution to a DataFrame
|
| 1081 |
+
df_curtailment = m.solution['y_curt'].sel(i=iRes).to_dataframe().reset_index()
|
| 1082 |
+
|
| 1083 |
+
# Convert 't'-column in a datetime format
|
| 1084 |
+
df_curtailment['t'] = pd.to_datetime(df_curtailment['t'].str.strip("'"), format='%Y-%m-%d %H:%M %z')
|
| 1085 |
+
|
| 1086 |
+
# Store the English technology names in a separate column to maintain color consistency
|
| 1087 |
+
df_curtailment['i_en'] = df_curtailment['i']
|
| 1088 |
+
|
| 1089 |
+
# Check if the language is German and map English names to German for display
|
| 1090 |
+
if st.session_state.lang == 'DE':
|
| 1091 |
+
tech_mapping_en_to_de = {
|
| 1092 |
+
df.loc[f'tech_{tech.lower()}', 'EN']: df.loc[f'tech_{tech.lower()}', 'DE']
|
| 1093 |
+
for tech in df_curtailment['i_en'] if f'tech_{tech.lower()}' in df.index
|
| 1094 |
+
}
|
| 1095 |
+
# Replace the English technology names with German ones for display
|
| 1096 |
+
df_curtailment['i'] = df_curtailment['i_en'].replace(tech_mapping_en_to_de)
|
| 1097 |
+
else:
|
| 1098 |
+
df_curtailment['i'] = df_curtailment['i_en'] # Use English names if not German
|
| 1099 |
+
|
| 1100 |
+
# Area plot for curtailment of renewable energy
|
| 1101 |
+
fig = px.area(df_curtailment, y='y_curt', x='t',
|
| 1102 |
+
title=df.loc['plot_label_curtailment', st.session_state.lang],
|
| 1103 |
+
color='i_en', # Use the English names for consistent coloring
|
| 1104 |
+
color_discrete_map=color_dict,
|
| 1105 |
+
labels={'y_curt': '', 't': ''} # Delete double labeling
|
| 1106 |
+
)
|
| 1107 |
+
|
| 1108 |
+
# Remove line traces and use fill colors for the area plot
|
| 1109 |
+
fig.update_traces(line=dict(width=0))
|
| 1110 |
+
fig.for_each_trace(lambda trace: trace.update(fillcolor=trace.line.color))
|
| 1111 |
+
|
| 1112 |
+
# Update the legend title to reflect the correct language (German or English)
|
| 1113 |
+
fig.update_layout(legend_title_text=df.loc['label_technology', st.session_state.lang])
|
| 1114 |
+
|
| 1115 |
+
# For German language, update the legend to show German technology names
|
| 1116 |
+
if st.session_state.lang == 'DE':
|
| 1117 |
+
fig.for_each_trace(lambda t: t.update(name=df_curtailment.loc[df_curtailment['i_en'] == t.name, 'i'].values[0]))
|
| 1118 |
+
|
| 1119 |
+
# Display the plot
|
| 1120 |
+
with col:
|
| 1121 |
+
st.plotly_chart(fig)
|
| 1122 |
+
|
| 1123 |
+
return df_curtailment
|
| 1124 |
+
|
| 1125 |
+
|
| 1126 |
+
|
| 1127 |
+
def plot_storage_charging(m, iSto, color_dict, col, df):
|
| 1128 |
+
"""
|
| 1129 |
+
Plots the charging of storage technologies.
|
| 1130 |
+
Supports both German and English labels for titles and axes while ensuring color consistency.
|
| 1131 |
+
"""
|
| 1132 |
+
# Convert the storage charging solution to a DataFrame
|
| 1133 |
+
df_charging = m.solution['y_ch'].sel(i=iSto).to_dataframe().reset_index()
|
| 1134 |
+
|
| 1135 |
+
# Drop out infinitesimal numbers
|
| 1136 |
+
df_charging['y_ch'] = df_charging['y_ch'].apply(lambda x: 0 if x < 0.01 else x)
|
| 1137 |
+
|
| 1138 |
+
# Convert 't'-column in a datetime format
|
| 1139 |
+
df_charging['t'] = pd.to_datetime(df_charging['t'].str.strip("'"), format='%Y-%m-%d %H:%M %z')
|
| 1140 |
+
|
| 1141 |
+
# Store the English technology names in a separate column to maintain color consistency
|
| 1142 |
+
df_charging['i_en'] = df_charging['i']
|
| 1143 |
+
|
| 1144 |
+
# Check if the language is German and map English names to German for display
|
| 1145 |
+
if st.session_state.lang == 'DE':
|
| 1146 |
+
tech_mapping_en_to_de = {
|
| 1147 |
+
df.loc[f'tech_{tech.lower()}', 'EN']: df.loc[f'tech_{tech.lower()}', 'DE']
|
| 1148 |
+
for tech in df_charging['i_en'] if f'tech_{tech.lower()}' in df.index
|
| 1149 |
+
}
|
| 1150 |
+
# Replace the English technology names with German ones for display
|
| 1151 |
+
df_charging['i'] = df_charging['i_en'].replace(tech_mapping_en_to_de)
|
| 1152 |
+
else:
|
| 1153 |
+
df_charging['i'] = df_charging['i_en'] # Use English names if not German
|
| 1154 |
+
|
| 1155 |
+
# Area plot for storage charging
|
| 1156 |
+
fig = px.area(df_charging, y='y_ch', x='t',
|
| 1157 |
+
title=df.loc['plot_label_storage_charging', st.session_state.lang],
|
| 1158 |
+
color='i_en', # Use the English names for consistent coloring
|
| 1159 |
+
color_discrete_map=color_dict,
|
| 1160 |
+
labels={'y_ch': '', 't': ''} # Delete double labeling
|
| 1161 |
+
)
|
| 1162 |
+
|
| 1163 |
+
# Remove line traces and use fill colors for the area plot
|
| 1164 |
+
fig.update_traces(line=dict(width=0))
|
| 1165 |
+
fig.for_each_trace(lambda trace: trace.update(fillcolor=trace.line.color))
|
| 1166 |
+
|
| 1167 |
+
# Update the legend title to reflect the correct language (German or English)
|
| 1168 |
+
fig.update_layout(legend_title_text=df.loc['label_technology', st.session_state.lang])
|
| 1169 |
+
|
| 1170 |
+
# For German language, update the legend to show German technology names
|
| 1171 |
+
if st.session_state.lang == 'DE':
|
| 1172 |
+
fig.for_each_trace(lambda t: t.update(name=df_charging.loc[df_charging['i_en'] == t.name, 'i'].values[0]))
|
| 1173 |
+
|
| 1174 |
+
# Display the plot
|
| 1175 |
+
with col:
|
| 1176 |
+
st.plotly_chart(fig)
|
| 1177 |
+
|
| 1178 |
+
return df_charging
|
| 1179 |
+
|
| 1180 |
+
|
| 1181 |
+
|
| 1182 |
+
def plot_hydrogen_production(m, iPtG, color_dict, col, df):
|
| 1183 |
+
"""
|
| 1184 |
+
Plots the hydrogen production.
|
| 1185 |
+
Supports both German and English labels for titles and axes while ensuring color consistency.
|
| 1186 |
+
"""
|
| 1187 |
+
# Convert the hydrogen production data to a DataFrame
|
| 1188 |
+
df_h2_prod = m.solution['y_h2'].sel(i=iPtG).to_dataframe().reset_index()
|
| 1189 |
+
|
| 1190 |
+
# Convert 't'-column in a datetime format
|
| 1191 |
+
df_h2_prod['t'] = pd.to_datetime(df_h2_prod['t'].str.strip("'"), format='%Y-%m-%d %H:%M %z')
|
| 1192 |
+
|
| 1193 |
+
# Store the English technology names in a separate column to maintain color consistency
|
| 1194 |
+
df_h2_prod['i_en'] = df_h2_prod['i']
|
| 1195 |
+
|
| 1196 |
+
# Check if the language is German and map English names to German for display
|
| 1197 |
+
if st.session_state.lang == 'DE':
|
| 1198 |
+
tech_mapping_en_to_de = {
|
| 1199 |
+
df.loc[f'tech_{tech.lower()}', 'EN']: df.loc[f'tech_{tech.lower()}', 'DE']
|
| 1200 |
+
for tech in df_h2_prod['i_en'] if f'tech_{tech.lower()}' in df.index
|
| 1201 |
+
}
|
| 1202 |
+
# Replace the English technology names with German ones for display
|
| 1203 |
+
df_h2_prod['i'] = df_h2_prod['i_en'].replace(tech_mapping_en_to_de)
|
| 1204 |
+
else:
|
| 1205 |
+
df_h2_prod['i'] = df_h2_prod['i_en'] # Keep English names if not German
|
| 1206 |
+
|
| 1207 |
+
# Area plot for hydrogen production
|
| 1208 |
+
fig = px.area(df_h2_prod, y='y_h2', x='t',
|
| 1209 |
+
title=df.loc['plot_label_hydrogen_production', st.session_state.lang],
|
| 1210 |
+
color='i_en', # Use the English names for consistent coloring
|
| 1211 |
+
color_discrete_map=color_dict,
|
| 1212 |
+
labels={'y_h2': '', 't': ''} # Delete double labeling
|
| 1213 |
+
)
|
| 1214 |
+
|
| 1215 |
+
# Remove line traces and use fill colors for the area plot
|
| 1216 |
+
fig.update_traces(line=dict(width=0))
|
| 1217 |
+
fig.for_each_trace(lambda trace: trace.update(fillcolor=trace.line.color))
|
| 1218 |
+
|
| 1219 |
+
# Update the legend title to reflect the correct language (German or English)
|
| 1220 |
+
fig.update_layout(legend_title_text=df.loc['label_technology', st.session_state.lang])
|
| 1221 |
+
|
| 1222 |
+
# For German language, update the legend to show German technology names
|
| 1223 |
+
if st.session_state.lang == 'DE':
|
| 1224 |
+
fig.for_each_trace(lambda t: t.update(name=df_h2_prod.loc[df_h2_prod['i_en'] == t.name, 'i'].values[0]))
|
| 1225 |
+
|
| 1226 |
+
# Display the plot
|
| 1227 |
+
with col:
|
| 1228 |
+
st.plotly_chart(fig)
|
| 1229 |
+
|
| 1230 |
+
return df_h2_prod
|
| 1231 |
+
|
| 1232 |
+
|
| 1233 |
+
|
| 1234 |
+
def disaggregate_df(df, t, t_original, dt):
|
| 1235 |
+
"""
|
| 1236 |
+
Disaggregates the DataFrame based on the original time steps.
|
| 1237 |
+
"""
|
| 1238 |
+
if "t" not in list(df.columns):
|
| 1239 |
+
return df
|
| 1240 |
+
|
| 1241 |
+
# Change format of t back
|
| 1242 |
+
df['t'] = "'" + pd.to_datetime(df['t'], utc=True).dt.tz_convert('Europe/Berlin').dt.strftime('%Y-%m-%d %H:%M %z') + "'"
|
| 1243 |
+
|
| 1244 |
+
df_t_all = pd.DataFrame({"t_all": t_original.to_series(), 't': t.repeat(dt)}).reset_index(drop=True)
|
| 1245 |
+
df_output = df.merge(df_t_all, on='t').drop('t', axis=1).rename({'t_all': 't'}, axis=1)
|
| 1246 |
+
df_output = df_output[[df_output.columns[-1]] + list(df_output.columns[:-1])]
|
| 1247 |
+
# Drop the helping column i_en
|
| 1248 |
+
df_output = df_output.drop(columns=['i_en'], errors='ignore')
|
| 1249 |
+
return df_output.sort_values('t')
|
| 1250 |
+
|
| 1251 |
+
|
| 1252 |
+
if __name__ == "__main__":
|
| 1253 |
+
main()
|
language.csv
ADDED
|
@@ -0,0 +1,138 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
Label;DE;EN
|
| 2 |
+
menu_modell;Modell;Model
|
| 3 |
+
menu_doku;Dokumentation;Documentation
|
| 4 |
+
menu_impressum;�ber uns;About
|
| 5 |
+
menu_text;Ein Browser-Tool, das f�r ein besseres Verst�ndnis der mathematischen Optimierung in der Energiewirtschaft bestimmt ist. Sei neugierig!;A tool designated for better understanding of mathematical optimization in the context of energy economics. Be eager!
|
| 6 |
+
toast_text;�ffne das Men� links um zur Dokumentation und Sprachwahl zu gelangen!;Open the menu on the left side to access the documentation and to change the language!
|
| 7 |
+
model_title1;Input aus Datei;Settings from file
|
| 8 |
+
model_title2;Ergebnisse exportieren;Export result data
|
| 9 |
+
model_title3;Manueller Input aus der GUI;Manual settings from GUI
|
| 10 |
+
model_title4;Modell rechnen;Run model
|
| 11 |
+
model_title2.1;Ergebnisse als Exceldatei herunterladen;Download Excel workbook results
|
| 12 |
+
model_title1.3;Excel Vorlage herunterladen;Download Excel Template
|
| 13 |
+
model_title1.4;Eigenes Exceldokument hochladen;Upload own Excel File
|
| 14 |
+
model_run_info_gui;Rechne mit manuellen Werten aus der GUI;Run model with manual values from the GUI
|
| 15 |
+
model_run_info_excel;Rechne mit Werten aus der Excel;Run model with uploaded Excel values
|
| 16 |
+
model_label_co2;CO2 Budget [mio. t]; CO2 limit [mio. t]
|
| 17 |
+
model_label_CCGT;Erdgas Preis [EUR/MWh]; Fossil Gas Price [EUR/MWh]
|
| 18 |
+
model_label_OCGT;Erdgas Preis [EUR/MWh]; Fossil Gas Price [EUR/MWh]
|
| 19 |
+
model_label_h2;H2 Preis [EUR/MWh]; H2 Price [EUR/MWh]
|
| 20 |
+
model_label_Fossil Hard coal;Steinkohle Preis [EUR/MWh]; Fossil Hard Coal Price [EUR/MWh]
|
| 21 |
+
model_label_Lignite;Braunkohle Preis [EUR/MWh]; Fossil Lignite Price [EUR/MWh]
|
| 22 |
+
model_label_Fossil Oil;Erd�l Preis [EUR/MWh]; Fossil Oil Price [EUR/MWh]
|
| 23 |
+
model_label_t;L�nge der Zeitschritte [h]; Timestep length [h]
|
| 24 |
+
model_label_t_info;Nur Werte zwischen 1 und 8760 eintragen (bzw. 8784 f�r Schaltjahre).;Enter only integers between 1 and 8760 (or 8784 for leap years).
|
| 25 |
+
model_label_tech;Technologien;Technologies for investment
|
| 26 |
+
tech_nuclear;Atomkraft;Nuclear
|
| 27 |
+
tech_biomass;Biomasse;Biomass
|
| 28 |
+
tech_lignite;Braunkohle;Lignite
|
| 29 |
+
tech_CCGT;Gas- und Dampfkraftwerk;Combined Cycle Gas Turbine
|
| 30 |
+
tech_OCGT;Gasturbine;Gasturbine
|
| 31 |
+
tech_fossil hard coal;Steinkohle;Fossil Hard coal
|
| 32 |
+
tech_fossil oil;�l;Fossil Oil
|
| 33 |
+
tech_ror;Laufwasser;RoR
|
| 34 |
+
tech_hydro water reservoir;Wasserreservoir;Hydro Water Reservoir
|
| 35 |
+
tech_pv;PV;PV
|
| 36 |
+
tech_windoff;Offshore Wind;WindOff
|
| 37 |
+
tech_windon;Onshore Wind;WindOn
|
| 38 |
+
tech_h2;Wasserstoff;H2
|
| 39 |
+
tech_pumped hydro storage;Pumpspeicher;Pumped Hydro Storage
|
| 40 |
+
tech_battery storages;Batteriespeicher;Battery storages
|
| 41 |
+
tech_electrolyzer;Elektrolyseure;Electrolyzer
|
| 42 |
+
run_model_button;Starte das Modell;Run Model
|
| 43 |
+
run_model_button_info;Hier klicken um die Optimierungsrechnung des Energiesystems zu starten.;Click to run the energy system optimization model.
|
| 44 |
+
plot_label_total_costs;Gesamtkosten in Mrd. EUR: ;Total costs in bn. EUR:
|
| 45 |
+
plot_label_co2_price;CO2 Preis in EUR/t: ;CO2 price in EUR/t:
|
| 46 |
+
plot_label_new_capacities;Neue Kapazit�ten [MW];New Capacities [MW]
|
| 47 |
+
plot_label_new_capacities_pie;Neue Kapazit�ten [MW] als Kreisdiagramm;New Capacities [MW] as pie chart
|
| 48 |
+
plot_label_production;Stromproduktion [MW];Production [MW]
|
| 49 |
+
plot_label_total_production_pie;Gesamtproduktion [GWh] als Kreisdiagramm;Total Production [GWh] as pie chart
|
| 50 |
+
plot_label_electricity_prices;Strompreise [EUR/MWh];Electricity prices [EUR/MWh]
|
| 51 |
+
plot_label_price_duration_curve;Preisdauerlinie [EUR/MWh];Price duration curve [EUR/MWh]
|
| 52 |
+
plot_label_load_duration_curve;Lastdauerlinie [MWh];Load duration curve [MWh]
|
| 53 |
+
label_electricity_price;Strompreis;Electricity price
|
| 54 |
+
label_time;Zeit;Time
|
| 55 |
+
label_technology;Technologien;Technologies
|
| 56 |
+
label_hours_of_year;Stunden des Jahres;Hours of the year
|
| 57 |
+
label_hours;Stunden;Hours
|
| 58 |
+
plot_label_contribution_margin;Deckungsbeitr�ge [EUR];Contribution margins [EUR]
|
| 59 |
+
plot_label_curtailment;Abregelung [MWh];Curtailment [MWh]
|
| 60 |
+
plot_label_storage_charging;Einspeicherung [MWh];Storage charging [MWh]
|
| 61 |
+
plot_label_hydrogen_production;Wasserstofferzeugung [MWh_th];Hydrogen production [MWh_th]
|
| 62 |
+
plot_label_residual_load;Residuallast [MW];Residual load [MW]
|
| 63 |
+
plot_label_load;Last [MW];Load [MW]
|
| 64 |
+
plot_label_residual_load_curve;Residuallastdauerlinie und gestapelte Erzeugung [MW];Residual load duration curve and stacked production [MW]
|
| 65 |
+
plot_label_sum_curtailment;Summe der EE-Abregelung [MW];Sum of the RES curtailment [MW]
|
| 66 |
+
;;
|
| 67 |
+
constr_header1;Mathematische Modellformulierung;Mathematical model formulation
|
| 68 |
+
constr_header2;Diese Seite zeigt die Details der mathematischen Modellformulierung & Nebenbedingungen des optimierenden Energiesystemmodells.;This page provides details on the mathematical formulation & constraints of the energy system optimization model.
|
| 69 |
+
constr_header3;Zielfunktion und Nebenbedingungen;Objective function and constraints
|
| 70 |
+
constr_subheader_obj_func;Zielfunktion;Objective function
|
| 71 |
+
constr_subheader_obj_func_descr;Minimierung der Gesamtkosten;Minimization of total costs
|
| 72 |
+
subheader_constr;Nebenbedingungen;Constraints
|
| 73 |
+
constr_load_serve;Energiebedarf muss gedeckt werden:;Load-serving constraint:
|
| 74 |
+
constr_c_op;Betriebskosten abz�glich Einnahmen durch Wasserstoffproduktion:;Operational costs minus revenue for produced hydrogen:
|
| 75 |
+
constr_c_inv;Investitionskostenbeschr�nkung:;Investment costs constraint:
|
| 76 |
+
constr_max_cap;Begrenzung der maximalen Kapazit�t:;Maximum capacity constraint:
|
| 77 |
+
constr_inv_cap;Beschr�nkung der Kapazit�tsinvestitionen:;Capacity limits for investment:
|
| 78 |
+
constr_prevent_ptg;Verhinderung der Stromproduktion durch PtG:;Prevent power production by PtG:
|
| 79 |
+
constr_prevent_chg;Verhinderung des Aufladens f�r Nicht-Speichertechnologien:;Prevent charging for non-storage technologies:
|
| 80 |
+
constr_max_chg;Maximale Auflade- und Entladebeschr�nkung f�r Speicher:;Maximum storage charging and discharging constraint:
|
| 81 |
+
constr_max_cap_electrolyzer;Maximale Kapazit�t des Elektrolyseurs:;Maximum electrolyzer capacity constraint:
|
| 82 |
+
constr_prod_ptg;H2-Produktion durch PtG:;PtG hydrogen production constraint:
|
| 83 |
+
constr_inf_res;Einspeisung erneuerbarer Energien:;Infeed of renewables constraint:
|
| 84 |
+
constr_max_fil_sto;Maximale F�llstandbeschr�nkung f�r Speicherwerke:;Maximum filling level restriction for storage power plants:
|
| 85 |
+
constr_fil_hyres;F�llstandbeschr�nkung f�r Wasserkraftspeicher:;Filling level restriction for hydro reservoir:
|
| 86 |
+
constr_fil_sto;F�llstandbeschr�nkung f�r andere Speicher:;Filling level restriction for other storages:
|
| 87 |
+
constr_co2_lim;CO2-Beschr�nkung:;CO2 emission constraint:
|
| 88 |
+
;;
|
| 89 |
+
symb_header1;Symbole;Symbols
|
| 90 |
+
symb_header2;Wir verwenden Gro�- und Kleinbuchstaben f�r Variablen und Parameter. Hochgestellte Buchstaben werden zur weiteren Beschreibung verwendet. Die tiefgestellten Buchstaben stehen f�r Mengen.;We use capital and lowercase letters for variables and parameters. Superscripts are used for further description. Subscripts represent sets.
|
| 91 |
+
symb_header_sets;Sets/Mengen;Sets
|
| 92 |
+
symb_time_steps;Menge der Zeitschritte;Set of time steps
|
| 93 |
+
symb_tech;Menge der Technologien;Set of technologies
|
| 94 |
+
symb_sto_tech;Menge der Speichertechnologien;Set of storage technologies
|
| 95 |
+
symb_conv_tech;Menge der Umwandlungstechnologien;Set of conversion technologies
|
| 96 |
+
symb_ptg;Menge der PtG-Technologien;Set of power-to-gas technologies
|
| 97 |
+
symb_res;Menge der erneuerbaren Erzeugungstechnologien;Set of renewable energy sources
|
| 98 |
+
symb_hyres;Menge der Hydroreservoirs;Set of hydro reservoir technologies
|
| 99 |
+
symb_no_inv;Menge der Technologien, in die nicht investiert wird;Set of technologies without investment
|
| 100 |
+
symb_header_variables;Variablen;Variables
|
| 101 |
+
symb_tot_costs;Gesamtkosten (Zielfunktion);Total costs (objective function)
|
| 102 |
+
symb_c_op;Betriebskosten;Operational costs
|
| 103 |
+
symb_c_inv;Investitionskosten;Investment costs
|
| 104 |
+
symb_inst_cap;Installierte Leistung einer Technologie $i$;Installed capacity of technology $i$
|
| 105 |
+
symb_el_prod;Stromproduktion der Technologie $i$ zum Zeitpunkt $t$;Electricity production of technology $i$ at time $t$
|
| 106 |
+
symb_el_ch;Stromverbrauch zum Laden des Speichers der Technologie $i$ zum Zeitpunkt $t$;Electricity consumption for charging storage of technology $i$ at time $t$
|
| 107 |
+
symb_sto_fil;Speicherf�llstand der Technologie $i$ zum Zeitpunkt $t$;Storage filling level of technology $i$ at time $t$
|
| 108 |
+
symb_curt;Abregelung der erneuerbaren Energie f�r Technologie $i$ zum Zeitpunkt $t$;Curtailment of renewable energy for technology $i$ at time $t$
|
| 109 |
+
symb_h2_ptg;Wasserstoffproduktion f�r die Power-to-Gas-Technologie $i$ zum Zeitpunkt $t$;Hydrogen production for power-to-gas technology $i$ at time $t$
|
| 110 |
+
symb_header_parameters;Parameter;Parameters
|
| 111 |
+
symb_energy_demand;Stromverbrauch zum Zeitpunkt $t$;Energy demand at time $t$
|
| 112 |
+
symb_price_h2;Market Price Hydrogen;Market price hydrogen
|
| 113 |
+
symb_fuel_costs;Brennstoffkosten f�r Technologie $i$;Fuel cost for technology $i$
|
| 114 |
+
symb_c_op_other;Weitere Betriebskosten f�r Technologie $i$;Other operational costs for technology $i$
|
| 115 |
+
symb_c_inv_tech;Investitionskosten f�r Technologie $i$;Investment cost for technology $i$
|
| 116 |
+
symb_eff_fac;Wirkungsgrad der Technologie $i$;Efficiency of technology $i$
|
| 117 |
+
symb_max_cap_tech;Kapazit�t f�r Technologie $i$ zum Zeitpunkt t = 0;Installed capacity for technology $i$ at $t=0$
|
| 118 |
+
symb_co2_fac;CO2-Emissionsfaktor f�r Technologie $i$;CO2 emissions factor for technology $i$
|
| 119 |
+
symb_co2_limit;CO2-Emissionsgrenze;CO2 emissions limit
|
| 120 |
+
symb_etp;Energie-Leistung-Verh�ltnis (Speicherzeit) f�r Speichertechnologie $i$;Energy-to-power ratio for storage technology $i$
|
| 121 |
+
symb_res_supply;Erneuerbare Stromerzeugung zum Zeitpunkt $t$ f�r erneuerbare Technologie $i$;Renewable supply at time $t$ for renewable technology $i$
|
| 122 |
+
symb_hyRes_inflow;Zufluss Hydroreservoir;Inflow for hydro reservoir
|
| 123 |
+
symb_annuity;Annuit�tenfaktor f�r Technologie $i$;Annuity factor for technology $i$
|
| 124 |
+
;;
|
| 125 |
+
sheet_name_total_costs;Gesamtkosten;Total costs
|
| 126 |
+
sheet_name_co2_price;CO2 Preis;CO2 price
|
| 127 |
+
sheet_name_prices;Preise;Prices
|
| 128 |
+
sheet_name_contribution_margin;Deckungsbeitr�ge;Contribution Margin
|
| 129 |
+
sheet_name_capacities;Kapazit�ten;Capacities
|
| 130 |
+
sheet_name_production;Produktion;Production
|
| 131 |
+
sheet_name_charging;Ein-Ausspeichern;Charging
|
| 132 |
+
sheet_name_demand;Nachfrage;Demand
|
| 133 |
+
sheet_name_curtailment;Abregelung;Curtailment
|
| 134 |
+
sheet_name_h2_production;H2 Produktion;H2 production
|
| 135 |
+
;;
|
| 136 |
+
label_build_model;Erstelle das Modell�;Build model�
|
| 137 |
+
label_solve_model;L�se das Modell�;Solve model...
|
| 138 |
+
label_generate_plots;Grafiken erstellen�;Generate output figures�
|
media/Logo_HEMF.svg
ADDED
|
|
media/Logo_UDE.svg
ADDED
|
|
media/OPT____S.ttf
ADDED
|
Binary file (69.3 kB). View file
|
|
|
media/OPT____S.woff2
ADDED
|
Binary file (32.2 kB). View file
|
|
|
media/favicon.ico
ADDED
|
|
model_data.pkl
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:7e8333b788fd8e853be74fca60a4cfb4c57c32177bd4ebc6fb2bc9f971302521
|
| 3 |
+
size 1373852
|
requirements.txt
CHANGED
|
@@ -1,3 +1,9 @@
|
|
| 1 |
-
|
| 2 |
-
pandas
|
| 3 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
numpy
|
| 2 |
+
pandas
|
| 3 |
+
xarray
|
| 4 |
+
plotly
|
| 5 |
+
streamlit
|
| 6 |
+
xlsxwriter
|
| 7 |
+
linopy
|
| 8 |
+
openpyxl
|
| 9 |
+
highspy
|
sourced.py
ADDED
|
@@ -0,0 +1,215 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# %%
|
| 2 |
+
import pandas as pd
|
| 3 |
+
|
| 4 |
+
import pickle
|
| 5 |
+
|
| 6 |
+
|
| 7 |
+
# %%
|
| 8 |
+
# Define the file path for the pickle file
|
| 9 |
+
pickle_file_path = 'model_data.pkl'
|
| 10 |
+
|
| 11 |
+
# Function to save dictionaries to a pickle file
|
| 12 |
+
def save_to_pickle(sets_dict, params_dict):
|
| 13 |
+
with open(pickle_file_path, 'wb') as file:
|
| 14 |
+
pickle.dump({'sets': sets_dict, 'params': params_dict}, file)
|
| 15 |
+
|
| 16 |
+
# Function to load dictionaries from a pickle file
|
| 17 |
+
def load_from_pickle():
|
| 18 |
+
with open(pickle_file_path, 'rb') as file:
|
| 19 |
+
data = pickle.load(file)
|
| 20 |
+
return data['sets'], data['params']
|
| 21 |
+
|
| 22 |
+
|
| 23 |
+
|
| 24 |
+
def load_data_from_excel(url_excel, write_to_pickle_flag = True):
|
| 25 |
+
|
| 26 |
+
|
| 27 |
+
|
| 28 |
+
# Timesteps
|
| 29 |
+
df_excel = pd.read_excel(url_excel, sheet_name='Timesteps_All', header=None)
|
| 30 |
+
t = pd.Index(df_excel.iloc[:, 0], name='t')
|
| 31 |
+
|
| 32 |
+
# Technologies
|
| 33 |
+
df_excel = pd.read_excel(url_excel, sheet_name='Technologies')
|
| 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:7, 2], name='iConv')
|
| 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]
|
| 53 |
+
p_co2 = 0
|
| 54 |
+
dt = 1
|
| 55 |
+
|
| 56 |
+
# Demand
|
| 57 |
+
df_excel= pd.read_excel(url_excel, sheet_name = 'Demand')
|
| 58 |
+
#df_melt = pd.melt(df_excel, id_vars='Zeit')
|
| 59 |
+
df_excel = df_excel.rename(columns = {'Timesteps':'t', 'Unnamed: 1':'Demand'})
|
| 60 |
+
#df_excel = i.to_frame().reset_index(drop=True).merge(df_excel, how = 'left')
|
| 61 |
+
df_excel = df_excel.fillna(0)
|
| 62 |
+
df_excel = df_excel.set_index('t')
|
| 63 |
+
D_t = df_excel.iloc[:,0].to_xarray()
|
| 64 |
+
|
| 65 |
+
## Efficiencies
|
| 66 |
+
df_excel = pd.read_excel(url_excel, sheet_name = 'Efficiency')
|
| 67 |
+
df_excel = df_excel.rename(columns = {'All':'i', 'Unnamed: 1':'Efficiency'})
|
| 68 |
+
df_excel = i.to_frame().reset_index(drop=True).merge(df_excel, how = 'left')
|
| 69 |
+
df_excel = df_excel.fillna(0)
|
| 70 |
+
df_excel = df_excel.set_index('i')
|
| 71 |
+
eff_i = df_excel.iloc[:,0].to_xarray()
|
| 72 |
+
|
| 73 |
+
## Lifespan
|
| 74 |
+
df_excel = pd.read_excel(url_excel, sheet_name = 'Lifespan')
|
| 75 |
+
df_excel = df_excel.rename(columns = {'All':'i', 'Unnamed: 1':'Lifespan'})
|
| 76 |
+
df_excel = i.to_frame().reset_index(drop=True).merge(df_excel, how = 'left')
|
| 77 |
+
df_excel = df_excel.fillna(0)
|
| 78 |
+
df_excel = df_excel.set_index('i')
|
| 79 |
+
life_i = df_excel.iloc[:,0].to_xarray()
|
| 80 |
+
|
| 81 |
+
## Variable costs
|
| 82 |
+
# Fuel costs
|
| 83 |
+
df_excel = pd.read_excel(url_excel, sheet_name = 'FuelCosts')
|
| 84 |
+
df_excel = df_excel.rename(columns = {'Conventionals':'i', 'Unnamed: 1':'FuelCosts'})
|
| 85 |
+
df_excel = i.to_frame().reset_index(drop=True).merge(df_excel, how = 'left')
|
| 86 |
+
df_excel = df_excel.fillna(0)
|
| 87 |
+
df_excel = df_excel.set_index('i')
|
| 88 |
+
c_fuel_i = df_excel.iloc[:,0].to_xarray()
|
| 89 |
+
# Apply slider value
|
| 90 |
+
#c_fuel_i.loc[dict(i = 'Fossil Gas')] = price_gas
|
| 91 |
+
#c_fuel_i.loc[dict(i = 'H2')] = price_h2
|
| 92 |
+
|
| 93 |
+
# Other var. costs
|
| 94 |
+
df_excel = pd.read_excel(url_excel, sheet_name = 'OtherVarCosts')
|
| 95 |
+
df_excel = df_excel.rename(columns = {'Conventionals':'i', 'Unnamed: 1':'OtherVarCosts'})
|
| 96 |
+
df_excel = i.to_frame().reset_index(drop=True).merge(df_excel, how = 'left')
|
| 97 |
+
df_excel = df_excel.fillna(0)
|
| 98 |
+
df_excel = df_excel.set_index('i')
|
| 99 |
+
c_other_i = df_excel.iloc[:,0].to_xarray()
|
| 100 |
+
|
| 101 |
+
# Investment costs
|
| 102 |
+
df_excel = pd.read_excel(url_excel, sheet_name = 'InvCosts')
|
| 103 |
+
df_excel = df_excel.rename(columns = {'All':'i', 'Unnamed: 1':'InvCosts'})
|
| 104 |
+
df_excel = i.to_frame().reset_index(drop=True).merge(df_excel, how = 'left')
|
| 105 |
+
df_excel = df_excel.fillna(0)
|
| 106 |
+
df_excel = df_excel.set_index('i')
|
| 107 |
+
interest_rate = 0.07
|
| 108 |
+
annuity_factor_i = (interest_rate * (1 + interest_rate)**life_i) / ((1 + interest_rate)**life_i - 1)
|
| 109 |
+
c_inv_i = df_excel.iloc[:,0].to_xarray()*1000*annuity_factor_i
|
| 110 |
+
|
| 111 |
+
# Emission factor
|
| 112 |
+
df_excel = pd.read_excel(url_excel, sheet_name = 'EmFactor')
|
| 113 |
+
df_excel = df_excel.rename(columns = {'Conventionals':'i', 'Unnamed: 1':'EmFactor'})
|
| 114 |
+
df_excel = i.to_frame().reset_index(drop=True).merge(df_excel, how = 'left')
|
| 115 |
+
df_excel = df_excel.fillna(0)
|
| 116 |
+
df_excel = df_excel.set_index('i')
|
| 117 |
+
co2_factor_i = df_excel.iloc[:,0].to_xarray()
|
| 118 |
+
|
| 119 |
+
## Calculation of variable costs
|
| 120 |
+
c_var_i = (c_fuel_i.sel(i = iConv) + p_co2 * co2_factor_i.sel(i = iConv)) / eff_i.sel(i = iConv) + c_other_i.sel(i = iConv)
|
| 121 |
+
|
| 122 |
+
# RES capacity factors
|
| 123 |
+
#df_excel = pd.read_excel(url_excel, sheet_name = 'RES',header=[0,1])
|
| 124 |
+
#df_excel = pd.read_excel(url_excel, sheet_name = 'RES', index_col=['Timesteps'], columns=['PV', 'WindOn', 'WindOff', 'RoR'])
|
| 125 |
+
df_excel = pd.read_excel(url_excel, sheet_name = 'RES')
|
| 126 |
+
df_excel = df_excel.set_index(['Timesteps'])
|
| 127 |
+
df_test = df_excel
|
| 128 |
+
df_excel = df_excel.stack()
|
| 129 |
+
#df_excel = df_excel.rename(columns={'PV', 'WindOn', 'WindOff', 'RoR'})
|
| 130 |
+
df_test2 = df_excel
|
| 131 |
+
#df_excel = i.to_frame().reset_index(drop=True).merge(df_excel, how = 'left')
|
| 132 |
+
#df_excel = df_excel.fillna(0)
|
| 133 |
+
|
| 134 |
+
#df_test = df_excel.set_index(['Timesteps', 'PV', 'WindOn', 'WindOff', 'RoR']).stack([0])
|
| 135 |
+
#df_test.index = df_test.index.set_names(['t','i'])
|
| 136 |
+
s_t_r_iRes = df_excel.to_xarray().rename({'level_1': 'i','Timesteps':'t'})
|
| 137 |
+
|
| 138 |
+
#s_t_r_iRes = df_excel.iloc[:,0].to_xarray()
|
| 139 |
+
|
| 140 |
+
# Base capacities
|
| 141 |
+
df_excel = pd.read_excel(url_excel, sheet_name = 'InstalledCap')
|
| 142 |
+
df_excel = df_excel.rename(columns = {'All':'i', 'Unnamed: 1':'InstalledCap'})
|
| 143 |
+
df_excel = i.to_frame().reset_index(drop=True).merge(df_excel, how = 'left')
|
| 144 |
+
df_excel = df_excel.fillna(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 = {'Storage':'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 = {'Timesteps':'t', 'Hydro Water Reservoir':'Inflow'})
|
| 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 = {}
|
| 166 |
+
params_dict = {}
|
| 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
|
| 178 |
+
params_dict['dt'] = dt
|
| 179 |
+
params_dict['D_t'] = D_t
|
| 180 |
+
params_dict['eff_i'] = eff_i
|
| 181 |
+
params_dict['life_i'] = life_i
|
| 182 |
+
params_dict['c_fuel_i'] = c_fuel_i
|
| 183 |
+
params_dict['c_other_i'] = c_other_i
|
| 184 |
+
params_dict['c_inv_i'] = c_inv_i
|
| 185 |
+
params_dict['co2_factor_i'] = co2_factor_i
|
| 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)
|
| 194 |
+
|
| 195 |
+
return sets_dict, params_dict
|
| 196 |
+
|
| 197 |
+
|
| 198 |
+
# %%
|
| 199 |
+
# # Example usage:
|
| 200 |
+
# url_excel = "Input_Jahr_2021.xlsx" # Replace with your actual file path
|
| 201 |
+
# limit_co2 = 0.5
|
| 202 |
+
# price_co2 = 50
|
| 203 |
+
# price_gas = 3
|
| 204 |
+
# price_h2 = 5
|
| 205 |
+
|
| 206 |
+
# sets, params = load_data_from_excel(url_excel,write_to_pickle_flag=True)
|
| 207 |
+
|
| 208 |
+
# # %%
|
| 209 |
+
# sets, params = load_data_from_excel(url_excel,load_from_pickle_flag=True)
|
| 210 |
+
# # %%
|
| 211 |
+
|
| 212 |
+
|
| 213 |
+
if __name__ == "__main__":
|
| 214 |
+
url_excel = r'Input_Jahr_2023.xlsx'
|
| 215 |
+
sets_dict, params_dict= load_data_from_excel(url_excel, write_to_pickle_flag= False)
|