Spaces:
Sleeping
Sleeping
Update utils/cooling_load.py
Browse files- utils/cooling_load.py +30 -18
utils/cooling_load.py
CHANGED
|
@@ -4,7 +4,7 @@ Based on ASHRAE steady-state calculation methods.
|
|
| 4 |
|
| 5 |
Author: Dr Majed Abuseif
|
| 6 |
Date: April 2025
|
| 7 |
-
Version: 1.0.
|
| 8 |
"""
|
| 9 |
|
| 10 |
import streamlit as st
|
|
@@ -28,7 +28,7 @@ class CoolingLoadCalculator:
|
|
| 28 |
self.ashrae_tables = ASHRAETables()
|
| 29 |
self.heat_transfer = HeatTransferCalculations()
|
| 30 |
self.hours = list(range(24))
|
| 31 |
-
self.valid_latitudes = ['24N', '
|
| 32 |
self.valid_months = ['JAN', 'FEB', 'MAR', 'APR', 'MAY', 'JUN', 'JUL', 'AUG', 'SEP', 'OCT', 'NOV', 'DEC']
|
| 33 |
self.valid_wall_groups = ['A', 'B', 'C', 'D']
|
| 34 |
self.valid_roof_groups = ['A', 'B', 'C', 'D', 'E', 'F', 'G']
|
|
@@ -41,13 +41,15 @@ class CoolingLoadCalculator:
|
|
| 41 |
latitude: Latitude input (str, float, or other)
|
| 42 |
|
| 43 |
Returns:
|
| 44 |
-
Valid latitude string ('24N', '
|
| 45 |
"""
|
| 46 |
try:
|
| 47 |
if not isinstance(latitude, str):
|
| 48 |
latitude = str(latitude)
|
| 49 |
|
| 50 |
latitude = latitude.strip().upper()
|
|
|
|
|
|
|
| 51 |
|
| 52 |
# Handle concatenated formats like '24N_JUL'
|
| 53 |
if '_' in latitude:
|
|
@@ -58,33 +60,43 @@ class CoolingLoadCalculator:
|
|
| 58 |
logger.warning(f"Detected concatenated input: {latitude}. Using latitude={lat_part}")
|
| 59 |
latitude = lat_part
|
| 60 |
|
| 61 |
-
# Handle formats like '31.973N'
|
| 62 |
if '.' in latitude or any(c.isdigit() for c in latitude):
|
|
|
|
| 63 |
num_part = ''.join(c for c in latitude if c.isdigit() or c == '.')
|
| 64 |
try:
|
| 65 |
lat_val = float(num_part)
|
| 66 |
-
if lat_val <=
|
| 67 |
-
|
| 68 |
-
elif lat_val <=
|
| 69 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 70 |
else:
|
| 71 |
-
|
|
|
|
|
|
|
|
|
|
| 72 |
except ValueError:
|
| 73 |
if st.session_state.get('debug_mode', False):
|
| 74 |
-
logger.warning(f"Cannot parse latitude: {latitude}. Defaulting to '
|
| 75 |
-
return '
|
| 76 |
|
| 77 |
-
if latitude
|
| 78 |
-
|
| 79 |
-
|
| 80 |
-
return '24N'
|
| 81 |
|
| 82 |
-
|
|
|
|
|
|
|
|
|
|
| 83 |
|
| 84 |
except Exception as e:
|
| 85 |
if st.session_state.get('debug_mode', False):
|
| 86 |
logger.error(f"Error validating latitude {latitude}: {str(e)}")
|
| 87 |
-
return '
|
| 88 |
|
| 89 |
def validate_month(self, month: Any) -> str:
|
| 90 |
"""
|
|
@@ -174,7 +186,7 @@ class CoolingLoadCalculator:
|
|
| 174 |
|
| 175 |
try:
|
| 176 |
# Validate inputs
|
| 177 |
-
latitude = self.validate_latitude(outdoor_conditions.get('latitude', '
|
| 178 |
month = self.validate_month(outdoor_conditions.get('month', 'JUL'))
|
| 179 |
if st.session_state.get('debug_mode', False):
|
| 180 |
logger.debug(f"calculate_hourly_cooling_loads: latitude={latitude}, month={month}, outdoor_conditions={outdoor_conditions}")
|
|
|
|
| 4 |
|
| 5 |
Author: Dr Majed Abuseif
|
| 6 |
Date: April 2025
|
| 7 |
+
Version: 1.0.5
|
| 8 |
"""
|
| 9 |
|
| 10 |
import streamlit as st
|
|
|
|
| 28 |
self.ashrae_tables = ASHRAETables()
|
| 29 |
self.heat_transfer = HeatTransferCalculations()
|
| 30 |
self.hours = list(range(24))
|
| 31 |
+
self.valid_latitudes = ['24N', '32N', '40N', '48N', '56N'] # Updated to match error message
|
| 32 |
self.valid_months = ['JAN', 'FEB', 'MAR', 'APR', 'MAY', 'JUN', 'JUL', 'AUG', 'SEP', 'OCT', 'NOV', 'DEC']
|
| 33 |
self.valid_wall_groups = ['A', 'B', 'C', 'D']
|
| 34 |
self.valid_roof_groups = ['A', 'B', 'C', 'D', 'E', 'F', 'G']
|
|
|
|
| 41 |
latitude: Latitude input (str, float, or other)
|
| 42 |
|
| 43 |
Returns:
|
| 44 |
+
Valid latitude string ('24N', '32N', '40N', '48N', '56N')
|
| 45 |
"""
|
| 46 |
try:
|
| 47 |
if not isinstance(latitude, str):
|
| 48 |
latitude = str(latitude)
|
| 49 |
|
| 50 |
latitude = latitude.strip().upper()
|
| 51 |
+
if st.session_state.get('debug_mode', False):
|
| 52 |
+
logger.debug(f"Validating latitude: {latitude}")
|
| 53 |
|
| 54 |
# Handle concatenated formats like '24N_JUL'
|
| 55 |
if '_' in latitude:
|
|
|
|
| 60 |
logger.warning(f"Detected concatenated input: {latitude}. Using latitude={lat_part}")
|
| 61 |
latitude = lat_part
|
| 62 |
|
| 63 |
+
# Handle numerical formats like '31.973N'
|
| 64 |
if '.' in latitude or any(c.isdigit() for c in latitude):
|
| 65 |
+
# Extract numerical part, removing 'N' or 'S'
|
| 66 |
num_part = ''.join(c for c in latitude if c.isdigit() or c == '.')
|
| 67 |
try:
|
| 68 |
lat_val = float(num_part)
|
| 69 |
+
if lat_val <= 28:
|
| 70 |
+
mapped_latitude = '24N'
|
| 71 |
+
elif lat_val <= 36:
|
| 72 |
+
mapped_latitude = '32N'
|
| 73 |
+
elif lat_val <= 44:
|
| 74 |
+
mapped_latitude = '40N'
|
| 75 |
+
elif lat_val <= 52:
|
| 76 |
+
mapped_latitude = '48N'
|
| 77 |
else:
|
| 78 |
+
mapped_latitude = '56N'
|
| 79 |
+
if st.session_state.get('debug_mode', False):
|
| 80 |
+
logger.debug(f"Mapped numerical latitude {lat_val} to {mapped_latitude}")
|
| 81 |
+
return mapped_latitude
|
| 82 |
except ValueError:
|
| 83 |
if st.session_state.get('debug_mode', False):
|
| 84 |
+
logger.warning(f"Cannot parse numerical latitude: {latitude}. Defaulting to '32N'")
|
| 85 |
+
return '32N'
|
| 86 |
|
| 87 |
+
# Check if latitude is already valid
|
| 88 |
+
if latitude in self.valid_latitudes:
|
| 89 |
+
return latitude
|
|
|
|
| 90 |
|
| 91 |
+
# Handle invalid or unrecognized formats
|
| 92 |
+
if st.session_state.get('debug_mode', False):
|
| 93 |
+
logger.warning(f"Invalid latitude: {latitude}. Defaulting to '32N'")
|
| 94 |
+
return '32N'
|
| 95 |
|
| 96 |
except Exception as e:
|
| 97 |
if st.session_state.get('debug_mode', False):
|
| 98 |
logger.error(f"Error validating latitude {latitude}: {str(e)}")
|
| 99 |
+
return '32N'
|
| 100 |
|
| 101 |
def validate_month(self, month: Any) -> str:
|
| 102 |
"""
|
|
|
|
| 186 |
|
| 187 |
try:
|
| 188 |
# Validate inputs
|
| 189 |
+
latitude = self.validate_latitude(outdoor_conditions.get('latitude', '32N'))
|
| 190 |
month = self.validate_month(outdoor_conditions.get('month', 'JUL'))
|
| 191 |
if st.session_state.get('debug_mode', False):
|
| 192 |
logger.debug(f"calculate_hourly_cooling_loads: latitude={latitude}, month={month}, outdoor_conditions={outdoor_conditions}")
|