naohiro701 commited on
Commit
d536f1c
·
verified ·
1 Parent(s): 2a987db

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +35 -1
app.py CHANGED
@@ -37,7 +37,7 @@ def optimize_energy_system(city_code, solar_cost, onshore_wind_cost, offshore_wi
37
  data, error = get_renewable_energy_data(city_code)
38
  if error:
39
  st.error(error)
40
- return None, None, None, None
41
 
42
  for col in data.columns[1:]:
43
  data[col] = pd.to_numeric(data[col], errors='coerce')
@@ -143,6 +143,40 @@ def optimize_energy_system(city_code, solar_cost, onshore_wind_cost, offshore_wi
143
  yaxis=dict(showgrid=True, gridwidth=0.5, gridcolor='lightgray')
144
  )
145
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
146
  # Create capacity range visualization for each technology
147
  fig_capacity_ranges = go.Figure()
148
  technologies = ['solar', 'onshore_wind', 'offshore_wind', 'river']
 
37
  data, error = get_renewable_energy_data(city_code)
38
  if error:
39
  st.error(error)
40
+ return None, None, None, None, None
41
 
42
  for col in data.columns[1:]:
43
  data[col] = pd.to_numeric(data[col], errors='coerce')
 
143
  yaxis=dict(showgrid=True, gridwidth=0.5, gridcolor='lightgray')
144
  )
145
 
146
+ # Heatmap generation for each renewable energy source
147
+ heatmaps = []
148
+ for energy_source in ['solar', 'onshore_wind', 'offshore_wind', 'river']:
149
+ df_heatmap = data[['Time', f'{energy_source} hourly capacity factor']].copy()
150
+ df_heatmap['Time'] = pd.to_datetime(df_heatmap['Time'], errors='coerce')
151
+ df_heatmap['day_of_year'] = df_heatmap['Time'].dt.dayofyear
152
+ df_heatmap['hour_of_day'] = df_heatmap['Time'].dt.hour
153
+
154
+ pivot_df = df_heatmap.pivot_table(
155
+ index='hour_of_day',
156
+ columns='day_of_year',
157
+ values=f'{energy_source} hourly capacity factor',
158
+ aggfunc='mean'
159
+ )
160
+
161
+ fig_heatmap = px.imshow(
162
+ pivot_df.values,
163
+ labels=dict(x="Day of Year", y="Hour of Day", color=f"{energy_source.replace('_', ' ').title()} Capacity Factor"),
164
+ x=pivot_df.columns,
165
+ y=pivot_df.index,
166
+ aspect="auto",
167
+ color_continuous_scale='Plasma'
168
+ )
169
+
170
+ fig_heatmap.update_layout(
171
+ title=f'{energy_source.replace("_", " ").title()} Hourly Capacity Factor (24 Hours x 365 Days)',
172
+ xaxis_title='Day of Year',
173
+ yaxis_title='Hour of Day',
174
+ font=dict(size=12),
175
+ plot_bgcolor='white',
176
+ margin=dict(l=40, r=40, t=40, b=40),
177
+ )
178
+ heatmaps.append(fig_heatmap)
179
+
180
  # Create capacity range visualization for each technology
181
  fig_capacity_ranges = go.Figure()
182
  technologies = ['solar', 'onshore_wind', 'offshore_wind', 'river']