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
|
|
|
|
|
|
|
|
| 1 |
+
import streamlit as st
|
| 2 |
+
import requests
|
| 3 |
+
import pandas as pd
|
| 4 |
+
from io import StringIO
|
| 5 |
+
import pulp
|
| 6 |
+
import plotly.graph_objs as go
|
| 7 |
+
from plotly.subplots import make_subplots
|
| 8 |
+
import plotly.express as px
|
| 9 |
+
import datetime
|
| 10 |
+
|
| 11 |
+
# Function to fetch renewable energy data
|
| 12 |
+
def get_renewable_energy_data(city_code):
|
| 13 |
+
"""
|
| 14 |
+
Fetch renewable energy data from an external source based on a city code.
|
| 15 |
+
|
| 16 |
+
Args:
|
| 17 |
+
- city_code (str): The code representing the city for which the renewable energy data is to be fetched.
|
| 18 |
+
Returns:
|
| 19 |
+
- result_df (DataFrame): A DataFrame containing the energy data with time and capacity factors for each energy type.
|
| 20 |
+
- error (str): Error message if the data fetching fails.
|
| 21 |
+
"""
|
| 22 |
+
url = f"https://energy-sustainability.jp/_ajax/renewable_energy/get/?code={city_code}"
|
| 23 |
+
response = requests.get(url)
|
| 24 |
+
if response.status_code != 200:
|
| 25 |
+
return None, "データの取得に失敗しました。" # Data fetch failed.
|
| 26 |
+
|
| 27 |
+
data = response.json()
|
| 28 |
+
if not data:
|
| 29 |
+
return None, "データが見つかりませんでした。" # Data not found.
|
| 30 |
+
|
| 31 |
+
# Extract base times from the first energy type.
|
| 32 |
+
base_times = data[next(iter(data))]['x']
|
| 33 |
+
result_df = pd.DataFrame({"Time": base_times})
|
| 34 |
+
|
| 35 |
+
# Loop through each energy type and append hourly capacity factor data.
|
| 36 |
+
for energy_type, energy_data in data.items():
|
| 37 |
+
if 'x' in energy_data and 'y' in energy_data:
|
| 38 |
+
values = energy_data['y']
|
| 39 |
+
result_df[f"{energy_type} hourly capacity factor"] = values
|
| 40 |
+
|
| 41 |
+
return result_df, None
|
| 42 |
+
|
| 43 |
+
# Function to optimize the energy system
|
| 44 |
+
def optimize_energy_system(city_code, solar_cost, onshore_wind_cost, offshore_wind_cost, river_cost, battery_cost, yearly_demand):
|
| 45 |
+
"""
|
| 46 |
+
Optimize the energy system using linear programming to minimize cost while meeting demand with renewable sources and batteries.
|
| 47 |
+
|
| 48 |
+
Args:
|
| 49 |
+
- city_code (str): The code of the city for which energy data is to be optimized.
|
| 50 |
+
- solar_cost (float): The cost of solar capacity per MW.
|
| 51 |
+
- onshore_wind_cost (float): The cost of onshore wind capacity per MW.
|
| 52 |
+
- offshore_wind_cost (float): The cost of offshore wind capacity per MW.
|
| 53 |
+
- river_cost (float): The cost of river (hydro) capacity per MW.
|
| 54 |
+
- battery_cost (float): The cost of battery capacity per MWh.
|
| 55 |
+
- yearly_demand (float): The total yearly demand in TWh/year.
|
| 56 |
+
Returns:
|
| 57 |
+
- fig (Figure): A plotly figure showing the optimized energy dispatch and state of charge (SOC) over time.
|
| 58 |
+
- curtailment_values (list): List of curtailment values for visualization.
|
| 59 |
+
- price_per_hour (list): List of estimated electricity price per hour for visualization.
|
| 60 |
+
"""
|
| 61 |
+
data, error = get_renewable_energy_data(city_code)
|
| 62 |
+
if error:
|
| 63 |
+
st.error(error)
|
| 64 |
+
return None, None, None
|
| 65 |
+
|
| 66 |
+
# Convert capacity factor columns to numeric values, handling any errors and filling missing data.
|
| 67 |
+
for col in data.columns[1:]:
|
| 68 |
+
data[col] = pd.to_numeric(data[col], errors='coerce')
|
| 69 |
+
|
| 70 |
+
data = data.fillna(0) # Fill missing values with zero.
|
| 71 |
+
|
| 72 |
+
# Extract necessary data for optimization.
|
| 73 |
+
time_steps = range(len(data['Time']))
|
| 74 |
+
solar_cf = data['solar hourly capacity factor']
|
| 75 |
+
onshore_wind_cf = data['onshore_wind hourly capacity factor']
|
| 76 |
+
offshore_wind_cf = data['offshore_wind hourly capacity factor']
|
| 77 |
+
river_cf = data['river hourly capacity factor']
|
| 78 |
+
demand_cf = data['demand hourly capacity factor']
|
| 79 |
+
|
| 80 |
+
# Define regions and technologies.
|
| 81 |
+
regions = ['region1']
|
| 82 |
+
technologies = ['solar', 'onshore_wind', 'offshore_wind', 'river']
|
| 83 |
+
capacity_factor = {
|
| 84 |
+
'solar': solar_cf,
|
| 85 |
+
'onshore_wind': onshore_wind_cf,
|
| 86 |
+
'offshore_wind': offshore_wind_cf,
|
| 87 |
+
'river': river_cf
|
| 88 |
+
}
|
| 89 |
+
|
| 90 |
+
# Cost definitions for renewable capacity and battery.
|
| 91 |
+
renewable_capacity_cost = {'solar': solar_cost, 'onshore_wind': onshore_wind_cost, 'offshore_wind': offshore_wind_cost, 'river': river_cost}
|
| 92 |
+
battery_cost_per_mwh = battery_cost
|
| 93 |
+
battery_efficiency = 0.9 # Battery efficiency.
|
| 94 |
+
|
| 95 |
+
# Scale demand from capacity factor and yearly demand in TWh/year to hourly demand in MW.
|
| 96 |
+
demand = demand_cf * yearly_demand / 100 * 1000 * 1000
|
| 97 |
+
|
| 98 |
+
# Define LP variables for renewable capacities, curtailment, battery capacity, charge, discharge, and state of charge (SOC).
|
| 99 |
+
renewable_capacity = pulp.LpVariable.dicts("renewable_capacity",
|
| 100 |
+
[(r, g) for r in regions for g in technologies],
|
| 101 |
+
lowBound=0, cat='Continuous')
|
| 102 |
+
curtailment = pulp.LpVariable.dicts("curtailment",
|
| 103 |
+
[(r, t) for r in regions for t in time_steps],
|
| 104 |
+
lowBound=0, cat='Continuous')
|
| 105 |
+
battery_capacity = pulp.LpVariable("battery_capacity", lowBound=0, cat='Continuous')
|
| 106 |
+
battery_charge = pulp.LpVariable.dicts("battery_charge", time_steps, lowBound=0, cat='Continuous')
|
| 107 |
+
battery_discharge = pulp.LpVariable.dicts("battery_discharge", time_steps, lowBound=0, cat='Continuous')
|
| 108 |
+
SOC = pulp.LpVariable.dicts("SOC", time_steps, lowBound=0, cat='Continuous')
|
| 109 |
+
|
| 110 |
+
# Define the optimization problem: minimize the total system cost.
|
| 111 |
+
model = pulp.LpProblem("EnergySystemOptimizationWithBattery", pulp.LpMinimize)
|
| 112 |
+
|
| 113 |
+
model += pulp.lpSum([renewable_capacity[(r, g)] * renewable_capacity_cost[g]
|
| 114 |
+
for r in regions for g in technologies]) + \
|
| 115 |
+
battery_capacity * battery_cost_per_mwh, "TotalCost"
|
| 116 |
+
|
| 117 |
+
# Constraints to meet demand, manage curtailment, and update state of charge for the battery.
|
| 118 |
+
for r in regions:
|
| 119 |
+
for t in time_steps:
|
| 120 |
+
model += pulp.lpSum([renewable_capacity[(r, g)] * capacity_factor[g][t]
|
| 121 |
+
for g in technologies]) + battery_discharge[t] == demand[t] + battery_charge[t] + curtailment[(r,t)], f"DemandConstraint_{r}_{t}"
|
| 122 |
+
|
| 123 |
+
if t == 0:
|
| 124 |
+
model += SOC[t] == battery_charge[t] * battery_efficiency - battery_discharge[t] * (1 / battery_efficiency), f"SOCUpdate_{t}"
|
| 125 |
+
else:
|
| 126 |
+
model += SOC[t] == SOC[t-1] + battery_charge[t] * battery_efficiency - battery_discharge[t] * (1 / battery_efficiency), f"SOCUpdate_{t}"
|
| 127 |
+
|
| 128 |
+
model += SOC[t] <= battery_capacity, f"SOCUpperBound_{t}"
|
| 129 |
+
|
| 130 |
+
# Solve the optimization model.
|
| 131 |
+
model.solve()
|
| 132 |
+
|
| 133 |
+
# Extract optimized supply and battery values.
|
| 134 |
+
supply_solar = solar_cf * renewable_capacity[('region1', 'solar')].varValue
|
| 135 |
+
supply_onshore_wind = onshore_wind_cf * renewable_capacity[('region1', 'onshore_wind')].varValue
|
| 136 |
+
supply_offshore_wind = offshore_wind_cf * renewable_capacity[('region1', 'offshore_wind')].varValue
|
| 137 |
+
supply_river = river_cf * renewable_capacity[('region1', 'river')].varValue
|
| 138 |
+
|
| 139 |
+
battery_discharge_values = [battery_discharge[t].varValue for t in time_steps]
|
| 140 |
+
battery_charge_values = [-battery_charge[t].varValue for t in time_steps]
|
| 141 |
+
SOC_values = [SOC[t].varValue for t in time_steps]
|
| 142 |
+
curtailment_values = [curtailment[(r, t)].varValue for r in regions for t in time_steps]
|
| 143 |
+
|
| 144 |
+
# Calculate price per hour based on demand and generation (simplified example).
|
| 145 |
+
price_per_hour = [100 + 0.05 * demand[t] for t in time_steps] # Base price + factor for demand.
|
| 146 |
+
|
| 147 |
+
# Normalize state of charge (SOC) to a percentage.
|
| 148 |
+
max_SOC = max(SOC_values)
|
| 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(
|
| 209 |
+
title_text='Optimized result',
|
| 210 |
+
title_x=0.5,
|
| 211 |
+
yaxis_title='Power dispatch (MW)',
|
| 212 |
+
legend_title='Source',
|
| 213 |
+
font=dict(size=12),
|
| 214 |
+
margin=dict(l=40, r=40, t=40, b=40),
|
| 215 |
+
hovermode='x unified',
|
| 216 |
+
plot_bgcolor='white',
|
| 217 |
+
xaxis=dict(showgrid=True, gridwidth=0.5, gridcolor='lightgray'),
|
| 218 |
+
yaxis=dict(showgrid=True, gridwidth=0.5, gridcolor='lightgray')
|
| 219 |
+
)
|
| 220 |
+
# Update the y-axis titles for each subplot.
|
| 221 |
+
fig.update_yaxes(title_text="State of Charge (%)", row=2, col=1)
|
| 222 |
+
fig.update_yaxes(title_text="Electricity Price (¥/MWh)", row=3, col=1)
|
| 223 |
+
|
| 224 |
+
return fig, curtailment_values, price_per_hour
|
| 225 |
+
|
| 226 |
+
# Streamlit UI for the application
|
| 227 |
+
st.set_page_config(page_title='Renewable Energy System Optimization', layout='wide')
|
| 228 |
+
st.title('Renewable Energy System Optimization')
|
| 229 |
+
|
| 230 |
+
# Explanation of the project
|
| 231 |
+
st.markdown("""
|
| 232 |
+
### Overview
|
| 233 |
+
This application is designed to help researchers and policymakers explore and optimize renewable energy systems for a specified region. By inputting cost parameters for different renewable energy sources and energy storage systems, the application determines the optimal mix of resources to meet energy demand while minimizing cost.
|
| 234 |
+
|
| 235 |
+
The optimization problem is solved using linear programming, ensuring a balance between supply and demand, and incorporating battery energy storage to manage intermittency issues inherent in renewable energy.
|
| 236 |
+
|
| 237 |
+
The visualizations provided help to better understand how different energy sources contribute to the overall power supply, how energy storage systems are utilized, and the impact of cost variations on energy prices.
|
| 238 |
+
""")
|
| 239 |
+
|
| 240 |
+
# Input fields for the user
|
| 241 |
+
with st.sidebar:
|
| 242 |
+
st.header('Input Parameters')
|
| 243 |
+
city_code = st.text_input("Enter City Code", value="")
|
| 244 |
+
solar_cost = st.number_input("Solar Capacity Cost (¥/MW)", value=80.0, help="Estimated average cost of solar capacity per MW")
|
| 245 |
+
onshore_wind_cost = st.number_input("Onshore Wind Capacity Cost (¥/MW)", value=120.0, help="Estimated average cost of onshore wind capacity per MW")
|
| 246 |
+
offshore_wind_cost = st.number_input("Offshore Wind Capacity Cost (¥/MW)", value=180.0, help="Estimated average cost of offshore wind capacity per MW")
|
| 247 |
+
river_cost = st.number_input("River Capacity Cost (¥/MW)", value=100.0, help="Estimated average cost of river (hydro) capacity per MW")
|
| 248 |
+
battery_cost = st.number_input("Battery Cost (¥/MWh)", value=80.0, help="Estimated average cost of battery storage per MWh")
|
| 249 |
+
yearly_demand = st.number_input("Yearly Power Demand (TWh/year)", value=15.0, help="Total yearly power demand in TWh")
|
| 250 |
+
|
| 251 |
+
# Button to trigger optimization
|
| 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")
|
| 261 |
+
st.markdown("The following plots provide additional insights into the renewable energy mix, curtailment, and electricity price variations.")
|
| 262 |
+
|
| 263 |
+
# Data for additional visualizations
|
| 264 |
+
renewable_data = {
|
| 265 |
+
'Solar': solar_cost,
|
| 266 |
+
'Onshore Wind': onshore_wind_cost,
|
| 267 |
+
'Offshore Wind': offshore_wind_cost,
|
| 268 |
+
'Run of River': river_cost
|
| 269 |
+
}
|
| 270 |
+
cost_df = pd.DataFrame(list(renewable_data.items()), columns=['Technology', 'Cost (¥/MW)'])
|
| 271 |
+
|
| 272 |
+
# Plot cost comparison
|
| 273 |
+
fig_cost = px.bar(cost_df, x='Technology', y='Cost (¥/MW)', color='Technology', title='Cost Comparison of Different Renewable Technologies', template='plotly_white')
|
| 274 |
+
st.plotly_chart(fig_cost, use_container_width=True, height=800)
|
| 275 |
+
|
| 276 |
+
# Plot curtailment over time
|
| 277 |
+
curtailment_df = pd.DataFrame({"Time": fig.data[0].x, "Curtailment (MW)": curtailment_values})
|
| 278 |
+
fig_curtailment = px.line(curtailment_df, x='Time', y='Curtailment (MW)', title='Curtailment Over Time', template='plotly_white')
|
| 279 |
+
st.plotly_chart(fig_curtailment, use_container_width=True, height=800)
|
| 280 |
+
|
| 281 |
+
# Plot electricity price over time
|
| 282 |
+
price_df = pd.DataFrame({"Time": fig.data[0].x, "Electricity Price (¥/MWh)": price_per_hour})
|
| 283 |
+
fig_price = px.line(price_df, x='Time', y='Electricity Price (¥/MWh)', title='Electricity Price Variation Over Time', template='plotly_white')
|
| 284 |
+
st.plotly_chart(fig_price, use_container_width=True, height=800)
|
| 285 |
+
|
| 286 |
+
# Correlation analysis of renewable capacity factors
|
| 287 |
+
if city_code:
|
| 288 |
+
st.markdown("### Correlation Between Renewable Energy Sources")
|
| 289 |
+
correlation_matrix = get_renewable_energy_data(city_code)[0].corr()
|
| 290 |
+
if correlation_matrix is not None:
|
| 291 |
+
fig_corr = px.imshow(correlation_matrix, title='Correlation Matrix of Renewable Capacity Factors', labels={'color': 'Correlation'}, template='plotly_white')
|
| 292 |
+
st.plotly_chart(fig_corr, use_container_width=True, height=800)
|
| 293 |
+
fig_corr = px.imshow(correlation_matrix, title='Correlation Matrix of Renewable Capacity Factors', labels={'color': 'Correlation'}, template='plotly_white')
|
| 294 |
+
st.plotly_chart(fig_corr, use_container_width=True)
|
| 295 |
+
|
| 296 |
+
# Note: You may need to adjust initial values or labels to fit your requirements.
|