Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -210,10 +210,54 @@ def optimize_energy_system(city_code, solar_cost, onshore_wind_cost, offshore_wi
|
|
| 210 |
yaxis=dict(showgrid=True, gridwidth=0.5, gridcolor='lightgray')
|
| 211 |
)
|
| 212 |
|
| 213 |
-
|
| 214 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 215 |
|
| 216 |
-
return
|
| 217 |
|
| 218 |
# Streamlit UI setup
|
| 219 |
st.set_page_config(page_title='Renewable Energy System Optimization', layout='wide')
|
|
@@ -248,8 +292,10 @@ with st.sidebar:
|
|
| 248 |
offshore_wind_range = st.slider("Offshore Wind Capacity Range (MW)", 0, 10000, (0, 10000))
|
| 249 |
river_range = st.slider("River Capacity Range (MW)", 0, 10000, (0, 10000))
|
| 250 |
|
|
|
|
|
|
|
| 251 |
if st.button('Calculate Optimal Energy Mix'):
|
| 252 |
-
fig_energy, heatmaps, curtailment_values, soc_per_hour, fig_capacity_ranges, renewable_capacity
|
| 253 |
city_code, solar_cost, onshore_wind_cost, offshore_wind_cost, river_cost, battery_cost, yearly_demand, solar_range, wind_range, river_range, offshore_wind_range
|
| 254 |
)
|
| 255 |
|
|
@@ -277,6 +323,17 @@ if st.button('Calculate Optimal Energy Mix'):
|
|
| 277 |
# Plot optimized capacity vs. capacity ranges
|
| 278 |
st.plotly_chart(fig_capacity_ranges, use_container_width=True, height=800)
|
| 279 |
|
| 280 |
-
|
| 281 |
-
|
| 282 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 210 |
yaxis=dict(showgrid=True, gridwidth=0.5, gridcolor='lightgray')
|
| 211 |
)
|
| 212 |
|
| 213 |
+
return fig_energy, heatmaps, curtailment_values, SOC_normalized, fig_capacity_ranges, renewable_capacity
|
| 214 |
+
|
| 215 |
+
# 資源コストの感度解析を行う関数
|
| 216 |
+
def analyze_cost_sensitivity(renewable_capacity_cost, technologies, renewable_capacity):
|
| 217 |
+
# コストの変動範囲(0.5倍から1.5倍)
|
| 218 |
+
cost_multipliers = np.linspace(0.5, 1.5, 11)
|
| 219 |
+
|
| 220 |
+
# 結果を格納する辞書
|
| 221 |
+
sensitivity_results = {}
|
| 222 |
+
|
| 223 |
+
for tech in technologies:
|
| 224 |
+
# 各技術ごとのコスト変動に対する総コストの変化を計算
|
| 225 |
+
original_cost = renewable_capacity_cost[tech]
|
| 226 |
+
total_costs = []
|
| 227 |
+
|
| 228 |
+
for multiplier in cost_multipliers:
|
| 229 |
+
# コストを変更
|
| 230 |
+
modified_cost = original_cost * multiplier
|
| 231 |
+
# 総コスト = 変更後のコスト * 設備容量
|
| 232 |
+
total_cost = modified_cost * renewable_capacity[('region1', tech)].varValue
|
| 233 |
+
total_costs.append(total_cost)
|
| 234 |
+
|
| 235 |
+
# 技術ごとに結果を保存
|
| 236 |
+
sensitivity_results[tech] = total_costs
|
| 237 |
+
|
| 238 |
+
# 可視化
|
| 239 |
+
fig = go.Figure()
|
| 240 |
+
|
| 241 |
+
for tech, total_costs in sensitivity_results.items():
|
| 242 |
+
fig.add_trace(go.Scatter(
|
| 243 |
+
x=cost_multipliers,
|
| 244 |
+
y=total_costs,
|
| 245 |
+
mode='lines+markers',
|
| 246 |
+
name=f'{tech} Cost Sensitivity'
|
| 247 |
+
))
|
| 248 |
+
|
| 249 |
+
# グラフのレイアウト
|
| 250 |
+
fig.update_layout(
|
| 251 |
+
title='Cost Sensitivity Analysis: Impact of Cost Changes on Total System Cost',
|
| 252 |
+
xaxis_title='Cost Multiplier (0.5x to 1.5x)',
|
| 253 |
+
yaxis_title='Total System Cost (¥)',
|
| 254 |
+
hovermode='x unified',
|
| 255 |
+
plot_bgcolor='white',
|
| 256 |
+
xaxis=dict(showgrid=True, gridwidth=0.5, gridcolor='lightgray'),
|
| 257 |
+
yaxis=dict(showgrid=True, gridwidth=0.5, gridcolor='lightgray')
|
| 258 |
+
)
|
| 259 |
|
| 260 |
+
return fig
|
| 261 |
|
| 262 |
# Streamlit UI setup
|
| 263 |
st.set_page_config(page_title='Renewable Energy System Optimization', layout='wide')
|
|
|
|
| 292 |
offshore_wind_range = st.slider("Offshore Wind Capacity Range (MW)", 0, 10000, (0, 10000))
|
| 293 |
river_range = st.slider("River Capacity Range (MW)", 0, 10000, (0, 10000))
|
| 294 |
|
| 295 |
+
calculated_optimal_energy_mix = False
|
| 296 |
+
|
| 297 |
if st.button('Calculate Optimal Energy Mix'):
|
| 298 |
+
fig_energy, heatmaps, curtailment_values, soc_per_hour, fig_capacity_ranges, renewable_capacity = optimize_energy_system(
|
| 299 |
city_code, solar_cost, onshore_wind_cost, offshore_wind_cost, river_cost, battery_cost, yearly_demand, solar_range, wind_range, river_range, offshore_wind_range
|
| 300 |
)
|
| 301 |
|
|
|
|
| 323 |
# Plot optimized capacity vs. capacity ranges
|
| 324 |
st.plotly_chart(fig_capacity_ranges, use_container_width=True, height=800)
|
| 325 |
|
| 326 |
+
calculated_optimal_energy_mix = True
|
| 327 |
+
|
| 328 |
+
# Streamlit UIに感度解析ボタンを追加
|
| 329 |
+
if st.button('Analyze Cost Sensitivity'):
|
| 330 |
+
if calculated_optimal_energy_mix:
|
| 331 |
+
fig_sensitivity = analyze_cost_sensitivity({
|
| 332 |
+
'solar': solar_cost,
|
| 333 |
+
'onshore_wind': onshore_wind_cost,
|
| 334 |
+
'offshore_wind': offshore_wind_cost,
|
| 335 |
+
'river': river_cost
|
| 336 |
+
}, ['solar', 'onshore_wind', 'offshore_wind', 'river'], renewable_capacity)
|
| 337 |
+
st.plotly_chart(fig_sensitivity, use_container_width=True, height=800)
|
| 338 |
+
else:
|
| 339 |
+
st.error("Please calculate the optimal energy mix first before running the cost sensitivity analysis.")
|