forked from s_ranjbar/city_retrofit
added test for global irradiance calculation
This commit is contained in:
parent
0ab96ec226
commit
c71821fd78
|
@ -449,24 +449,30 @@ class City:
|
||||||
def merge(self, city) -> City:
|
def merge(self, city) -> City:
|
||||||
_merge_city = self.copy
|
_merge_city = self.copy
|
||||||
selected_city_object = None
|
selected_city_object = None
|
||||||
|
building = None
|
||||||
# set initial minimum radiation to a higher number
|
# set initial minimum radiation to a higher number
|
||||||
min_radiation = 1000000
|
min_radiation = 1999999
|
||||||
for city_object in city.city_objects:
|
for city_object in city.city_objects:
|
||||||
if city_object.type == 'building':
|
if city_object.type == 'building':
|
||||||
|
building = city_object
|
||||||
building_radiation = 0
|
building_radiation = 0
|
||||||
for surface in city_object.surfaces:
|
for surface in city_object.surfaces:
|
||||||
radiation = surface.global_irradiance
|
radiation = surface.global_irradiance
|
||||||
if "yearly" in radiation:
|
if 'year' not in radiation and 'month' not in radiation:
|
||||||
building_radiation += radiation["yearly"].iloc[0]
|
continue
|
||||||
elif "monthly" in radiation and "yearly" not in radiation:
|
elif "year" in radiation:
|
||||||
radiation["yearly"] = pd.DataFrame({radiation["monthly"].sum()})
|
building_radiation += radiation["year"].iloc[0]
|
||||||
building_radiation += radiation["yearly"].iloc[0]
|
elif "month" in radiation and "year" not in radiation:
|
||||||
|
surface.global_irradiance["year"] = pd.DataFrame({radiation["month"].sum()})
|
||||||
|
building_radiation += radiation["year"].iloc[0]
|
||||||
if building_radiation < min_radiation:
|
if building_radiation < min_radiation:
|
||||||
min_radiation = building_radiation
|
min_radiation = building_radiation
|
||||||
selected_city_object = city_object
|
selected_city_object = city_object
|
||||||
# merge the city object with the minimum radiation
|
# merge the city object with the minimum radiation
|
||||||
if selected_city_object is not None:
|
if selected_city_object is not None:
|
||||||
_merge_city.add_city_object(selected_city_object)
|
_merge_city.add_city_object(selected_city_object)
|
||||||
|
else:
|
||||||
|
_merge_city.add_city_object(building)
|
||||||
return _merge_city
|
return _merge_city
|
||||||
|
|
||||||
@property
|
@property
|
||||||
|
|
|
@ -6,8 +6,12 @@ Project Coder Guille Gutierrez Guillermo.GutierrezMorote@concordia.ca
|
||||||
"""
|
"""
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
from unittest import TestCase
|
from unittest import TestCase
|
||||||
|
|
||||||
from hub.imports.geometry_factory import GeometryFactory
|
from hub.imports.geometry_factory import GeometryFactory
|
||||||
|
import platform
|
||||||
|
from hub.exports.exports_factory import ExportsFactory
|
||||||
|
import subprocess
|
||||||
|
from subprocess import SubprocessError, TimeoutExpired, CalledProcessError
|
||||||
|
from hub.imports.results_factory import ResultFactory
|
||||||
|
|
||||||
|
|
||||||
class TestCityMerge(TestCase):
|
class TestCityMerge(TestCase):
|
||||||
|
@ -20,6 +24,16 @@ class TestCityMerge(TestCase):
|
||||||
:return: None
|
:return: None
|
||||||
"""
|
"""
|
||||||
self._example_path = (Path(__file__).parent / 'tests_data').resolve()
|
self._example_path = (Path(__file__).parent / 'tests_data').resolve()
|
||||||
|
self._output_path = (Path(__file__).parent / 'tests_outputs').resolve()
|
||||||
|
self._weather_file = (self._example_path / 'CAN_PQ_Montreal.Intl.AP.716270_CWEC.epw').resolve()
|
||||||
|
self._climate_file = (self._example_path / 'New_York.cli').resolve()
|
||||||
|
self._executable = None
|
||||||
|
if platform.system() == 'Linux':
|
||||||
|
self._executable = 'citysim_sra'
|
||||||
|
if platform.system() == 'Darwin':
|
||||||
|
self._executable = 'citysim_sra'
|
||||||
|
elif platform.system() == 'Windows':
|
||||||
|
self._executable = 'shortwave_integer'
|
||||||
|
|
||||||
def _get_citygml(self, file):
|
def _get_citygml(self, file):
|
||||||
file_path = (self._example_path / file).resolve()
|
file_path = (self._example_path / file).resolve()
|
||||||
|
@ -34,3 +48,23 @@ class TestCityMerge(TestCase):
|
||||||
self.assertEqual(len(city_1.city_objects), 1, 'Wrong amount of city_objects found in city_1')
|
self.assertEqual(len(city_1.city_objects), 1, 'Wrong amount of city_objects found in city_1')
|
||||||
self.assertEqual(len(city_2.city_objects), 1, 'Wrong amount of city_objects found in city_2')
|
self.assertEqual(len(city_2.city_objects), 1, 'Wrong amount of city_objects found in city_2')
|
||||||
self.assertEqual(len(city.city_objects), 2, 'Wrong amount of city_objects found in city')
|
self.assertEqual(len(city.city_objects), 2, 'Wrong amount of city_objects found in city')
|
||||||
|
|
||||||
|
def test_merge_with_radiation(self):
|
||||||
|
city_one = self._get_citygml('one_building_in_kelowna.gml')
|
||||||
|
city_two = self._get_citygml('pluto_building.gml')
|
||||||
|
city_two.name = 'New_York'
|
||||||
|
city_two.climate_file = self._climate_file
|
||||||
|
try:
|
||||||
|
ExportsFactory(export_type='sra', city=city_two, path=self._output_path, weather_file=self._weather_file,
|
||||||
|
target_buildings=city_two.buildings, weather_format='epw').export()
|
||||||
|
subprocess.run([self._executable, f'{str(self._output_path)}/{city_two.name}_sra.xml'], stdout=subprocess.DEVNULL)
|
||||||
|
except (SubprocessError, TimeoutExpired, CalledProcessError) as error:
|
||||||
|
raise Exception(error)
|
||||||
|
ResultFactory('sra', city_two, self._output_path).enrich()
|
||||||
|
merged_city = city_one.merge(city_two)
|
||||||
|
self.assertEqual(len(merged_city.buildings), 2)
|
||||||
|
self.assertEqual(merged_city.buildings[1].surfaces[0].global_irradiance['year'].iloc[0], 254.3453196347032)
|
||||||
|
self.assertEqual(merged_city.buildings[0].surfaces[0].global_irradiance, {})
|
||||||
|
self.assertEqual(merged_city.buildings[0].surfaces[2].global_irradiance, {})
|
||||||
|
self.assertEqual(city_one.buildings[0].surfaces[0].global_irradiance, merged_city.buildings[0].surfaces[0].global_irradiance)
|
||||||
|
self.assertEqual(city_two.buildings[0].surfaces[0].global_irradiance, merged_city.buildings[1].surfaces[0].global_irradiance)
|
||||||
|
|
8768
hub/unittests/tests_data/CAN_PQ_Montreal.Intl.AP.716270_CWEC.epw
Normal file
8768
hub/unittests/tests_data/CAN_PQ_Montreal.Intl.AP.716270_CWEC.epw
Normal file
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue
Block a user