Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -7,15 +7,14 @@ import plotly.express as px
|
|
| 7 |
import numpy as np
|
| 8 |
|
| 9 |
# Function to fetch renewable energy data
|
| 10 |
-
def
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
data = response.json()
|
| 17 |
if not data:
|
| 18 |
-
return None, "
|
| 19 |
|
| 20 |
base_times = data[next(iter(data))]['x']
|
| 21 |
result_df = pd.DataFrame({"Time": base_times})
|
|
@@ -25,14 +24,11 @@ def get_renewable_energy_data(city_code):
|
|
| 25 |
values = energy_data['y']
|
| 26 |
result_df[f"{energy_type} hourly capacity factor"] = values
|
| 27 |
|
| 28 |
-
return
|
| 29 |
|
| 30 |
# Function to optimize the energy system and create visualizations
|
| 31 |
-
def optimize_energy_system(
|
| 32 |
-
data, error =
|
| 33 |
-
if error:
|
| 34 |
-
st.error(error)
|
| 35 |
-
return None, None, None, None, None, None
|
| 36 |
|
| 37 |
for col in data.columns[1:]:
|
| 38 |
data[col] = pd.to_numeric(data[col], errors='coerce')
|
|
@@ -276,7 +272,6 @@ The optimization problem aims to balance supply and demand at minimal cost, whil
|
|
| 276 |
|
| 277 |
with st.sidebar:
|
| 278 |
st.header('Input Parameters')
|
| 279 |
-
city_code = st.text_input("Enter City Code", value=999999)
|
| 280 |
solar_cost = st.number_input("Solar Capacity Cost (¥/MW)", value=80.0)
|
| 281 |
onshore_wind_cost = st.number_input("Onshore Wind Capacity Cost (¥/MW)", value=120.0)
|
| 282 |
offshore_wind_cost = st.number_input("Offshore Wind Capacity Cost (¥/MW)", value=180.0)
|
|
@@ -292,7 +287,7 @@ calculated_optimal_energy_mix = False
|
|
| 292 |
|
| 293 |
if st.button('Calculate Optimal Energy Mix'):
|
| 294 |
fig_energy, heatmaps, curtailment_values, soc_per_hour, fig_capacity_ranges, renewable_capacity = optimize_energy_system(
|
| 295 |
-
|
| 296 |
)
|
| 297 |
|
| 298 |
if fig_energy:
|
|
|
|
| 7 |
import numpy as np
|
| 8 |
|
| 9 |
# Function to fetch renewable energy data
|
| 10 |
+
def get_json():
|
| 11 |
+
"""
|
| 12 |
+
open data.json
|
| 13 |
+
"""
|
| 14 |
+
with open('data.json') as f:
|
| 15 |
+
data = json.load(f)
|
|
|
|
| 16 |
if not data:
|
| 17 |
+
return None, "No data found."
|
| 18 |
|
| 19 |
base_times = data[next(iter(data))]['x']
|
| 20 |
result_df = pd.DataFrame({"Time": base_times})
|
|
|
|
| 24 |
values = energy_data['y']
|
| 25 |
result_df[f"{energy_type} hourly capacity factor"] = values
|
| 26 |
|
| 27 |
+
return data
|
| 28 |
|
| 29 |
# Function to optimize the energy system and create visualizations
|
| 30 |
+
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):
|
| 31 |
+
data, error = get_json()
|
|
|
|
|
|
|
|
|
|
| 32 |
|
| 33 |
for col in data.columns[1:]:
|
| 34 |
data[col] = pd.to_numeric(data[col], errors='coerce')
|
|
|
|
| 272 |
|
| 273 |
with st.sidebar:
|
| 274 |
st.header('Input Parameters')
|
|
|
|
| 275 |
solar_cost = st.number_input("Solar Capacity Cost (¥/MW)", value=80.0)
|
| 276 |
onshore_wind_cost = st.number_input("Onshore Wind Capacity Cost (¥/MW)", value=120.0)
|
| 277 |
offshore_wind_cost = st.number_input("Offshore Wind Capacity Cost (¥/MW)", value=180.0)
|
|
|
|
| 287 |
|
| 288 |
if st.button('Calculate Optimal Energy Mix'):
|
| 289 |
fig_energy, heatmaps, curtailment_values, soc_per_hour, fig_capacity_ranges, renewable_capacity = optimize_energy_system(
|
| 290 |
+
solar_cost, onshore_wind_cost, offshore_wind_cost, river_cost, battery_cost, yearly_demand, solar_range, wind_range, river_range, offshore_wind_range
|
| 291 |
)
|
| 292 |
|
| 293 |
if fig_energy:
|