hub/non_functional_tests/test_geometry_factory.py

226 lines
11 KiB
Python
Raw Normal View History

"""
TestGeometryFactory test and validate the city model structure geometric parameters
SPDX - License - Identifier: LGPL - 3.0 - or -later
Copyright © 2020 Project Author Pilar Monsalvete Alvarez de Uribarri pilar.monsalvete@concordia.ca
"""
from pathlib import Path
from unittest import TestCase
from imports.geometry_factory import GeometryFactory
from imports.geometry.helpers.geometry_helper import GeometryHelper
class TestGeometryFactory(TestCase):
"""
Non-functional TestGeometryFactory
Load testing
"""
def setUp(self) -> None:
"""
Test setup
:return: None
"""
self._city = None
self._example_path = (Path(__file__).parent / 'tests_data').resolve()
def _get_citygml(self, file):
file_path = (self._example_path / file).resolve()
self._city = GeometryFactory('citygml', file_path).city
self.assertIsNotNone(self._city, 'city is none')
return self._city
def _get_obj(self, file):
# todo: solve the incongruences between city and city_debug
file_path = (self._example_path / file).resolve()
self._city = GeometryFactory('obj', file_path)._city_debug
self.assertIsNotNone(self._city, 'city is none')
return self._city
@staticmethod
def _internal_function(function_format, original_function):
new_function = original_function
if function_format == 'hft':
new_function = GeometryHelper.hft_to_function[original_function]
elif function_format == 'pluto':
new_function = GeometryHelper.pluto_to_function[original_function]
elif function_format == 'alkis':
# todo: not implemented yet!!
raise NotImplementedError
return new_function
# citygml
def test_stuttgart_gml(self):
file = '20190815_mitte_out_MC_FloursurfaceADD.gml'
city = self._get_citygml(file)
for building in city.buildings:
self.assertIsNotNone(building.volume, 'building volume is none')
def test_citygml_buildings(self):
"""
Test city objects in the city
:return: None
"""
file = 'one_building_in_kelowna.gml'
city = self._get_citygml(file)
for building in city.buildings:
self.assertIsNotNone(building.name, 'building name is none')
self.assertIsNotNone(building.lod, 'building lod is none')
self.assertIsNotNone(building.centroid, 'building centroid is none')
self.assertIsNotNone(building.year_of_construction, 'building year_of_construction is none')
self.assertIsNotNone(building.function, 'building function is none')
self.assertIsNotNone(building.volume, 'building volume is none')
self.assertIsNotNone(building.surfaces, 'building surfaces is none')
self.assertIsNotNone(building.surfaces[0].name, 'surface not found')
self.assertIsNone(building.basement_heated, 'building basement_heated is not none')
self.assertIsNone(building.attic_heated, 'building attic_heated is not none')
self.assertIsNotNone(building.terrains, 'building terrains is none')
self.assertIsNotNone(building.usage_zones, 'building usage_zones is none')
self.assertIsNone(building.average_storey_height, 'building average_storey_height is not none')
self.assertIsNone(building.storeys_above_ground, 'building storeys_above_ground is not none')
self.assertIsNotNone(building.thermal_zones, 'building thermal_zones is none')
self.assertIsNotNone(building.type, 'building type is none')
self.assertIsNotNone(building.max_height, 'building max_height is none')
self.assertIsNotNone(building.floor_area, 'building floor_area is none')
def test_citygml_surfaces(self):
"""
Test surfaces in city objects
:return: None
"""
file = 'one_building_in_kelowna.gml'
city = self._get_citygml(file)
for building in city.buildings:
for surface in building.surfaces:
self.assertIsNotNone(surface.name, 'surface name is none')
self.assertIsNotNone(surface.type, 'surface type is none')
self.assertIsNotNone(surface.azimuth, 'surface azimuth is none')
self.assertIsNotNone(surface.inclination, 'surface inclination is none')
self.assertIsNotNone(surface.area_below_ground, 'surface area_below_ground is none')
self.assertIsNotNone(surface.area_above_ground, 'surface area_above_ground is none')
self.assertIsNotNone(surface.global_irradiance, 'monthly irradiance is none')
self.assertIsNone(surface.swr, 'surface swr is not none')
self.assertIsNotNone(surface.bounds_lower_corner, 'surface envelope_lower_corner is none')
self.assertIsNotNone(surface.bounds_upper_corner, 'surface envelope_upper_corner is none')
self.assertIsNotNone(surface.area_above_ground, 'surface area_above_ground is none')
self.assertIsNotNone(surface.perimeter_polygon, 'surface perimeter_polygon is none')
self.assertIsNone(surface.holes_polygons, 'surface hole_polygons is not none')
self.assertIsNotNone(surface.solid_polygon, 'surface solid_polygon is none')
def test_citygml_thermal_zone(self):
"""
Test thermal zones in city objects
:return: None
"""
file = 'one_building_in_kelowna.gml'
city = self._get_citygml(file)
for building in city.buildings:
for thermal_zone in building.thermal_zones:
self.assertIsNotNone(thermal_zone.surfaces, 'thermal_zone surfaces is none')
self.assertIsNotNone(thermal_zone.bounded, 'thermal_zone bounded is none')
self.assertIsNotNone(thermal_zone.floor_area, 'thermal_zone floor_area is none')
self.assertIsNotNone(thermal_zone.is_heated, 'thermal_zone heated is none')
self.assertIsNotNone(thermal_zone.is_cooled, 'thermal_zone cooled is none')
self.assertIsNone(thermal_zone.additional_thermal_bridge_u_value,
'thermal_zone additional_thermal_bridge_u_value is not none')
self.assertIsNone(thermal_zone.effective_thermal_capacity,
'thermal_zone effective_thermal_capacity is not none')
self.assertIsNone(thermal_zone.indirectly_heated_area_ratio,
'thermal_zone indirectly_heated_area_ratio is not none')
self.assertIsNone(thermal_zone.infiltration_rate_system_off,
'thermal_zone infiltration_rate_system_off is not none')
self.assertIsNone(thermal_zone.infiltration_rate_system_on,
'thermal_zone infiltration_rate_system_on is not none')
self.assertIsNone(thermal_zone.usage_zones,
'thermal_zone usage_zones are not none')
def test_citygml_thermal_boundary(self):
"""
Test thermal boundaries in thermal zones
:return: None
"""
file = 'one_building_in_kelowna.gml'
city = self._get_citygml(file)
for building in city.buildings:
for thermal_zone in building.thermal_zones:
for thermal_boundary in thermal_zone.bounded:
self.assertIsNotNone(thermal_boundary.surface, 'thermal_boundary surface is none')
self.assertIsNotNone(thermal_boundary.type, 'thermal_boundary type is none')
self.assertIsNotNone(thermal_boundary.area, 'thermal_boundary area is none')
self.assertIsNotNone(thermal_boundary.area_above_ground, 'thermal_boundary area_above_ground is none')
self.assertIsNotNone(thermal_boundary.area_below_ground, 'thermal_boundary area_below_ground is none')
self.assertIsNotNone(thermal_boundary.azimuth, 'thermal_boundary azimuth is none')
self.assertIsNotNone(thermal_boundary.delimits, 'thermal_boundary delimits is none')
self.assertIsNotNone(thermal_boundary.inclination, 'thermal_boundary inclination is none')
def test_citygml_thermal_opening(self):
"""
Test thermal openings in thermal zones
:return: None
"""
file = 'one_building_in_kelowna.gml'
city = self._get_citygml(file)
for building in city.buildings:
for thermal_zone in building.thermal_zones:
for thermal_boundary in thermal_zone.bounded:
for thermal_opening in thermal_boundary.thermal_openings:
self.assertIsNone(thermal_opening.frame_ratio, 'thermal_opening frame_ratio was initialized')
self.assertIsNone(thermal_opening.g_value, 'thermal_opening g_value was initialized')
self.assertIsNone(thermal_opening.conductivity, 'thermal_opening conductivity_w_mk was initialized')
self.assertIsNone(thermal_opening.back_side_solar_transmittance_at_normal_incidence,
'thermal_opening back_side_solar_transmittance_at_normal_incidence was initialized')
self.assertRaises(Exception, lambda: thermal_opening.openable_ratio,
'thermal_opening openable_ratio is not raising an exception')
self.assertIsNone(thermal_opening.front_side_solar_transmittance_at_normal_incidence,
'thermal_opening front_side_solar_transmittance_at_normal_incidence was initialized')
self.assertIsNone(thermal_opening.thickness, 'thermal_opening thickness_m was initialized')
self.assertRaises(Exception, lambda: thermal_opening.u_value, 'thermal_opening u_value was initialized')
self.assertIsNone(thermal_opening.overall_u_value, 'thermal_opening overall_u_value was initialized')
self.assertIsNone(thermal_opening.hi, 'thermal_opening hi was initialized')
self.assertIsNone(thermal_opening.he, 'thermal_opening he was initialized')
def test_citygml_function(self):
"""
Test city objects' functions in the city
:return: None
"""
# case 1: hft
file = 'one_building_in_kelowna.gml'
function_format = 'hft'
city = self._get_citygml(file)
for building in city.buildings:
building.function = self._internal_function(function_format, building.function)
self.assertEqual(building.function, 'residential', 'format hft')
# case 2: Pluto
file = 'pluto_building.gml'
function_format = 'pluto'
city = self._get_citygml(file)
for building in city.buildings:
building.function = self._internal_function(function_format, building.function)
self.assertEqual(building.function, 'secondary school', 'format pluto')
# case 3: Alkis
file = 'one_building_in_kelowna_alkis.gml'
function_format = 'alkis'
city = self._get_citygml(file)
for building in city.buildings:
self.assertRaises(Exception, lambda: self._internal_function(function_format, building.function))
# obj
def test_import_obj(self):
file = 'kelowna.obj'
city = self._get_obj(file)
self.assertIsNotNone(city, 'city is none')
for building in city.buildings:
self.assertIsNotNone(building, 'building is none')
# osm
def test_subway(self):
"""
Test subway parsing
:return:
"""
file_path = (self._example_path / 'subway.osm').resolve()
subway_entrances = self._features = GeometryFactory('osm_subway', file_path).features
self.assertIsNotNone(subway_entrances, 'subway entrances is none')
self.assertEqual(len(subway_entrances), 20, 'Wrong number of subway entrances')