Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -158,66 +158,71 @@ def create_wind_rose(df, ax):
|
|
| 158 |
|
| 159 |
def create_plots(df):
|
| 160 |
"""Create all weather plots including SWE estimates"""
|
| 161 |
-
# Create figure with adjusted
|
| 162 |
-
fig = plt.figure(figsize=(20,
|
| 163 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 164 |
|
| 165 |
# Temperature plot
|
| 166 |
ax1 = fig.add_subplot(gs[0])
|
| 167 |
ax1.plot(df['datetime'], df['temp'], label='Temperature', color='red')
|
| 168 |
ax1.plot(df['datetime'], df['wind_chill'], label='Wind Chill', color='blue')
|
| 169 |
-
ax1.set_title('Temperature and Wind Chill Over Time')
|
| 170 |
ax1.set_xlabel('Date')
|
| 171 |
ax1.set_ylabel('Temperature (°F)')
|
| 172 |
ax1.legend()
|
| 173 |
ax1.grid(True)
|
| 174 |
-
|
| 175 |
|
| 176 |
# Wind speed plot
|
| 177 |
ax2 = fig.add_subplot(gs[1])
|
| 178 |
ax2.plot(df['datetime'], df['wind_speed'], label='Wind Speed', color='blue')
|
| 179 |
ax2.plot(df['datetime'], df['wind_gust'], label='Wind Gust', color='orange')
|
| 180 |
-
ax2.set_title('Wind Speed and Gusts Over Time')
|
| 181 |
ax2.set_xlabel('Date')
|
| 182 |
ax2.set_ylabel('Wind Speed (mph)')
|
| 183 |
ax2.legend()
|
| 184 |
ax2.grid(True)
|
| 185 |
-
|
| 186 |
|
| 187 |
-
# Snow depth plot
|
| 188 |
ax3 = fig.add_subplot(gs[2])
|
| 189 |
ax3.plot(df['datetime'], df['snow_depth'], color='blue', label='Snow Depth')
|
| 190 |
-
ax3.set_title('Snow Depth Over Time')
|
| 191 |
ax3.set_xlabel('Date')
|
| 192 |
ax3.set_ylabel('Snow Depth (inches)')
|
| 193 |
ax3.grid(True)
|
| 194 |
-
|
| 195 |
|
| 196 |
-
# Daily new snow bar plot
|
| 197 |
ax4 = fig.add_subplot(gs[3])
|
| 198 |
daily_snow = df.groupby('date')['snowfall_3hr'].sum()
|
| 199 |
ax4.bar(daily_snow.index, daily_snow.values, color='blue')
|
| 200 |
-
ax4.set_title('Daily New Snow')
|
| 201 |
ax4.set_xlabel('Date')
|
| 202 |
ax4.set_ylabel('New Snow (inches)')
|
| 203 |
-
|
| 204 |
|
| 205 |
# SWE bar plot
|
| 206 |
ax5 = fig.add_subplot(gs[4])
|
| 207 |
daily_swe = df.groupby('date')['swe'].mean()
|
| 208 |
ax5.bar(daily_swe.index, daily_swe.values, color='lightblue')
|
| 209 |
-
ax5.set_title('Snow/Water Equivalent')
|
| 210 |
ax5.set_xlabel('Date')
|
| 211 |
ax5.set_ylabel('SWE (inches)')
|
| 212 |
-
|
| 213 |
|
| 214 |
-
|
|
|
|
| 215 |
|
| 216 |
# Create separate wind rose figure
|
| 217 |
fig_rose = plt.figure(figsize=(10, 10))
|
| 218 |
ax_rose = WindroseAxes.from_ax(fig=fig_rose)
|
| 219 |
create_wind_rose(df, ax_rose)
|
| 220 |
-
|
| 221 |
|
| 222 |
return fig, fig_rose
|
| 223 |
|
|
|
|
| 158 |
|
| 159 |
def create_plots(df):
|
| 160 |
"""Create all weather plots including SWE estimates"""
|
| 161 |
+
# Create figure with adjusted height and spacing
|
| 162 |
+
fig = plt.figure(figsize=(20, 24))
|
| 163 |
+
|
| 164 |
+
# Calculate height ratios for different plots
|
| 165 |
+
height_ratios = [1, 1, 1, 1, 1] # Equal height for all plots
|
| 166 |
+
gs = GridSpec(5, 1, figure=fig, height_ratios=height_ratios)
|
| 167 |
+
gs.update(hspace=0.4) # Increase vertical spacing between plots
|
| 168 |
|
| 169 |
# Temperature plot
|
| 170 |
ax1 = fig.add_subplot(gs[0])
|
| 171 |
ax1.plot(df['datetime'], df['temp'], label='Temperature', color='red')
|
| 172 |
ax1.plot(df['datetime'], df['wind_chill'], label='Wind Chill', color='blue')
|
| 173 |
+
ax1.set_title('Temperature and Wind Chill Over Time', pad=20)
|
| 174 |
ax1.set_xlabel('Date')
|
| 175 |
ax1.set_ylabel('Temperature (°F)')
|
| 176 |
ax1.legend()
|
| 177 |
ax1.grid(True)
|
| 178 |
+
ax1.tick_params(axis='x', rotation=45)
|
| 179 |
|
| 180 |
# Wind speed plot
|
| 181 |
ax2 = fig.add_subplot(gs[1])
|
| 182 |
ax2.plot(df['datetime'], df['wind_speed'], label='Wind Speed', color='blue')
|
| 183 |
ax2.plot(df['datetime'], df['wind_gust'], label='Wind Gust', color='orange')
|
| 184 |
+
ax2.set_title('Wind Speed and Gusts Over Time', pad=20)
|
| 185 |
ax2.set_xlabel('Date')
|
| 186 |
ax2.set_ylabel('Wind Speed (mph)')
|
| 187 |
ax2.legend()
|
| 188 |
ax2.grid(True)
|
| 189 |
+
ax2.tick_params(axis='x', rotation=45)
|
| 190 |
|
| 191 |
+
# Snow depth plot
|
| 192 |
ax3 = fig.add_subplot(gs[2])
|
| 193 |
ax3.plot(df['datetime'], df['snow_depth'], color='blue', label='Snow Depth')
|
| 194 |
+
ax3.set_title('Snow Depth Over Time', pad=20)
|
| 195 |
ax3.set_xlabel('Date')
|
| 196 |
ax3.set_ylabel('Snow Depth (inches)')
|
| 197 |
ax3.grid(True)
|
| 198 |
+
ax3.tick_params(axis='x', rotation=45)
|
| 199 |
|
| 200 |
+
# Daily new snow bar plot
|
| 201 |
ax4 = fig.add_subplot(gs[3])
|
| 202 |
daily_snow = df.groupby('date')['snowfall_3hr'].sum()
|
| 203 |
ax4.bar(daily_snow.index, daily_snow.values, color='blue')
|
| 204 |
+
ax4.set_title('Daily New Snow', pad=20)
|
| 205 |
ax4.set_xlabel('Date')
|
| 206 |
ax4.set_ylabel('New Snow (inches)')
|
| 207 |
+
ax4.tick_params(axis='x', rotation=45)
|
| 208 |
|
| 209 |
# SWE bar plot
|
| 210 |
ax5 = fig.add_subplot(gs[4])
|
| 211 |
daily_swe = df.groupby('date')['swe'].mean()
|
| 212 |
ax5.bar(daily_swe.index, daily_swe.values, color='lightblue')
|
| 213 |
+
ax5.set_title('Snow/Water Equivalent', pad=20)
|
| 214 |
ax5.set_xlabel('Date')
|
| 215 |
ax5.set_ylabel('SWE (inches)')
|
| 216 |
+
ax5.tick_params(axis='x', rotation=45)
|
| 217 |
|
| 218 |
+
# Adjust layout
|
| 219 |
+
plt.subplots_adjust(top=0.95, bottom=0.05, left=0.1, right=0.95)
|
| 220 |
|
| 221 |
# Create separate wind rose figure
|
| 222 |
fig_rose = plt.figure(figsize=(10, 10))
|
| 223 |
ax_rose = WindroseAxes.from_ax(fig=fig_rose)
|
| 224 |
create_wind_rose(df, ax_rose)
|
| 225 |
+
fig_rose.subplots_adjust(top=0.95, bottom=0.05, left=0.1, right=0.95)
|
| 226 |
|
| 227 |
return fig, fig_rose
|
| 228 |
|