Spaces:
Sleeping
Sleeping
Update data/ashrae_tables.py
Browse files- data/ashrae_tables.py +39 -14
data/ashrae_tables.py
CHANGED
@@ -1332,6 +1332,12 @@ class ASHRAETables:
|
|
1332 |
Raises:
|
1333 |
ValueError: If inputs are invalid or out of range.
|
1334 |
"""
|
|
|
|
|
|
|
|
|
|
|
|
|
1335 |
if element_type not in ['wall', 'roof']:
|
1336 |
raise ValueError("element_type must be 'wall' or 'roof'")
|
1337 |
if hour not in range(24):
|
@@ -1351,31 +1357,50 @@ class ASHRAETables:
|
|
1351 |
latitudes = [24, 32, 40, 48, 56]
|
1352 |
lat1, lat2 = max([lat for lat in latitudes if lat <= latitude], default=24), min([lat for lat in latitudes if lat >= latitude], default=56)
|
1353 |
|
|
|
|
|
|
|
|
|
1354 |
# Load the appropriate table
|
1355 |
table = self.cltd_wall if element_type == 'wall' else self.cltd_roof
|
1356 |
key1 = f"{group}_{int(lat1)}"
|
1357 |
key2 = f"{group}_{int(lat2)}"
|
1358 |
|
|
|
1359 |
if key1 not in table or key2 not in table:
|
1360 |
-
|
1361 |
-
|
1362 |
-
|
1363 |
-
|
1364 |
-
|
1365 |
-
except KeyError:
|
1366 |
-
raise ValueError(f"Invalid orientation {orientation} for group {group}")
|
1367 |
-
|
1368 |
-
# Linear interpolation
|
1369 |
-
if lat1 == lat2:
|
1370 |
-
cltd = cltd1
|
1371 |
else:
|
1372 |
-
|
1373 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1374 |
|
1375 |
# Apply corrections
|
1376 |
-
lm = self.month_correction.get(
|
1377 |
f = self._load_fenestration_correction().get('Standard', 1.0)
|
1378 |
corrected_cltd = self.apply_cltd_corrections(cltd, lm, solar_absorptivity, f)
|
|
|
|
|
|
|
1379 |
return corrected_cltd
|
1380 |
|
1381 |
@lru_cache(maxsize=1000)
|
|
|
1332 |
Raises:
|
1333 |
ValueError: If inputs are invalid or out of range.
|
1334 |
"""
|
1335 |
+
import streamlit as st # For debug logging
|
1336 |
+
|
1337 |
+
# Log inputs for debugging
|
1338 |
+
if st.session_state.get('debug_mode', False):
|
1339 |
+
st.write(f"Debug: get_cltd inputs: element_type={element_type}, group={group}, orientation={orientation}, hour={hour}, latitude={latitude}, solar_absorptivity={solar_absorptivity}")
|
1340 |
+
|
1341 |
if element_type not in ['wall', 'roof']:
|
1342 |
raise ValueError("element_type must be 'wall' or 'roof'")
|
1343 |
if hour not in range(24):
|
|
|
1357 |
latitudes = [24, 32, 40, 48, 56]
|
1358 |
lat1, lat2 = max([lat for lat in latitudes if lat <= latitude], default=24), min([lat for lat in latitudes if lat >= latitude], default=56)
|
1359 |
|
1360 |
+
# Log selected latitudes
|
1361 |
+
if st.session_state.get('debug_mode', False):
|
1362 |
+
st.write(f"Debug: Selected latitudes for interpolation: lat1={lat1}, lat2={lat2}")
|
1363 |
+
|
1364 |
# Load the appropriate table
|
1365 |
table = self.cltd_wall if element_type == 'wall' else self.cltd_roof
|
1366 |
key1 = f"{group}_{int(lat1)}"
|
1367 |
key2 = f"{group}_{int(lat2)}"
|
1368 |
|
1369 |
+
# Check if keys exist; use fallback if not
|
1370 |
if key1 not in table or key2 not in table:
|
1371 |
+
if st.session_state.get('debug_mode', False):
|
1372 |
+
st.write(f"Debug: Available table keys: {list(table.keys())}")
|
1373 |
+
st.error(f"Warning: Group {group} not found for latitude {lat1} or {lat2}. Using fallback CLTD value.")
|
1374 |
+
# Fallback CLTD value (average for medium construction, per ASHRAE)
|
1375 |
+
cltd = 8.0
|
|
|
|
|
|
|
|
|
|
|
|
|
1376 |
else:
|
1377 |
+
try:
|
1378 |
+
cltd1 = table[key1].at[hour, orientation]
|
1379 |
+
cltd2 = table[key2].at[hour, orientation]
|
1380 |
+
if st.session_state.get('debug_mode', False):
|
1381 |
+
st.write(f"Debug: CLTD values: cltd1={cltd1} at {key1}, cltd2={cltd2} at {key2}")
|
1382 |
+
except KeyError:
|
1383 |
+
if st.session_state.get('debug_mode', False):
|
1384 |
+
st.write(f"Debug: Available orientations for {key1}: {list(table[key1].columns)}")
|
1385 |
+
st.error(f"Warning: Invalid orientation {orientation} for group {group}. Using fallback CLTD value.")
|
1386 |
+
cltd = 8.0
|
1387 |
+
else:
|
1388 |
+
# Linear interpolation
|
1389 |
+
if lat1 == lat2:
|
1390 |
+
cltd = cltd1
|
1391 |
+
else:
|
1392 |
+
weight = (latitude - lat1) / (lat2 - lat1)
|
1393 |
+
cltd = cltd1 + weight * (cltd2 - cltd1)
|
1394 |
+
if st.session_state.get('debug_mode', False):
|
1395 |
+
st.write(f"Debug: Interpolated CLTD: weight={weight}, cltd={cltd}")
|
1396 |
|
1397 |
# Apply corrections
|
1398 |
+
lm = self.month_correction.get(month, 0.0) # Simplified access for July
|
1399 |
f = self._load_fenestration_correction().get('Standard', 1.0)
|
1400 |
corrected_cltd = self.apply_cltd_corrections(cltd, lm, solar_absorptivity, f)
|
1401 |
+
if st.session_state.get('debug_mode', False):
|
1402 |
+
st.write(f"Debug: Applied corrections: lm={lm}, f={f}, corrected_cltd={corrected_cltd}")
|
1403 |
+
|
1404 |
return corrected_cltd
|
1405 |
|
1406 |
@lru_cache(maxsize=1000)
|