forked from s_ranjbar/city_retrofit
218 lines
11 KiB
Python
218 lines
11 KiB
Python
"""
|
|
TestGeometryFactory test and validate the city model structure geometric parameters
|
|
SPDX - License - Identifier: LGPL - 3.0 - or -later
|
|
Copyright © 2020 Project Author Guille Gutierrez guillermo.gutierrezmorote@concordia.ca
|
|
Contributors Pilar Monsalvete Alvarez de Uribarri pilar.monsalvete@concordia.ca
|
|
"""
|
|
import os
|
|
from pathlib import Path
|
|
from unittest import TestCase
|
|
from city_model_structure.city import City
|
|
from imports.geometry_factory import GeometryFactory
|
|
|
|
|
|
class TestGeometryFactory(TestCase):
|
|
"""
|
|
TestGeometryFactory TestCase 1
|
|
"""
|
|
def setUp(self) -> None:
|
|
"""
|
|
Test setup
|
|
:return: None
|
|
"""
|
|
self._city_gml = None
|
|
self._example_path = (Path(__file__).parent / 'tests_data').resolve()
|
|
|
|
def _get_citygml(self, file):
|
|
if self._city_gml is None:
|
|
file_path = (self._example_path / file).resolve()
|
|
self._city_gml = GeometryFactory('citygml', file_path).city
|
|
self.assertIsNotNone(self._city_gml, 'city is none')
|
|
return self._city_gml
|
|
|
|
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')
|
|
|
|
def test_citygml_city_serialization(self):
|
|
"""
|
|
Test the City from citygml serialization de-serialization
|
|
:return: None
|
|
"""
|
|
file = 'lod2_buildings.gml'
|
|
pickle_file = (self._example_path / 'lod2_buildings.pickle').resolve()
|
|
city = self._get_citygml(file)
|
|
self.assertIsNotNone(city.city_objects, 'city_objects is none')
|
|
for building in city.buildings:
|
|
self.assertIsNotNone(city.city_object(building.name), 'city_object return none')
|
|
self.assertIsNotNone(city.srs_name, 'srs_name is none')
|
|
self.assertIsNotNone(city.lower_corner, 'lower_corner is none')
|
|
self.assertIsNotNone(city.upper_corner, 'upper_corner is none')
|
|
self.assertIsNotNone(city.name, 'name is none')
|
|
self.assertIsNotNone(city.country_code, 'country code is none')
|
|
city.save(pickle_file)
|
|
city = City.load(pickle_file)
|
|
# repeat the city tests
|
|
self.assertIsNotNone(city.city_objects, 'city_objects is none')
|
|
for building in city.buildings:
|
|
self.assertIsNotNone(city.city_object(building.name), 'city_object return none')
|
|
self.assertIsNotNone(city.srs_name, 'srs_name is none')
|
|
self.assertIsNotNone(city.lower_corner, 'lower_corner is none')
|
|
self.assertIsNotNone(city.upper_corner, 'upper_corner is none')
|
|
self.assertIsNotNone(city.name, 'name is none')
|
|
self.assertIsNotNone(city.country_code, 'country code is none')
|
|
os.remove(pickle_file)
|
|
|
|
def test_citygml_buildings(self):
|
|
"""
|
|
Test city objects in the city
|
|
:return: None
|
|
"""
|
|
file = 'lod2_buildings.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 = 'lod2_buildings.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 = 'lod2_buildings.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 = 'lod2_buildings.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 = 'lod2_buildings.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_surfaces_triangulation(self):
|
|
"""
|
|
Test city surfaces triangulation and polygon creation
|
|
:return:
|
|
"""
|
|
file = (self._example_path / 'gml_17_12_2020.gml').resolve()
|
|
city = GeometryFactory('citygml', file).city
|
|
|
|
counter = 0
|
|
for building in city.buildings:
|
|
if building.name != 'BLD121958':
|
|
print(building.name, building.volume)
|
|
if str(building.volume) == 'inf':
|
|
counter += 1
|
|
print('total number of buildings with volume inf', counter)
|
|
|
|
def test_stuttgart_gml(self):
|
|
file = '20190815_mitte_out_MC_FloursurfaceADD.gml'
|
|
city = self._get_citygml(file)
|
|
pickle_file = (self._example_path / '20190815_mitte_out_MC_FloursurfaceADD.pickle').resolve()
|
|
city.save(pickle_file)
|
|
for building in city.buildings:
|
|
self.assertIsNotNone(building.volume, 'building volume is none')
|