""" 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 from pathlib import Path from unittest import TestCase from factories.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.parent / 'tests_data').resolve() def _get_citygml(self): if self._city_gml is None: # file_path = (self._example_path / 'EngHT_Flat_model_01.gml').resolve() file_path = (self._example_path / 'lod2_buildings.gml').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(self): """ Test the City parsing :return: None """ city = self._get_citygml() 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') 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()) def test_citygml_surfaces(self): """ Test surfaces in city objects :return: None """ city = self._get_citygml() for building in city.buildings: for surface in building.surfaces: self.assertIsNotNone(surface.name, 'surface name is none') self.assertIsNotNone(surface.area, 'surface area 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.polygon, 'surface polygon is none') self.assertIsNotNone(surface.shapely, 'surface shapely is none') self.assertIsNotNone(surface.global_irradiance, 'monthly irradiance is none') self.assertIsNotNone(surface.normal, 'surface normal is none') self.assertIsNotNone(surface.projection, 'surface projection is none') 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') self.assertIsNotNone(surface.ground_polygon, 'surface ground_polygon is none') self.assertIsNotNone(surface.ground_points, 'surface ground_points is none') self.assertIsNotNone(surface.intersect(surface), 'self intersection is none') def test_citygml_thermal_zone(self): """ Test thermal zones in city objects :return: None """ city = self._get_citygml() 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.heated, 'thermal_zone heated is none') self.assertIsNotNone(thermal_zone.cooled, 'thermal_zone cooled is none') self.assertEqual(thermal_zone.additional_thermal_bridge_u_value, 0.0, 'thermal_zone additional_thermal_bridge_u_value is not 0.0') self.assertIsNone(thermal_zone.effective_thermal_capacity, 'thermal_zone effective_thermal_capacity is not none') self.assertEqual(thermal_zone.indirectly_heated_area_ratio, 0.0, '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.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') def test_citygml_thermal_boundary(self): """ Test thermal boundaries in thermal zones :return: None """ city = self._get_citygml() for building in city.buildings: for thermal_zone in building.thermal_zones: 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() 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.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') 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')