58 lines
2.0 KiB
Python
58 lines
2.0 KiB
Python
|
"""
|
||
|
TestWeatherFactory test and validate the city model structure weather parameters
|
||
|
SPDX - License - Identifier: LGPL - 3.0 - or -later
|
||
|
Copyright © 2020 Project Author Pilar Monsalvete pilar_monsalvete@yahoo.es
|
||
|
"""
|
||
|
from pathlib import Path
|
||
|
from unittest import TestCase
|
||
|
|
||
|
from factories.geometry_factory import GeometryFactory
|
||
|
from factories.weather_factory import WeatherFactory
|
||
|
|
||
|
|
||
|
class TestWeatherFactory(TestCase):
|
||
|
"""
|
||
|
TestWeatherFactory TestCase
|
||
|
"""
|
||
|
def setUp(self) -> None:
|
||
|
"""
|
||
|
Configure test environment
|
||
|
:return:
|
||
|
"""
|
||
|
self._city_gml = None
|
||
|
self._nyc_with_weather = None
|
||
|
self._example_path = (Path(__file__).parent.parent / 'tests_data').resolve()
|
||
|
|
||
|
def _get_citygml(self):
|
||
|
if self._city_gml is None:
|
||
|
file_path = (self._example_path / 'buildings.gml').resolve()
|
||
|
self._city_gml = GeometryFactory('citygml', file_path).city
|
||
|
self.assertIsNotNone(self._city_gml, 'city is none')
|
||
|
return self._city_gml
|
||
|
|
||
|
def _get_city_with_weather(self):
|
||
|
if self._nyc_with_weather is None:
|
||
|
self._nyc_with_weather = self._get_citygml()
|
||
|
WeatherFactory('dat', self._nyc_with_weather, base_path=self._example_path)
|
||
|
return self._nyc_with_weather
|
||
|
|
||
|
def test_city_with_weather(self):
|
||
|
"""
|
||
|
Enrich the city with the weather information and verify it
|
||
|
:return: None
|
||
|
"""
|
||
|
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')
|