finished test_weather_factory.py

This commit is contained in:
pilar 2020-10-30 08:25:36 -04:00
parent b17bab8df7
commit 3a22e7afff
3 changed files with 78 additions and 150 deletions

View File

@ -47,15 +47,10 @@ class Building(CityObject):
self._m_cooling = pd.DataFrame()
self._h_cooling = pd.DataFrame()
self._cooling = pd.DataFrame()
self._m_external_temperature = pd.DataFrame()
self._h_external_temperature = pd.DataFrame()
self._external_temperature = pd.DataFrame()
self._h_global_horizontal = pd.DataFrame()
self._global_horizontal = pd.DataFrame()
self._h_diffuse = pd.DataFrame()
self._diffuse = pd.DataFrame()
self._h_beam = pd.DataFrame()
self._beam = pd.DataFrame()
self._external_temperature = dict()
self._global_horizontal = dict()
self._diffuse = dict()
self._beam = dict()
# ToDo: Check this for LOD4
self._thermal_zones = []
@ -392,147 +387,65 @@ class Building(CityObject):
return self._cooling
@property
def _monthly_external_temperature(self) -> pd.DataFrame:
def external_temperature(self) -> dict:
"""
external temperature surrounding the building in grads Celsius monthly based
:return: DataFrame with 12 values and a header with the source of those
external temperature surrounding the building in grads Celsius
:return: dict{DataFrame(float)}
"""
return self._m_external_temperature
@_monthly_external_temperature.setter
def _monthly_external_temperature(self, value):
"""
external temperature surrounding the building in grads Celsius monthly based
:param value: DataFrame(external temperature)
"""
if self._m_external_temperature.empty:
self._m_external_temperature = value
else:
self._m_external_temperature = pd.concat([self._m_external_temperature, value], axis=1)
@property
def _hourly_external_temperature(self) -> pd.DataFrame:
"""
external temperature surrounding the building in grads Celsius hourly based
:return: DataFrame with 8760 values and a header with the source of those
"""
return self._h_external_temperature
@_hourly_external_temperature.setter
def _hourly_external_temperature(self, value):
"""
external temperature surrounding the building in grads Celsius hourly based
:param value: DataFrame(external temperature)
"""
if self._h_external_temperature.empty:
self._h_external_temperature = value
else:
self._h_external_temperature = pd.concat([self._h_external_temperature, value], axis=1)
def external_temperature(self, time_scale) -> pd.DataFrame:
"""
Get external temperature surrounding the building in grads Celsius in a defined time_scale
:param time_scale: string.
:return: DataFrame(float)
"""
if time_scale == cte.time_scale['hour']:
self._external_temperature = self._hourly_external_temperature
elif time_scale == cte.time_scale['month']:
self._external_temperature = self._monthly_external_temperature
else:
raise NotImplementedError
return self._external_temperature
@external_temperature.setter
def external_temperature(self, value):
"""
external temperature surrounding the building in grads Celsius
:param value: dict{DataFrame(external temperature)}
"""
self._external_temperature = value
@property
def _hourly_global_horizontal(self) -> pd.DataFrame:
def global_horizontal(self) -> dict:
"""
global horizontal radiation surrounding the building in W/m2 hourly based
:return: DataFrame with 8760 values and a header with the source of those
global horizontal radiation surrounding the building in W/m2
:return: dict{DataFrame(float)}
"""
return self._h_global_horizontal
@_hourly_global_horizontal.setter
def _hourly_global_horizontal(self, value):
"""
global horizontal radiation surrounding the building in W/m2 hourly based
:param value: DataFrame(external temperature)
"""
if self._h_global_horizontal.empty:
self._h_global_horizontal = value
else:
self._h_global_horizontal = pd.concat([self._h_global_horizontal, value], axis=1)
def global_horizontal(self, time_scale) -> pd.DataFrame:
"""
Get global horizontal radiation surrounding the building in W/m2 in a defined time_scale
:param time_scale: string.
:return: DataFrame(float)
"""
if time_scale == cte.time_scale['hour']:
self._global_horizontal = self._hourly_global_horizontal
else:
raise NotImplementedError
return self._global_horizontal
@global_horizontal.setter
def global_horizontal(self, value):
"""
global horizontal radiation surrounding the building in W/m2
:param value: dict{DataFrame(global horizontal radiation)}
"""
self._global_horizontal = value
@property
def _hourly_diffuse(self) -> pd.DataFrame:
def diffuse(self) -> dict:
"""
diffuse radiation surrounding the building in W/m2 hourly based
:return: DataFrame with 8760 values and a header with the source of those
diffuse radiation surrounding the building in W/m2
:return: dict{DataFrame(float)}
"""
return self._h_diffuse
@_hourly_diffuse.setter
def _hourly_diffuse(self, value):
"""
diffuse radiation surrounding the building in W/m2 hourly based
:param value: DataFrame(external temperature)
"""
if self._h_diffuse.empty:
self._h_diffuse = value
else:
self._h_diffuse = pd.concat([self._h_diffuse, value], axis=1)
def diffuse(self, time_scale) -> pd.DataFrame:
"""
Get diffuse radiation surrounding the building in W/m2 in a defined time_scale
:param time_scale: string.
:return: DataFrame(float)
"""
if time_scale == cte.time_scale['hour']:
self._diffuse = self._hourly_diffuse
else:
raise NotImplementedError
return self._diffuse
@diffuse.setter
def diffuse(self, value):
"""
diffuse radiation surrounding the building in W/m2
:param value: dict{DataFrame(diffuse radiation)}
"""
self._diffuse = value
@property
def _hourly_beam(self) -> pd.DataFrame:
def beam(self) -> dict:
"""
beam radiation surrounding the building in W/m2 hourly based
:return: DataFrame with 8760 values and a header with the source of those
beam radiation surrounding the building in W/m2
:return: dict{DataFrame(float)}
"""
return self._h_beam
@_hourly_beam.setter
def _hourly_beam(self, value):
"""
beam radiation surrounding the building in W/m2 hourly based
:param value: DataFrame(external temperature)
"""
if self._h_beam.empty:
self._h_beam = value
else:
self._h_beam = pd.concat([self._h_beam, value], axis=1)
def beam(self, time_scale) -> pd.DataFrame:
"""
Get beam radiation surrounding the building in W/m2 in a defined time_scale
:param time_scale: string.
:return: DataFrame(float)
"""
if time_scale == cte.time_scale['hour']:
self._beam = self._hourly_beam
else:
raise NotImplementedError
return self._beam
@beam.setter
def beam(self, value):
"""
beam radiation surrounding the building in W/m2
:param value: dict{DataFrame(beam radiation)}
"""
self._beam = value

