system_assignation/tests/test_geometry_factory.py

265 lines
14 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
"""
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.parent / 'tests_data').resolve()
2021-01-27 16:08:11 -05:00
self._pickle_file = (self._example_path / 'kelowna_test_case.pickle').resolve()
self._kelowna_pickle_file = (self._example_path / 'kelowna_test_case.pickle').resolve()
self._output_path = (Path(__file__).parent / 'surface_outputs').resolve()
2020-05-29 07:25:33 -04:00
def _get_citygml(self):
2020-05-29 07:25:33 -04:00
if self._city_gml is None:
2020-12-01 07:33:23 -05:00
file_path = (self._example_path / 'lod2_buildings.gml').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
"""
city = self._get_citygml()
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')
city.save(self._pickle_file)
city = City.load(self._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')
os.remove(self._pickle_file.resolve())
2020-12-01 16:29:20 -05:00
def test_surfaces_triangulation(self):
"""
Test city surfaces triangulation and polygon creation
:return:
"""
print(self._pickle_file)
city = City.load(self._pickle_file)
counter = 0
for building in city.buildings:
if building.name != 'BLD121958':
print('building name', building.name)
print('volume', building.name, building.volume)
if str(building.volume) == 'inf':
counter += 1
building.stl_export(self._output_path)
print('total number of buildings with volume inf', counter)
def test_citygml_buildings(self):
"""
Test city objects in the city
:return: None
"""
city = self._get_citygml()
for building in city.buildings:
self.assertIsNotNone(building.name, 'building name is none')
self.assertIsNotNone(building.lod, 'building lod is none')
self.assertIsNotNone(building.location, 'building location 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.assertIsNotNone(building.basement_heated, 'building basement_heated is none')
self.assertIsNotNone(building.attic_heated, 'building attic_heated is none')
self.assertIsNotNone(building.terrains, 'building terrains is none')
self.assertIsNotNone(building.foot_print, 'building foot_print 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.heated_volume, 'building heated_volume is 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')
building.stl_export(self._example_path)
os.remove(Path(self._example_path, building.name + '.stl').resolve())
2020-05-29 07:25:33 -04:00
def test_citygml_surfaces(self):
"""
Test surfaces in city objects
:return: None
"""
city = self._get_citygml()
print(city)
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')
self.assertIsNotNone(surface.points_list, 'surface points_list is none')
self.assertIsNotNone(surface.global_irradiance, 'monthly irradiance is none')
2020-05-29 07:25:33 -04:00
self.assertIsNotNone(surface.swr, 'surface swr is none')
self.assertIsNotNone(surface.min_x, 'surface min_x is none')
self.assertIsNotNone(surface.min_y, 'surface min_y is none')
self.assertIsNotNone(surface.min_z, 'surface min_z is none')
print('points', surface.points)
print('coordinates', surface._coordinates)
2020-05-29 07:25:33 -04:00
def test_citygml_thermal_zone(self):
"""
Test thermal zones in city objects
:return: None
"""
city = self._get_citygml()
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')
self.assertIsNotNone(thermal_zone.heated, 'thermal_zone heated is none')
self.assertIsNotNone(thermal_zone.cooled, 'thermal_zone cooled is none')
2020-06-15 14:59:53 -04:00
self.assertEqual(thermal_zone.additional_thermal_bridge_u_value, 0.0,
'thermal_zone additional_thermal_bridge_u_value is not 0.0')
2020-05-29 07:25:33 -04:00
self.assertIsNone(thermal_zone.effective_thermal_capacity,
'thermal_zone effective_thermal_capacity is not none')
2020-06-15 14:59:53 -04:00
self.assertEqual(thermal_zone.indirectly_heated_area_ratio, 0.0,
'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')
2020-06-15 14:59:53 -04:00
self.assertEqual(thermal_zone.infiltration_rate_system_on, 0.0,
'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
"""
city = self._get_citygml()
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:
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')
self.assertRaises(Exception, lambda: thermal_boundary.u_value, 'thermal_boundary u_value was initialized')
self.assertIsNone(thermal_boundary.layers, 'thermal_boundary layers was initialized')
self.assertRaises(Exception, lambda: thermal_boundary.outside_solar_absorptance,
'thermal_boundary outside_solar_absorptance was initialized')
self.assertIsNone(thermal_boundary.outside_thermal_absorptance,
'thermal_boundary outside_thermal_absorptance was initialized')
self.assertIsNone(thermal_boundary.outside_visible_absorptance,
'thermal_boundary outside_visible_absorptance was initialized')
self.assertRaises(Exception, lambda: thermal_boundary.shortwave_reflectance,
'thermal_boundary shortwave_reflectance was initialized')
self.assertRaises(Exception, lambda: thermal_boundary.window_area,
'thermal_boundary window_area was initialized')
self.assertIsNone(thermal_boundary.window_ratio, 'thermal_boundary window_ratio was initialized')
def test_citygml_thermal_opening(self):
"""
Test thermal openings in thermal zones
:return: None
"""
city = self._get_citygml()
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:
self.assertTrue(thermal_opening.frame_ratio == 0, 'thermal_opening frame_ratio was not 0')
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-01-27 16:08:11 -05:00
def test_stuttgart_gml(self):
file_path = (self._example_path / '20190815_mitte_out_MC_FloursurfaceADD.gml').resolve()
city = GeometryFactory('citygml', file_path).city
pickle_file = (self._example_path / '20190815_mitte_out_MC_FloursurfaceADD.pickle').resolve()
city.save(pickle_file)
counter = 0
for building in city.buildings:
if building.name != 'BLD121958':
print('building name', building.name)
print('volume', building.name, building.volume)
if str(building.volume) == 'inf':
counter += 1
building.stl_export(self._output_path)
print('total number of buildings with volume inf', counter)
def test_divide_mesh_by_plane(self):
file_path = (self._example_path / 'FZK-Haus-LoD-all-KIT-IAI-KHH-B36-V1.gml').resolve()
# todo @Guille: this file has 5 lods (0, 1, 2, 3 and 4), all as one single city_object.
# Only lod1 is read and saved
city = GeometryFactory('citygml', file_path).city
for building in city.buildings:
print(building.name)
print(building.volume)
print(building.thermal_zones[0].floor_area)
print(len(building.storeys))
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 ' \
'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 0.0 0.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 1.0 1.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 2.0 2.0 0.0']
surface = Surface(coordinates, holes_coordinates=holes_coordinates, remove_last=True)
print(surface.points)
print(surface.holes_points)
print(surface.perimeter_vertices)
print(surface.hole_surfaces[1].area)
print(surface.perimeter_surface.area)
print(surface.solid_surface.area)
print(surface.hole_surfaces[1].normal)
print(surface.perimeter_surface.normal)
print(surface.solid_surface.normal)