nakas commited on
Commit
1552018
·
verified ·
1 Parent(s): fad1ae6

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +16 -14
app.py CHANGED
@@ -140,12 +140,17 @@ def create_wind_rose(df, ax=None):
140
  wd = df['wind_dir_deg'].dropna().values
141
 
142
  if len(ws) > 0 and len(wd) > 0:
 
 
 
 
 
143
  # Create the wind rose
144
  ax.bar(wd, ws, nsector=36, normed=True, opening=0.8,
145
- bins=np.array([0, 5, 10, 15, 20, 25, 30, 35, 40]),
146
- colors=plt.cm.viridis(np.linspace(0, 1, 8)))
147
  ax.set_legend(title='Wind Speed (mph)', bbox_to_anchor=(1.2, 0.5))
148
- return ax
 
149
 
150
  def create_daily_wind_roses(df):
151
  """Create wind roses for each day"""
@@ -168,7 +173,7 @@ def create_plots(df):
168
  """Create all weather plots"""
169
  # Create main figure with subplots
170
  fig = plt.figure(figsize=(20, 25))
171
- gs = GridSpec(5, 2, figure=fig, height_ratios=[1, 1, 1, 1, 1])
172
 
173
  # Temperature plot
174
  ax1 = fig.add_subplot(gs[0, :])
@@ -195,7 +200,7 @@ def create_plots(df):
195
  plt.setp(ax2.xaxis.get_majorticklabels(), rotation=45, ha='right')
196
 
197
  # Snow depth plot
198
- ax3 = fig.add_subplot(gs[2, :])
199
  ax3.plot(df['datetime'], df['snow_depth'], color='blue', label='Snow Depth')
200
  ax3.set_title('Snow Depth Over Time', pad=20)
201
  ax3.set_xlabel('Date')
@@ -205,7 +210,7 @@ def create_plots(df):
205
  plt.setp(ax3.xaxis.get_majorticklabels(), rotation=45, ha='right')
206
 
207
  # Daily new snow bar plot
208
- ax4 = fig.add_subplot(gs[3, :])
209
  daily_snow = df.groupby('date')['snowfall_24hr'].max()
210
  bars = ax4.bar(range(len(daily_snow)), daily_snow.values, color='blue', width=0.8)
211
 
@@ -227,17 +232,15 @@ def create_plots(df):
227
  ax4.set_ylabel('New Snow (inches)')
228
  ax4.grid(True, axis='y')
229
 
230
- # Add overall wind rose
231
- fig_wind = plt.figure(figsize=(8, 8))
232
- ax5 = WindroseAxes.from_ax(fig=fig_wind)
233
  create_wind_rose(df, ax5)
234
  ax5.set_title('Overall Wind Rose')
235
 
236
- # Add latest day's wind rose
237
  latest_date = df['date'].iloc[0]
238
  latest_data = df[df['date'] == latest_date]
239
- fig_latest = plt.figure(figsize=(8, 8))
240
- ax6 = WindroseAxes.from_ax(fig=fig_latest)
241
  create_wind_rose(latest_data, ax6)
242
  ax6.set_title(f'Latest Day Wind Rose\n{latest_date}')
243
 
@@ -321,8 +324,7 @@ with gr.Blocks(title="Weather Station Data Analyzer") as demo:
321
  with gr.Row():
322
  weather_plots = gr.Plot(label="Weather Plots")
323
 
324
- with gr.Row():
325
- gallery = gr.Gallery(label="Daily Wind Roses", columns=3, rows=2, height=400)
326
 
327
  analyze_btn.click(
328
  fn=analyze_weather_data,
 
140
  wd = df['wind_dir_deg'].dropna().values
141
 
142
  if len(ws) > 0 and len(wd) > 0:
143
+ # Define wind speed bins
144
+ bins = np.array([0, 5, 10, 15, 20, 25, 30, 35])
145
+ # Create color map
146
+ colors = plt.cm.viridis(np.linspace(0, 1, len(bins)-1))
147
+
148
  # Create the wind rose
149
  ax.bar(wd, ws, nsector=36, normed=True, opening=0.8,
150
+ bins=bins, colors=colors)
 
151
  ax.set_legend(title='Wind Speed (mph)', bbox_to_anchor=(1.2, 0.5))
152
+ return True
153
+ return False
154
 
155
  def create_daily_wind_roses(df):
156
  """Create wind roses for each day"""
 
173
  """Create all weather plots"""
174
  # Create main figure with subplots
175
  fig = plt.figure(figsize=(20, 25))
176
+ gs = GridSpec(4, 2, figure=fig, height_ratios=[1, 1, 1, 1])
177
 
178
  # Temperature plot
179
  ax1 = fig.add_subplot(gs[0, :])
 
200
  plt.setp(ax2.xaxis.get_majorticklabels(), rotation=45, ha='right')
201
 
202
  # Snow depth plot
203
+ ax3 = fig.add_subplot(gs[2, 0])
204
  ax3.plot(df['datetime'], df['snow_depth'], color='blue', label='Snow Depth')
205
  ax3.set_title('Snow Depth Over Time', pad=20)
206
  ax3.set_xlabel('Date')
 
210
  plt.setp(ax3.xaxis.get_majorticklabels(), rotation=45, ha='right')
211
 
212
  # Daily new snow bar plot
213
+ ax4 = fig.add_subplot(gs[2, 1])
214
  daily_snow = df.groupby('date')['snowfall_24hr'].max()
215
  bars = ax4.bar(range(len(daily_snow)), daily_snow.values, color='blue', width=0.8)
216
 
 
232
  ax4.set_ylabel('New Snow (inches)')
233
  ax4.grid(True, axis='y')
234
 
235
+ # Wind roses
236
+ ax5 = fig.add_subplot(gs[3, 0], projection='windrose')
 
237
  create_wind_rose(df, ax5)
238
  ax5.set_title('Overall Wind Rose')
239
 
240
+ # Latest day's wind rose
241
  latest_date = df['date'].iloc[0]
242
  latest_data = df[df['date'] == latest_date]
243
+ ax6 = fig.add_subplot(gs[3, 1], projection='windrose')
 
244
  create_wind_rose(latest_data, ax6)
245
  ax6.set_title(f'Latest Day Wind Rose\n{latest_date}')
246
 
 
324
  with gr.Row():
325
  weather_plots = gr.Plot(label="Weather Plots")
326
 
327
+ gallery = gr.Gallery(label="Daily Wind Roses", columns=3, rows=2, height=400)
 
328
 
329
  analyze_btn.click(
330
  fn=analyze_weather_data,