Spaces:
Sleeping
Sleeping
Update data/climate_data.py
Browse files- data/climate_data.py +59 -5
data/climate_data.py
CHANGED
|
@@ -91,6 +91,54 @@ class ClimateData:
|
|
| 91 |
self.countries = sorted(list(set(loc.country for loc in self.locations.values())))
|
| 92 |
self.country_states = self._group_locations_by_country_state()
|
| 93 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 94 |
@staticmethod
|
| 95 |
def calculate_wet_bulb(dry_bulb: np.ndarray, relative_humidity: np.ndarray) -> np.ndarray:
|
| 96 |
"""Calculate Wet Bulb Temperature using Stull (2011) approximation."""
|
|
@@ -249,9 +297,12 @@ class ClimateData:
|
|
| 249 |
monthly_humidity=monthly_humidity
|
| 250 |
)
|
| 251 |
self.add_location(location)
|
| 252 |
-
|
|
|
|
|
|
|
|
|
|
| 253 |
st.success("Climate data saved manually!")
|
| 254 |
-
st.write(f"Debug: Saved climate data for {location.city}: {location.
|
| 255 |
self.display_design_conditions(location)
|
| 256 |
self.visualize_data(location, epw_data=None)
|
| 257 |
except Exception as e:
|
|
@@ -329,9 +380,12 @@ class ClimateData:
|
|
| 329 |
monthly_humidity=monthly_humidity
|
| 330 |
)
|
| 331 |
self.add_location(location)
|
| 332 |
-
|
|
|
|
|
|
|
|
|
|
| 333 |
st.success("Climate data extracted from EPW file with calculated Wet Bulb Temperature!")
|
| 334 |
-
st.write(f"Debug: Saved climate data for {location.city}: {location.
|
| 335 |
self.display_design_conditions(location)
|
| 336 |
self.visualize_data(location, epw_data=epw_data)
|
| 337 |
except Exception as e:
|
|
@@ -541,5 +595,5 @@ class ClimateData:
|
|
| 541 |
|
| 542 |
if __name__ == "__main__":
|
| 543 |
climate_data = ClimateData()
|
| 544 |
-
session_state = {"building_info": {"country": "Iceland", "city": "
|
| 545 |
climate_data.display_climate_input(session_state)
|
|
|
|
| 91 |
self.countries = sorted(list(set(loc.country for loc in self.locations.values())))
|
| 92 |
self.country_states = self._group_locations_by_country_state()
|
| 93 |
|
| 94 |
+
def get_location_by_id(self, location_id: str, session_state: Dict[str, Any]) -> Optional[Dict[str, Any]]:
|
| 95 |
+
"""Retrieve climate data by ID from session state or locations."""
|
| 96 |
+
if "climate_data" in session_state and session_state["climate_data"].get("id") == location_id:
|
| 97 |
+
return session_state["climate_data"]
|
| 98 |
+
if location_id in self.locations:
|
| 99 |
+
return self.locations[location_id].to_dict()
|
| 100 |
+
return None
|
| 101 |
+
|
| 102 |
+
@staticmethod
|
| 103 |
+
def validate_climate_data(data: Dict[str, Any]) -> bool:
|
| 104 |
+
"""Validate climate data for required fields and ranges."""
|
| 105 |
+
required_fields = [
|
| 106 |
+
"id", "country", "city", "latitude", "longitude", "elevation",
|
| 107 |
+
"climate_zone", "heating_degree_days", "cooling_degree_days",
|
| 108 |
+
"winter_design_temp", "summer_design_temp_db", "summer_design_temp_wb",
|
| 109 |
+
"summer_daily_range", "monthly_temps", "monthly_humidity"
|
| 110 |
+
]
|
| 111 |
+
month_names = ["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"]
|
| 112 |
+
|
| 113 |
+
for field in required_fields:
|
| 114 |
+
if field not in data:
|
| 115 |
+
return False
|
| 116 |
+
|
| 117 |
+
if not (-90 <= data["latitude"] <= 90 and -180 <= data["longitude"] <= 180):
|
| 118 |
+
return False
|
| 119 |
+
if data["elevation"] < 0:
|
| 120 |
+
return False
|
| 121 |
+
if data["climate_zone"] not in ["0A", "0B", "1A", "1B", "2A", "2B", "3A", "3B", "3C", "4A", "4B", "4C", "5A", "5B", "5C", "6A", "6B", "7", "8"]:
|
| 122 |
+
return False
|
| 123 |
+
if not (data["heating_degree_days"] >= 0 and data["cooling_degree_days"] >= 0):
|
| 124 |
+
return False
|
| 125 |
+
if not (-50 <= data["winter_design_temp"] <= 20):
|
| 126 |
+
return False
|
| 127 |
+
if not (0 <= data["summer_design_temp_db"] <= 50 and 0 <= data["summer_design_temp_wb"] <= 40):
|
| 128 |
+
return False
|
| 129 |
+
if data["summer_daily_range"] < 0:
|
| 130 |
+
return False
|
| 131 |
+
|
| 132 |
+
for month in month_names:
|
| 133 |
+
if month not in data["monthly_temps"] or month not in data["monthly_humidity"]:
|
| 134 |
+
return False
|
| 135 |
+
if not (-50 <= data["monthly_temps"][month] <= 50):
|
| 136 |
+
return False
|
| 137 |
+
if not (0 <= data["monthly_humidity"][month] <= 100):
|
| 138 |
+
return False
|
| 139 |
+
|
| 140 |
+
return True
|
| 141 |
+
|
| 142 |
@staticmethod
|
| 143 |
def calculate_wet_bulb(dry_bulb: np.ndarray, relative_humidity: np.ndarray) -> np.ndarray:
|
| 144 |
"""Calculate Wet Bulb Temperature using Stull (2011) approximation."""
|
|
|
|
| 297 |
monthly_humidity=monthly_humidity
|
| 298 |
)
|
| 299 |
self.add_location(location)
|
| 300 |
+
climate_data_dict = location.to_dict()
|
| 301 |
+
if not self.validate_climate_data(climate_data_dict):
|
| 302 |
+
raise ValueError("Invalid climate data. Please check all inputs.")
|
| 303 |
+
session_state["climate_data"] = climate_data_dict # Save to session state
|
| 304 |
st.success("Climate data saved manually!")
|
| 305 |
+
st.write(f"Debug: Saved climate data for {location.city} (ID: {location.id}): {climate_data_dict}") # Debug
|
| 306 |
self.display_design_conditions(location)
|
| 307 |
self.visualize_data(location, epw_data=None)
|
| 308 |
except Exception as e:
|
|
|
|
| 380 |
monthly_humidity=monthly_humidity
|
| 381 |
)
|
| 382 |
self.add_location(location)
|
| 383 |
+
climate_data_dict = location.to_dict()
|
| 384 |
+
if not self.validate_climate_data(climate_data_dict):
|
| 385 |
+
raise ValueError("Invalid climate data extracted from EPW file.")
|
| 386 |
+
session_state["climate_data"] = climate_data_dict # Save to session state
|
| 387 |
st.success("Climate data extracted from EPW file with calculated Wet Bulb Temperature!")
|
| 388 |
+
st.write(f"Debug: Saved climate data for {location.city} (ID: {location.id}): {climate_data_dict}") # Debug
|
| 389 |
self.display_design_conditions(location)
|
| 390 |
self.visualize_data(location, epw_data=epw_data)
|
| 391 |
except Exception as e:
|
|
|
|
| 595 |
|
| 596 |
if __name__ == "__main__":
|
| 597 |
climate_data = ClimateData()
|
| 598 |
+
session_state = {"building_info": {"country": "Iceland", "city": "Reyugalvik"}, "page": "Climate Data"}
|
| 599 |
climate_data.display_climate_input(session_state)
|