2020-10-30 06:23:29 -04:00
|
|
|
"""
|
|
|
|
TestWeatherFactory test and validate the city model structure weather parameters
|
|
|
|
SPDX - License - Identifier: LGPL - 3.0 - or -later
|
2021-06-10 08:29:24 -04:00
|
|
|
Copyright © 2020 Project Author Pilar Monsalvete Alvarez de Uribarri pilar.monsalvete@concordia.ca
|
2020-10-30 06:23:29 -04:00
|
|
|
"""
|
|
|
|
from pathlib import Path
|
|
|
|
from unittest import TestCase
|
|
|
|
|
2021-03-02 18:57:09 -05:00
|
|
|
from imports.geometry_factory import GeometryFactory
|
|
|
|
from imports.weather_factory import WeatherFactory
|
2021-05-25 13:34:57 -04:00
|
|
|
import helpers.constants as cte
|
2020-10-30 06:23:29 -04:00
|
|
|
|
|
|
|
|
|
|
|
class TestWeatherFactory(TestCase):
|
|
|
|
"""
|
|
|
|
TestWeatherFactory TestCase
|
|
|
|
"""
|
|
|
|
def setUp(self) -> None:
|
|
|
|
"""
|
|
|
|
Configure test environment
|
|
|
|
:return:
|
|
|
|
"""
|
|
|
|
self._city_gml = None
|
2021-01-11 17:11:50 -05:00
|
|
|
self._city_with_weather = None
|
|
|
|
self._city_name = 'new_york_city'
|
2021-04-13 15:09:13 -04:00
|
|
|
self._example_path = (Path(__file__).parent.parent / 'data' / 'weather').resolve()
|
2020-10-30 06:23:29 -04:00
|
|
|
|
2021-01-11 17:11:50 -05:00
|
|
|
def _get_citygml(self, file_path):
|
2021-04-06 18:06:19 -04:00
|
|
|
self._city_gml = GeometryFactory('citygml', file_path).city
|
|
|
|
self.assertIsNotNone(self._city_gml, 'city is none')
|
2020-10-30 06:23:29 -04:00
|
|
|
return self._city_gml
|
|
|
|
|
2021-01-11 17:11:50 -05:00
|
|
|
def test_weather_xls(self):
|
2021-08-27 12:51:30 -04:00
|
|
|
"""
|
|
|
|
Enrich the city with xls weather file and verify it
|
|
|
|
"""
|
2021-03-16 12:33:22 -04:00
|
|
|
file_path = (Path(__file__).parent / 'tests_data' / 'iso_52016_1_2017_lod2.gml').resolve()
|
2021-01-11 17:11:50 -05:00
|
|
|
city_with_weather = self._get_citygml(file_path)
|
2021-04-13 15:09:13 -04:00
|
|
|
WeatherFactory('xls', city_with_weather, base_path=self._example_path).enrich()
|
2021-01-11 17:11:50 -05:00
|
|
|
for building in city_with_weather.buildings:
|
2021-05-25 13:34:57 -04:00
|
|
|
values = building.external_temperature[cte.HOUR][['iso52016']]
|
2021-01-11 17:11:50 -05:00
|
|
|
self.assertFalse(values.empty, 'wrong value external_temperature')
|
2021-05-25 13:34:57 -04:00
|
|
|
values = building.global_horizontal[cte.HOUR][['iso52016']]
|
2021-01-11 17:11:50 -05:00
|
|
|
self.assertFalse(values.empty, 'wrong value global horizontal')
|
2021-04-13 15:09:13 -04:00
|
|
|
|
|
|
|
def test_weather_epw(self):
|
2021-08-27 12:51:30 -04:00
|
|
|
"""
|
|
|
|
Enrich the city with epw weather and verify it
|
|
|
|
"""
|
2021-04-13 15:09:13 -04:00
|
|
|
file_path = (Path(__file__).parent / 'tests_data' / 'one_building_in_kelowna.gml').resolve()
|
|
|
|
city_with_weather = self._get_citygml(file_path)
|
|
|
|
_file_name = 'CAN_BC_Summerland.717680_CWEC.epw'
|
2021-05-25 13:34:57 -04:00
|
|
|
print(len(city_with_weather.buildings))
|
2021-04-13 15:09:13 -04:00
|
|
|
WeatherFactory('epw', city_with_weather, base_path=self._example_path, file_name=_file_name).enrich()
|
2021-05-25 13:34:57 -04:00
|
|
|
print(len(city_with_weather.buildings))
|
2021-04-13 15:09:13 -04:00
|
|
|
for building in city_with_weather.buildings:
|
2021-05-25 13:34:57 -04:00
|
|
|
values = building.external_temperature[cte.HOUR][['epw']]
|
2021-04-13 15:09:13 -04:00
|
|
|
self.assertFalse(values.empty, 'wrong value external_temperature')
|
2021-05-25 13:34:57 -04:00
|
|
|
values = building.global_horizontal[cte.HOUR][['epw']]
|
2021-04-13 15:09:13 -04:00
|
|
|
self.assertFalse(values.empty, 'wrong value global horizontal')
|