Replaced previous test with insel export
This commit is contained in:
parent
1a86449e58
commit
c9cc46f943
@ -1,108 +0,0 @@
|
|||||||
"""
|
|
||||||
TestCityMerge test and validate the merge of several cities into one
|
|
||||||
SPDX - License - Identifier: LGPL - 3.0 - or -later
|
|
||||||
Copyright © 2022 Concordia CERC group
|
|
||||||
Project Coder Guille Gutierrez Guillermo.GutierrezMorote@concordia.ca
|
|
||||||
"""
|
|
||||||
|
|
||||||
import copy
|
|
||||||
import distutils.spawn
|
|
||||||
import subprocess
|
|
||||||
from pathlib import Path
|
|
||||||
from unittest import TestCase
|
|
||||||
|
|
||||||
from hub.city_model_structure.city import City
|
|
||||||
from hub.imports.geometry_factory import GeometryFactory
|
|
||||||
from hub.imports.results_factory import ResultFactory
|
|
||||||
from hub.exports.exports_factory import ExportsFactory
|
|
||||||
import hub.helpers.constants as cte
|
|
||||||
|
|
||||||
|
|
||||||
class TestCityMerge(TestCase):
|
|
||||||
"""
|
|
||||||
Functional TestCityMerge
|
|
||||||
"""
|
|
||||||
def setUp(self) -> None:
|
|
||||||
"""
|
|
||||||
Test setup
|
|
||||||
:return: None
|
|
||||||
"""
|
|
||||||
self._example_path = (Path(__file__).parent / 'tests_data').resolve()
|
|
||||||
self._output_path = (Path(__file__).parent / 'tests_outputs').resolve()
|
|
||||||
self._executable = 'sra'
|
|
||||||
|
|
||||||
def test_merge(self):
|
|
||||||
file_path = Path(self._example_path / 'test.geojson').resolve()
|
|
||||||
full_city = GeometryFactory('geojson', file_path, height_field='citygml_me').city
|
|
||||||
self.assertEqual(17, len(full_city.buildings), 'Wrong number of buildings')
|
|
||||||
odd_city = City(full_city.lower_corner, full_city.upper_corner, full_city.srs_name)
|
|
||||||
even_city = City(full_city.lower_corner, full_city.upper_corner, full_city.srs_name)
|
|
||||||
for building in full_city.buildings:
|
|
||||||
if int(building.name) % 2 == 0:
|
|
||||||
even_city.add_city_object(copy.deepcopy(building))
|
|
||||||
else:
|
|
||||||
odd_city.add_city_object(copy.deepcopy(building))
|
|
||||||
self.assertEqual(8, len(odd_city.buildings), 'Wrong number of odd buildings')
|
|
||||||
self.assertEqual(9, len(even_city.buildings), 'Wrong number of par buildings')
|
|
||||||
merged_city = odd_city.merge(even_city)
|
|
||||||
self.assertEqual(17, len(merged_city.buildings), 'Wrong number of buildings in merged city')
|
|
||||||
merged_city = even_city.merge(odd_city)
|
|
||||||
self.assertEqual(17, len(merged_city.buildings), 'Wrong number of buildings in merged city')
|
|
||||||
merged_city = full_city.merge(odd_city).merge(even_city)
|
|
||||||
self.assertEqual(17, len(merged_city.buildings), 'Wrong number of buildings in merged city')
|
|
||||||
|
|
||||||
def test_merge_with_radiation(self):
|
|
||||||
sra = distutils.spawn.find_executable('sra')
|
|
||||||
file_path = Path(self._example_path / 'test.geojson').resolve()
|
|
||||||
|
|
||||||
full_city = GeometryFactory('geojson', file_path, height_field='citygml_me').city
|
|
||||||
even_city = City(full_city.lower_corner, full_city.upper_corner, full_city.srs_name)
|
|
||||||
for building in full_city.buildings:
|
|
||||||
if int(building.name) % 2 == 0:
|
|
||||||
even_city.add_city_object(copy.deepcopy(building))
|
|
||||||
ExportsFactory('sra', full_city, self._output_path).export()
|
|
||||||
sra_file = str((self._output_path / f'{full_city.name}_sra.xml').resolve())
|
|
||||||
subprocess.run([sra, sra_file], stdout=subprocess.DEVNULL)
|
|
||||||
ResultFactory('sra', full_city, self._output_path).enrich()
|
|
||||||
self.assertEqual(17, len(full_city.buildings), 'Wrong number of buildings')
|
|
||||||
merged_city = full_city.merge(even_city)
|
|
||||||
|
|
||||||
full_city_building_total_radiation = 0
|
|
||||||
for building in merged_city.buildings:
|
|
||||||
for surface in building.surfaces:
|
|
||||||
if surface.global_irradiance:
|
|
||||||
full_city_building_total_radiation += surface.global_irradiance[cte.YEAR][0]
|
|
||||||
|
|
||||||
merged_city_building_total_radiation = 0
|
|
||||||
for building in merged_city.buildings:
|
|
||||||
for surface in building.surfaces:
|
|
||||||
if surface.global_irradiance:
|
|
||||||
merged_city_building_total_radiation += surface.global_irradiance[cte.YEAR][0]
|
|
||||||
self.assertEqual(full_city_building_total_radiation, merged_city_building_total_radiation)
|
|
||||||
|
|
||||||
merged_city = even_city.merge(full_city)
|
|
||||||
merged_city_building_total_radiation = 0
|
|
||||||
for building in merged_city.buildings:
|
|
||||||
for surface in building.surfaces:
|
|
||||||
if surface.global_irradiance:
|
|
||||||
merged_city_building_total_radiation += surface.global_irradiance[cte.YEAR][0]
|
|
||||||
self.assertEqual(full_city_building_total_radiation, merged_city_building_total_radiation)
|
|
||||||
|
|
||||||
for building in even_city.buildings:
|
|
||||||
for surface in building.surfaces:
|
|
||||||
surface.global_irradiance[cte.YEAR] = [3]
|
|
||||||
|
|
||||||
merged_city = full_city.merge(even_city)
|
|
||||||
first_merged_city_building_total_radiation = 0
|
|
||||||
for building in merged_city.buildings:
|
|
||||||
for surface in building.surfaces:
|
|
||||||
if surface.global_irradiance:
|
|
||||||
first_merged_city_building_total_radiation += surface.global_irradiance[cte.YEAR][0]
|
|
||||||
merged_city = even_city.merge(full_city)
|
|
||||||
second_merged_city_building_total_radiation = 0
|
|
||||||
for building in merged_city.buildings:
|
|
||||||
for surface in building.surfaces:
|
|
||||||
if surface.global_irradiance:
|
|
||||||
second_merged_city_building_total_radiation += surface.global_irradiance[cte.YEAR][0]
|
|
||||||
self.assertAlmostEqual(first_merged_city_building_total_radiation, second_merged_city_building_total_radiation, 8)
|
|
||||||
|
|
136
tests/test_insel_exports.py
Normal file
136
tests/test_insel_exports.py
Normal file
@ -0,0 +1,136 @@
|
|||||||
|
"""
|
||||||
|
TestInselExports test
|
||||||
|
SPDX - License - Identifier: LGPL - 3.0 - or -later
|
||||||
|
Copyright © 2022 Concordia CERC group
|
||||||
|
Project Coder Pilar Monsalvete Alvarez de Uribarri pilar.monsalvete@concordia.ca
|
||||||
|
"""
|
||||||
|
|
||||||
|
from pathlib import Path
|
||||||
|
from unittest import TestCase
|
||||||
|
import pandas as pd
|
||||||
|
import hub.helpers.constants as cte
|
||||||
|
from hub.helpers.monthly_values import MonthlyValues
|
||||||
|
from hub.imports.geometry_factory import GeometryFactory
|
||||||
|
from hub.imports.construction_factory import ConstructionFactory
|
||||||
|
from hub.imports.usage_factory import UsageFactory
|
||||||
|
from hub.exports.energy_building_exports_factory import EnergyBuildingsExportsFactory
|
||||||
|
from hub.imports.weather_factory import WeatherFactory
|
||||||
|
|
||||||
|
|
||||||
|
class TestExports(TestCase):
|
||||||
|
"""
|
||||||
|
TestExports class contains the unittest for export functionality
|
||||||
|
"""
|
||||||
|
def setUp(self) -> None:
|
||||||
|
"""
|
||||||
|
Test setup
|
||||||
|
:return: None
|
||||||
|
"""
|
||||||
|
self._city = None
|
||||||
|
self._complete_city = None
|
||||||
|
self._example_path = (Path(__file__).parent / 'tests_data').resolve()
|
||||||
|
self._output_path = (Path(__file__).parent / 'tests_outputs').resolve()
|
||||||
|
|
||||||
|
def _get_citygml(self, file):
|
||||||
|
file_path = (self._example_path / file).resolve()
|
||||||
|
self._city = GeometryFactory('citygml', path=file_path).city
|
||||||
|
self.assertIsNotNone(self._city, 'city is none')
|
||||||
|
return self._city
|
||||||
|
|
||||||
|
def _set_irradiance_surfaces(self, city):
|
||||||
|
"""
|
||||||
|
saves in building surfaces the correspondent irradiance at different time-scales depending on the mode
|
||||||
|
if building is None, it saves all buildings' surfaces in file, if building is specified, it saves only that
|
||||||
|
specific building values
|
||||||
|
:parameter city: city
|
||||||
|
:return: none
|
||||||
|
"""
|
||||||
|
city.level_of_detail.surface_radiation = 2
|
||||||
|
path = (self._example_path / "one_building_in_kelowna_sra_SW.out").resolve()
|
||||||
|
self._results = pd.read_csv(path, sep='\s+', header=0).to_dict(orient='list')
|
||||||
|
_irradiance = {}
|
||||||
|
for key in self._results:
|
||||||
|
header_name = key.split(':')
|
||||||
|
result = [x / cte.WATTS_HOUR_TO_JULES for x in self._results[key]]
|
||||||
|
city_object_name = header_name[1]
|
||||||
|
building = self._city.city_object(city_object_name)
|
||||||
|
surface_id = header_name[2]
|
||||||
|
surface = building.surface_by_id(surface_id)
|
||||||
|
monthly_result = MonthlyValues.get_total_month(result)
|
||||||
|
yearly_result = [sum(result)]
|
||||||
|
_irradiance[cte.YEAR] = yearly_result
|
||||||
|
_irradiance[cte.MONTH] = monthly_result
|
||||||
|
_irradiance[cte.HOUR] = result
|
||||||
|
surface.global_irradiance = _irradiance
|
||||||
|
|
||||||
|
def test_insel_monthly_energy_balance_export(self):
|
||||||
|
"""
|
||||||
|
export to Insel MonthlyEnergyBalance
|
||||||
|
"""
|
||||||
|
city = self._get_citygml('one_building_in_kelowna.gml')
|
||||||
|
WeatherFactory('epw', city).enrich()
|
||||||
|
for building in city.buildings:
|
||||||
|
building.external_temperature[cte.MONTH] = MonthlyValues().\
|
||||||
|
get_mean_values(building.external_temperature[cte.HOUR])
|
||||||
|
self._set_irradiance_surfaces(city)
|
||||||
|
|
||||||
|
for building in city.buildings:
|
||||||
|
self.assertIsNotNone(building.external_temperature[cte.MONTH], f'building {building.name} '
|
||||||
|
f'external_temperature is none')
|
||||||
|
for surface in building.surfaces:
|
||||||
|
if surface.type != 'Ground':
|
||||||
|
self.assertIsNotNone(surface.global_irradiance[cte.MONTH], f'surface in building {building.name} '
|
||||||
|
f'global_irradiance is none')
|
||||||
|
|
||||||
|
for building in city.buildings:
|
||||||
|
building.year_of_construction = 2006
|
||||||
|
if building.function is None:
|
||||||
|
building.function = 'large office'
|
||||||
|
building.attic_heated = 0
|
||||||
|
building.basement_heated = 0
|
||||||
|
ConstructionFactory('nrel', city).enrich()
|
||||||
|
UsageFactory('comnet', city).enrich()
|
||||||
|
|
||||||
|
# parameters written:
|
||||||
|
for building in city.buildings:
|
||||||
|
self.assertIsNotNone(building.volume, f'building {building.name} volume is none')
|
||||||
|
self.assertIsNotNone(building.average_storey_height, f'building {building.name} average_storey_height is none')
|
||||||
|
self.assertIsNotNone(building.storeys_above_ground, f'building {building.name} storeys_above_ground is none')
|
||||||
|
self.assertIsNotNone(building.attic_heated, f'building {building.name} attic_heated is none')
|
||||||
|
self.assertIsNotNone(building.basement_heated, f'building {building.name} basement_heated is none')
|
||||||
|
for internal_zone in building.internal_zones:
|
||||||
|
self.assertIsNotNone(internal_zone.area, f'internal zone {internal_zone.id} area is none')
|
||||||
|
for thermal_zone in internal_zone.thermal_zones_from_internal_zones:
|
||||||
|
self.assertIsNotNone(thermal_zone.indirectly_heated_area_ratio, f'thermal zone {thermal_zone.id} '
|
||||||
|
f'indirectly_heated_area_ratio is none')
|
||||||
|
self.assertIsNotNone(thermal_zone.effective_thermal_capacity, f'thermal zone {thermal_zone.id} '
|
||||||
|
f'effective_thermal_capacity is none')
|
||||||
|
self.assertIsNotNone(thermal_zone.additional_thermal_bridge_u_value, f'thermal zone {thermal_zone.id} '
|
||||||
|
f'additional_thermal_bridge_u_value '
|
||||||
|
f'is none')
|
||||||
|
self.assertIsNotNone(thermal_zone.total_floor_area, f'thermal zone {thermal_zone.id} '
|
||||||
|
f'total_floor_area is none')
|
||||||
|
for thermal_boundary in thermal_zone.thermal_boundaries:
|
||||||
|
self.assertIsNotNone(thermal_boundary.type)
|
||||||
|
self.assertIsNotNone(thermal_boundary.opaque_area)
|
||||||
|
self.assertIsNotNone(thermal_boundary.window_ratio)
|
||||||
|
self.assertIsNotNone(thermal_boundary.u_value)
|
||||||
|
self.assertIsNotNone(thermal_boundary.thermal_openings)
|
||||||
|
if thermal_boundary.type is not cte.GROUND:
|
||||||
|
self.assertIsNotNone(thermal_boundary.external_surface.short_wave_reflectance)
|
||||||
|
|
||||||
|
for usage in internal_zone.usages:
|
||||||
|
self.assertIsNotNone(usage.percentage, f'usage zone {usage.name} percentage is none')
|
||||||
|
self.assertIsNotNone(usage.internal_gains, f'usage zone {usage.name} internal_gains is none')
|
||||||
|
self.assertIsNotNone(usage.thermal_control, f'usage zone {usage.name} thermal_control is none')
|
||||||
|
self.assertIsNotNone(usage.hours_day, f'usage zone {usage.name} hours_day is none')
|
||||||
|
self.assertIsNotNone(usage.days_year, f'usage zone {usage.name} days_year is none')
|
||||||
|
self.assertIsNotNone(
|
||||||
|
usage.mechanical_air_change,
|
||||||
|
f'usage zone {usage.name} mechanical_air_change is none'
|
||||||
|
)
|
||||||
|
# export files
|
||||||
|
try:
|
||||||
|
EnergyBuildingsExportsFactory('insel_monthly_energy_balance', city, self._output_path).export()
|
||||||
|
except Exception:
|
||||||
|
self.fail("Insel MonthlyEnergyBalance ExportsFactory raised ExceptionType unexpectedly!")
|
8761
tests/tests_data/one_building_in_kelowna_sra_SW.out
Normal file
8761
tests/tests_data/one_building_in_kelowna_sra_SW.out
Normal file
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue
Block a user