File size: 11,088 Bytes
6cc22a6 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 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 258 259 260 |
"""
Weather data module for HVAC Load Calculator.
This module provides access to weather data for cooling load calculations.
"""
from typing import Dict, List, Any, Optional, Tuple
import pandas as pd
import numpy as np
import datetime
class WeatherDataProvider:
"""Class for providing weather data for cooling load calculations."""
def __init__(self):
"""Initialize weather data provider."""
# Default monthly average temperatures for a temperate climate
self.default_monthly_temps = {
"Jan": {"avg_temp": 0.0, "daily_range": 8.0, "relative_humidity": 70.0},
"Feb": {"avg_temp": 2.0, "daily_range": 9.0, "relative_humidity": 65.0},
"Mar": {"avg_temp": 7.0, "daily_range": 10.0, "relative_humidity": 60.0},
"Apr": {"avg_temp": 12.0, "daily_range": 11.0, "relative_humidity": 55.0},
"May": {"avg_temp": 17.0, "daily_range": 12.0, "relative_humidity": 50.0},
"Jun": {"avg_temp": 22.0, "daily_range": 13.0, "relative_humidity": 55.0},
"Jul": {"avg_temp": 25.0, "daily_range": 13.0, "relative_humidity": 60.0},
"Aug": {"avg_temp": 24.0, "daily_range": 12.0, "relative_humidity": 65.0},
"Sep": {"avg_temp": 19.0, "daily_range": 11.0, "relative_humidity": 60.0},
"Oct": {"avg_temp": 13.0, "daily_range": 10.0, "relative_humidity": 65.0},
"Nov": {"avg_temp": 7.0, "daily_range": 9.0, "relative_humidity": 70.0},
"Dec": {"avg_temp": 2.0, "daily_range": 8.0, "relative_humidity": 75.0}
}
# Design conditions for major cities
self.city_design_conditions = {
"New York": {
"latitude": "40N",
"summer_db": 32.0, # °C, dry bulb
"summer_wb": 24.0, # °C, wet bulb
"summer_daily_range": 11.0, # °C
"winter_db": -10.0, # °C
"winter_humidity": 40.0 # %
},
"Los Angeles": {
"latitude": "34N",
"summer_db": 35.0,
"summer_wb": 23.0,
"summer_daily_range": 10.0,
"winter_db": 5.0,
"winter_humidity": 50.0
},
"Chicago": {
"latitude": "42N",
"summer_db": 33.0,
"summer_wb": 25.0,
"summer_daily_range": 12.0,
"winter_db": -18.0,
"winter_humidity": 35.0
},
"Houston": {
"latitude": "30N",
"summer_db": 36.0,
"summer_wb": 26.0,
"summer_daily_range": 9.0,
"winter_db": 0.0,
"winter_humidity": 60.0
},
"Phoenix": {
"latitude": "33N",
"summer_db": 42.0,
"summer_wb": 24.0,
"summer_daily_range": 15.0,
"winter_db": 2.0,
"winter_humidity": 30.0
},
"Miami": {
"latitude": "26N",
"summer_db": 33.0,
"summer_wb": 27.0,
"summer_daily_range": 8.0,
"winter_db": 10.0,
"winter_humidity": 70.0
},
"London": {
"latitude": "51N",
"summer_db": 28.0,
"summer_wb": 20.0,
"summer_daily_range": 10.0,
"winter_db": -5.0,
"winter_humidity": 80.0
},
"Tokyo": {
"latitude": "36N",
"summer_db": 33.0,
"summer_wb": 27.0,
"summer_daily_range": 8.0,
"winter_db": 0.0,
"winter_humidity": 60.0
},
"Sydney": {
"latitude": "34S",
"summer_db": 31.0,
"summer_wb": 22.0,
"summer_daily_range": 9.0,
"winter_db": 8.0,
"winter_humidity": 65.0
},
"Singapore": {
"latitude": "1N",
"summer_db": 33.0,
"summer_wb": 28.0,
"summer_daily_range": 7.0,
"winter_db": 23.0,
"winter_humidity": 85.0
}
}
def get_monthly_weather_data(self, city: str = None) -> Dict[str, Dict[str, float]]:
"""
Get monthly weather data for a city.
Args:
city: City name (optional)
Returns:
Dictionary of monthly weather data
"""
# If city is provided and exists in our database, adjust the monthly data
if city and city in self.city_design_conditions:
city_data = self.city_design_conditions[city]
# Create a copy of the default data
monthly_data = self.default_monthly_temps.copy()
# Adjust the data based on the city's design conditions
# This is a simplified approach; in a real implementation, you would use more detailed data
# Summer months (Northern Hemisphere: Jun, Jul, Aug; Southern Hemisphere: Dec, Jan, Feb)
summer_months = ["Jun", "Jul", "Aug"] if "N" in city_data["latitude"] else ["Dec", "Jan", "Feb"]
winter_months = ["Dec", "Jan", "Feb"] if "N" in city_data["latitude"] else ["Jun", "Jul", "Aug"]
# Adjust summer months
for month in summer_months:
monthly_data[month]["avg_temp"] = city_data["summer_db"] - 3.0 # Average is typically lower than design
monthly_data[month]["daily_range"] = city_data["summer_daily_range"]
monthly_data[month]["relative_humidity"] = 60.0 # Approximate
# Adjust winter months
for month in winter_months:
monthly_data[month]["avg_temp"] = city_data["winter_db"] + 5.0 # Average is typically higher than design
monthly_data[month]["daily_range"] = city_data["summer_daily_range"] * 0.7 # Winter range is typically smaller
monthly_data[month]["relative_humidity"] = city_data["winter_humidity"]
# Adjust transition months (simple linear interpolation)
transition_months = [m for m in monthly_data.keys() if m not in summer_months and m not in winter_months]
# Sort months chronologically
all_months = ["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"]
transition_months.sort(key=lambda m: all_months.index(m))
# Get average summer and winter values
summer_avg_temp = sum(monthly_data[m]["avg_temp"] for m in summer_months) / len(summer_months)
winter_avg_temp = sum(monthly_data[m]["avg_temp"] for m in winter_months) / len(winter_months)
# Interpolate for transition months
num_transition = len(transition_months)
for i, month in enumerate(transition_months):
factor = (i + 1) / (num_transition + 1)
if "N" in city_data["latitude"]: # Northern Hemisphere
if all_months.index(month) < all_months.index("Jun"): # Spring
monthly_data[month]["avg_temp"] = winter_avg_temp + factor * (summer_avg_temp - winter_avg_temp)
else: # Fall
monthly_data[month]["avg_temp"] = summer_avg_temp - factor * (summer_avg_temp - winter_avg_temp)
else: # Southern Hemisphere
if all_months.index(month) < all_months.index("Dec") and all_months.index(month) >= all_months.index("Jun"): # Winter to Summer
monthly_data[month]["avg_temp"] = winter_avg_temp + factor * (summer_avg_temp - winter_avg_temp)
else: # Summer to Winter
monthly_data[month]["avg_temp"] = summer_avg_temp - factor * (summer_avg_temp - winter_avg_temp)
return monthly_data
# If no city is provided or city is not in our database, return default data
return self.default_monthly_temps
def get_design_conditions(self, city: str) -> Dict[str, Any]:
"""
Get design conditions for a city.
Args:
city: City name
Returns:
Dictionary of design conditions
"""
if city in self.city_design_conditions:
return self.city_design_conditions[city]
else:
# Return default design conditions
return {
"latitude": "40N",
"summer_db": 35.0,
"summer_wb": 25.0,
"summer_daily_range": 11.0,
"winter_db": -10.0,
"winter_humidity": 50.0
}
def get_hourly_temperatures(self, base_temp: float, daily_range: float) -> List[float]:
"""
Calculate hourly temperatures based on daily range.
Args:
base_temp: Base temperature (daily average)
daily_range: Daily temperature range
Returns:
List of hourly temperatures
"""
from utils.ashrae_integration import get_daily_range_percentage
hourly_temps = []
for hour in range(1, 25):
# Get percentage of daily range for this hour
percentage = get_daily_range_percentage(hour) / 100.0
# Calculate temperature
temp = base_temp - daily_range / 2.0 + daily_range * percentage
hourly_temps.append(temp)
return hourly_temps
def get_hourly_humidity(self, base_humidity: float, hourly_temps: List[float], base_temp: float) -> List[float]:
"""
Calculate hourly relative humidity based on temperature variation.
Args:
base_humidity: Base relative humidity (daily average)
hourly_temps: Hourly temperatures
base_temp: Base temperature (daily average)
Returns:
List of hourly relative humidity values
"""
hourly_humidity = []
for temp in hourly_temps:
# This is a simplified approach; in a real implementation, you would use psychrometric formulas
# Humidity tends to be inversely related to temperature
temp_diff = temp - base_temp
humidity_adjustment = -temp_diff * 2.0 # Rough approximation: 2% humidity change per °C
humidity = base_humidity + humidity_adjustment
humidity = max(10.0, min(100.0, humidity)) # Clamp between 10% and 100%
hourly_humidity.append(humidity)
return hourly_humidity
# Create a singleton instance
weather_data_provider = WeatherDataProvider()
|