Spaces:
Sleeping
Sleeping
Update data/climate_data.py
Browse files- data/climate_data.py +37 -27
data/climate_data.py
CHANGED
|
@@ -20,7 +20,6 @@ from io import StringIO
|
|
| 20 |
# Define paths
|
| 21 |
DATA_DIR = os.path.dirname(os.path.abspath(__file__))
|
| 22 |
|
| 23 |
-
|
| 24 |
@dataclass
|
| 25 |
class ClimateLocation:
|
| 26 |
"""Class representing a climate location with ASHRAE 169 data."""
|
|
@@ -63,7 +62,6 @@ class ClimateLocation:
|
|
| 63 |
"monthly_humidity": self.monthly_humidity
|
| 64 |
}
|
| 65 |
|
| 66 |
-
|
| 67 |
class ClimateData:
|
| 68 |
"""Class for managing ASHRAE 169 climate data."""
|
| 69 |
|
|
@@ -229,32 +227,37 @@ class ClimateData:
|
|
| 229 |
monthly_humidity[month] = st.number_input(f"{month} Humidity (%)", min_value=0.0, max_value=100.0, value=50.0, step=5.0, key=f"hum_{month}")
|
| 230 |
|
| 231 |
if st.form_submit_button("Save Climate Data"):
|
| 232 |
-
|
| 233 |
-
|
| 234 |
-
|
| 235 |
-
|
| 236 |
-
|
| 237 |
-
|
| 238 |
-
|
| 239 |
-
|
| 240 |
-
|
| 241 |
-
|
| 242 |
-
|
| 243 |
-
|
| 244 |
-
|
| 245 |
-
|
| 246 |
-
|
| 247 |
-
|
| 248 |
-
|
| 249 |
-
|
| 250 |
-
|
| 251 |
-
|
| 252 |
-
|
| 253 |
-
|
| 254 |
-
|
| 255 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 256 |
|
| 257 |
-
# EPW Upload Tab
|
| 258 |
with tab2:
|
| 259 |
uploaded_file = st.file_uploader("Upload EPW File", type=["epw"])
|
| 260 |
if uploaded_file:
|
|
@@ -326,7 +329,9 @@ class ClimateData:
|
|
| 326 |
monthly_humidity=monthly_humidity
|
| 327 |
)
|
| 328 |
self.add_location(location)
|
|
|
|
| 329 |
st.success("Climate data extracted from EPW file with calculated Wet Bulb Temperature!")
|
|
|
|
| 330 |
self.display_design_conditions(location)
|
| 331 |
self.visualize_data(location, epw_data=epw_data)
|
| 332 |
except Exception as e:
|
|
@@ -341,6 +346,11 @@ class ClimateData:
|
|
| 341 |
else:
|
| 342 |
st.button("Continue to Building Components", disabled=True)
|
| 343 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 344 |
def display_design_conditions(self, location: ClimateLocation):
|
| 345 |
"""Display a table of design conditions including additional parameters for HVAC calculations."""
|
| 346 |
st.subheader("Design Conditions for HVAC Calculations")
|
|
|
|
| 20 |
# Define paths
|
| 21 |
DATA_DIR = os.path.dirname(os.path.abspath(__file__))
|
| 22 |
|
|
|
|
| 23 |
@dataclass
|
| 24 |
class ClimateLocation:
|
| 25 |
"""Class representing a climate location with ASHRAE 169 data."""
|
|
|
|
| 62 |
"monthly_humidity": self.monthly_humidity
|
| 63 |
}
|
| 64 |
|
|
|
|
| 65 |
class ClimateData:
|
| 66 |
"""Class for managing ASHRAE 169 climate data."""
|
| 67 |
|
|
|
|
| 227 |
monthly_humidity[month] = st.number_input(f"{month} Humidity (%)", min_value=0.0, max_value=100.0, value=50.0, step=5.0, key=f"hum_{month}")
|
| 228 |
|
| 229 |
if st.form_submit_button("Save Climate Data"):
|
| 230 |
+
try:
|
| 231 |
+
# Generate ID internally using country and city from session_state
|
| 232 |
+
generated_id = f"{session_state.building_info['country'][:2].upper()}-{session_state.building_info['city'][:3].upper()}"
|
| 233 |
+
location = ClimateLocation(
|
| 234 |
+
id=generated_id,
|
| 235 |
+
country=session_state.building_info["country"],
|
| 236 |
+
state_province="N/A", # Default since input removed
|
| 237 |
+
city=session_state.building_info["city"],
|
| 238 |
+
latitude=latitude,
|
| 239 |
+
longitude=longitude,
|
| 240 |
+
elevation=elevation,
|
| 241 |
+
climate_zone=climate_zone,
|
| 242 |
+
heating_degree_days=hdd,
|
| 243 |
+
cooling_degree_days=cdd,
|
| 244 |
+
winter_design_temp=winter_design_temp,
|
| 245 |
+
summer_design_temp_db=summer_design_temp_db,
|
| 246 |
+
summer_design_temp_wb=summer_design_temp_wb,
|
| 247 |
+
summer_daily_range=summer_daily_range,
|
| 248 |
+
monthly_temps=monthly_temps,
|
| 249 |
+
monthly_humidity=monthly_humidity
|
| 250 |
+
)
|
| 251 |
+
self.add_location(location)
|
| 252 |
+
session_state["climate_data"] = location.to_dict() # Save to session state
|
| 253 |
+
st.success("Climate data saved manually!")
|
| 254 |
+
st.write(f"Debug: Saved climate data for {location.city}: {location.to_dict()}") # Debug
|
| 255 |
+
self.display_design_conditions(location)
|
| 256 |
+
self.visualize_data(location, epw_data=None)
|
| 257 |
+
except Exception as e:
|
| 258 |
+
st.error(f"Error saving climate data: {str(e)}. Please check inputs and try again.")
|
| 259 |
|
| 260 |
+
# EPW Upload Tab
|
| 261 |
with tab2:
|
| 262 |
uploaded_file = st.file_uploader("Upload EPW File", type=["epw"])
|
| 263 |
if uploaded_file:
|
|
|
|
| 329 |
monthly_humidity=monthly_humidity
|
| 330 |
)
|
| 331 |
self.add_location(location)
|
| 332 |
+
session_state["climate_data"] = location.to_dict() # Save to session state
|
| 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.to_dict()}") # Debug
|
| 335 |
self.display_design_conditions(location)
|
| 336 |
self.visualize_data(location, epw_data=epw_data)
|
| 337 |
except Exception as e:
|
|
|
|
| 346 |
else:
|
| 347 |
st.button("Continue to Building Components", disabled=True)
|
| 348 |
|
| 349 |
+
# Display saved session state data (if any)
|
| 350 |
+
if "climate_data" in session_state and session_state["climate_data"]:
|
| 351 |
+
st.subheader("Saved Climate Data")
|
| 352 |
+
st.json(session_state["climate_data"]) # Display as JSON for clarity
|
| 353 |
+
|
| 354 |
def display_design_conditions(self, location: ClimateLocation):
|
| 355 |
"""Display a table of design conditions including additional parameters for HVAC calculations."""
|
| 356 |
st.subheader("Design Conditions for HVAC Calculations")
|