diff --git a/.idea/libs.iml b/.idea/libs.iml index 7c3d775b..c268a131 100644 --- a/.idea/libs.iml +++ b/.idea/libs.iml @@ -9,4 +9,7 @@ + + \ No newline at end of file diff --git a/city_model_structure/attributes/surface.py b/city_model_structure/attributes/surface.py index b1be28d8..0ff20d18 100644 --- a/city_model_structure/attributes/surface.py +++ b/city_model_structure/attributes/surface.py @@ -16,7 +16,7 @@ class Surface: """ Surface class """ - def __init__(self, coordinates, holes_coordinates=None, surface_type=None, name=None, swr='0.2'): + def __init__(self, coordinates, holes_coordinates=None, surface_type=None, name=None, swr=None): self._coordinates = coordinates self._holes_coordinates = holes_coordinates self._type = surface_type diff --git a/city_model_structure/attributes/thermal_zone.py b/city_model_structure/attributes/thermal_zone.py index a1345312..00c17dc9 100644 --- a/city_model_structure/attributes/thermal_zone.py +++ b/city_model_structure/attributes/thermal_zone.py @@ -32,7 +32,7 @@ class ThermalZone: self._volume = None @property - def heated(self): + def is_heated(self): """ Get thermal zone heated flag :return: Boolean @@ -40,7 +40,7 @@ class ThermalZone: return self._is_heated @property - def cooled(self): + def is_cooled(self): """ Get thermal zone cooled flag :return: Boolean @@ -79,7 +79,7 @@ class ThermalZone: @property def surfaces(self) -> List[Surface]: - # todo: This property should be erased + # todo: This property should be erased (@Guille: why??) """ Get thermal zone surfaces :return: [Surface] diff --git a/city_model_structure/building.py b/city_model_structure/building.py index 54cb5ae6..48f2380f 100644 --- a/city_model_structure/building.py +++ b/city_model_structure/building.py @@ -145,7 +145,7 @@ class Building(CityObject): :return: float """ # ToDo: this need to be calculated based on the basement and attic heated values - return self.volume + raise NotImplementedError @property def year_of_construction(self): @@ -329,7 +329,7 @@ class Building(CityObject): # height = self.average_storey_height number_of_storeys = 4 height = 1.5 - mesh = self.polyhedron.polyhedron_trimesh + mesh = self.simplified_polyhedron.polyhedron_trimesh normal_plane = [0, 0, -1] rest_mesh = mesh for n in range(0, number_of_storeys - 1): diff --git a/city_model_structure/city.py b/city_model_structure/city.py index cb87779d..4a4216ee 100644 --- a/city_model_structure/city.py +++ b/city_model_structure/city.py @@ -31,6 +31,7 @@ class City: self._geometry = GeometryHelper() # todo: right now extracted at city level, in the future should be extracted also at building level if exist self._location = None + self._country_code = None @property def _get_location(self): @@ -53,7 +54,16 @@ class City: City country code :return: str """ - return self._get_location[0] + return self._country_code + + @country_code.setter + def country_code(self, value): + """ + City country code + :param value:str + :return: None + """ + self._country_code = value @property def name(self): @@ -61,7 +71,15 @@ class City: City name :return: str """ - return self._get_location[1] + return self._name + + @name.setter + def name(self, value): + """ + City name + :return: str + """ + self._name = value @property def city_objects(self) -> Union[List[CityObject], None]: diff --git a/city_model_structure/city_object.py b/city_model_structure/city_object.py index d9f6f488..cab047bf 100644 --- a/city_model_structure/city_object.py +++ b/city_model_structure/city_object.py @@ -3,7 +3,6 @@ CityObject module SPDX - License - Identifier: LGPL - 3.0 - or -later Copyright © 2020 Project Author Guille Gutierrez guillermo.gutierrezmorote@concordia.ca """ -from pathlib import Path from typing import List, Union from city_model_structure.attributes.surface import Surface from helpers.geometry_helper import GeometryHelper diff --git a/requirements.txt b/requirements.txt index 3da4534a..24f9d4f4 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,58 +1,10 @@ xmltodict~=0.12.0 -numpy~=1.19.0 -trimesh~=3.7.0 -pyproj~=2.6.1.post1 -pyny3d~=0.2 -matplotlib~=3.2.1 -Shapely~=1.7.0 -pandas~=1.0.4 -pip>=20.1.1 -pyzmq~=19.0.1 -pexpect~=4.8.0 -tornado~=6.0.4 -parso~=0.7.0 -jedi~=0.17.0 -pytz~=2020.1 -setuptools~=47.3.0 -scipy~=1.5.0 -six~=1.15.0 -webencodings~=0.5.1 -packaging~=20.4 -bleach~=3.1.5 -MarkupSafe~=1.1.1 -ipywidgets~=7.5.1 -traitlets~=4.3.3 -ipython~=7.15.0 -python-dateutil~=2.8.1 -Pygments~=2.6.1 -ipykernel~=5.3.0 -testpath~=0.4.4 -decorator~=4.4.2 -backcall~=0.2.0 -pickleshare~=0.7.5 -wcwidth~=0.2.4 -ptyprocess~=0.6.0 -notebook~=6.0.3 -nbformat~=5.0.7 -jsonschema~=3.2.0 -Jinja2~=2.11.2 -Send2Trash~=1.5.0 -terminado~=0.8.3 -nbconvert~=5.6.1 -defusedxml~=0.6.0 -pandocfilters~=1.4.2 -mistune~=0.8.4 -entrypoints~=0.3 -pyparsing~=2.4.7 -attrs~=19.3.0 -pyrsistent~=0.16.0 -cycler~=0.10.0 -kiwisolver~=1.2.0 -zipp~=3.1.0 -requests~=2.24.0 +numpy~=1.20.1 +trimesh~=3.9.8 +pyproj~=3.0.1 +pandas~=1.2.3 +requests~=2.25.1 esoreader~=1.2.3 geomeppy~=0.11.8 -pyglet~=1.5.8 -networkx~=2.5 -xlrd~=1.2.0 -open3d~=0.11.2 \ No newline at end of file +open3d~=0.12.0 +pathlib~=1.0.1 \ No newline at end of file diff --git a/tests/test_geometry_factory.py b/tests/test_geometry_factory.py index 97e2901e..cce65763 100644 --- a/tests/test_geometry_factory.py +++ b/tests/test_geometry_factory.py @@ -22,13 +22,10 @@ class TestGeometryFactory(TestCase): """ self._city_gml = None self._example_path = (Path(__file__).parent.parent / 'tests_data').resolve() - 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() - def _get_citygml(self): + def _get_citygml(self, file): if self._city_gml is None: - file_path = (self._example_path / 'lod2_buildings.gml').resolve() + file_path = (self._example_path / file).resolve() self._city_gml = GeometryFactory('citygml', file_path)._city_debug self.assertIsNotNone(self._city_gml, 'city is none') return self._city_gml @@ -48,7 +45,9 @@ class TestGeometryFactory(TestCase): Test the City from citygml serialization de-serialization :return: None """ - city = self._get_citygml() + file = 'lod2_buildings.gml' + pickle_file = (self._example_path / 'lod2_buildings.pickle').resolve() + city = self._get_citygml(file) 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') @@ -57,8 +56,8 @@ class TestGeometryFactory(TestCase): 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) + city.save(pickle_file) + city = City.load(pickle_file) # repeat the city tests self.assertIsNotNone(city.city_objects, 'city_objects is none') for building in city.buildings: @@ -68,31 +67,15 @@ class TestGeometryFactory(TestCase): 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()) - - 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 - print('total number of buildings with volume inf', counter) + os.remove(pickle_file) def test_citygml_buildings(self): """ Test city objects in the city :return: None """ - city = self._get_citygml() + file = 'lod2_buildings.gml' + city = self._get_citygml(file) for building in city.buildings: self.assertIsNotNone(building.name, 'building name is none') self.assertIsNotNone(building.lod, 'building lod is none') @@ -102,26 +85,24 @@ class TestGeometryFactory(TestCase): 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.assertIsNone(building.basement_heated, 'building basement_heated is not none') + self.assertIsNone(building.attic_heated, 'building attic_heated is not 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()) + self.assertIsNotNone(building.floor_area, 'building floor_area is none') def test_citygml_surfaces(self): """ Test surfaces in city objects :return: None """ - city = self._get_citygml() + file = 'lod2_buildings.gml' + city = self._get_citygml(file) for building in city.buildings: for surface in building.surfaces: self.assertIsNotNone(surface.name, 'surface name is none') @@ -131,36 +112,45 @@ class TestGeometryFactory(TestCase): 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.assertIsNone(surface.holes_points, 'surface holes_points is not none') + self.assertIsNotNone(surface.perimeter_points, 'surface perimeter_points is none') self.assertIsNotNone(surface.points_list, 'surface points_list is none') + self.assertIsNone(surface.holes_points_list, 'surface holes_points_list is not none') + self.assertIsNotNone(surface.perimeter_points_list, 'surface perimeter_points_list is none') self.assertIsNotNone(surface.global_irradiance, 'monthly irradiance is none') - self.assertIsNotNone(surface.swr, 'surface swr is none') + self.assertIsNone(surface.swr, 'surface swr is not 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.area_above_ground, 'surface area_above_ground is none') + self.assertIsNotNone(surface.perimeter_polygon, 'surface perimeter_polygon is none') + self.assertIsNone(surface.hole_polygons, 'surface hole_polygons is not none') + self.assertIsNotNone(surface.solid_polygon, 'surface solid_polygon is none') def test_citygml_thermal_zone(self): """ Test thermal zones in city objects :return: None """ - city = self._get_citygml() + file = 'lod2_buildings.gml' + city = self._get_citygml(file) 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.is_heated, 'thermal_zone heated is not none') + self.assertIsNone(thermal_zone.is_cooled, 'thermal_zone cooled is not 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.assertEqual(thermal_zone.indirectly_heated_area_ratio, 0.0, - 'thermal_zone indirectly_heated_area_ratio 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.assertEqual(thermal_zone.infiltration_rate_system_on, 0.0, - 'thermal_zone infiltration_rate_system_on 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') @@ -169,10 +159,12 @@ class TestGeometryFactory(TestCase): Test thermal boundaries in thermal zones :return: None """ - city = self._get_citygml() + file = 'lod2_buildings.gml' + city = self._get_citygml(file) for building in city.buildings: for thermal_zone in building.thermal_zones: for thermal_boundary in thermal_zone.bounded: + self.assertIsNotNone(thermal_boundary.surface, 'thermal_boundary surface is none') 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') @@ -180,31 +172,22 @@ class TestGeometryFactory(TestCase): 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') + # todo: assert exception 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() + file = 'lod2_buildings.gml' + city = self._get_citygml(file) 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.frame_ratio, 'thermal_opening frame_ratio was initialized') 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, @@ -215,27 +198,39 @@ class TestGeometryFactory(TestCase): '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') + self.assertIsNone(thermal_opening.overall_u_value, 'thermal_opening overall_u_value was initialized') + self.assertIsNone(thermal_opening.hi, 'thermal_opening hi was initialized') + self.assertIsNone(thermal_opening.he, 'thermal_opening he was initialized') + + def test_surfaces_triangulation(self): + """ + Test city surfaces triangulation and polygon creation + :return: + """ + file = (self._example_path / 'gml_17_12_2020.pickle').resolve() + city = City.load(file) - 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) + print(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_stuttgart_gml(self): + file = '20190815_mitte_out_MC_FloursurfaceADD.gml' + city = self._get_citygml(file) + pickle_file = (self._example_path / '20190815_mitte_out_MC_FloursurfaceADD.pickle').resolve() + city.save(pickle_file) + for building in city.buildings: + self.assertIsNotNone(building.volume, 'building volume is none') + def test_divide_mesh_by_plane(self): - file_path = (self._example_path / 'FZK-Haus-LoD-all-KIT-IAI-KHH-B36-V1.gml').resolve() + file = 'FZK-Haus-LoD-all-KIT-IAI-KHH-B36-V1.gml' # 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 + city = self._get_citygml(file) for building in city.buildings: print(building.name) print(building.volume) diff --git a/tests_data/kelowna_test_case.pickle b/tests_data/kelowna_test_case.pickle deleted file mode 100644 index af0a71b1..00000000 Binary files a/tests_data/kelowna_test_case.pickle and /dev/null differ