forked from s_ranjbar/city_retrofit
213 lines
10 KiB
Python
213 lines
10 KiB
Python
"""
|
|
TestGeometryFactory test and validate the city model structure geometric parameters
|
|
SPDX - License - Identifier: LGPL - 3.0 - or -later
|
|
Copyright © 2022 Concordia CERC group
|
|
Project Coder Pilar Monsalvete Alvarez de Uribarri pilar.monsalvete@concordia.ca
|
|
"""
|
|
from pathlib import Path
|
|
from unittest import TestCase
|
|
|
|
import hub.exports.exports_factory
|
|
from hub.imports.usage_factory import UsageFactory
|
|
|
|
from hub.exports.energy_building_exports_factory import EnergyBuildingsExportsFactory
|
|
from hub.helpers.dictionaries import MontrealFunctionToHubFunction, Dictionaries
|
|
from hub.helpers.geometry_helper import GeometryHelper
|
|
from hub.imports.construction_factory import ConstructionFactory
|
|
from hub.imports.geometry_factory import GeometryFactory
|
|
|
|
|
|
class TestGeometryFactory(TestCase):
|
|
"""
|
|
Non-functional TestGeometryFactory
|
|
Load testing
|
|
"""
|
|
|
|
def setUp(self) -> None:
|
|
"""
|
|
Test setup
|
|
:return: None
|
|
"""
|
|
self._city = None
|
|
self._example_path = (Path(__file__).parent / 'tests_data').resolve()
|
|
self._output_path = (Path(__file__).parent / 'tests_outputs').resolve()
|
|
|
|
def _get_city(self, file, file_type, height_field=None, year_of_construction_field=None, function_field=None):
|
|
file_path = (self._example_path / file).resolve()
|
|
self._city = GeometryFactory(file_type,
|
|
path=file_path,
|
|
height_field=height_field,
|
|
year_of_construction_field=year_of_construction_field,
|
|
function_field=function_field,
|
|
).city
|
|
self.assertIsNotNone(self._city, 'city is none')
|
|
return self._city
|
|
|
|
def _check_buildings(self, city):
|
|
for building in city.buildings:
|
|
self.assertIsNotNone(building.name, 'building name is none')
|
|
self.assertIsNotNone(building.type, 'building type is none')
|
|
self.assertIsNotNone(building.volume, 'building volume is none')
|
|
self.assertIsNotNone(building.detailed_polyhedron, 'building detailed polyhedron is none')
|
|
self.assertIsNotNone(building.simplified_polyhedron, 'building simplified polyhedron is none')
|
|
self.assertIsNotNone(building.surfaces, 'building surfaces is none')
|
|
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')
|
|
self.assertIsNotNone(building.internal_zones, 'no internal zones created')
|
|
self.assertIsNotNone(building.grounds, 'building grounds is none')
|
|
self.assertIsNotNone(building.walls, 'building walls is none')
|
|
self.assertIsNotNone(building.roofs, 'building roofs is none')
|
|
self.assertIsNotNone(building.internal_zones, 'building internal zones is none')
|
|
for internal_zone in building.internal_zones:
|
|
self.assertIsNone(internal_zone.usages, 'usage zones are defined')
|
|
self.assertIsNone(internal_zone.thermal_zones, 'thermal zones are defined')
|
|
self.assertIsNone(building.basement_heated, 'building basement_heated is not none')
|
|
self.assertIsNone(building.attic_heated, 'building attic_heated is not none')
|
|
self.assertIsNone(building.terrains, 'building terrains is not 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.assertEqual(len(building.heating), 0, 'building heating is not none')
|
|
self.assertEqual(len(building.cooling), 0, 'building cooling is not none')
|
|
self.assertIsNotNone(building.eave_height, 'building eave height is none')
|
|
self.assertIsNotNone(building.roof_type, 'building roof type is none')
|
|
self.assertIsNotNone(building.floor_area, 'building floor_area is none')
|
|
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')
|
|
self.assertIsNotNone(surface.perimeter_area, 'surface area_above_ground is none')
|
|
self.assertIsNotNone(surface.azimuth, 'surface azimuth is none')
|
|
self.assertIsNotNone(surface.inclination, 'surface inclination is none')
|
|
self.assertIsNotNone(surface.type, 'surface type is none')
|
|
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')
|
|
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')
|
|
|
|
# citygml_classes
|
|
def test_import_citygml(self):
|
|
"""
|
|
Test city objects in the city
|
|
:return: None
|
|
"""
|
|
file = 'FZK_Haus_LoD_2.gml'
|
|
city = self._get_city(file, 'citygml')
|
|
self.assertTrue(len(city.buildings) == 1)
|
|
self._check_buildings(city)
|
|
for building in city.buildings:
|
|
self._check_surfaces(building)
|
|
city = ConstructionFactory('nrel', city).enrich()
|
|
|
|
def test_import_rhino(self):
|
|
"""
|
|
Test rhino import
|
|
"""
|
|
file = 'dompark.3dm'
|
|
city = self._get_city(file, 'rhino')
|
|
self.assertIsNotNone(city, 'city is none')
|
|
self.assertTrue(len(city.buildings) == 36)
|
|
|
|
def test_import_obj(self):
|
|
"""
|
|
Test obj import
|
|
"""
|
|
file = 'kelowna.obj'
|
|
city = self._get_city(file, 'obj')
|
|
self.assertTrue(len(city.buildings) == 1)
|
|
self._check_buildings(city)
|
|
for building in city.buildings:
|
|
self._check_surfaces(building)
|
|
|
|
def test_import_geojson(self):
|
|
"""
|
|
Test geojson import
|
|
"""
|
|
file = '2000_buildings.geojson'
|
|
city = GeometryFactory('geojson',
|
|
path=(self._example_path / file).resolve(),
|
|
height_field='building_height',
|
|
year_of_construction_field='ANNEE_CONS',
|
|
name_field='ID_UEV',
|
|
function_field='CODE_UTILI',
|
|
function_to_hub=MontrealFunctionToHubFunction().dictionary).city
|
|
# include 25 square meter condition for a building reduces buildings number from 2289 to 2057
|
|
for building in city.buildings:
|
|
print(building.name)
|
|
self.assertEqual(2057, len(city.buildings), 'wrong number of buildings')
|
|
|
|
def test_map_neighbours(self):
|
|
"""
|
|
Test neighbours map creation
|
|
"""
|
|
file = 'neighbours.geojson'
|
|
city = self._get_city(file, 'geojson',
|
|
height_field='citygml_me',
|
|
year_of_construction_field='ANNEE_CONS',
|
|
function_field='LIBELLE_UT')
|
|
info_lod1 = GeometryHelper.city_mapping(city, plot=False)
|
|
city = self._get_city(file, 'geojson',
|
|
year_of_construction_field='ANNEE_CONS',
|
|
function_field='LIBELLE_UT')
|
|
|
|
# info_lod0 = GeometryHelper.city_mapping(city, plot=False)
|
|
hub.exports.exports_factory.ExportsFactory('obj', city, self._output_path).export()
|
|
self.assertEqual(info_lod0, info_lod1)
|
|
for building in city.buildings:
|
|
self.assertEqual(2, len(building.neighbours))
|
|
|
|
self.assertEqual('2_part_0_zone_0', city.city_object('1_part_0_zone_0').neighbours[0].name)
|
|
self.assertEqual('3_part_0_zone_0', city.city_object('1_part_0_zone_0').neighbours[1].name)
|
|
self.assertEqual('1_part_0_zone_0', city.city_object('2_part_0_zone_0').neighbours[0].name)
|
|
self.assertEqual('3_part_0_zone_0', city.city_object('2_part_0_zone_0').neighbours[1].name)
|
|
self.assertEqual('1_part_0_zone_0', city.city_object('3_part_0_zone_0').neighbours[0].name)
|
|
self.assertEqual('2_part_0_zone_0', city.city_object('3_part_0_zone_0').neighbours[1].name)
|
|
|
|
def test_neighbours(self):
|
|
"""
|
|
Test neighbours map creation
|
|
"""
|
|
file_path = (self._example_path / 'concordia_clean.geojson').resolve()
|
|
city = GeometryFactory('geojson',
|
|
path=file_path,
|
|
height_field='citygml_me',
|
|
year_of_construction_field='ANNEE_CONS',
|
|
name_field='OBJECTID_12',
|
|
function_field='CODE_UTILI',
|
|
function_to_hub=Dictionaries().montreal_function_to_hub_function).city
|
|
# print(city.lower_corner, city.upper_corner)
|
|
for building in city.buildings:
|
|
#for ground in building.grounds:
|
|
# print(ground.perimeter_polygon.coordinates)
|
|
# print(ground.perimeter_polygon.coordinates[0][0] - city.lower_corner[0], ground.perimeter_polygon.coordinates[0][1] - city.lower_corner[1])
|
|
# print(ground.perimeter_polygon.coordinates[1][0] - city.lower_corner[0], ground.perimeter_polygon.coordinates[1][1] - city.lower_corner[1])
|
|
break
|
|
ConstructionFactory('nrcan', city).enrich()
|
|
UsageFactory('nrcan', city).enrich()
|
|
info_lod1 = GeometryHelper.city_mapping(city, plot=True)
|
|
for building in city.buildings:
|
|
print(building.name)
|
|
ns = ''
|
|
for n in building.neighbours:
|
|
ns = f'{ns} {n.name}'
|
|
for surface in n.surfaces:
|
|
print('shared', surface.percentage_shared)
|
|
print('\t', ns)
|
|
# EnergyBuildingsExportsFactory('idf', city, self._output_path).export()
|
|
|
|
|