From ce03602a2a9ba39c6810ced012ec67e575d2bfb4 Mon Sep 17 00:00:00 2001 From: Guille Date: Tue, 9 Jun 2020 15:14:47 -0400 Subject: [PATCH] Add code comment to the classes --- city_model_structure/city_object.py | 100 ++++++++++++++++++++++++++-- pylintrc | 2 +- 2 files changed, 94 insertions(+), 8 deletions(-) diff --git a/city_model_structure/city_object.py b/city_model_structure/city_object.py index be2a3811..c5dca20b 100644 --- a/city_model_structure/city_object.py +++ b/city_model_structure/city_object.py @@ -3,6 +3,7 @@ CityObject module SPDX - License - Identifier: LGPL - 3.0 - or -later Copyright © 2020 Project Author Guille Gutierrez guillermo.gutierrezmorote@concordia.ca """ +from typing import Union, List from matplotlib import pylab from city_model_structure.polyhedron import Polyhedron from city_model_structure.thermal_zone import ThermalZone @@ -15,10 +16,13 @@ from pathlib import Path import matplotlib.patches as patches from helpers.geometry import Geometry from city_model_structure.usage_zone import UsageZone -from typing import Union, List + class CityObject: + """ + CityObject class + """ def __init__(self, name, lod, surfaces, terrains, year_of_construction, function, lower_corner, attic_heated=0, basement_heated=0): self._name = name @@ -48,17 +52,26 @@ class CityObject: for t in self._thermal_zones: t.bounded = [ThermalBoundary(s, [t]) for s in t.surfaces] surface_id = 0 - for s in self._surfaces: - s.lower_corner = self._lower_corner - s.parent(self, surface_id) + for surface in self._surfaces: + surface.lower_corner = self._lower_corner + surface.parent(self, surface_id) surface_id += 1 @property def usage_zones(self) -> List[UsageZone]: + """ + Get city object usage zones + :return: [UsageZone] + """ return self._usage_zones @usage_zones.setter def usage_zones(self, values): + """ + Set city objects usage zones + :param values: [UsageZones] + :return: None + """ # ToDo: this is only valid for one usage zone need to be revised for multiple usage zones. self._usage_zones = values for thermal_zone in self.thermal_zones: @@ -66,37 +79,76 @@ class CityObject: @property def terrains(self) -> List[Surface]: + """ + Get city object terrain surfaces + :return: [Surface] + """ return self._terrains @property def attic_heated(self): + """ + Get if the city object attic is heated + :return: Boolean + """ return self._attic_heated @attic_heated.setter def attic_heated(self, value): + """ + Set if the city object attic is heated + :param value: Boolean + :return: None + """ self._attic_heated = value @property def basement_heated(self): + """ + Get if the city object basement is heated + :return: Boolean + """ return self._basement_heated @basement_heated.setter def basement_heated(self, value): + """ + Set if the city object basement is heated + :param value: Boolean + :return: None + """ self._attic_heated = value @property def name(self): + """ + City object name + :return: str + """ return self._name @property def lod(self): + """ + City object level of detail 1, 2, 3 or 4 + :return: int + """ return self._lod @property def surfaces(self) -> List[Surface]: + """ + City object surfaces + :return: [Surface] + """ return self._surfaces def surface(self, name) -> Union[Surface, None]: + """ + Get the city object surface with a given name + :param name: Surface name:str + :return: None or Surface + """ for s in self.surfaces: if s.name == name: return s @@ -104,22 +156,39 @@ class CityObject: @property def thermal_zones(self) -> List[ThermalZone]: + """ + City object thermal zones + :return: [ThermalZone] + """ return self._thermal_zones @property def volume(self): + """ + City object volume in cubic meters + :return: float + """ if self._polyhedron is None: self._polyhedron = Polyhedron(self.surfaces) return self._polyhedron.volume @property def heated_volume(self): + """ + City object heated volume in cubic meters + :return: float + """ if self._polyhedron is None: self._polyhedron = Polyhedron(self.surfaces) # ToDo: this need to be the calculated based on the basement and attic heated values return self._polyhedron.volume def stl_export(self, path): + """ + Export the city object to stl file (city_object_name.stl) + :param path: path to export + :return: None + """ if self._polyhedron is None: self._polyhedron = Polyhedron(self.surfaces) full_path = (Path(path) / (self._name + '.stl')).resolve() @@ -127,18 +196,35 @@ class CityObject: @property def year_of_construction(self): + """ + City object year of construction + :return: int + """ return self._year_of_construction @property def function(self): + """ + City object function + :return: str + """ return self._function @property def average_storey_height(self): + """ + Get city object average storey height in meters + :return: float + """ return self._average_storey_height @average_storey_height.setter def average_storey_height(self, value): + """ + Set city object average storey height in meters + :param value: average storey height in meters:float + :return: None + """ self._average_storey_height = value @property @@ -158,9 +244,9 @@ class CityObject: for point_tuple in polygon.exterior.coords: almost_equal = False for point in points: - p1 = CityObject._tuple_to_point(point) - p2 = CityObject._tuple_to_point(point_tuple) - if self._geometry.almost_equal(p1, p2): + point_1 = CityObject._tuple_to_point(point) + point_2 = CityObject._tuple_to_point(point_tuple) + if self._geometry.almost_equal(point_1, point_2): almost_equal = True break if not almost_equal: diff --git a/pylintrc b/pylintrc index 7a754652..5dd34c8c 100644 --- a/pylintrc +++ b/pylintrc @@ -221,7 +221,7 @@ ignored-classes=optparse.Values,thread._local,_thread._local # (useful for modules/projects where namespaces are manipulated during runtime # and thus existing member attributes cannot be deduced by static analysis). It # supports qualified module names, as well as Unix pattern matching. -ignored-modules=pyproj, reverse_geocoder +ignored-modules=pyproj, reverse_geocoder, matplotlib, shapely, numpy # Show a hint with possible names when a member name was not found. The aspect # of finding the hint is based on edit distance.