2020-10-19 10:07:03 -04:00
|
|
|
"""
|
|
|
|
monthly_to_hourly_demand module
|
|
|
|
SPDX - License - Identifier: LGPL - 3.0 - or -later
|
|
|
|
Copyright © 2020 Project Author Pilar Monsalvete pilar_monsalvete@yahoo.es
|
|
|
|
"""
|
|
|
|
import pandas as pd
|
2021-03-16 12:19:35 -04:00
|
|
|
from city_model_structure.attributes.occupants import Occupants
|
2020-11-02 13:41:42 -05:00
|
|
|
import calendar as cal
|
2020-10-19 10:07:03 -04:00
|
|
|
|
2020-11-26 06:34:11 -05:00
|
|
|
|
2020-10-19 10:07:03 -04:00
|
|
|
class MonthlyToHourlyDemand:
|
|
|
|
"""
|
|
|
|
MonthlyToHourlyDemand class
|
|
|
|
"""
|
2020-11-02 13:41:42 -05:00
|
|
|
def __init__(self, building, conditioning_seasons):
|
2020-10-19 10:07:03 -04:00
|
|
|
self._hourly_heating = pd.DataFrame()
|
|
|
|
self._hourly_cooling = pd.DataFrame()
|
|
|
|
self._building = building
|
2020-11-02 13:41:42 -05:00
|
|
|
self._conditioning_seasons = conditioning_seasons
|
2020-10-19 10:07:03 -04:00
|
|
|
|
2021-04-15 10:04:44 -04:00
|
|
|
def hourly_heating(self, key):
|
2020-10-26 08:26:31 -04:00
|
|
|
"""
|
|
|
|
hourly distribution of the monthly heating of a building
|
2021-04-15 10:04:44 -04:00
|
|
|
:param key: string
|
2020-10-26 08:26:31 -04:00
|
|
|
:return: [hourly_heating]
|
|
|
|
"""
|
2020-10-19 10:07:03 -04:00
|
|
|
# todo: this method and the insel model have to be reviewed for more than one thermal zone
|
2020-11-02 13:41:42 -05:00
|
|
|
external_temp = self._building.external_temperature['hour']
|
2020-10-19 10:07:03 -04:00
|
|
|
|
|
|
|
# todo: review index depending on how the schedules are defined, either 8760 or 24 hours
|
|
|
|
for usage_zone in self._building.usage_zones:
|
2020-11-02 13:41:42 -05:00
|
|
|
temp_set = float(usage_zone.heating_setpoint)
|
|
|
|
temp_back = float(usage_zone.heating_setback)
|
2021-03-16 12:19:35 -04:00
|
|
|
occupancy = Occupants().get_complete_year_schedule(usage_zone.schedules['Occupancy'])
|
2020-11-02 13:41:42 -05:00
|
|
|
heating_schedule = self._conditioning_seasons['heating']
|
2020-10-19 10:07:03 -04:00
|
|
|
|
2020-11-02 13:41:42 -05:00
|
|
|
hourly_heating = []
|
2020-10-19 10:07:03 -04:00
|
|
|
i = 0
|
2020-11-02 13:41:42 -05:00
|
|
|
temp_grad_day = []
|
|
|
|
for month in range(1, 13):
|
2020-10-19 10:07:03 -04:00
|
|
|
temp_grad_month = 0
|
2020-11-02 13:41:42 -05:00
|
|
|
month_range = cal.monthrange(2015, month)
|
|
|
|
for day in range(1, month_range[1]+1):
|
2020-10-19 10:07:03 -04:00
|
|
|
external_temp_med = 0
|
|
|
|
for hour in range(0, 24):
|
2021-04-15 10:04:44 -04:00
|
|
|
external_temp_med += external_temp[key][i]/24
|
2020-10-19 10:07:03 -04:00
|
|
|
for hour in range(0, 24):
|
2020-11-02 13:41:42 -05:00
|
|
|
if external_temp_med < temp_set and heating_schedule[month-1] == 1:
|
|
|
|
if occupancy[hour] > 0:
|
2021-04-15 10:04:44 -04:00
|
|
|
temp_grad_day.append(temp_set - external_temp[key][i])
|
2020-10-19 10:07:03 -04:00
|
|
|
else:
|
2021-04-15 10:04:44 -04:00
|
|
|
temp_grad_day.append(temp_back - external_temp[key][i])
|
2020-10-19 10:07:03 -04:00
|
|
|
else:
|
2020-11-02 13:41:42 -05:00
|
|
|
temp_grad_day.append(0)
|
2020-10-19 10:07:03 -04:00
|
|
|
|
2020-11-02 13:41:42 -05:00
|
|
|
temp_grad_month += temp_grad_day[i]
|
2020-10-19 10:07:03 -04:00
|
|
|
i += 1
|
|
|
|
|
2020-11-02 13:41:42 -05:00
|
|
|
for day in range(1, month_range[1] + 1):
|
|
|
|
for hour in range(0, 24):
|
|
|
|
j = (day - 1) * 24 + hour
|
|
|
|
monthly_demand = self._building.heating['month']['INSEL'][month-1]
|
|
|
|
hourly_demand = float(monthly_demand)*float(temp_grad_day[j])/float(temp_grad_month)
|
|
|
|
hourly_heating.append(hourly_demand)
|
|
|
|
|
|
|
|
self._hourly_heating = pd.DataFrame(data=hourly_heating, columns=['monthly to hourly'])
|
2020-10-19 10:07:03 -04:00
|
|
|
return self._hourly_heating
|
|
|
|
|
|
|
|
@property
|
|
|
|
def hourly_cooling(self) -> NotImplementedError:
|
|
|
|
raise NotImplementedError
|