Update app.py
Browse files
app.py
CHANGED
|
@@ -6,35 +6,18 @@ import plotly.graph_objs as go
|
|
| 6 |
import plotly.express as px
|
| 7 |
import numpy as np
|
| 8 |
import matplotlib.pyplot as plt
|
|
|
|
| 9 |
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
data = response.json()
|
| 18 |
-
if not data:
|
| 19 |
-
return None, "No data found."
|
| 20 |
-
|
| 21 |
-
base_times = data[next(iter(data))]['x']
|
| 22 |
-
result_df = pd.DataFrame({"Time": base_times})
|
| 23 |
-
|
| 24 |
-
for energy_type, energy_data in data.items():
|
| 25 |
-
if 'x' in energy_data and 'y' in energy_data:
|
| 26 |
-
values = energy_data['y']
|
| 27 |
-
result_df[f"{energy_type} hourly capacity factor"] = values
|
| 28 |
-
|
| 29 |
-
return result_df, None
|
| 30 |
|
| 31 |
# Optimize energy system and use MGA
|
| 32 |
-
def optimize_energy_system(
|
| 33 |
-
data
|
| 34 |
-
if error:
|
| 35 |
-
st.error(error)
|
| 36 |
-
return None, None, None, None, None, None, None
|
| 37 |
-
|
| 38 |
for col in data.columns[1:]:
|
| 39 |
data[col] = pd.to_numeric(data[col], errors='coerce')
|
| 40 |
data = data.fillna(0)
|
|
@@ -163,7 +146,6 @@ st.title('Modeling to Generate Alternatives (MGA) in Renewable Energy System Opt
|
|
| 163 |
# Sidebar Inputs
|
| 164 |
with st.sidebar:
|
| 165 |
st.header('Input Parameters')
|
| 166 |
-
city_code = st.text_input("Enter City Code", value="999999")
|
| 167 |
solar_cost = st.number_input("Solar Capacity Cost (¥/MW)", value=80.0)
|
| 168 |
onshore_wind_cost = st.number_input("Onshore Wind Capacity Cost (¥/MW)", value=120.0)
|
| 169 |
offshore_wind_cost = st.number_input("Offshore Wind Capacity Cost (¥/MW)", value=180.0)
|
|
@@ -185,7 +167,7 @@ with st.sidebar:
|
|
| 185 |
|
| 186 |
if st.button("Run MGA Optimization"):
|
| 187 |
# 実行して alternative_solutions を取得
|
| 188 |
-
alternative_solutions = optimize_energy_system(
|
| 189 |
|
| 190 |
if alternative_solutions:
|
| 191 |
# # コスト積み上げ用データの収集
|
|
|
|
| 6 |
import plotly.express as px
|
| 7 |
import numpy as np
|
| 8 |
import matplotlib.pyplot as plt
|
| 9 |
+
import json
|
| 10 |
|
| 11 |
+
def get_json():
|
| 12 |
+
"""
|
| 13 |
+
ローカルのdata.json を取得する
|
| 14 |
+
"""
|
| 15 |
+
with open('data.json') as f:
|
| 16 |
+
return json.load(f)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 17 |
|
| 18 |
# Optimize energy system and use MGA
|
| 19 |
+
def optimize_energy_system(solar_cost, onshore_wind_cost, offshore_wind_cost, river_cost, battery_cost, yearly_demand, solar_range, wind_range, river_range, offshore_wind_range, thresholds, selected_tech):
|
| 20 |
+
data = get_json()
|
|
|
|
|
|
|
|
|
|
|
|
|
| 21 |
for col in data.columns[1:]:
|
| 22 |
data[col] = pd.to_numeric(data[col], errors='coerce')
|
| 23 |
data = data.fillna(0)
|
|
|
|
| 146 |
# Sidebar Inputs
|
| 147 |
with st.sidebar:
|
| 148 |
st.header('Input Parameters')
|
|
|
|
| 149 |
solar_cost = st.number_input("Solar Capacity Cost (¥/MW)", value=80.0)
|
| 150 |
onshore_wind_cost = st.number_input("Onshore Wind Capacity Cost (¥/MW)", value=120.0)
|
| 151 |
offshore_wind_cost = st.number_input("Offshore Wind Capacity Cost (¥/MW)", value=180.0)
|
|
|
|
| 167 |
|
| 168 |
if st.button("Run MGA Optimization"):
|
| 169 |
# 実行して alternative_solutions を取得
|
| 170 |
+
alternative_solutions = optimize_energy_system(solar_cost, onshore_wind_cost, offshore_wind_cost, river_cost, battery_cost, yearly_demand, solar_range, wind_range, river_range, offshore_wind_range, [t / 100 for t in thresholds], selected_technologies)
|
| 171 |
|
| 172 |
if alternative_solutions:
|
| 173 |
# # コスト積み上げ用データの収集
|