diff --git a/hub/exports/building_energy/insel/insel_monthly_energy_balance.py b/hub/exports/building_energy/insel/insel_monthly_energy_balance.py index 4774dbf3..494953af 100644 --- a/hub/exports/building_energy/insel/insel_monthly_energy_balance.py +++ b/hub/exports/building_energy/insel/insel_monthly_energy_balance.py @@ -46,7 +46,7 @@ class InselMonthlyEnergyBalance: if building.internal_zones is not None: for internal_zone in building.internal_zones: if internal_zone.thermal_zones is None: - logging.warning(f'Building %s has missing values. Monthly Energy Balance cannot be processed', building.name) + logging.warning('Building %s has missing values. Monthly Energy Balance cannot be processed', building.name) break self._contents.append( self._generate_meb_template(building, output_path, self._radiation_calculation_method, self._weather_format) @@ -69,7 +69,6 @@ class InselMonthlyEnergyBalance: file_name = self._insel_files_paths[i_file] with open(Path(self._path / file_name).resolve(), 'w', encoding='utf8') as insel_file: insel_file.write(content) - return def _sanity_check(self): levels_of_detail = self._city.level_of_detail @@ -142,9 +141,9 @@ class InselMonthlyEnergyBalance: parameters.append(f'{internal_zone.thermal_zones[0].total_floor_area * percentage_usage} ' f'% BP(11) #1 Area of zone {i + 1} (m2)') total_internal_gain = 0 - for ig in usage.internal_gains: - internal_gain = ig.average_internal_gain * (ig.convective_fraction + ig.radiative_fraction) - for schedule in ig.schedules: + for i_gain in usage.internal_gains: + internal_gain = i_gain.average_internal_gain * (i_gain.convective_fraction + i_gain.radiative_fraction) + for schedule in i_gain.schedules: total_values = sum(schedule.values) total_hours = 0 for day_type in schedule.day_types: diff --git a/hub/exports/formats/obj.py b/hub/exports/formats/obj.py index 4dcfeb64..2d0776d6 100644 --- a/hub/exports/formats/obj.py +++ b/hub/exports/formats/obj.py @@ -29,7 +29,7 @@ class Obj: file_name = self._city.name + '.obj' file_path = (Path(self._path).resolve() / file_name).resolve() vertices = {} - with open(file_path, 'w') as obj: + with open(file_path, 'w', encoding='utf-8') as obj: obj.write("# cerc-hub export\n") vertex_index = 0 faces = [] @@ -42,7 +42,7 @@ class Obj: face = 'f ' for coordinate in surface.perimeter_polygon.coordinates: vertex = self._to_vertex(coordinate) - if vertex not in vertices.keys(): + if vertex not in vertices: vertex_index += 1 vertices[vertex] = vertex_index current = vertex_index diff --git a/hub/exports/formats/simplified_radiosity_algorithm.py b/hub/exports/formats/simplified_radiosity_algorithm.py index 92718ff3..9c93d2d8 100644 --- a/hub/exports/formats/simplified_radiosity_algorithm.py +++ b/hub/exports/formats/simplified_radiosity_algorithm.py @@ -73,7 +73,7 @@ class SimplifiedRadiosityAlgorithm: representative_building = self._city.buildings[0] content += f'{day} {month} {hour} {representative_building.global_horizontal[cte.HOUR].epw[i]} ' \ f'{representative_building.beam[cte.HOUR].epw[i]}\n' - with open(file, "w") as file: + with open(file, 'w', encoding='utf-8') as file: file.write(content) def _export_sra_xml(self): @@ -139,5 +139,5 @@ class SimplifiedRadiosityAlgorithm: } } } - with open(self._file_name, "w") as file: + with open(self._file_name, 'w', encoding='utf-8') as file: file.write(xmltodict.unparse(sra, pretty=True, short_empty_elements=True)) diff --git a/hub/exports/formats/triangular.py b/hub/exports/formats/triangular.py index 25715d5b..eada8772 100644 --- a/hub/exports/formats/triangular.py +++ b/hub/exports/formats/triangular.py @@ -28,5 +28,5 @@ class Triangular: for building in self._city.buildings: trimesh = trimesh.union(building.simplified_polyhedron.trimesh) - with open(file_path, self._write_mode) as file: + with open(file_path, self._write_mode, encoding='utf-8') as file: file.write(trimesh.export(file_type=self._triangular_format)) diff --git a/hub/helpers/auth.py b/hub/helpers/auth.py index edf213ea..9797f51b 100644 --- a/hub/helpers/auth.py +++ b/hub/helpers/auth.py @@ -1,5 +1,5 @@ """ -Constant module +Auth module SPDX - License - Identifier: LGPL - 3.0 - or -later Copyright © 2023 Concordia CERC group Project Coder Peter Yefi peteryefi@gmail.com @@ -9,6 +9,9 @@ import bcrypt class Auth(object): + """ + Auth class + """ @staticmethod def hash_password(password: str) -> str: diff --git a/hub/helpers/constants.py b/hub/helpers/constants.py index 37ae857c..c42b47e4 100644 --- a/hub/helpers/constants.py +++ b/hub/helpers/constants.py @@ -204,8 +204,8 @@ MIN_FLOAT = float('-inf') # Tools SRA = 'sra' INSEL_MEB = 'insel meb' -COOLING_PEAK_LOAD = f'cooling peak load' -HEATING_PEAK_LOAD = f'heating peak load' +COOLING_PEAK_LOAD = 'cooling peak load' +HEATING_PEAK_LOAD = 'heating peak load' # Costs units CURRENCY_PER_SQM = 'currency/m2' diff --git a/hub/helpers/data/alkis_function_to_hub_function.py b/hub/helpers/data/alkis_function_to_hub_function.py index 7c01bc22..cf28361a 100644 --- a/hub/helpers/data/alkis_function_to_hub_function.py +++ b/hub/helpers/data/alkis_function_to_hub_function.py @@ -10,6 +10,9 @@ import hub.helpers.constants as cte class AlkisFunctionToHubFunction: + """ + Alkis function to hub function class + """ def __init__(self): self._dictionary = {"1000": cte.RESIDENTIAL, @@ -183,4 +186,8 @@ class AlkisFunctionToHubFunction: @property def dictionary(self) -> dict: + """ + Get the dictionary + :return: {} + """ return self._dictionary diff --git a/hub/helpers/data/hft_function_to_hub_function.py b/hub/helpers/data/hft_function_to_hub_function.py index b9d814c1..cd728ce0 100644 --- a/hub/helpers/data/hft_function_to_hub_function.py +++ b/hub/helpers/data/hft_function_to_hub_function.py @@ -9,7 +9,9 @@ import hub.helpers.constants as cte class HftFunctionToHubFunction: - + """ + Hft function to hub function class + """ def __init__(self): self._dictionary = { 'residential': cte.RESIDENTIAL, @@ -29,4 +31,8 @@ class HftFunctionToHubFunction: @property def dictionary(self) -> dict: + """ + Get the dictionary + :return: {} + """ return self._dictionary diff --git a/hub/helpers/data/hub_function_to_montreal_custom_costs_function.py b/hub/helpers/data/hub_function_to_montreal_custom_costs_function.py index 5e0d58f5..06b2e16b 100644 --- a/hub/helpers/data/hub_function_to_montreal_custom_costs_function.py +++ b/hub/helpers/data/hub_function_to_montreal_custom_costs_function.py @@ -9,6 +9,9 @@ import hub.helpers.constants as cte class HubFunctionToMontrealCustomCostsFunction: + """ + Hub function to montreal custom cost function + """ def __init__(self): self._dictionary = { @@ -75,4 +78,8 @@ class HubFunctionToMontrealCustomCostsFunction: @property def dictionary(self) -> dict: + """ + Get the dictionary + :return: {} + """ return self._dictionary diff --git a/hub/helpers/data/hub_function_to_nrcan_construction_function.py b/hub/helpers/data/hub_function_to_nrcan_construction_function.py index 82370e08..8cec3715 100644 --- a/hub/helpers/data/hub_function_to_nrcan_construction_function.py +++ b/hub/helpers/data/hub_function_to_nrcan_construction_function.py @@ -9,7 +9,9 @@ import hub.helpers.constants as cte class HubFunctionToNrcanConstructionFunction: - + """ + Hub function to nrcan construction function class + """ def __init__(self): self._dictionary = { cte.RESIDENTIAL: 'MidriseApartment', @@ -75,4 +77,8 @@ class HubFunctionToNrcanConstructionFunction: @property def dictionary(self) -> dict: + """ + Get the dictionary + :return: {} + """ return self._dictionary diff --git a/hub/helpers/data/hub_function_to_nrel_construction_function.py b/hub/helpers/data/hub_function_to_nrel_construction_function.py index 0d9aedd8..ca4144a3 100644 --- a/hub/helpers/data/hub_function_to_nrel_construction_function.py +++ b/hub/helpers/data/hub_function_to_nrel_construction_function.py @@ -9,6 +9,9 @@ import hub.helpers.constants as cte class HubFunctionToNrelConstructionFunction: + """ + Hub function to nrel construction function + """ def __init__(self): self._dictionary = { @@ -75,4 +78,8 @@ class HubFunctionToNrelConstructionFunction: @property def dictionary(self) -> dict: + """ + Get the dictionary + :return: {} + """ return self._dictionary diff --git a/hub/helpers/data/hub_usage_to_comnet_usage.py b/hub/helpers/data/hub_usage_to_comnet_usage.py index 3fb16c5a..f58193ac 100644 --- a/hub/helpers/data/hub_usage_to_comnet_usage.py +++ b/hub/helpers/data/hub_usage_to_comnet_usage.py @@ -9,6 +9,9 @@ import hub.helpers.constants as cte class HubUsageToComnetUsage: + """ + Hub usage to comnet usage class + """ def __init__(self): self._dictionary = { @@ -75,4 +78,8 @@ class HubUsageToComnetUsage: @property def dictionary(self) -> dict: + """ + Get the dictionary + :return: {} + """ return self._dictionary diff --git a/hub/helpers/data/hub_usage_to_hft_usage.py b/hub/helpers/data/hub_usage_to_hft_usage.py index 988e0649..dbc4847e 100644 --- a/hub/helpers/data/hub_usage_to_hft_usage.py +++ b/hub/helpers/data/hub_usage_to_hft_usage.py @@ -9,6 +9,9 @@ import hub.helpers.constants as cte class HubUsageToHftUsage: + """ + Hub usage to hft usage class + """ def __init__(self): self._dictionary = { @@ -75,4 +78,8 @@ class HubUsageToHftUsage: @property def dictionary(self) -> dict: + """ + Get the dictionary + :return: {} + """ return self._dictionary diff --git a/hub/helpers/data/hub_usage_to_nrcan_usage.py b/hub/helpers/data/hub_usage_to_nrcan_usage.py index 94eaa68f..ed280903 100644 --- a/hub/helpers/data/hub_usage_to_nrcan_usage.py +++ b/hub/helpers/data/hub_usage_to_nrcan_usage.py @@ -9,6 +9,9 @@ import hub.helpers.constants as cte class HubUsageToNrcanUsage: + """ + Hub usage to nrcan usage class + """ def __init__(self): self._dictionary = { @@ -75,4 +78,8 @@ class HubUsageToNrcanUsage: @property def dictionary(self) -> dict: + """ + Get the dictionary + :return: {} + """ return self._dictionary diff --git a/hub/helpers/data/montreal_demand_type_to_hub_energy_demand_type.py b/hub/helpers/data/montreal_demand_type_to_hub_energy_demand_type.py index 26d0d454..de137777 100644 --- a/hub/helpers/data/montreal_demand_type_to_hub_energy_demand_type.py +++ b/hub/helpers/data/montreal_demand_type_to_hub_energy_demand_type.py @@ -9,7 +9,9 @@ import hub.helpers.constants as cte class MontrealDemandTypeToHubEnergyDemandType: - + """ + Montreal demand type to hub energy demand type + """ def __init__(self): self._dictionary = {'heating': cte.HEATING, 'cooling': cte.COOLING, @@ -19,4 +21,8 @@ class MontrealDemandTypeToHubEnergyDemandType: @property def dictionary(self) -> dict: + """ + Get the dictionary + :return: {} + """ return self._dictionary diff --git a/hub/helpers/data/pluto_function_to_hub_function.py b/hub/helpers/data/pluto_function_to_hub_function.py index 0e89b656..7d201bf7 100644 --- a/hub/helpers/data/pluto_function_to_hub_function.py +++ b/hub/helpers/data/pluto_function_to_hub_function.py @@ -9,7 +9,9 @@ import hub.helpers.constants as cte class PlutoFunctionToHubFunction: - + """ + Pluto function to hub function class + """ def __init__(self): self._dictionary = { 'A0': cte.SINGLE_FAMILY_HOUSE, @@ -214,4 +216,8 @@ class PlutoFunctionToHubFunction: @property def dictionary(self) -> dict: + """ + Get the dictionary + :return: {} + """ return self._dictionary diff --git a/hub/helpers/geometry_helper.py b/hub/helpers/geometry_helper.py index d76e1af9..a558f2d8 100644 --- a/hub/helpers/geometry_helper.py +++ b/hub/helpers/geometry_helper.py @@ -7,12 +7,12 @@ Code contributors: Pilar Monsalvete Alvarez de Uribarri pilar.monsalvete@concord """ import math from pathlib import Path +from typing import Dict -import numpy as np from PIL import Image from trimesh import Trimesh from trimesh import intersections -from typing import Dict +import numpy as np from hub.city_model_structure.attributes.polygon import Polygon from hub.city_model_structure.attributes.polyhedron import Polyhedron @@ -20,6 +20,9 @@ from hub.helpers.location import Location class MapPoint: + """ + Map point class + """ def __init__(self, x, y): self._x = int(x) self._y = int(y) @@ -47,10 +50,9 @@ class MapPoint: def __getitem__(self, index): if index == 0: return self._x - elif index == 1: + if index == 1: return self._y - else: - raise IndexError('Index error') + raise IndexError('Index error') class GeometryHelper: @@ -146,11 +148,11 @@ class GeometryHelper: building_key = f'{building.name}_{building_start_coordinate}_{neighbour_start_coordinate}' # Add my neighbour info to my shared lines - if building.name in lines_information.keys() and neighbour_key in lines_information[building.name]: + if building.name in lines_information and neighbour_key in lines_information[building.name]: shared_points = int(lines_information[building.name][neighbour_key]['shared_points']) lines_information[building.name][neighbour_key]['shared_points'] = shared_points + 1 else: - if building.name not in lines_information.keys(): + if building.name not in lines_information: lines_information[building.name] = {} lines_information[building.name][neighbour_key] = { 'neighbour_name': neighbour.name, @@ -166,11 +168,11 @@ class GeometryHelper: } # Add my info to my neighbour shared lines - if neighbour.name in lines_information.keys() and building_key in lines_information[neighbour.name]: + if neighbour.name in lines_information and building_key in lines_information[neighbour.name]: shared_points = int(lines_information[neighbour.name][building_key]['shared_points']) lines_information[neighbour.name][building_key]['shared_points'] = shared_points + 1 else: - if neighbour.name not in lines_information.keys(): + if neighbour.name not in lines_information: lines_information[neighbour.name] = {} lines_information[neighbour.name][building_key] = { 'neighbour_name': building.name, @@ -262,8 +264,8 @@ class GeometryHelper: # once triangulate_polygon in Polygon class is solved normal_plane_opp = [None] * len(normal_plane) - for i in range(0, len(normal_plane)): - normal_plane_opp[i] = - normal_plane[i] + for index, normal in enumerate(normal_plane): + normal_plane_opp[index] = - normal section_1 = intersections.slice_mesh_plane(trimesh, normal_plane, point_plane) if section_1 is None: @@ -293,8 +295,8 @@ class GeometryHelper: distance = math.inf country = 'Unknown' city = 'Unknown' - with open(_data_path, 'r', encoding='utf-8') as f: - for line_number, line in enumerate(f): + with open(_data_path, 'r', encoding='utf-8') as file: + for _, line in enumerate(file): fields = line.split('\t') file_city_name = fields[2] file_latitude = float(fields[4]) @@ -316,7 +318,7 @@ class GeometryHelper: :return: float """ power = 0 - for dimension in range(0, len(vertex1)): - power += math.pow(vertex2[dimension] - vertex1[dimension], 2) + for dimension, current_vertex in enumerate(vertex1): + power += math.pow(vertex2[dimension] - current_vertex, 2) distance = math.sqrt(power) return distance diff --git a/hub/helpers/monthly_values.py b/hub/helpers/monthly_values.py index 2dfa80d2..cfab31bf 100644 --- a/hub/helpers/monthly_values.py +++ b/hub/helpers/monthly_values.py @@ -1,19 +1,25 @@ """ -Monthly values +Monthly values module SPDX - License - Identifier: LGPL - 3.0 - or -later Copyright © 2020 Project Author Pilar Monsalvete pilar_monsalvete@yahoo.es """ - +import calendar as cal import pandas as pd import numpy as np -import calendar as cal class MonthlyValues: + """ + Monthly values class + """ def __init__(self): self._month_hour = None def get_mean_values(self, values): + """ + Calculates the mean values for each month + :return: DataFrame(float) + """ out = None if values is not None: if 'month' not in values.columns: @@ -23,6 +29,10 @@ class MonthlyValues: return out def get_total_month(self, values): + """ + Calculates the total value for each month + :return: DataFrame(int) + """ out = None if values is not None: if 'month' not in values.columns: diff --git a/hub/helpers/peak_loads.py b/hub/helpers/peak_loads.py index 9bfb00d6..e46a8b51 100644 --- a/hub/helpers/peak_loads.py +++ b/hub/helpers/peak_loads.py @@ -48,6 +48,10 @@ class PeakLoads: @staticmethod def peak_loads_from_hourly(hourly_values): + """ + Get peak loads from hourly + :return: [int] + """ month = 1 peaks = [0 for _ in range(12)] for i, value in enumerate(hourly_values): @@ -59,6 +63,10 @@ class PeakLoads: @property def heating_peak_loads_from_methodology(self): + """ + Get heating peak loads by calculate + :return: [int] + """ if not self._can_be_calculated(): return None monthly_heating_loads = [] @@ -79,13 +87,16 @@ class PeakLoads: heating_load_ventilation_sensible = loads.get_heating_ventilation_load_sensible(heating_ambient_temperature) heating_load_ventilation_latent = 0 heating_load = heating_load_transmitted + heating_load_ventilation_sensible + heating_load_ventilation_latent - if heating_load < 0: - heating_load = 0 + heating_load = max(heating_load, 0) monthly_heating_loads.append(heating_load) return monthly_heating_loads @property def cooling_peak_loads_from_methodology(self): + """ + Get cooling peak loads by calculate + :return: [int] + """ if not self._can_be_calculated(): return None monthly_cooling_loads = [] @@ -113,7 +124,6 @@ class PeakLoads: cooling_load_latent = 0 cooling_load = cooling_load_sensible + cooling_load_latent - if cooling_load > 0: - cooling_load = 0 + cooling_load = min(cooling_load, 0) monthly_cooling_loads.append(abs(cooling_load)) return monthly_cooling_loads diff --git a/hub/helpers/utils.py b/hub/helpers/utils.py index 89fa97d8..49fc982b 100644 --- a/hub/helpers/utils.py +++ b/hub/helpers/utils.py @@ -15,8 +15,11 @@ def validate_import_export_type(cls_name: type, handler: str): :param handler: import export handler :return: None """ - functions = [function[1:] for function in dir(cls_name) if (type(getattr(cls_name, function)) is property or callable(getattr(cls_name, function))) and function in cls_name.__dict__ and function[0] == '_' and function != '__init__'] + functions = [ + function[1:] for function in dir(cls_name) + if type(getattr(cls_name, function)) in (property, callable(getattr(cls_name, function))) and function in cls_name.__dict__ and function[0] == '_' and function != '__init__' + ] if handler.lower() not in functions: - error_message = f'Wrong import type [{handler}]. Valid functions include {functions}' - logging.error(error_message) - raise Exception(error_message) + error_message = f'Wrong import type [{handler}]. Valid functions include {functions}' + logging.error(error_message) + raise ValueError(error_message) diff --git a/requirements.txt b/requirements.txt index 1538a51d..72293904 100644 --- a/requirements.txt +++ b/requirements.txt @@ -24,5 +24,4 @@ geopandas triangle psycopg2-binary Pillow -pathlib -pickle5 \ No newline at end of file +pathlib \ No newline at end of file