city_retrofit/tests/test_geometry_factory.py

148 lines
9.6 KiB
Python
Raw Normal View History

2020-05-29 07:25:33 -04:00
from unittest import TestCase
from pathlib import Path
from geometry.geometry_factory import GeometryFactory
import os
2020-06-03 16:56:17 -04:00
from city_model_structure.surface import Surface
2020-05-29 07:25:33 -04:00
class TestGeometryFactory(TestCase):
def setUp(self) -> 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 / '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_citygml_city(self):
city = self.get_citygml()
self.assertIsNotNone(city.city_objects, 'city_objects is none')
for city_object in city.city_objects:
self.assertIsNotNone(city.city_object(city_object.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')
self.assertIsNotNone(city.location, 'location is none')
2020-05-29 07:25:33 -04:00
def test_citygml_city_objects(self):
city = self.get_citygml()
for city_object in city.city_objects:
self.assertIsNotNone(city_object.name, 'city_object name is none')
self.assertIsNotNone(city_object.lod, 'city_object lod is none')
self.assertIsNotNone(city_object.year_of_construction, 'city_object year_of_construction is none')
self.assertIsNotNone(city_object.function, 'city_object function is none')
self.assertIsNotNone(city_object.volume, 'city_object volume is none')
self.assertIsNotNone(city_object.surfaces, 'city_object surfaces is none')
self.assertIsNotNone(city_object.surfaces[0].name, 'surface not found')
2020-05-29 07:25:33 -04:00
self.assertIsNotNone(city_object.basement_heated, 'city_object basement_heated is none')
self.assertIsNotNone(city_object.attic_heated, 'city_object attic_heated is none')
self.assertIsNotNone(city_object.terrains, 'city_object terrains is none')
self.assertIsNotNone(city_object.foot_print, 'city_object foot_print is none')
self.assertIsNotNone(city_object.usage_zones, 'city_object usage_zones is none')
self.assertIsNone(city_object.average_storey_height, 'city_object average_storey_height is not none')
self.assertIsNone(city_object.storeys_above_ground, 'city_object storeys_above_ground is not none')
self.assertIsNotNone(city_object.heated_volume, 'city_object heated_volume is none')
self.assertIsNotNone(city_object.thermal_zones, 'city_object thermal_zones is none')
self.assertIsNotNone(city_object.type, 'city_object type is none')
self.assertIsNotNone(city_object.max_height, 'city_object max_height is none')
city_object.stl_export(self._example_path)
os.remove(Path(self._example_path, city_object.name + '.stl').resolve())
2020-05-29 07:25:33 -04:00
def test_citygml_surfaces(self):
city = self.get_citygml()
for city_object in city.city_objects:
for surface in city_object.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_hour, 'surface global_irradiance_hour is none')
self.assertIsNotNone(surface.global_irradiance_month, 'surface global_irradiance_month 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')
2020-05-29 07:25:33 -04:00
def test_citygml_thermal_zone(self):
city = self.get_citygml()
for city_object in city.city_objects:
for thermal_zone in city_object.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.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')
2020-05-29 07:25:33 -04:00
def test_citygml_thermal_boundary(self):
city = self.get_citygml()
for city_object in city.city_objects:
for thermal_zone in city_object.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):
city = self.get_citygml()
for city_object in city.city_objects:
for thermal_zone in city_object.thermal_zones:
for thermal_boundary in thermal_zone.bounded:
for thermal_opening in thermal_boundary.thermal_openings:
self.assertIsNone(thermal_opening.area, 'thermal_opening area was initialized')
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_w_mk, 'thermal_opening conductivity_w_mk was initialized')
self.assertIsNone(thermal_opening.inside_reflectance, 'thermal_opening inside_reflectance was initialized')
self.assertRaises(Exception, lambda: thermal_opening.openable_ratio,
'thermal_opening openable_ratio is not raising an exception')
self.assertIsNone(thermal_opening.outside_reflectance,
'thermal_opening outside_reflectance was initialized')
self.assertIsNone(thermal_opening.thickness_m, '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')