nakas commited on
Commit
422dcf7
·
verified ·
1 Parent(s): 2195fe7

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +14 -8
app.py CHANGED
@@ -140,7 +140,7 @@ def parse_weather_data(data):
140
  def calculate_total_new_snow(df):
141
  """
142
  Calculate total new snow by:
143
- 1. Summing 3-hour snowfall amounts within each day period
144
  2. Using 9 AM as the daily reset point
145
  3. Filtering out obvious anomalies (>9 inches in 3 hours)
146
 
@@ -153,7 +153,7 @@ def calculate_total_new_snow(df):
153
  # Sort by datetime to ensure correct calculation
154
  df = df.sort_values('datetime')
155
 
156
- # Create a copy of the dataframe with just the columns we need
157
  snow_df = df[['datetime', 'snowfall_3hr']].copy()
158
 
159
  # Create a day group that starts at 9 AM instead of midnight
@@ -162,17 +162,21 @@ def calculate_total_new_snow(df):
162
  )
163
 
164
  def process_daily_snow(group):
165
- """Sum up the 3-hour snowfall amounts for each day period"""
166
  # Sort by time to ensure proper sequence
167
  group = group.sort_values('datetime')
168
 
169
- # Filter out obvious anomalies (more than 9 inches in 3 hours)
170
- MAX_THREE_HOUR_SNOW = 9.0 # Maximum reasonable snow in 3 hours
171
- valid_snow = group['snowfall_3hr'].where(group['snowfall_3hr'] <= MAX_THREE_HOUR_SNOW, 0.0)
 
 
172
 
173
- # Sum up all valid 3-hour amounts
174
- daily_total = valid_snow.sum()
 
175
 
 
176
  return daily_total
177
 
178
  # Calculate daily snow totals
@@ -211,6 +215,8 @@ def create_daily_snow_plot(df, ax):
211
  ha='center', va='bottom')
212
 
213
 
 
 
214
 
215
  def create_wind_rose(df, ax):
216
  """Create a wind rose plot"""
 
140
  def calculate_total_new_snow(df):
141
  """
142
  Calculate total new snow by:
143
+ 1. Using ONLY the 3-hour snowfall amounts
144
  2. Using 9 AM as the daily reset point
145
  3. Filtering out obvious anomalies (>9 inches in 3 hours)
146
 
 
153
  # Sort by datetime to ensure correct calculation
154
  df = df.sort_values('datetime')
155
 
156
+ # Create a copy of the dataframe with ONLY datetime and 3-hour snowfall
157
  snow_df = df[['datetime', 'snowfall_3hr']].copy()
158
 
159
  # Create a day group that starts at 9 AM instead of midnight
 
162
  )
163
 
164
  def process_daily_snow(group):
165
+ """Sum up ONLY the 3-hour snowfall amounts for each day period"""
166
  # Sort by time to ensure proper sequence
167
  group = group.sort_values('datetime')
168
 
169
+ # Print debugging information
170
+ print(f"\nSnowfall amounts for {group['day_group'].iloc[0]}:")
171
+ for _, row in group.iterrows():
172
+ if pd.notna(row['snowfall_3hr']):
173
+ print(f"{row['datetime'].strftime('%Y-%m-%d %H:%M')}: {row['snowfall_3hr']} inches")
174
 
175
+ # Sum only the valid 3-hour amounts, treating NaN as 0
176
+ valid_amounts = group['snowfall_3hr'].fillna(0)
177
+ daily_total = valid_amounts.sum()
178
 
179
+ print(f"Daily total: {daily_total} inches")
180
  return daily_total
181
 
182
  # Calculate daily snow totals
 
215
  ha='center', va='bottom')
216
 
217
 
218
+
219
+
220
 
221
  def create_wind_rose(df, ax):
222
  """Create a wind rose plot"""