2020-11-26 09:26:55 -05:00
|
|
|
"""
|
|
|
|
weather helper
|
|
|
|
SPDX - License - Identifier: LGPL - 3.0 - or -later
|
2022-04-08 09:35:33 -04:00
|
|
|
Copyright © 2022 Concordia CERC group
|
|
|
|
Project Coder Pilar Monsalvete Alvarez de Uribarri pilar.monsalvete@concordia.ca
|
2020-11-26 09:26:55 -05:00
|
|
|
"""
|
2023-08-07 12:32:33 -04:00
|
|
|
|
2023-06-06 13:32:37 -04:00
|
|
|
import logging
|
2020-10-28 13:42:58 -04:00
|
|
|
import math
|
2023-05-30 17:13:49 -04:00
|
|
|
import hub.helpers.constants as cte
|
2024-06-27 15:18:26 -04:00
|
|
|
from datetime import datetime, timedelta
|
2020-10-28 13:42:58 -04:00
|
|
|
|
2021-08-27 12:51:30 -04:00
|
|
|
class Weather:
|
2020-11-26 09:26:55 -05:00
|
|
|
"""
|
|
|
|
Weather class
|
|
|
|
"""
|
2020-10-28 13:42:58 -04:00
|
|
|
|
2023-06-06 13:32:37 -04:00
|
|
|
_epw_file = {
|
|
|
|
'CA.02.5935': 'https://energyplus-weather.s3.amazonaws.com/north_and_central_america_wmo_region_4/CAN/BC/CAN_BC_Summerland.717680_CWEC/CAN_BC_Summerland.717680_CWEC.epw',
|
|
|
|
'CA.10.06': 'https://energyplus-weather.s3.amazonaws.com/north_and_central_america_wmo_region_4/CAN/PQ/CAN_PQ_Montreal.Intl.AP.716270_CWEC/CAN_PQ_Montreal.Intl.AP.716270_CWEC.epw',
|
2023-06-09 11:21:45 -04:00
|
|
|
'CA.10.13': 'https://energyplus-weather.s3.amazonaws.com/north_and_central_america_wmo_region_4/CAN/PQ/CAN_PQ_Montreal.Intl.AP.716270_CWEC/CAN_PQ_Montreal.Intl.AP.716270_CWEC.epw',
|
2023-06-07 15:27:38 -04:00
|
|
|
'CA.10.14': 'https://energyplus-weather.s3.amazonaws.com/north_and_central_america_wmo_region_4/CAN/PQ/CAN_PQ_Montreal.Intl.AP.716270_CWEC/CAN_PQ_Montreal.Intl.AP.716270_CWEC.epw',
|
|
|
|
'CA.10.16': 'https://energyplus-weather.s3.amazonaws.com/north_and_central_america_wmo_region_4/CAN/PQ/CAN_PQ_Montreal.Intl.AP.716270_CWEC/CAN_PQ_Montreal.Intl.AP.716270_CWEC.epw',
|
2023-06-06 13:32:37 -04:00
|
|
|
'DE.01.082': 'https://energyplus-weather.s3.amazonaws.com/europe_wmo_region_6/DEU/DEU_Stuttgart.107380_IWEC/DEU_Stuttgart.107380_IWEC.epw',
|
2023-07-10 16:32:22 -04:00
|
|
|
'US.NY.047': 'https://energyplus-weather.s3.amazonaws.com/north_and_central_america_wmo_region_4/USA/NY/USA_NY_New.York.City-Central.Park.94728_TMY/USA_NY_New.York.City-Central.Park.94728_TMY.epw',
|
|
|
|
'CA.10.12': 'https://energyplus-weather.s3.amazonaws.com/north_and_central_america_wmo_region_4/CAN/PQ/CAN_PQ_Quebec.717140_CWEC/CAN_PQ_Quebec.717140_CWEC.epw',
|
2023-11-14 22:50:15 -05:00
|
|
|
'IL.01.': 'https://energyplus-weather.s3.amazonaws.com/europe_wmo_region_6/ISR/ISR_Eilat.401990_MSI/ISR_Eilat.401990_MSI.epw',
|
|
|
|
'ES.07.PM': 'https://energyplus-weather.s3.amazonaws.com/europe_wmo_region_6/ESP/ESP_Palma.083060_SWEC/ESP_Palma.083060_SWEC.epw'
|
2023-06-06 13:32:37 -04:00
|
|
|
}
|
2023-06-07 15:27:38 -04:00
|
|
|
# todo: this dictionary need to be completed, a data science student task?
|
2023-06-06 13:32:37 -04:00
|
|
|
|
2020-10-28 13:42:58 -04:00
|
|
|
@staticmethod
|
|
|
|
def sky_temperature(ambient_temperature):
|
2020-11-26 09:26:55 -05:00
|
|
|
"""
|
2021-08-30 14:39:24 -04:00
|
|
|
Get sky temperature from ambient temperature in Celsius
|
2023-03-20 14:15:57 -04:00
|
|
|
:return: List[float]
|
2020-11-26 09:26:55 -05:00
|
|
|
"""
|
2023-05-17 17:10:30 -04:00
|
|
|
# Swinbank - Source sky model approximation(1963) based on cloudiness statistics(32 %) in the United States
|
2020-10-28 13:42:58 -04:00
|
|
|
# ambient temperatures( in °C)
|
|
|
|
# sky temperatures( in °C)
|
|
|
|
values = []
|
2020-10-30 13:47:59 -04:00
|
|
|
for temperature in ambient_temperature:
|
2021-05-25 13:34:57 -04:00
|
|
|
value = 0.037536 * math.pow((temperature + cte.KELVIN), 1.5) \
|
|
|
|
+ 0.32 * (temperature + cte.KELVIN) - cte.KELVIN
|
2020-10-28 13:42:58 -04:00
|
|
|
values.append(value)
|
2020-10-30 13:47:59 -04:00
|
|
|
return values
|
2023-02-08 13:40:06 -05:00
|
|
|
|
2023-03-20 14:15:57 -04:00
|
|
|
@staticmethod
|
|
|
|
def cold_water_temperature(ambient_temperature):
|
|
|
|
"""
|
|
|
|
Get cold water temperature from ambient temperature in Celsius
|
|
|
|
:return: dict
|
|
|
|
"""
|
|
|
|
# Equation from "TOWARDS DEVELOPMENT OF AN ALGORITHM FOR MAINS WATER TEMPERATURE", 2004, Jay Burch
|
|
|
|
# and Craig Christensen, National Renewable Energy Laboratory
|
|
|
|
# ambient temperatures( in °C)
|
|
|
|
# cold water temperatures( in °C)
|
2024-06-27 15:18:26 -04:00
|
|
|
t_out_fahrenheit = [1.8 * t_out + 32 for t_out in ambient_temperature]
|
|
|
|
t_out_average = sum(t_out_fahrenheit) / len(t_out_fahrenheit)
|
|
|
|
max_difference = max(t_out_fahrenheit) - min(t_out_fahrenheit)
|
|
|
|
ratio = 0.4 + 0.01 * (t_out_average - 44)
|
|
|
|
lag = 35 - (t_out_average - 35)
|
|
|
|
number_of_day = [a for a in range(1, 366)]
|
|
|
|
day_of_year = [day for day in number_of_day for _ in range(24)]
|
|
|
|
cold_temperature_fahrenheit = []
|
2023-03-20 14:15:57 -04:00
|
|
|
cold_temperature = []
|
2024-06-27 15:18:26 -04:00
|
|
|
for i in range(len(ambient_temperature)):
|
|
|
|
cold_temperature_fahrenheit.append(t_out_average + 6 + ratio * (max_difference / 2) *
|
|
|
|
math.sin(math.radians(0.986 * (day_of_year[i] - 15 - lag) - 90)))
|
|
|
|
cold_temperature.append((cold_temperature_fahrenheit[i] - 32) / 1.8)
|
2023-08-07 12:32:33 -04:00
|
|
|
return cold_temperature
|
2023-06-06 13:32:37 -04:00
|
|
|
|
|
|
|
def epw_file(self, region_code):
|
|
|
|
"""
|
|
|
|
returns the url for the weather file for the given location or default (Montreal data)
|
|
|
|
:return: str
|
|
|
|
"""
|
|
|
|
if region_code not in self._epw_file:
|
|
|
|
logging.warning('Specific weather data unknown for %s using Montreal data instead', region_code)
|
|
|
|
return self._epw_file['CA.10.06']
|
|
|
|
return self._epw_file[region_code]
|