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-03-20 14:15:57 -04:00
|
|
|
|
2020-10-28 13:42:58 -04:00
|
|
|
import math
|
2023-02-08 13:40:06 -05:00
|
|
|
import calendar as cal
|
2023-05-30 17:13:49 -04:00
|
|
|
import pandas as pd
|
2023-02-08 13:40:06 -05:00
|
|
|
import numpy as np
|
2023-05-30 17:13:49 -04:00
|
|
|
import hub.helpers.constants as cte
|
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
|
|
|
|
|
|
|
@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)
|
|
|
|
ambient_temperature_fahrenheit = []
|
|
|
|
average_temperature = 0
|
|
|
|
maximum_temperature = -1000
|
|
|
|
minimum_temperature = 1000
|
|
|
|
for temperature in ambient_temperature:
|
|
|
|
value = temperature * 9 / 5 + 32
|
|
|
|
ambient_temperature_fahrenheit.append(value)
|
|
|
|
average_temperature += value / 8760
|
|
|
|
if value > maximum_temperature:
|
|
|
|
maximum_temperature = value
|
|
|
|
if value < minimum_temperature:
|
|
|
|
minimum_temperature = value
|
|
|
|
delta_temperature = maximum_temperature - minimum_temperature
|
|
|
|
ratio = 0.4 + 0.01 * (average_temperature - 44)
|
|
|
|
lag = 35 - 1 * (average_temperature - 44)
|
|
|
|
cold_temperature = []
|
|
|
|
for temperature in ambient_temperature_fahrenheit:
|
|
|
|
radians = (0.986 * (temperature-15-lag) - 90) * math.pi / 180
|
|
|
|
cold_temperature.append((average_temperature + 6 + ratio * (delta_temperature/2) * math.sin(radians) - 32) * 5/9)
|
|
|
|
return pd.DataFrame(cold_temperature, columns=['epw'])
|
|
|
|
|
2023-02-08 13:40:06 -05:00
|
|
|
def get_monthly_mean_values(self, values):
|
2023-05-30 17:13:49 -04:00
|
|
|
"""
|
|
|
|
Get the monthly mean for the given values
|
|
|
|
:return: float
|
|
|
|
"""
|
2023-02-08 13:40:06 -05:00
|
|
|
out = None
|
|
|
|
if values is not None:
|
|
|
|
if 'month' not in values.columns:
|
|
|
|
values = pd.concat([self.month_hour, pd.DataFrame(values)], axis=1)
|
|
|
|
out = values.groupby('month', as_index=False).mean()
|
|
|
|
del out['month']
|
|
|
|
return out
|
|
|
|
|
2023-03-20 14:15:57 -04:00
|
|
|
@staticmethod
|
|
|
|
def get_yearly_mean_values(values):
|
2023-05-30 17:13:49 -04:00
|
|
|
"""
|
|
|
|
Get the yearly mean for the given values
|
|
|
|
:return: float
|
|
|
|
"""
|
2023-02-08 13:40:06 -05:00
|
|
|
return values.mean()
|
|
|
|
|
|
|
|
def get_total_month(self, values):
|
2023-05-30 17:13:49 -04:00
|
|
|
"""
|
|
|
|
Get the total value the given values
|
|
|
|
:return: float
|
|
|
|
"""
|
2023-02-08 13:40:06 -05:00
|
|
|
out = None
|
|
|
|
if values is not None:
|
|
|
|
if 'month' not in values.columns:
|
|
|
|
values = pd.concat([self.month_hour, pd.DataFrame(values)], axis=1)
|
|
|
|
out = pd.DataFrame(values).groupby('month', as_index=False).sum()
|
|
|
|
del out['month']
|
|
|
|
return out
|
|
|
|
|
|
|
|
@property
|
|
|
|
def month_hour(self):
|
|
|
|
"""
|
|
|
|
returns a DataFrame that has x values of the month number (January = 1, February = 2...),
|
|
|
|
being x the number of hours of the corresponding month
|
|
|
|
:return: DataFrame(int)
|
|
|
|
"""
|
|
|
|
array = []
|
|
|
|
for i in range(0, 12):
|
|
|
|
days_of_month = cal.monthrange(2015, i+1)[1]
|
|
|
|
total_hours = days_of_month * 24
|
|
|
|
array = np.concatenate((array, np.full(total_hours, i + 1)))
|
|
|
|
return pd.DataFrame(array, columns=['month'])
|