Spaces:
Sleeping
Sleeping
Update data/ashrae_tables.py
Browse files- data/ashrae_tables.py +32 -12
data/ashrae_tables.py
CHANGED
|
@@ -15,6 +15,7 @@ ENHANCEMENTS:
|
|
| 15 |
"""
|
| 16 |
|
| 17 |
from typing import Dict, List, Any, Optional, Tuple
|
|
|
|
| 18 |
import pandas as pd
|
| 19 |
import numpy as np
|
| 20 |
import os
|
|
@@ -189,10 +190,25 @@ class ASHRAETables:
|
|
| 189 |
0.9: 1.15 # Dark surfaces
|
| 190 |
}
|
| 191 |
|
| 192 |
-
|
| 193 |
logging.basicConfig(level=logging.INFO, format='%(asctime)s - %(levelname)s - %(message)s')
|
| 194 |
logger = logging.getLogger(__name__)
|
| 195 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 196 |
def _load_latitude_correction(self) -> pd.DataFrame:
|
| 197 |
"""
|
| 198 |
Load latitude correction factors for CLTD based on ASHRAE Handbook—Fundamentals (2017, Chapter 18, Table 7).
|
|
@@ -331,17 +347,21 @@ class ASHRAETables:
|
|
| 331 |
Raises:
|
| 332 |
ValueError: If source or subcategory is invalid.
|
| 333 |
"""
|
| 334 |
-
|
| 335 |
-
|
| 336 |
-
|
| 337 |
-
if subcategory
|
| 338 |
-
|
| 339 |
-
|
| 340 |
-
|
| 341 |
-
|
| 342 |
-
|
| 343 |
-
|
| 344 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 345 |
|
| 346 |
def interpolate_cltd(self, latitude: float, cltd_table_low: pd.DataFrame, cltd_table_high: pd.DataFrame, lat_low: float, lat_high: float) -> pd.DataFrame:
|
| 347 |
"""
|
|
|
|
| 15 |
"""
|
| 16 |
|
| 17 |
from typing import Dict, List, Any, Optional, Tuple
|
| 18 |
+
import logging
|
| 19 |
import pandas as pd
|
| 20 |
import numpy as np
|
| 21 |
import os
|
|
|
|
| 190 |
0.9: 1.15 # Dark surfaces
|
| 191 |
}
|
| 192 |
|
| 193 |
+
# Configure logging
|
| 194 |
logging.basicConfig(level=logging.INFO, format='%(asctime)s - %(levelname)s - %(message)s')
|
| 195 |
logger = logging.getLogger(__name__)
|
| 196 |
|
| 197 |
+
def __init__(self):
|
| 198 |
+
"""
|
| 199 |
+
Initialize ASHRAE tables with logging for debugging.
|
| 200 |
+
"""
|
| 201 |
+
logger.info("Initializing ASHRAETables")
|
| 202 |
+
try:
|
| 203 |
+
self.latitude_correction = self._load_latitude_correction()
|
| 204 |
+
self.occupancy_heat_gain = self._load_occupancy_heat_gain_table()
|
| 205 |
+
self.equipment_heat_gain = self._load_equipment_heat_gain_table()
|
| 206 |
+
self.heat_gain = self._load_heat_gain_table()
|
| 207 |
+
logger.info("ASHRAETables initialized successfully")
|
| 208 |
+
except Exception as e:
|
| 209 |
+
logger.error(f"Error initializing ASHRAETables: {str(e)}")
|
| 210 |
+
raise
|
| 211 |
+
|
| 212 |
def _load_latitude_correction(self) -> pd.DataFrame:
|
| 213 |
"""
|
| 214 |
Load latitude correction factors for CLTD based on ASHRAE Handbook—Fundamentals (2017, Chapter 18, Table 7).
|
|
|
|
| 347 |
Raises:
|
| 348 |
ValueError: If source or subcategory is invalid.
|
| 349 |
"""
|
| 350 |
+
try:
|
| 351 |
+
if source not in self.heat_gain['category'].values:
|
| 352 |
+
raise ValueError(f"Invalid source: {source}")
|
| 353 |
+
if subcategory:
|
| 354 |
+
if subcategory not in self.heat_gain[self.heat_gain['category'] == source]['subcategory'].values:
|
| 355 |
+
raise ValueError(f"Invalid subcategory for {source}: {subcategory}")
|
| 356 |
+
row = self.heat_gain[(self.heat_gain['category'] == source) & (self.heat_gain['subcategory'] == subcategory)]
|
| 357 |
+
else:
|
| 358 |
+
row = self.heat_gain[self.heat_gain['category'] == source]
|
| 359 |
+
if row.empty:
|
| 360 |
+
raise ValueError(f"No data found for source: {source}, subcategory: {subcategory}")
|
| 361 |
+
return float(row['sensible'].iloc[0]), float(row['latent'].iloc[0])
|
| 362 |
+
except Exception as e:
|
| 363 |
+
logger.error(f"Error in get_heat_gain: {str(e)}")
|
| 364 |
+
raise
|
| 365 |
|
| 366 |
def interpolate_cltd(self, latitude: float, cltd_table_low: pd.DataFrame, cltd_table_high: pd.DataFrame, lat_low: float, lat_high: float) -> pd.DataFrame:
|
| 367 |
"""
|