city_retrofit/tests/test_geometry_factory.py

244 lines
13 KiB
Python
Raw Normal View History

2020-06-09 14:07:47 -04:00
"""
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 Álvarez de Uribarri pilar.monsalvete@concordia.ca
2020-06-09 14:07:47 -04:00
"""
import os
2020-05-29 07:25:33 -04:00
from pathlib import Path
from unittest import TestCase
from city_model_structure.city import City
from imports.geometry_factory import GeometryFactory
from city_model_structure.attributes.surface import Surface
2020-05-29 07:25:33 -04:00
class TestGeometryFactory(TestCase):
"""
2020-10-21 09:16:29 -04:00
TestGeometryFactory TestCase 1
"""
2020-05-29 07:25:33 -04:00
def setUp(self) -> None:
"""
Test setup
:return: None
"""
2020-05-29 07:25:33 -04:00
self._city_gml = None
self._example_path = (Path(__file__).parent / 'tests_data').resolve()
2020-05-29 07:25:33 -04:00
2021-03-15 11:47:30 -04:00
def _get_citygml(self, file):
2020-05-29 07:25:33 -04:00
if self._city_gml is None:
2021-03-15 11:47:30 -04:00
file_path = (self._example_path / file).resolve()
self._city_gml = GeometryFactory('citygml', file_path)._city_debug
2020-05-29 07:25:33 -04:00
self.assertIsNotNone(self._city_gml, 'city is none')
return self._city_gml
2020-06-30 16:11:45 -04:00
def test_subway(self):
"""
Test subway parsing
:return:
"""
file_path = (self._example_path / 'subway.osm').resolve()
2020-06-30 18:06:27 -04:00
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')
2020-06-30 16:11:45 -04:00
2020-12-15 11:10:25 -05:00
def test_citygml_city_serialization(self):
"""
2020-12-15 11:10:25 -05:00
Test the City from citygml serialization de-serialization
:return: None
"""
2021-03-15 11:47:30 -04:00
file = 'lod2_buildings.gml'
pickle_file = (self._example_path / 'lod2_buildings.pickle').resolve()
city = self._get_citygml(file)
2020-06-22 13:26:50 -04:00
self.assertIsNotNone(city.city_objects, 'city_objects is none')
2020-06-26 10:06:43 -04:00
for building in city.buildings:
self.assertIsNotNone(city.city_object(building.name), 'city_object return none')
2020-05-29 07:25:33 -04:00
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')
2021-03-15 11:47:30 -04:00
city.save(pickle_file)
city = City.load(pickle_file)
# repeat the city tests
2020-12-01 16:29:20 -05:00
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')
2021-03-15 11:47:30 -04:00
os.remove(pickle_file)
def test_citygml_buildings(self):
"""
Test city objects in the city
:return: None
"""
2021-03-15 11:47:30 -04:00
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')
2021-03-15 11:47:30 -04:00
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')
2021-03-15 11:47:30 -04:00
self.assertIsNotNone(building.floor_area, 'building floor_area is none')
2020-05-29 07:25:33 -04:00
def test_citygml_surfaces(self):
"""
Test surfaces in city objects
:return: None
"""
2021-03-15 11:47:30 -04:00
file = 'lod2_buildings.gml'
city = self._get_citygml(file)
2020-06-26 10:06:43 -04:00
for building in city.buildings:
for surface in building.surfaces:
2020-05-29 07:25:33 -04:00
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.points, 'surface points is none')
2021-03-15 11:47:30 -04:00
self.assertIsNone(surface.holes_points, 'surface holes_points is not none')
self.assertIsNotNone(surface.perimeter_points, 'surface perimeter_points is none')
2020-05-29 07:25:33 -04:00
self.assertIsNotNone(surface.points_list, 'surface points_list is none')
2021-03-15 11:47:30 -04:00
self.assertIsNone(surface.holes_points_list, 'surface holes_points_list is not none')
self.assertIsNotNone(surface.perimeter_points_list, 'surface perimeter_points_list is none')
self.assertIsNotNone(surface.global_irradiance, 'monthly irradiance is none')
2021-03-15 11:47:30 -04:00
self.assertIsNone(surface.swr, 'surface swr is not none')
self.assertIsNotNone(surface.envelope_lower_corner, 'surface envelope_lower_corner is none')
self.assertIsNotNone(surface.envelope_upper_corner, 'surface envelope_upper_corner is none')
2021-03-15 11:47:30 -04:00
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')
2021-03-15 11:47:30 -04:00
self.assertIsNotNone(surface.solid_polygon, 'surface solid_polygon is none')
2020-05-29 07:25:33 -04:00
def test_citygml_thermal_zone(self):
"""
Test thermal zones in city objects
:return: None
"""
2021-03-15 11:47:30 -04:00
file = 'lod2_buildings.gml'
city = self._get_citygml(file)
2020-06-26 10:06:43 -04:00
for building in city.buildings:
for thermal_zone in building.thermal_zones:
2020-05-29 07:25:33 -04:00
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')
2021-03-15 11:47:30 -04:00
self.assertIsNone(thermal_zone.is_heated, 'thermal_zone heated is not none')
self.assertIsNone(thermal_zone.is_cooled, 'thermal_zone cooled is not none')
self.assertIsNone(thermal_zone.additional_thermal_bridge_u_value,
'thermal_zone additional_thermal_bridge_u_value is not none')
2020-05-29 07:25:33 -04:00
self.assertIsNone(thermal_zone.effective_thermal_capacity,
'thermal_zone effective_thermal_capacity is not none')
2021-03-15 11:47:30 -04:00
self.assertIsNone(thermal_zone.indirectly_heated_area_ratio,
'thermal_zone indirectly_heated_area_ratio is not none')
2020-05-29 07:25:33 -04:00
self.assertIsNone(thermal_zone.infiltration_rate_system_off,
'thermal_zone infiltration_rate_system_off is not none')
2021-03-15 11:47:30 -04:00
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')
2020-05-29 07:25:33 -04:00
def test_citygml_thermal_boundary(self):
"""
Test thermal boundaries in thermal zones
:return: None
"""
2021-03-15 11:47:30 -04:00
file = 'lod2_buildings.gml'
city = self._get_citygml(file)
2020-06-26 10:06:43 -04:00
for building in city.buildings:
for thermal_zone in building.thermal_zones:
2020-05-29 07:25:33 -04:00
for thermal_boundary in thermal_zone.bounded:
2021-03-15 11:47:30 -04:00
self.assertIsNotNone(thermal_boundary.surface, 'thermal_boundary surface is none')
2020-05-29 07:25:33 -04:00
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
"""
2021-03-15 11:47:30 -04:00
file = 'lod2_buildings.gml'
city = self._get_citygml(file)
2020-06-26 10:06:43 -04:00
for building in city.buildings:
for thermal_zone in building.thermal_zones:
2020-05-29 07:25:33 -04:00
for thermal_boundary in thermal_zone.bounded:
for thermal_opening in thermal_boundary.thermal_openings:
2021-03-15 11:47:30 -04:00
self.assertIsNone(thermal_opening.frame_ratio, 'thermal_opening frame_ratio was initialized')
2020-05-29 07:25:33 -04:00
self.assertIsNone(thermal_opening.g_value, 'thermal_opening g_value was initialized')
self.assertIsNone(thermal_opening.conductivity, 'thermal_opening conductivity_w_mk was initialized')
2020-06-15 14:59:53 -04:00
self.assertIsNone(thermal_opening.back_side_solar_transmittance_at_normal_incidence,
'thermal_opening back_side_solar_transmittance_at_normal_incidence was initialized')
2020-05-29 07:25:33 -04:00
self.assertRaises(Exception, lambda: thermal_opening.openable_ratio,
'thermal_opening openable_ratio is not raising an exception')
2020-06-15 14:59:53 -04:00
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')
2020-06-03 16:56:17 -04:00
self.assertRaises(Exception, lambda: thermal_opening.u_value, 'thermal_opening u_value was initialized')
2021-03-15 11:47:30 -04:00
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.pickle').resolve()
city = City.load(file)
2021-01-27 16:08:11 -05:00
counter = 0
for building in city.buildings:
if building.name != 'BLD121958':
2021-03-15 11:47:30 -04:00
print(building.name, building.volume)
2021-01-27 16:08:11 -05:00
if str(building.volume) == 'inf':
counter += 1
print('total number of buildings with volume inf', counter)
2021-03-15 11:47:30 -04:00
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')
def test_surface(self):
coordinates = '0.0 0.0 0.0 0.0 4.0 0.0 4.0 4.0 0.0 4.0 0.0 0.0 0.0 0.0 0.0 ' \
'1.0 1.0 0.0 2.0 1.0 0.0 2.0 2.0 0.0 1.0 2.0 0.0 1.0 1.0 0.0 0.0 0.0 0.0 ' \
2021-03-08 12:56:19 -05:00
'2.0 2.0 0.0 3.0 2.0 0.0 3.0 3.0 0.0 2.0 3.0 0.0 2.0 2.0 0.0'
holes_coordinates = ['1.0 1.0 0.0 2.0 1.0 0.0 2.0 2.0 0.0 1.0 2.0 0.0',
'2.0 2.0 0.0 3.0 2.0 0.0 3.0 3.0 0.0 2.0 3.0 0.0']
surface = Surface(coordinates, holes_coordinates=holes_coordinates)
print('solid:', surface.points)
print(surface.holes_points)
2021-03-08 12:56:19 -05:00
print('perimeter:', surface.perimeter_points)
for i in range(0, len(holes_coordinates)):
print(surface.holes_polygons[i].area)
print('perimeter:', surface.perimeter_polygon.area)
print('solid:', surface.solid_polygon.area)
2021-03-08 12:56:19 -05:00
for i in range(0, len(holes_coordinates)):
print(surface.holes_polygons[i].normal)
print('perimeter:', surface.perimeter_polygon.normal)
print('solid:', surface.solid_polygon.normal)