From 3af4bd1267b9396e27bb72faa57e113b417c29cb Mon Sep 17 00:00:00 2001 From: Guille Date: Wed, 10 Jun 2020 11:08:38 -0400 Subject: [PATCH] Add code comment to the classes --- city_model_structure/city.py | 3 +- city_model_structure/city_object.py | 35 ++++- city_model_structure/internal_gains.py | 51 +++++++- city_model_structure/layer.py | 33 ++++- city_model_structure/material.py | 123 ++++++++++++++---- city_model_structure/thermal_boundary.py | 4 +- city_model_structure/thermal_zone.py | 4 +- city_model_structure/window.py | 19 ++- .../us_base_physics_parameters.py | 12 +- pylintrc | 6 +- .../usage_feeders/us_base_usage_parameters.py | 4 +- 11 files changed, 229 insertions(+), 65 deletions(-) diff --git a/city_model_structure/city.py b/city_model_structure/city.py index 40f80e98..fcd9157d 100644 --- a/city_model_structure/city.py +++ b/city_model_structure/city.py @@ -3,7 +3,6 @@ City module SPDX - License - Identifier: LGPL - 3.0 - or -later Copyright © 2020 Project Author Guille Gutierrez guillermo.gutierrezmorote@concordia.ca """ - import sys from typing import List, Union import pyproj @@ -119,7 +118,7 @@ class City: def name(self, value): """ Set the city name - :param value: + :param value:str :return: None """ self._name = value diff --git a/city_model_structure/city_object.py b/city_model_structure/city_object.py index c5dca20b..a139872b 100644 --- a/city_model_structure/city_object.py +++ b/city_model_structure/city_object.py @@ -4,6 +4,7 @@ SPDX - License - Identifier: LGPL - 3.0 - or -later Copyright © 2020 Project Author Guille Gutierrez guillermo.gutierrezmorote@concordia.ca """ from typing import Union, List +from pathlib import Path from matplotlib import pylab from city_model_structure.polyhedron import Polyhedron from city_model_structure.thermal_zone import ThermalZone @@ -12,13 +13,12 @@ from city_model_structure.surface import Surface from shapely import ops from shapely.geometry import MultiPolygon import numpy as np -from pathlib import Path + import matplotlib.patches as patches from helpers.geometry import Geometry from city_model_structure.usage_zone import UsageZone - class CityObject: """ CityObject class @@ -146,7 +146,7 @@ class CityObject: def surface(self, name) -> Union[Surface, None]: """ Get the city object surface with a given name - :param name: Surface name:str + :param name: str :return: None or Surface """ for s in self.surfaces: @@ -185,8 +185,8 @@ class CityObject: def stl_export(self, path): """ - Export the city object to stl file (city_object_name.stl) - :param path: path to export + Export the city object to stl file (city_object_name.stl) to the given path + :param path: str :return: None """ if self._polyhedron is None: @@ -222,17 +222,26 @@ class CityObject: def average_storey_height(self, value): """ Set city object average storey height in meters - :param value: average storey height in meters:float + :param value: float :return: None """ self._average_storey_height = value @property def storeys_above_ground(self): + """ + Get city object storeys number above ground + :return: int + """ return self._storeys_above_ground @storeys_above_ground.setter def storeys_above_ground(self, value): + """ + Set city object storeys number above ground + :param value: int + :return: + """ self._storeys_above_ground = value @staticmethod @@ -259,6 +268,10 @@ class CityObject: @property def foot_print(self) -> Surface: + """ + City object foot print surface + :return: Surface + """ if self._foot_print is None: shapelys = [] union = None @@ -268,7 +281,7 @@ class CityObject: shapelys.append(surface.shapely) union = ops.unary_union(shapelys) shapelys = [union] - if type(union) == MultiPolygon: + if isinstance(union, MultiPolygon): Exception('foot print returns a multipolygon') points_list = [] for point_tuple in union.exterior.coords: @@ -288,10 +301,18 @@ class CityObject: @property def type(self): + """ + City object type + :return: str + """ return self._type @property def max_height(self): + """ + City object maximal height in meters + :return: float + """ if self._polyhedron is None: self._polyhedron = Polyhedron(self.surfaces) return self._polyhedron.max_z diff --git a/city_model_structure/internal_gains.py b/city_model_structure/internal_gains.py index b2cca6fa..4f4b1696 100644 --- a/city_model_structure/internal_gains.py +++ b/city_model_structure/internal_gains.py @@ -6,40 +6,79 @@ Copyright © 2020 Project Author Guille Gutierrez guillermo.gutierrezmorote@conc class InternalGains: + """ + InternalGains class + """ def __init__(self): - self._average_internal_gain_w_m2 = None + self._average_internal_gain = None self._convective_fraction = None self._radiative_fraction = None self._latent_fraction = None @property - def average_internal_gain_w_m2(self): - return self._average_internal_gain_w_m2 + def average_internal_gain(self): + """ + Get internal gains average internal gain in w/m2 + :return: float + """ + return self._average_internal_gain - @average_internal_gain_w_m2.setter - def average_internal_gain_w_m2(self, value): - self._average_internal_gain_w_m2 = value + @average_internal_gain.setter + def average_internal_gain(self, value): + """ + Set internal gains average internal gain in w/m2 + :param value: float + :return: None + """ + self._average_internal_gain = value @property def convective_fraction(self): + """ + Get internal gains convective fraction + :return: float + """ return self._convective_fraction @convective_fraction.setter def convective_fraction(self, value): + """ + Set internal gains convective fraction + :param value: float + :return: None + """ self._convective_fraction = value @property def radiative_fraction(self): + """ + Get internal gains radiative fraction + :return: float + """ return self._radiative_fraction @radiative_fraction.setter def radiative_fraction(self, value): + """ + Set internal gains convective fraction + :param value: float + :return: None + """ self._radiative_fraction = value @property def latent_fraction(self): + """ + Get internal gains latent fraction + :return: float + """ return self._latent_fraction @latent_fraction.setter def latent_fraction(self, value): + """ + Set internal gains latent fraction + :param value: float + :return: None + """ self._latent_fraction = value diff --git a/city_model_structure/layer.py b/city_model_structure/layer.py index daaf4527..550502de 100644 --- a/city_model_structure/layer.py +++ b/city_model_structure/layer.py @@ -7,22 +7,43 @@ from city_model_structure.material import Material class Layer: + """ + Layer class + """ def __init__(self): self._material = None - self._thickness_m = None + self._thickness = None @property def material(self) -> Material: + """ + Get layer material + :return: Material + """ return self._material @material.setter def material(self, value): + """ + Set layer material + :param value: Material + :return: None + """ self._material = value @property - def thickness_m(self): - return self._thickness_m + def thickness(self): + """ + Get layer thickness in meters + :return: float + """ + return self._thickness - @thickness_m.setter - def thickness_m(self, value): - self._thickness_m = value + @thickness.setter + def thickness(self, value): + """ + Get layer thickness in meters + :param value: float + :return: None + """ + self._thickness = value diff --git a/city_model_structure/material.py b/city_model_structure/material.py index 71030a4f..ddb23ba9 100644 --- a/city_model_structure/material.py +++ b/city_model_structure/material.py @@ -6,76 +6,151 @@ Copyright © 2020 Project Author Guille Gutierrez guillermo.gutierrezmorote@conc class Material: + """ + Material class + """ def __init__(self): - self._conductivity_wm_k = None - self._specific_heat_jkg_k = None - self._density_kg_m3 = None + self._conductivity = None + self._specific_heat = None + self._density = None self._solar_absorptance = None self._thermal_absorptance = None self._visible_absorptance = None self._no_mass = False - self._thermal_resistance_m2k_w = None + self._thermal_resistance = None @property - def conductivity_wm_k(self): - return self._conductivity_wm_k + def conductivity(self): + """ + Get material conductivity in W/mK + :return: float + """ + return self._conductivity - @conductivity_wm_k.setter - def conductivity_wm_k(self, value): - self._conductivity_wm_k = value + @conductivity.setter + def conductivity(self, value): + """ + Set material conductivity in W/mK + :param value: float + :return: None + """ + self._conductivity = value @property - def specific_heat_jkg_k(self): - return self._specific_heat_jkg_k + def specific_heat(self): + """ + Get material conductivity in J/kgK + :return: float + """ + return self._specific_heat - @specific_heat_jkg_k.setter - def specific_heat_jkg_k(self, value): - self._specific_heat_jkg_k = value + @specific_heat.setter + def specific_heat(self, value): + """ + Get material conductivity in J/kgK + :param value: float + :return: None + """ + self._specific_heat = value @property - def density_kg_m3(self): - return self._density_kg_m3 + def density(self): + """ + Get material density in kg/m3 + :return: float + """ + return self._density - @density_kg_m3.setter - def density_kg_m3(self, value): - self._density_kg_m3 = value + @density.setter + def density(self, value): + """ + Set material density in kg/m3 + :param value: float + :return: None + """ + self._density = value @property def solar_absorptance(self): + """ + Get material solar absorptance + :return: float + """ return self._solar_absorptance @solar_absorptance.setter def solar_absorptance(self, value): + """ + Set material solar absorptance + :param value: float + :return: None + """ self._solar_absorptance = value @property def thermal_absorptance(self): + """ + Get material thermal absorptance + :return: float + """ return self._thermal_absorptance @thermal_absorptance.setter def thermal_absorptance(self, value): + """ + Set material thermal absorptance + :param value: float + :return: None + """ self._thermal_absorptance = value @property def visible_absorptance(self): + """ + Get material visible absorptance + :return: float + """ return self._visible_absorptance @visible_absorptance.setter def visible_absorptance(self, value): + """ + Set material visible absorptance + :param value: float + :return: None + """ self._visible_absorptance = value @property def no_mass(self): + """ + Get material no mass flag + :return: Boolean + """ return self._no_mass @no_mass.setter def no_mass(self, value): + """ + Set material no mass flag + :param value: Boolean + :return: None + """ self._no_mass = value @property - def thermal_resistance_m2k_w(self): - return self._thermal_resistance_m2k_w + def thermal_resistance(self): + """ + Get material thermal resistance in m2K/W + :return: float + """ + return self._thermal_resistance - @thermal_resistance_m2k_w.setter - def thermal_resistance_m2k_w(self, value): - self._thermal_resistance_m2k_w = value + @thermal_resistance.setter + def thermal_resistance(self, value): + """ + Set material thermal resistance in m2K/W + :param value: float + :return: None + """ + self._thermal_resistance = value diff --git a/city_model_structure/thermal_boundary.py b/city_model_structure/thermal_boundary.py index 1326028d..a1e0bc38 100644 --- a/city_model_structure/thermal_boundary.py +++ b/city_model_structure/thermal_boundary.py @@ -119,9 +119,9 @@ class ThermalBoundary: try: for layer in self.layers: if layer.material.no_mass: - r_value += float(layer.material.thermal_resistance_m2k_w) + r_value += float(layer.material.thermal_resistance) else: - r_value = r_value + float(layer.material.conductivity_wm_k)/float(layer.thickness_m) + r_value = r_value + float(layer.material.conductivity) / float(layer.thickness) self._u_value = 1.0/r_value except TypeError: raise Exception('Constructions layers are not initialized') diff --git a/city_model_structure/thermal_zone.py b/city_model_structure/thermal_zone.py index 0197b43c..5f745345 100644 --- a/city_model_structure/thermal_zone.py +++ b/city_model_structure/thermal_zone.py @@ -3,8 +3,8 @@ ThermalZone module SPDX - License - Identifier: LGPL - 3.0 - or -later Copyright © 2020 Project Author Guille Gutierrez guillermo.gutierrezmorote@concordia.ca """ +from __future__ import annotations from typing import List -from city_model_structure.thermal_boundary import ThermalBoundary from city_model_structure.usage_zone import UsageZone @@ -40,7 +40,7 @@ class ThermalZone: return self._floor_area @property - def bounded(self) -> List[ThermalBoundary]: + def bounded(self) -> List['ThermalBoundary']: return self._bounded @bounded.setter diff --git a/city_model_structure/window.py b/city_model_structure/window.py index 749dba24..f14f0540 100644 --- a/city_model_structure/window.py +++ b/city_model_structure/window.py @@ -6,8 +6,11 @@ Copyright © 2020 Project Author Guille Gutierrez guillermo.gutierrezmorote@conc class Window: + """ + Window class + """ def __init__(self): - self._conductivity_wm_k = None + self._conductivity = None self._solar_transmittance_at_normal_incidence = None self._front_side_solar_reflectance_at_normal_incidence = None self._back_side_solar_reflectance_at_normal_incidence = None @@ -16,12 +19,16 @@ class Window: self._shgc = None @property - def conductivity_wm_k(self): - return self._conductivity_wm_k + def conductivity(self): + """ + Get window conductivity in W/mK + :return: float + """ + return self._conductivity - @conductivity_wm_k.setter - def conductivity_wm_k(self, value): - self._conductivity_wm_k = value + @conductivity.setter + def conductivity(self, value): + self._conductivity = value @property def solar_transmittance_at_normal_incidence(self): diff --git a/physics/physics_feeders/us_base_physics_parameters.py b/physics/physics_feeders/us_base_physics_parameters.py index 8eb34a72..e0bc5ba8 100644 --- a/physics/physics_feeders/us_base_physics_parameters.py +++ b/physics/physics_feeders/us_base_physics_parameters.py @@ -62,19 +62,19 @@ class UsBasePhysicsParameters: for current_layer in c_lib['layers']['layer']: layer = Layer() if 'thickness' in current_layer: - layer.thickness_m = current_layer['thickness']['#text'] + layer.thickness = current_layer['thickness']['#text'] material_lib = self.search_construction_type('material', current_layer['material']) material = Material() if 'conductivity' in material_lib: - material.conductivity_wm_k = material_lib['conductivity']['#text'] - material.specific_heat_jkg_k = material_lib['specific_heat']['#text'] - material.density_kg_m3 = material_lib['density']['#text'] + material.conductivity = material_lib['conductivity']['#text'] + material.specific_heat = material_lib['specific_heat']['#text'] + material.density = material_lib['density']['#text'] material.solar_absorptance = material_lib['solar_absorptance']['#text'] material.thermal_absorptance = material_lib['thermal_absorptance']['#text'] material.visible_absorptance = material_lib['visible_absorptance']['#text'] material.no_mass = 'no_mass' in material_lib if 'thermal_resistance' in material_lib: - material.thermal_resistance_m2k_w = material_lib['thermal_resistance']['#text'] + material.thermal_resistance = material_lib['thermal_resistance']['#text'] layer.material = material thermal_boundary.layers.append(layer) for opening in thermal_boundary.thermal_openings: @@ -84,7 +84,7 @@ class UsBasePhysicsParameters: opening.conductivity_w_mk = w_lib['conductivity']['#text'] opening.frame_ratio = w_lib['frame_ratio']['#text'] opening.g_value = w_lib['solar_transmittance_at_normal_incidence']['#text'] - opening.thickness_m = w_lib['thickness']['#text'] + opening.thickness = w_lib['thickness']['#text'] opening.inside_reflectance = 1.0-float(w_lib['back_side_solar_transmittance_at_normal_incidence']['#text']) opening.outside_reflectance = \ 1.0-float(w_lib['front_side_solar_transmittance_at_normal_incidence']['#text']) diff --git a/pylintrc b/pylintrc index 5dd34c8c..999d300e 100644 --- a/pylintrc +++ b/pylintrc @@ -18,7 +18,7 @@ ignore-patterns= # Python code to execute, usually for sys.path manipulation such as # pygtk.require(). -init-hook='sys.path = list(); sys.path.append(".")' +init-hook='sys.path = list(); sys.path.append("./helpers/"); sys.path.append("../")' # Use multiple processes to speed up Pylint. Specifying 0 will auto-detect the # number of processors available to use. @@ -138,7 +138,9 @@ disable=print-statement, xreadlines-attribute, deprecated-sys-function, exception-escape, - comprehension-escape + comprehension-escape, + import-error, + no-name-in-module # Enable the message, report, category or checker with the given id(s). You can # either give multiple identifier separated by comma (,) or put this option diff --git a/usage/usage_feeders/us_base_usage_parameters.py b/usage/usage_feeders/us_base_usage_parameters.py index 1b1434f1..df65e610 100644 --- a/usage/usage_feeders/us_base_usage_parameters.py +++ b/usage/usage_feeders/us_base_usage_parameters.py @@ -51,7 +51,7 @@ class UsBaseUsageParameters: int_gains = InternalGains() int_gains.latent_fraction = zone_usage_type['occupancy']['internGains']['latentFraction'] int_gains.convective_fraction = zone_usage_type['occupancy']['internGains']['convectiveFraction'] - int_gains.average_internal_gain_w_m2 = zone_usage_type['occupancy']['internGains']['averageInternGainPerSqm'] + int_gains.average_internal_gain = zone_usage_type['occupancy']['internGains']['averageInternGainPerSqm'] int_gains.radiative_fraction = zone_usage_type['occupancy']['internGains']['radiantFraction'] usage_zone.internal_gains = [int_gains] return usage_zone @@ -76,7 +76,7 @@ class UsBaseUsageParameters: if 'convectiveFraction' in usage_zone_variant['occupancy']['internGains']: usage_zone.int_gains[0].convective_fraction = usage_zone_variant['occupancy']['internGains']['convectiveFraction'] if 'averageInternGainPerSqm' in usage_zone_variant['occupancy']['internGains']: - usage_zone.int_gains[0].average_internal_gain_w_m2 = \ + usage_zone.int_gains[0].average_internal_gain = \ usage_zone_variant['occupancy']['internGains']['averageInternGainPerSqm'] if 'radiantFraction' in usage_zone_variant['occupancy']['internGains']: usage_zone.int_gains[0].radiative_fraction = usage_zone_variant['occupancy']['internGains']['radiantFraction']