View File

@ -24,8 +24,26 @@ class DatWeatherParameters:
self._weather_values = pd.read_csv(self._path, sep='\s+', header=None,
names=['hour', 'global_horiz', 'temperature', 'diffuse', 'beam', 'empty'])
for building in self._city.buildings:
building._hourly_external_temperature = pd.DataFrame(self._weather_values[['temperature']].to_numpy(), columns=['inseldb'])
building._hourly_global_horizontal = pd.DataFrame(self._weather_values[['global_horiz']].to_numpy(), columns=['inseldb'])
building._hourly_diffuse = pd.DataFrame(self._weather_values[['diffuse']].to_numpy(), columns=['inseldb'])
building._hourly_beam = pd.DataFrame(self._weather_values[['beam']].to_numpy(), columns=['inseldb'])
new_value = pd.DataFrame(self._weather_values[['temperature']].to_numpy(), columns=['inseldb'])
if 'hour' not in building.external_temperature:
building.external_temperature['hour'] = new_value
else:
pd.concat([building.external_temperature['hour'], new_value], axis=1)
new_value = pd.DataFrame(self._weather_values[['global_horiz']].to_numpy(), columns=['inseldb'])
if 'hour' not in building.global_horizontal:
building.global_horizontal['hour'] = new_value
else:
pd.concat([building.global_horizontal['hour'], new_value], axis=1)
new_value = pd.DataFrame(self._weather_values[['diffuse']].to_numpy(), columns=['inseldb'])
if 'hour' not in building.diffuse:
building.diffuse['hour'] = new_value
else:
pd.concat([building.diffuse['hour'], new_value], axis=1)
new_value = pd.DataFrame(self._weather_values[['beam']].to_numpy(), columns=['inseldb'])
if 'hour' not in building.beam:
building.beam['hour'] = new_value
else:
pd.concat([building.beam['hour'], new_value], axis=1)

View File

@ -5,6 +5,7 @@ Copyright © 2020 Project Author Pilar Monsalvete pilar_monsalvete@yahoo.es
"""
from pathlib import Path
from unittest import TestCase
import numpy as np
from factories.geometry_factory import GeometryFactory
from factories.weather_factory import WeatherFactory
@ -43,15 +44,11 @@ class TestWeatherFactory(TestCase):
"""
city = self._get_city_with_weather()
for building in city.buildings:
values = building.external_temperature('hour')[['inseldb']].to_numpy()
print(values[8])
self.assertEqual(values[8], [-1.4109149], 'wrong value external_temperature')
values = building.diffuse('hour')[['inseldb']].to_numpy()
print(values[8])
self.assertEqual(values[8], [40.0263214], 'wrong value diffuse')
values = building.beam('hour')[['inseldb']].to_numpy()
print(values[8])
self.assertEqual(values[8], [402.954041], 'wrong value beam')
values = building.global_horizontal('hour')[['inseldb']].to_numpy()
print(values[8])
self.assertEqual(values[8], [79.9888763], 'wrong value global horizontal')
values = building.external_temperature['hour'][['inseldb']].to_numpy()
self.assertEqual([-1.41], np.around(values[8], decimals=2), 'wrong value external_temperature')
values = building.global_horizontal['hour'][['inseldb']].to_numpy()
self.assertEqual([79.99], np.around(values[8], decimals=2), 'wrong value global horizontal')
values = building.diffuse['hour'][['inseldb']].to_numpy()
self.assertEqual([40.03], np.around(values[8], decimals=2), 'wrong value diffuse')
values = building.beam['hour'][['inseldb']].to_numpy()
self.assertEqual([402.95], np.around(values[8], decimals=2), 'wrong value beam')