Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -149,24 +149,60 @@ def optimize_energy_system(city_code, solar_cost, onshore_wind_cost, offshore_wi
|
|
| 149 |
SOC_normalized = [(soc / max_SOC) * 100 for soc in SOC_values] if max_SOC > 0 else [0] * len(SOC_values)
|
| 150 |
|
| 151 |
# Create a subplot with 3 rows for energy dispatch, state of charge (SOC), and electricity price.
|
| 152 |
-
|
| 153 |
-
|
| 154 |
-
|
| 155 |
-
|
| 156 |
-
|
| 157 |
-
|
| 158 |
-
|
| 159 |
-
|
| 160 |
-
|
| 161 |
-
|
| 162 |
-
|
| 163 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 164 |
|
| 165 |
-
#
|
| 166 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 167 |
|
| 168 |
-
#
|
| 169 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 170 |
|
| 171 |
# Layout settings for the figure.
|
| 172 |
fig.update_layout(
|
|
@@ -216,7 +252,9 @@ with st.sidebar:
|
|
| 216 |
if st.button('Calculate Optimal Energy Mix'):
|
| 217 |
fig, curtailment_values, price_per_hour = optimize_energy_system(city_code, solar_cost, onshore_wind_cost, offshore_wind_cost, river_cost, battery_cost, yearly_demand)
|
| 218 |
if fig:
|
| 219 |
-
st.plotly_chart(
|
|
|
|
|
|
|
| 220 |
|
| 221 |
# Additional analysis and visualizations
|
| 222 |
st.markdown("### Additional Analysis")
|
|
|
|
| 149 |
SOC_normalized = [(soc / max_SOC) * 100 for soc in SOC_values] if max_SOC > 0 else [0] * len(SOC_values)
|
| 150 |
|
| 151 |
# Create a subplot with 3 rows for energy dispatch, state of charge (SOC), and electricity price.
|
| 152 |
+
", "Electricity Price Over Time"))
|
| 153 |
+
|
| 154 |
+
# Create separate figure for power supply and demand
|
| 155 |
+
fig_supply_demand = go.Figure()
|
| 156 |
+
fig_supply_demand.add_trace(go.Scatter(x=data['Time'], y=supply_solar, mode='lines', stackgroup='one', name='Solar', line=dict(color='#FFD700', width=0))) # Solar: Gold
|
| 157 |
+
fig_supply_demand.add_trace(go.Scatter(x=data['Time'], y=supply_onshore_wind, mode='lines', stackgroup='one', name='Onshore Wind', line=dict(color='#1F78B4', width=0))) # Onshore Wind: Blue
|
| 158 |
+
fig_supply_demand.add_trace(go.Scatter(x=data['Time'], y=supply_offshore_wind, mode='lines', stackgroup='one', name='Offshore Wind', line=dict(color='#66C2A5', width=0))) # Offshore Wind: Light Green
|
| 159 |
+
fig_supply_demand.add_trace(go.Scatter(x=data['Time'], y=supply_river, mode='lines', stackgroup='one', name='Run of River', line=dict(color='#FF7F00', width=0))) # Run of River: Orange
|
| 160 |
+
fig_supply_demand.add_trace(go.Scatter(x=data['Time'], y=battery_discharge_values, mode='lines', stackgroup='one', name='Battery Discharge', fill='tonexty', line=dict(color='#6A3D9A', width=0))) # Battery Discharge: Brown
|
| 161 |
+
fig_supply_demand.add_trace(go.Scatter(x=data['Time'], y=battery_charge_values, mode='lines', stackgroup='two', name='Battery Charge', fill='tonexty', line=dict(color='#6A3D9A', width=0))) # Battery Charge: Purple
|
| 162 |
+
fig_supply_demand.add_trace(go.Scatter(x=data['Time'], y=-demand, mode='lines', stackgroup='two', name='Demand', line=dict(color='black', width=0))) # Demand: Black
|
| 163 |
+
fig_supply_demand.add_trace(go.Scatter(x=data['Time'], y=curtailment_values, mode='lines', stackgroup='two', name='Curtailment', line=dict(color='#aaaaaa', width=0))) # Curtailment: Grey
|
| 164 |
+
|
| 165 |
+
fig_supply_demand.update_layout(
|
| 166 |
+
title_text='Power Supply and Demand',
|
| 167 |
+
yaxis_title='Power dispatch (MW)',
|
| 168 |
+
legend_title='Source',
|
| 169 |
+
font=dict(size=12),
|
| 170 |
+
margin=dict(l=40, r=40, t=40, b=40),
|
| 171 |
+
hovermode='x unified',
|
| 172 |
+
plot_bgcolor='white',
|
| 173 |
+
xaxis=dict(showgrid=True, gridwidth=0.5, gridcolor='lightgray'),
|
| 174 |
+
yaxis=dict(showgrid=True, gridwidth=0.5, gridcolor='lightgray')
|
| 175 |
+
) # Curtailment: Grey
|
| 176 |
|
| 177 |
+
# Create separate figure for state of charge (SOC)
|
| 178 |
+
fig_soc = go.Figure()
|
| 179 |
+
fig_soc.add_trace(go.Scatter(x=data['Time'], y=SOC_normalized, mode='lines', name='State of Charge (SOC) - Normalized', line=dict(color='black')))
|
| 180 |
+
|
| 181 |
+
fig_soc.update_layout(
|
| 182 |
+
title_text='State of Charge (Battery)',
|
| 183 |
+
yaxis_title='State of Charge (%)',
|
| 184 |
+
font=dict(size=12),
|
| 185 |
+
margin=dict(l=40, r=40, t=40, b=40),
|
| 186 |
+
hovermode='x unified',
|
| 187 |
+
plot_bgcolor='white',
|
| 188 |
+
xaxis=dict(showgrid=True, gridwidth=0.5, gridcolor='lightgray'),
|
| 189 |
+
yaxis=dict(showgrid=True, gridwidth=0.5, gridcolor='lightgray')
|
| 190 |
+
)
|
| 191 |
|
| 192 |
+
# Create separate figure for electricity price over time
|
| 193 |
+
fig_price = go.Figure()
|
| 194 |
+
fig_price.add_trace(go.Scatter(x=data['Time'], y=price_per_hour, mode='lines', name='Electricity Price', line=dict(color='#FF4500')))
|
| 195 |
+
|
| 196 |
+
fig_price.update_layout(
|
| 197 |
+
title_text='Electricity Price Over Time',
|
| 198 |
+
yaxis_title='Electricity Price (¥/MWh)',
|
| 199 |
+
font=dict(size=12),
|
| 200 |
+
margin=dict(l=40, r=40, t=40, b=40),
|
| 201 |
+
hovermode='x unified',
|
| 202 |
+
plot_bgcolor='white',
|
| 203 |
+
xaxis=dict(showgrid=True, gridwidth=0.5, gridcolor='lightgray'),
|
| 204 |
+
yaxis=dict(showgrid=True, gridwidth=0.5, gridcolor='lightgray')
|
| 205 |
+
) # Price: Red-Orange
|
| 206 |
|
| 207 |
# Layout settings for the figure.
|
| 208 |
fig.update_layout(
|
|
|
|
| 252 |
if st.button('Calculate Optimal Energy Mix'):
|
| 253 |
fig, curtailment_values, price_per_hour = optimize_energy_system(city_code, solar_cost, onshore_wind_cost, offshore_wind_cost, river_cost, battery_cost, yearly_demand)
|
| 254 |
if fig:
|
| 255 |
+
st.plotly_chart(fig_supply_demand, use_container_width=True, height=800)
|
| 256 |
+
st.plotly_chart(fig_soc, use_container_width=True, height=800)
|
| 257 |
+
st.plotly_chart(fig_price, use_container_width=True, height=800)
|
| 258 |
|
| 259 |
# Additional analysis and visualizations
|
| 260 |
st.markdown("### Additional Analysis")
|