2021-05-27 17:20:06 -04:00
|
|
|
"""
|
|
|
|
TestGeometryFactory test and validate the city model structure geometric parameters
|
|
|
|
SPDX - License - Identifier: LGPL - 3.0 - or -later
|
2022-04-08 09:35:33 -04:00
|
|
|
Copyright © 2022 Concordia CERC group
|
|
|
|
Project Coder Pilar Monsalvete Alvarez de Uribarri pilar.monsalvete@concordia.ca
|
2021-05-27 17:20:06 -04:00
|
|
|
"""
|
|
|
|
from pathlib import Path
|
|
|
|
from unittest import TestCase
|
2023-03-17 12:45:53 -04:00
|
|
|
|
2023-01-24 10:51:50 -05:00
|
|
|
import hub.exports.exports_factory
|
2023-05-12 09:27:29 -04:00
|
|
|
from hub.helpers.dictionaries import MontrealFunctionToHubFunction
|
2023-03-21 14:22:28 -04:00
|
|
|
from hub.helpers.geometry_helper import GeometryHelper
|
2023-01-24 10:51:50 -05:00
|
|
|
from hub.imports.construction_factory import ConstructionFactory
|
|
|
|
from hub.imports.geometry_factory import GeometryFactory
|
2021-05-27 17:20:06 -04:00
|
|
|
|
|
|
|
|
|
|
|
class TestGeometryFactory(TestCase):
|
|
|
|
"""
|
|
|
|
Non-functional TestGeometryFactory
|
|
|
|
Load testing
|
|
|
|
"""
|
2023-03-21 14:22:28 -04:00
|
|
|
|
2021-05-27 17:20:06 -04:00
|
|
|
def setUp(self) -> None:
|
|
|
|
"""
|
|
|
|
Test setup
|
|
|
|
:return: None
|
|
|
|
"""
|
|
|
|
self._city = None
|
|
|
|
self._example_path = (Path(__file__).parent / 'tests_data').resolve()
|
2022-11-25 14:39:35 -05:00
|
|
|
self._output_path = (Path(__file__).parent / 'tests_outputs').resolve()
|
2021-05-27 17:20:06 -04:00
|
|
|
|
2022-11-25 14:39:35 -05:00
|
|
|
def _get_city(self, file, file_type, height_field=None, year_of_construction_field=None, function_field=None):
|
2022-05-03 14:50:41 -04:00
|
|
|
file_path = (self._example_path / file).resolve()
|
2022-11-25 14:39:35 -05:00
|
|
|
self._city = GeometryFactory(file_type,
|
|
|
|
path=file_path,
|
|
|
|
height_field=height_field,
|
|
|
|
year_of_construction_field=year_of_construction_field,
|
2023-03-21 14:22:28 -04:00
|
|
|
function_field=function_field,
|
|
|
|
).city
|
2022-05-03 14:50:41 -04:00
|
|
|
self.assertIsNotNone(self._city, 'city is none')
|
|
|
|
return self._city
|
|
|
|
|
2022-03-08 19:19:52 -05:00
|
|
|
def _check_buildings(self, city):
|
2021-05-27 17:20:06 -04:00
|
|
|
for building in city.buildings:
|
|
|
|
self.assertIsNotNone(building.name, 'building name is none')
|
2022-03-08 19:19:52 -05:00
|
|
|
self.assertIsNotNone(building.type, 'building type is none')
|
2021-05-27 17:20:06 -04:00
|
|
|
self.assertIsNotNone(building.volume, 'building volume is none')
|
2022-03-08 19:19:52 -05:00
|
|
|
self.assertIsNotNone(building.detailed_polyhedron, 'building detailed polyhedron is none')
|
|
|
|
self.assertIsNotNone(building.simplified_polyhedron, 'building simplified polyhedron is none')
|
2021-05-27 17:20:06 -04:00
|
|
|
self.assertIsNotNone(building.surfaces, 'building surfaces is none')
|
2022-03-08 19:19:52 -05:00
|
|
|
self.assertIsNotNone(building.max_height, 'building max_height is none')
|
|
|
|
self.assertEqual(len(building.external_temperature), 0, 'building external temperature is calculated')
|
|
|
|
self.assertEqual(len(building.global_horizontal), 0, 'building global horizontal is calculated')
|
|
|
|
self.assertEqual(len(building.diffuse), 0, 'building diffuse is calculated')
|
|
|
|
self.assertEqual(len(building.beam), 0, 'building beam is calculated')
|
|
|
|
self.assertIsNotNone(building.lower_corner, 'building lower corner is none')
|
|
|
|
self.assertEqual(len(building.sensors), 0, 'building sensors are assigned')
|
2022-03-17 18:49:44 -04:00
|
|
|
self.assertIsNotNone(building.internal_zones, 'no internal zones created')
|
2022-03-08 19:19:52 -05:00
|
|
|
self.assertIsNotNone(building.grounds, 'building grounds is none')
|
|
|
|
self.assertIsNotNone(building.walls, 'building walls is none')
|
|
|
|
self.assertIsNotNone(building.roofs, 'building roofs is none')
|
2022-03-24 16:51:01 -04:00
|
|
|
self.assertIsNotNone(building.internal_zones, 'building internal zones is none')
|
|
|
|
for internal_zone in building.internal_zones:
|
2022-12-06 15:28:59 -05:00
|
|
|
self.assertIsNone(internal_zone.usages, 'usage zones are defined')
|
2023-07-31 17:01:35 -04:00
|
|
|
self.assertIsNone(internal_zone.thermal_zones_from_internal_zones, 'thermal zones are defined')
|
2021-05-27 17:20:06 -04:00
|
|
|
self.assertIsNone(building.basement_heated, 'building basement_heated is not none')
|
|
|
|
self.assertIsNone(building.attic_heated, 'building attic_heated is not none')
|
2022-03-08 19:19:52 -05:00
|
|
|
self.assertIsNone(building.terrains, 'building terrains is not none')
|
2021-05-27 17:20:06 -04:00
|
|
|
self.assertIsNone(building.average_storey_height, 'building average_storey_height is not none')
|
2022-03-08 19:19:52 -05:00
|
|
|
self.assertIsNone(building.storeys_above_ground, 'building storeys_above_ground is not none')
|
2023-06-05 11:53:47 -04:00
|
|
|
self.assertEqual(len(building.heating_demand), 0, 'building heating is not none')
|
|
|
|
self.assertEqual(len(building.cooling_demand), 0, 'building cooling is not none')
|
2022-03-08 19:19:52 -05:00
|
|
|
self.assertIsNotNone(building.eave_height, 'building eave height is none')
|
|
|
|
self.assertIsNotNone(building.roof_type, 'building roof type is none')
|
2021-05-27 17:20:06 -04:00
|
|
|
self.assertIsNotNone(building.floor_area, 'building floor_area is none')
|
2022-03-08 19:19:52 -05:00
|
|
|
self.assertIsNone(building.households, 'building households is not none')
|
|
|
|
self.assertFalse(building.is_conditioned, 'building is_conditioned is conditioned')
|
|
|
|
|
|
|
|
def _check_surfaces(self, building):
|
|
|
|
for surface in building.surfaces:
|
|
|
|
self.assertIsNotNone(surface.name, 'surface name is none')
|
|
|
|
self.assertIsNotNone(surface.id, 'surface id is none')
|
|
|
|
self.assertIsNotNone(surface.lower_corner, 'surface envelope_lower_corner is none')
|
|
|
|
self.assertIsNotNone(surface.upper_corner, 'surface envelope_upper_corner is none')
|
2022-11-08 16:28:07 -05:00
|
|
|
self.assertIsNotNone(surface.perimeter_area, 'surface area_above_ground is none')
|
2022-03-08 19:19:52 -05:00
|
|
|
self.assertIsNotNone(surface.azimuth, 'surface azimuth is none')
|
|
|
|
self.assertIsNotNone(surface.inclination, 'surface inclination is none')
|
2022-11-09 14:22:26 -05:00
|
|
|
self.assertIsNotNone(surface.type, 'surface type is none')
|
2022-03-08 19:19:52 -05:00
|
|
|
self.assertEqual(len(surface.global_irradiance), 0, 'global irradiance is calculated')
|
|
|
|
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')
|
2022-11-09 14:22:26 -05:00
|
|
|
self.assertIsNone(surface.short_wave_reflectance, 'surface short_wave_reflectance is not none')
|
|
|
|
self.assertIsNone(surface.long_wave_emittance, 'surface long_wave_emittance is not none')
|
|
|
|
self.assertIsNotNone(surface.inverse, 'surface inverse is none')
|
|
|
|
self.assertEqual(len(surface.associated_thermal_boundaries), 0, 'associated_thermal_boundaries are assigned')
|
|
|
|
self.assertIsNone(surface.vegetation, 'surface vegetation is not none')
|
2021-05-27 17:20:06 -04:00
|
|
|
|
2022-03-08 19:19:52 -05:00
|
|
|
# citygml_classes
|
|
|
|
def test_import_citygml(self):
|
2021-06-23 09:53:33 -04:00
|
|
|
"""
|
2022-03-08 19:19:52 -05:00
|
|
|
Test city objects in the city
|
2021-06-23 09:53:33 -04:00
|
|
|
:return: None
|
|
|
|
"""
|
2022-11-25 14:39:35 -05:00
|
|
|
file = 'FZK_Haus_LoD_2.gml'
|
2023-02-23 15:40:09 -05:00
|
|
|
city = self._get_city(file, 'citygml')
|
2022-03-08 19:19:52 -05:00
|
|
|
self.assertTrue(len(city.buildings) == 1)
|
|
|
|
self._check_buildings(city)
|
2021-06-23 09:53:33 -04:00
|
|
|
for building in city.buildings:
|
2022-03-08 19:19:52 -05:00
|
|
|
self._check_surfaces(building)
|
2022-05-03 14:50:41 -04:00
|
|
|
city = ConstructionFactory('nrel', city).enrich()
|
|
|
|
|
|
|
|
def test_import_rhino(self):
|
|
|
|
"""
|
|
|
|
Test rhino import
|
|
|
|
"""
|
|
|
|
file = 'dompark.3dm'
|
2022-11-25 14:39:35 -05:00
|
|
|
city = self._get_city(file, 'rhino')
|
2022-05-03 14:50:41 -04:00
|
|
|
self.assertIsNotNone(city, 'city is none')
|
|
|
|
self.assertTrue(len(city.buildings) == 36)
|
2021-06-23 09:53:33 -04:00
|
|
|
|
2021-05-27 17:20:06 -04:00
|
|
|
def test_import_obj(self):
|
2021-08-27 12:51:30 -04:00
|
|
|
"""
|
|
|
|
Test obj import
|
|
|
|
"""
|
2021-05-27 17:20:06 -04:00
|
|
|
file = 'kelowna.obj'
|
2022-11-25 14:39:35 -05:00
|
|
|
city = self._get_city(file, 'obj')
|
2022-03-08 19:19:52 -05:00
|
|
|
self.assertTrue(len(city.buildings) == 1)
|
|
|
|
self._check_buildings(city)
|
2021-05-27 17:20:06 -04:00
|
|
|
for building in city.buildings:
|
2022-03-08 19:19:52 -05:00
|
|
|
self._check_surfaces(building)
|
2021-05-27 17:20:06 -04:00
|
|
|
|
2022-11-25 14:39:35 -05:00
|
|
|
def test_import_geojson(self):
|
|
|
|
"""
|
|
|
|
Test geojson import
|
|
|
|
"""
|
2023-06-05 13:42:15 -04:00
|
|
|
file = Path(self._example_path / 'test.geojson').resolve()
|
2023-03-21 14:22:28 -04:00
|
|
|
city = GeometryFactory('geojson',
|
2023-05-04 11:28:16 -04:00
|
|
|
path=file,
|
2023-06-05 13:42:15 -04:00
|
|
|
height_field='citygml_me',
|
2023-03-21 14:22:28 -04:00
|
|
|
year_of_construction_field='ANNEE_CONS',
|
2023-05-26 18:21:35 -04:00
|
|
|
aliases_field=['ID_UEV', 'CIVIQUE_DE', 'NOM_RUE'],
|
2023-03-21 14:22:28 -04:00
|
|
|
function_field='CODE_UTILI',
|
|
|
|
function_to_hub=MontrealFunctionToHubFunction().dictionary).city
|
2023-05-03 17:02:28 -04:00
|
|
|
hub.exports.exports_factory.ExportsFactory('obj', city, self._output_path).export()
|
2023-06-05 13:42:15 -04:00
|
|
|
for building in city.building_alias('01002777'):
|
|
|
|
self.assertEqual('1', building.name, 'Wrong building name when looking for alias')
|
|
|
|
self.assertEqual(8, len(city.building_alias('rue Sherbrooke Ouest (MTL+MTO+WMT)')))
|
|
|
|
self.assertEqual(17, len(city.buildings), 'wrong number of buildings')
|
2023-02-23 06:56:13 -05:00
|
|
|
|
2023-06-09 11:21:45 -04:00
|
|
|
self.assertIsNotNone(city.city_object('15'), 'Building name 15 is missing in the city')
|
|
|
|
city.remove_city_object(city.city_object('15'))
|
|
|
|
self.assertIsNone(city.city_object('15'), 'Building name 15 wasn\'t removed')
|
|
|
|
for building in city.buildings:
|
|
|
|
_building = city.city_object(building.name)
|
|
|
|
self.assertEqual(_building.name, building.name, 'hash map it\'s unsync')
|
|
|
|
|
2023-02-23 06:56:13 -05:00
|
|
|
def test_map_neighbours(self):
|
|
|
|
"""
|
|
|
|
Test neighbours map creation
|
|
|
|
"""
|
2023-06-05 13:42:15 -04:00
|
|
|
file = 'test.geojson'
|
2023-05-04 13:45:34 -04:00
|
|
|
|
2023-02-23 06:56:13 -05:00
|
|
|
city = self._get_city(file, 'geojson',
|
|
|
|
year_of_construction_field='ANNEE_CONS',
|
|
|
|
function_field='LIBELLE_UT')
|
2023-05-04 13:45:34 -04:00
|
|
|
info_lod0 = GeometryHelper.city_mapping(city, plot=False)
|
2023-03-17 12:56:47 -04:00
|
|
|
city = self._get_city(file, 'geojson',
|
2023-05-04 13:45:34 -04:00
|
|
|
height_field='citygml_me',
|
2023-03-17 12:56:47 -04:00
|
|
|
year_of_construction_field='ANNEE_CONS',
|
|
|
|
function_field='LIBELLE_UT')
|
2023-05-04 13:45:34 -04:00
|
|
|
info_lod1 = GeometryHelper.city_mapping(city, plot=False)
|
2023-03-16 10:51:41 -04:00
|
|
|
hub.exports.exports_factory.ExportsFactory('obj', city, self._output_path).export()
|
2023-03-15 14:21:38 -04:00
|
|
|
self.assertEqual(info_lod0, info_lod1)
|
2023-06-05 13:42:15 -04:00
|
|
|
self.assertEqual(2, len(city.city_object('1').neighbours))
|
|
|
|
self.assertEqual(3, len(city.city_object('2').neighbours))
|
|
|
|
self.assertEqual(2, len(city.city_object('3').neighbours))
|
|
|
|
self.assertEqual(2, len(city.city_object('4').neighbours))
|
|
|
|
self.assertEqual(3, len(city.city_object('5').neighbours))
|
|
|
|
self.assertEqual(3, len(city.city_object('6').neighbours))
|
|
|
|
self.assertEqual(1, len(city.city_object('8').neighbours))
|
|
|
|
self.assertEqual(2, len(city.city_object('9').neighbours))
|
|
|
|
self.assertEqual(2, len(city.city_object('10').neighbours))
|
|
|
|
self.assertEqual(2, len(city.city_object('11').neighbours))
|
|
|
|
self.assertEqual(2, len(city.city_object('12').neighbours))
|
|
|
|
self.assertEqual(1, len(city.city_object('13').neighbours))
|
|
|
|
self.assertEqual(2, len(city.city_object('14').neighbours))
|
|
|
|
self.assertEqual(1, len(city.city_object('15').neighbours))
|
|
|
|
self.assertEqual(1, len(city.city_object('16').neighbours))
|
|
|
|
self.assertEqual(2, len(city.city_object('67').neighbours))
|
|
|
|
self.assertEqual(1, len(city.city_object('68').neighbours))
|
2023-03-08 14:24:48 -05:00
|
|
|
|
2023-06-05 13:42:15 -04:00
|
|
|
self.assertEqual('12', city.city_object('8').neighbours[0].name)
|
|
|
|
self.assertEqual('14', city.city_object('13').neighbours[0].name)
|
|
|
|
self.assertEqual('14', city.city_object('15').neighbours[0].name)
|