naohiro701 commited on
Commit
c96b8a9
·
verified ·
1 Parent(s): 5a9b26f

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +1 -130
app.py CHANGED
@@ -110,8 +110,6 @@ def optimize_energy_system(city_code, solar_cost, onshore_wind_cost, offshore_wi
110
  SOC_values = [SOC[t].varValue for t in time_steps]
111
  curtailment_values = [-curtailment[(r, t)].varValue for r in regions for t in time_steps]
112
 
113
- price_per_hour = [100 + 0.05 * demand[t] for t in time_steps]
114
-
115
  max_SOC = max(SOC_values)
116
  SOC_normalized = [(soc / max_SOC) * 100 for soc in SOC_values] if max_SOC > 0 else [0] * len(SOC_values)
117
 
@@ -212,131 +210,4 @@ def optimize_energy_system(city_code, solar_cost, onshore_wind_cost, offshore_wi
212
  yaxis=dict(showgrid=True, gridwidth=0.5, gridcolor='lightgray')
213
  )
214
 
215
- return fig_energy, heatmaps, curtailment_values, SOC_normalized, fig_capacity_ranges, renewable_capacity
216
-
217
- # 資源コストの感度解析を行う関数
218
- def analyze_cost_sensitivity(renewable_capacity_cost, technologies, renewable_capacity):
219
- # コストの変動範囲(0.5倍から1.5倍)
220
- cost_multipliers = np.linspace(0.5, 1.5, 11)
221
-
222
- # 結果を格納する辞書
223
- sensitivity_results = {}
224
-
225
- for tech in technologies:
226
- # 各技術ごとのコスト変動に対する総コストの変化を計算
227
- original_cost = renewable_capacity_cost[tech]
228
- total_costs = []
229
-
230
- for multiplier in cost_multipliers:
231
- # コストを変更
232
- modified_cost = original_cost * multiplier
233
- # 総コスト = 変更後のコスト * 設備容量
234
- total_cost = modified_cost * renewable_capacity[('region1', tech)].varValue
235
- total_costs.append(total_cost)
236
-
237
- # 技術ごとに結果を保存
238
- sensitivity_results[tech] = total_costs
239
-
240
- # 可視化
241
- fig = go.Figure()
242
-
243
- for tech, total_costs in sensitivity_results.items():
244
- fig.add_trace(go.Scatter(
245
- x=cost_multipliers,
246
- y=total_costs,
247
- mode='lines+markers',
248
- name=f'{tech} Cost Sensitivity'
249
- ))
250
-
251
- # グラフのレイアウト
252
- fig.update_layout(
253
- title='Cost Sensitivity Analysis: Impact of Cost Changes on Total System Cost',
254
- xaxis_title='Cost Multiplier (0.5x to 1.5x)',
255
- yaxis_title='Total System Cost (¥)',
256
- hovermode='x unified',
257
- plot_bgcolor='white',
258
- xaxis=dict(showgrid=True, gridwidth=0.5, gridcolor='lightgray'),
259
- yaxis=dict(showgrid=True, gridwidth=0.5, gridcolor='lightgray')
260
- )
261
-
262
- return fig
263
-
264
- # Streamlit UI setup
265
- st.set_page_config(page_title='Renewable Energy System Optimization', layout='wide')
266
- st.title('Renewable Energy System Optimization')
267
-
268
- st.markdown("""
269
- ### Model Overview
270
-
271
- This application is designed to optimize renewable energy systems for a specific region. The model allows the user to set the costs for different renewable energy technologies and battery storage, as well as minimum and maximum capacity limits for each technology. The optimization uses linear programming to minimize the total cost while ensuring demand is met, incorporating energy storage to help manage intermittency.
272
-
273
- The renewable technologies considered are:
274
- - Solar PV
275
- - Onshore Wind
276
- - Offshore Wind
277
- - Run of River (Hydro)
278
-
279
- The optimization problem aims to balance supply and demand at minimal cost, while also providing flexibility in the form of battery energy storage. Curtailment and battery state of charge are also considered in the model.
280
-
281
- """)
282
-
283
- with st.sidebar:
284
- st.header('Input Parameters')
285
- city_code = st.text_input("Enter City Code", value=999999)
286
- solar_cost = st.number_input("Solar Capacity Cost (¥/MW)", value=80.0)
287
- onshore_wind_cost = st.number_input("Onshore Wind Capacity Cost (¥/MW)", value=120.0)
288
- offshore_wind_cost = st.number_input("Offshore Wind Capacity Cost (¥/MW)", value=180.0)
289
- river_cost = st.number_input("River Capacity Cost (¥/MW)", value=1000.0)
290
- battery_cost = st.number_input("Battery Cost (¥/MWh)", value=80.0)
291
- yearly_demand = st.number_input("Yearly Power Demand (TWh/year)", value=15.0)
292
- solar_range = st.slider("Solar Capacity Range (MW)", 0, 10000, (0, 10000))
293
- wind_range = st.slider("Onshore Wind Capacity Range (MW)", 0, 10000, (0, 10000))
294
- offshore_wind_range = st.slider("Offshore Wind Capacity Range (MW)", 0, 10000, (0, 10000))
295
- river_range = st.slider("River Capacity Range (MW)", 0, 10000, (0, 10000))
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
-
302
- if fig_energy:
303
- st.plotly_chart(fig_energy, use_container_width=True, height=800)
304
-
305
- # Additional visualizations
306
- st.markdown("### Hourly Capacity Factor Heatmaps")
307
- for fig_heatmap in heatmaps:
308
- st.plotly_chart(fig_heatmap, use_container_width=True, height=800)
309
-
310
- st.markdown("### Additional Analysis")
311
- st.markdown("The following plots provide additional insights into the renewable energy mix, curtailment, and electricity price variations.")
312
-
313
- # Plot cost comparison of different renewable technologies
314
- renewable_data = {
315
- 'Solar': solar_cost,
316
- 'Onshore Wind': onshore_wind_cost,
317
- 'Offshore Wind': offshore_wind_cost,
318
- 'Run of River': river_cost
319
- }
320
-
321
- # Plot curtailment over time
322
- curtailment_df = pd.DataFrame({"Time": fig_energy.data[0].x, "Curtailment (MW)": curtailment_values})
323
- fig_curtailment = px.line(curtailment_df, x='Time', y='Curtailment (MW)', title='Curtailment Over Time', template='plotly_white')
324
- st.plotly_chart(fig_curtailment, use_container_width=True, height=800)
325
-
326
- # Plot electricity price variation over time
327
- soc_df = pd.DataFrame({"Time": fig_energy.data[0].x, "State of charge [%]": soc_per_hour})
328
- fig_battery_operation = px.line(soc_df, x='Time', y='State of charge [%]', title='State of charge in battery', template='plotly_white')
329
- st.plotly_chart(fig_battery_operation, use_container_width=True, height=800)
330
-
331
- # Plot optimized capacity vs. capacity ranges
332
- st.plotly_chart(fig_capacity_ranges, use_container_width=True, height=800)
333
-
334
- # Streamlit UIに感度解析ボタンを追加
335
- if st.button('Analyze Cost Sensitivity'):
336
- fig_sensitivity = analyze_cost_sensitivity({
337
- 'solar': solar_cost,
338
- 'onshore_wind': onshore_wind_cost,
339
- 'offshore_wind': offshore_wind_cost,
340
- 'river': river_cost
341
- }, ['solar', 'onshore_wind', 'offshore_wind', 'river'], renewable_capacity)
342
- st.plotly_chart(fig_sensitivity, use_container_width=True, height=800)
 
110
  SOC_values = [SOC[t].varValue for t in time_steps]
111
  curtailment_values = [-curtailment[(r, t)].varValue for r in regions for t in time_steps]
112
 
 
 
113
  max_SOC = max(SOC_values)
114
  SOC_normalized = [(soc / max_SOC) * 100 for soc in SOC_values] if max_SOC > 0 else [0] * len(SOC_values)
115
 
 
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