mabuseif commited on
Commit
1446093
·
verified ·
1 Parent(s): e3754c7

Update app/climate_data.py

Browse files
Files changed (1) hide show
  1. app/climate_data.py +17 -5
app/climate_data.py CHANGED
@@ -237,6 +237,11 @@ class ClimateDataManager:
237
  if col in df.columns:
238
  df[col] = pd.to_numeric(df[col], errors='coerce')
239
 
 
 
 
 
 
240
  # Calculate design conditions
241
  design_conditions = self._calculate_design_conditions(df)
242
 
@@ -426,7 +431,7 @@ class ClimateDataManager:
426
 
427
  def _process_hourly_data(self, df: pd.DataFrame) -> List[Dict[str, Any]]:
428
  """
429
- Process hourly data from EPW DataFrame, including dew point, Sky Clearness Index, and total sky cover.
430
 
431
  Args:
432
  df: DataFrame containing EPW data
@@ -441,7 +446,8 @@ class ClimateDataManager:
441
  numeric_columns = [
442
  "dry_bulb_temp", "dew_point_temp", "relative_humidity", "atmospheric_pressure",
443
  "global_horizontal_radiation", "direct_normal_radiation",
444
- "diffuse_horizontal_radiation", "wind_speed", "wind_direction", "total_sky_cover"
 
445
  ]
446
 
447
  for col in numeric_columns:
@@ -473,6 +479,9 @@ class ClimateDataManager:
473
  # Extract total sky cover
474
  total_sky_cover = float(row["total_sky_cover"]) if not pd.isna(row["total_sky_cover"]) else None
475
 
 
 
 
476
  record = {
477
  "month": int(row["month"]),
478
  "day": int(row["day"]),
@@ -487,7 +496,8 @@ class ClimateDataManager:
487
  "wind_speed": float(row["wind_speed"]) if not pd.isna(row["wind_speed"]) else 0.0,
488
  "wind_direction": float(row["wind_direction"]) if not pd.isna(row["wind_direction"]) else 0.0,
489
  "sky_clearness_index": sky_clearness_index if sky_clearness_index is not None else None,
490
- "total_sky_cover": total_sky_cover
 
491
  }
492
  hourly_data.append(record)
493
 
@@ -863,7 +873,8 @@ def display_climate_summary(climate_data: Dict[str, Any]):
863
  "Wind Speed (m/s)": f"{record['wind_speed']:.1f}",
864
  "Wind Direction (°)": f"{record['wind_direction']:.1f}",
865
  "Sky Clearness Index": f"{record['sky_clearness_index']:.3f}" if record['sky_clearness_index'] is not None else "N/A",
866
- "Total Sky Cover": f"{record['total_sky_cover']:.1f}" if record['total_sky_cover'] is not None else "N/A"
 
867
  }
868
  for record in climate_data["hourly_data"]
869
  ]
@@ -906,6 +917,7 @@ def display_climate_help():
906
  * Wind speed and direction
907
  * Atmospheric pressure
908
  * Sky Clearness Index (calculated)
 
909
 
910
  **Where to Find EPW Files:**
911
 
@@ -928,7 +940,7 @@ def display_climate_help():
928
  * Typical/Extreme periods
929
  * Ground temperatures by depth
930
  * Monthly average temperatures and solar radiation
931
- * Hourly data statistics with downloadable tables (including dew point and Sky Clearness Index)
932
 
933
  This information will be used throughout the calculation process.
934
  """)
 
237
  if col in df.columns:
238
  df[col] = pd.to_numeric(df[col], errors='coerce')
239
 
240
+ # Calculate diffuse fraction
241
+ df['diffuse_fraction'] = df.apply(
242
+ lambda row: row['diffuse_horizontal_radiation'] / row['global_horizontal_radiation'] if row['global_horizontal_radiation'] > 0 else 0.0, axis=1
243
+ )
244
+
245
  # Calculate design conditions
246
  design_conditions = self._calculate_design_conditions(df)
247
 
 
431
 
432
  def _process_hourly_data(self, df: pd.DataFrame) -> List[Dict[str, Any]]:
433
  """
434
+ Process hourly data from EPW DataFrame, including dew point, Sky Clearness Index, diffuse fraction, and total sky cover.
435
 
436
  Args:
437
  df: DataFrame containing EPW data
 
446
  numeric_columns = [
447
  "dry_bulb_temp", "dew_point_temp", "relative_humidity", "atmospheric_pressure",
448
  "global_horizontal_radiation", "direct_normal_radiation",
449
+ "diffuse_horizontal_radiation", "wind_speed", "wind_direction", "total_sky_cover",
450
+ "diffuse_fraction"
451
  ]
452
 
453
  for col in numeric_columns:
 
479
  # Extract total sky cover
480
  total_sky_cover = float(row["total_sky_cover"]) if not pd.isna(row["total_sky_cover"]) else None
481
 
482
+ # Extract diffuse fraction
483
+ diffuse_fraction = float(row["diffuse_fraction"]) if not pd.isna(row["diffuse_fraction"]) else 0.0
484
+
485
  record = {
486
  "month": int(row["month"]),
487
  "day": int(row["day"]),
 
496
  "wind_speed": float(row["wind_speed"]) if not pd.isna(row["wind_speed"]) else 0.0,
497
  "wind_direction": float(row["wind_direction"]) if not pd.isna(row["wind_direction"]) else 0.0,
498
  "sky_clearness_index": sky_clearness_index if sky_clearness_index is not None else None,
499
+ "total_sky_cover": total_sky_cover,
500
+ "diffuse_fraction": diffuse_fraction
501
  }
502
  hourly_data.append(record)
503
 
 
873
  "Wind Speed (m/s)": f"{record['wind_speed']:.1f}",
874
  "Wind Direction (°)": f"{record['wind_direction']:.1f}",
875
  "Sky Clearness Index": f"{record['sky_clearness_index']:.3f}" if record['sky_clearness_index'] is not None else "N/A",
876
+ "Total Sky Cover": f"{record['total_sky_cover']:.1f}" if record['total_sky_cover'] is not None else "N/A",
877
+ "Diffuse Fraction": f"{record['diffuse_fraction']:.3f}" if record['diffuse_fraction'] is not None else "N/A"
878
  }
879
  for record in climate_data["hourly_data"]
880
  ]
 
917
  * Wind speed and direction
918
  * Atmospheric pressure
919
  * Sky Clearness Index (calculated)
920
+ * Diffuse Fraction (calculated)
921
 
922
  **Where to Find EPW Files:**
923
 
 
940
  * Typical/Extreme periods
941
  * Ground temperatures by depth
942
  * Monthly average temperatures and solar radiation
943
+ * Hourly data statistics with downloadable tables (including dew point, Sky Clearness Index, and Diffuse Fraction)
944
 
945
  This information will be used throughout the calculation process.
946
  """)