forked from s_ranjbar/city_retrofit
error in test_weather_factory.py
This commit is contained in:
parent
5c4f323e76
commit
b17bab8df7
|
@ -5,7 +5,7 @@
|
|||
<excludeFolder url="file://$MODULE_DIR$/venv" />
|
||||
<excludeFolder url="file://$MODULE_DIR$/venv38" />
|
||||
</content>
|
||||
<orderEntry type="inheritedJdk" />
|
||||
<orderEntry type="jdk" jdkName="Python 3.7 (libs)" jdkType="Python SDK" />
|
||||
<orderEntry type="sourceFolder" forTests="false" />
|
||||
</component>
|
||||
</module>
|
File diff suppressed because it is too large
Load Diff
|
@ -19,7 +19,7 @@ class UsBaseUsageParameters:
|
|||
self._city = city
|
||||
# todo: control not archetype found
|
||||
# ToDo: this is using the german library as a temporary approach, need to use/define a library for US
|
||||
path = str(Path(__file__).parent.parent.parent.parent / 'data/usage/de_library.xml')
|
||||
path = str(Path(__file__).parent.parent.parent / 'data/usage/de_library.xml')
|
||||
print('usage:', path)
|
||||
with open(path) as xml:
|
||||
self._library = xmltodict.parse(xml.read(), force_list='zoneUsageVariant')
|
||||
|
|
|
@ -18,10 +18,11 @@ class WeatherFactory:
|
|||
self._handler = '_' + handler.lower().replace(' ', '_')
|
||||
self._city = city
|
||||
self._base_path = base_path
|
||||
self._city_name = 'new_york_city'
|
||||
self.factory()
|
||||
|
||||
def _dat(self):
|
||||
DatWeatherParameters(self._city, Path(self._base_path / 'inseldb' + self._handler + '.dat'))
|
||||
DatWeatherParameters(self._city, self._base_path, self._city_name)
|
||||
|
||||
def _tmy(self):
|
||||
raise Exception('Not implemented')
|
||||
|
|
|
@ -5,25 +5,27 @@ Copyright © 2020 Project Author Pilar Monsalvete pilar_monsalvete@yahoo.es
|
|||
"""
|
||||
|
||||
import pandas as pd
|
||||
from pathlib import Path
|
||||
|
||||
|
||||
class DatWeatherParameters:
|
||||
"""
|
||||
DatWeatherParameters class
|
||||
"""
|
||||
def __init__(self, city, path):
|
||||
self._path = path
|
||||
def __init__(self, city, path, name):
|
||||
self._weather_values = None
|
||||
self._city = city
|
||||
self._city_name = name
|
||||
file_name = 'inseldb_' + self._city_name + '.dat'
|
||||
self._path = Path(path / file_name)
|
||||
|
||||
def weather_values(self):
|
||||
# TODO: catch error if file does not exist
|
||||
if self._weather_values is None:
|
||||
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']], columns=['inseldb'])
|
||||
building._hourly_global_horizontal = pd.DataFrame(self._weather_values[['global_horiz']], columns=['inseldb'])
|
||||
building._hourly_diffuse = pd.DataFrame(self._weather_values[['diffuse']], columns=['inseldb'])
|
||||
building._hourly_beam = pd.DataFrame(self._weather_values[['beam']], columns=['inseldb'])
|
||||
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'])
|
||||
|
||||
|
|
57
tests/test_weather_factory.py
Normal file
57
tests/test_weather_factory.py
Normal file
|
@ -0,0 +1,57 @@
|
|||
"""
|
||||
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')
|
8760
tests_data/inseldb_new_york_city.dat
Normal file
8760
tests_data/inseldb_new_york_city.dat
Normal file
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue
Block a user