From 63b91c4d679ed20bc5e17c13aec1d366e40bc9b5 Mon Sep 17 00:00:00 2001 From: Koa Wells Date: Thu, 16 Mar 2023 12:17:39 -0400 Subject: [PATCH] Add logger messages to all sys.out --- hub/catalog_factories/usage/usage_helper.py | 3 +++ hub/city_model_structure/attributes/polygon.py | 3 ++- hub/city_model_structure/attributes/polyhedron.py | 2 ++ hub/city_model_structure/building.py | 2 +- hub/city_model_structure/city.py | 4 ++++ hub/imports/construction/helpers/storeys_generation.py | 4 ++++ hub/imports/construction/nrcan_physics_parameters.py | 6 ++++++ hub/imports/construction/nrel_physics_parameters.py | 6 +++--- hub/imports/usage/comnet_usage_parameters.py | 3 +++ hub/imports/usage/nrcan_usage_parameters.py | 5 +++++ hub/imports/weather/dat_weather_parameters.py | 2 ++ hub/imports/weather/epw_weather_parameters.py | 8 ++++++++ hub/imports/weather/xls_weather_parameters.py | 2 ++ 13 files changed, 45 insertions(+), 5 deletions(-) diff --git a/hub/catalog_factories/usage/usage_helper.py b/hub/catalog_factories/usage/usage_helper.py index e2886bc9..03cef4e1 100644 --- a/hub/catalog_factories/usage/usage_helper.py +++ b/hub/catalog_factories/usage/usage_helper.py @@ -6,6 +6,7 @@ Project Coder Pilar Monsalvete Alvarez de Uribarri pilar.monsalvete@concordia.ca """ import sys import hub.helpers.constants as cte +from hub.hub_logger import logger from typing import Dict @@ -129,3 +130,5 @@ class UsageHelper: except KeyError: sys.stderr.write('Error: Comnet keyword not found. An update of the Comnet files might have been ' 'done changing the keywords.\n') + logger.error('Error: Comnet keyword not found. An update of the Comnet files might have been ' + 'done changing the keywords.\n') diff --git a/hub/city_model_structure/attributes/polygon.py b/hub/city_model_structure/attributes/polygon.py index 2755d399..3875dc6b 100644 --- a/hub/city_model_structure/attributes/polygon.py +++ b/hub/city_model_structure/attributes/polygon.py @@ -264,8 +264,8 @@ class Polygon: return mesh except ValueError: - logger.error(f'Not able to triangulate polygon\n') sys.stderr.write(f'Not able to triangulate polygon\n') + logger.error(f'Not able to triangulate polygon\n') _vertices = [[0, 0, 0], [0, 0, 1], [0, 1, 0]] _faces = [[0, 1, 2]] return Trimesh(vertices=_vertices, faces=_faces) @@ -293,6 +293,7 @@ class Polygon: """ if np.linalg.norm(vec_1) == 0 or np.linalg.norm(vec_2) == 0: sys.stderr.write("Warning: impossible to calculate angle between planes' normal. Return 0\n") + logger.error("Warning: impossible to calculate angle between planes' normal. Return 0\n") return 0 cosine = np.dot(vec_1, vec_2) / np.linalg.norm(vec_1) / np.linalg.norm(vec_2) if cosine > 1 and cosine - 1 < 1e-5: diff --git a/hub/city_model_structure/attributes/polyhedron.py b/hub/city_model_structure/attributes/polyhedron.py index 553f1e26..e4956611 100644 --- a/hub/city_model_structure/attributes/polyhedron.py +++ b/hub/city_model_structure/attributes/polyhedron.py @@ -12,6 +12,7 @@ import math import numpy as np from trimesh import Trimesh from hub.helpers.configuration_helper import ConfigurationHelper +from hub.hub_logger import logger class Polyhedron: @@ -116,6 +117,7 @@ class Polyhedron: for face in self.faces: if len(face) != 3: sys.stderr.write('Not able to generate trimesh\n') + logger.error('Not able to generate trimesh\n') return None self._trimesh = Trimesh(vertices=self.vertices, faces=self.faces) return self._trimesh diff --git a/hub/city_model_structure/building.py b/hub/city_model_structure/building.py index d5129142..df6ff4ff 100644 --- a/hub/city_model_structure/building.py +++ b/hub/city_model_structure/building.py @@ -71,8 +71,8 @@ class Building(CityObject): elif surface.type == cte.INTERIOR_SLAB: self._interior_slabs.append(surface) else: - logger.error(f'Building {self.name} [alias {self.alias}] has an unexpected surface type {surface.type}.\n') sys.stderr.write(f'Building {self.name} [alias {self.alias}] has an unexpected surface type {surface.type}.\n') + logger.error(f'Building {self.name} [alias {self.alias}] has an unexpected surface type {surface.type}.\n') @property def shell(self) -> Polyhedron: diff --git a/hub/city_model_structure/city.py b/hub/city_model_structure/city.py index 5f4da399..e24c7d10 100644 --- a/hub/city_model_structure/city.py +++ b/hub/city_model_structure/city.py @@ -16,6 +16,7 @@ import pyproj from typing import List, Union from pyproj import Transformer from pathlib import Path +from hub.hub_logger import logger from hub.city_model_structure.building import Building from hub.city_model_structure.city_object import CityObject from hub.city_model_structure.city_objects_cluster import CityObjectsCluster @@ -87,6 +88,8 @@ class City: except pyproj.exceptions.CRSError: sys.stderr.write('Invalid projection reference system, please check the input data. ' '(e.g. in CityGML files: srs_name)\n') + logger.error('Invalid projection reference system, please check the input data. ' + '(e.g. in CityGML files: srs_name)\n') sys.exit() transformer = Transformer.from_crs(input_reference, gps) coordinates = transformer.transform(self.lower_corner[0], self.lower_corner[1]) @@ -230,6 +233,7 @@ class City: raise NotImplementedError(city_object.type) if self._buildings is None or self._buildings == []: sys.stderr.write('Warning: impossible to remove city_object, the city is empty\n') + logger.error('Warning: impossible to remove city_object, the city is empty\n') else: if city_object in self._buildings: self._buildings.remove(city_object) diff --git a/hub/imports/construction/helpers/storeys_generation.py b/hub/imports/construction/helpers/storeys_generation.py index 179f7431..c9617fe6 100644 --- a/hub/imports/construction/helpers/storeys_generation.py +++ b/hub/imports/construction/helpers/storeys_generation.py @@ -10,6 +10,7 @@ import numpy as np from typing import List from hub.helpers import constants as cte +from hub.hub_logger import logger from hub.city_model_structure.attributes.polygon import Polygon from hub.city_model_structure.attributes.point import Point from hub.city_model_structure.building_demand.storey import Storey @@ -17,6 +18,7 @@ from hub.city_model_structure.building_demand.surface import Surface from hub.city_model_structure.building_demand.thermal_zone import ThermalZone + class StoreysGeneration: """ StoreysGeneration @@ -134,6 +136,8 @@ class StoreysGeneration: if storeys_above_ground is None or storeys_above_ground <= 0: sys.stderr.write('Warning: not enough information to divide building into storeys, ' 'either number of storeys or average storey height must be provided.\n') + logger.error('Warning: not enough information to divide building into storeys, ' + 'either number of storeys or average storey height must be provided.\n') return 0, 0 number_of_storeys = int(storeys_above_ground) height = eave_height / number_of_storeys diff --git a/hub/imports/construction/nrcan_physics_parameters.py b/hub/imports/construction/nrcan_physics_parameters.py index 4ceb4e57..45d4d318 100644 --- a/hub/imports/construction/nrcan_physics_parameters.py +++ b/hub/imports/construction/nrcan_physics_parameters.py @@ -7,7 +7,9 @@ Project Coder Pilar Monsalvete Alvarez de Uribarri pilar.monsalvete@concordia.ca import math import sys + import hub.helpers.constants as cte +from hub.hub_logger import logger from hub.catalog_factories.construction_catalog_factory import ConstructionCatalogFactory from hub.city_model_structure.building_demand.layer import Layer from hub.city_model_structure.building_demand.material import Material @@ -40,6 +42,10 @@ class NrcanPhysicsParameters: sys.stderr.write(f'Building {building.name} has unknown construction archetype for building function: ' f'{building.function}, building year of construction: {building.year_of_construction} ' f'and climate zone {self._climate_zone}\n') + logger.error(f'Building {building.name} has unknown construction archetype for building function: ' + f'{building.function}, building year of construction: {building.year_of_construction} ' + f'and climate zone {self._climate_zone}\n') + return # if building has no thermal zones defined from geometry, and the building will be divided in storeys, # one thermal zone per storey is assigned diff --git a/hub/imports/construction/nrel_physics_parameters.py b/hub/imports/construction/nrel_physics_parameters.py index 78f08d30..219117f3 100644 --- a/hub/imports/construction/nrel_physics_parameters.py +++ b/hub/imports/construction/nrel_physics_parameters.py @@ -39,12 +39,12 @@ class NrelPhysicsParameters: archetype = self._search_archetype(nrel_catalog, function, building.year_of_construction, self._climate_zone) except KeyError: - logger.error(f'Building {building.name} has unknown archetype for building function: {building.function} ' - f'and building year of construction: {building.year_of_construction} ' - f'and climate zone reference norm {self._climate_zone}\n') sys.stderr.write(f'Building {building.name} has unknown archetype for building function: {building.function} ' f'and building year of construction: {building.year_of_construction} ' f'and climate zone reference norm {self._climate_zone}\n') + logger.error(f'Building {building.name} has unknown archetype for building function: {building.function} ' + f'and building year of construction: {building.year_of_construction} ' + f'and climate zone reference norm {self._climate_zone}\n') return diff --git a/hub/imports/usage/comnet_usage_parameters.py b/hub/imports/usage/comnet_usage_parameters.py index 6dcab450..c0dc6b17 100644 --- a/hub/imports/usage/comnet_usage_parameters.py +++ b/hub/imports/usage/comnet_usage_parameters.py @@ -9,6 +9,7 @@ import sys import numpy import hub.helpers.constants as cte +from hub.hub_logger import logger from hub.helpers.dictionaries import Dictionaries from hub.city_model_structure.building_demand.usage import Usage from hub.city_model_structure.building_demand.lighting import Lighting @@ -42,6 +43,8 @@ class ComnetUsageParameters: except KeyError: sys.stderr.write(f'Building {building.name} has unknown usage archetype for building function:' f' {building.function}') + logger.error(f'Building {building.name} has unknown usage archetype for building function:' + f' {building.function}') return for internal_zone in building.internal_zones: diff --git a/hub/imports/usage/nrcan_usage_parameters.py b/hub/imports/usage/nrcan_usage_parameters.py index 68d8a2bf..284c57c2 100644 --- a/hub/imports/usage/nrcan_usage_parameters.py +++ b/hub/imports/usage/nrcan_usage_parameters.py @@ -8,6 +8,7 @@ Project Coder Pilar Monsalvete Alvarez de Uribarri pilar.monsalvete@concordia.ca import sys import hub.helpers.constants as cte +from hub.hub_logger import logger from hub.helpers.dictionaries import Dictionaries from hub.city_model_structure.building_demand.usage import Usage from hub.city_model_structure.building_demand.lighting import Lighting @@ -41,6 +42,8 @@ class NrcanUsageParameters: except KeyError: sys.stderr.write(f'Building {building.name} has unknown usage archetype for building function:' f' {building.function}') + logger.error(f'Building {building.name} has unknown usage archetype for building function:' + f' {building.function}') return usage_name = Dictionaries().hub_usage_to_comnet_usage[building.function] @@ -49,6 +52,8 @@ class NrcanUsageParameters: except KeyError: sys.stderr.write(f'Building {building.name} has unknown usage archetype for building function:' f' {building.function}') + logger.error(f'Building {building.name} has unknown usage archetype for building function:' + f' {building.function}') return for internal_zone in building.internal_zones: diff --git a/hub/imports/weather/dat_weather_parameters.py b/hub/imports/weather/dat_weather_parameters.py index 2ce20d20..9c116e70 100644 --- a/hub/imports/weather/dat_weather_parameters.py +++ b/hub/imports/weather/dat_weather_parameters.py @@ -9,6 +9,7 @@ import sys from pathlib import Path import pandas as pd import hub.helpers.constants as cte +from hub.hub_logger import logger class DatWeatherParameters: @@ -29,6 +30,7 @@ class DatWeatherParameters: names=['hour', 'global_horiz', 'temperature', 'diffuse', 'beam', 'empty']) except SystemExit: sys.stderr.write(f'Error: weather file {self._path} not found\n') + logger.error(f'Error: weather file {self._path} not found\n') sys.exit() for building in self._city.buildings: diff --git a/hub/imports/weather/epw_weather_parameters.py b/hub/imports/weather/epw_weather_parameters.py index 47ddb5fe..f3765f22 100644 --- a/hub/imports/weather/epw_weather_parameters.py +++ b/hub/imports/weather/epw_weather_parameters.py @@ -9,6 +9,7 @@ import sys from pathlib import Path import pandas as pd import hub.helpers.constants as cte +from hub.hub_logger import logger from hub.imports.weather.helpers.weather import Weather as wh @@ -44,6 +45,8 @@ class EpwWeatherParameters: except SystemExit: sys.stderr.write(f'Error: weather file {self._path} not found. Please download it from ' f'https://energyplus.net/weather and place it in folder data\\weather\\epw\n') + logger.error(f'Error: weather file {self._path} not found. Please download it from ' + f'https://energyplus.net/weather and place it in folder data\\weather\\epw\n') sys.exit() try: @@ -71,6 +74,7 @@ class EpwWeatherParameters: 'liquid_precipitation_quality_hr']) except SystemExit: sys.stderr.write(f'Error: wrong formatting of weather file {self._path}\n') + logger.error(f'Error: wrong formatting of weather file {self._path}\n') sys.exit() for building in self._city.buildings: @@ -80,6 +84,7 @@ class EpwWeatherParameters: number_invalid_records = new_value[new_value.epw == 99.9].count().epw if number_invalid_records > 0: sys.stderr.write(f'Warning: {self._path} invalid records (value of 99.9) in dry bulb temperature\n') + logger.error(f'Warning: {self._path} invalid records (value of 99.9) in dry bulb temperature\n') if cte.HOUR not in building.external_temperature: building.external_temperature[cte.HOUR] = new_value else: @@ -89,6 +94,7 @@ class EpwWeatherParameters: number_invalid_records = new_value[new_value.epw == 9999].count().epw if number_invalid_records > 0: sys.stderr.write(f'Warning: {self._path} invalid records (value of 9999) in global horizontal radiation\n') + logger.error(f'Warning: {self._path} invalid records (value of 9999) in global horizontal radiation\n') if cte.HOUR not in building.global_horizontal: building.global_horizontal[cte.HOUR] = new_value else: @@ -98,6 +104,7 @@ class EpwWeatherParameters: number_invalid_records = new_value[new_value.epw == 9999].count().epw if number_invalid_records > 0: sys.stderr.write(f'Warning: {self._path} invalid records (value of 9999) in diffuse horizontal radiation\n') + logger.error(f'Warning: {self._path} invalid records (value of 9999) in diffuse horizontal radiation\n') if cte.HOUR not in building.diffuse: building.diffuse[cte.HOUR] = new_value else: @@ -107,6 +114,7 @@ class EpwWeatherParameters: number_invalid_records = new_value[new_value.epw == 9999].count().epw if number_invalid_records > 0: sys.stderr.write(f'Warning: {self._path} invalid records (value of 9999) in direct horizontal radiation\n') + logger.error(f'Warning: {self._path} invalid records (value of 9999) in direct horizontal radiation\n') if cte.HOUR not in building.beam: building.beam[cte.HOUR] = new_value else: diff --git a/hub/imports/weather/xls_weather_parameters.py b/hub/imports/weather/xls_weather_parameters.py index fc991e36..75939f48 100644 --- a/hub/imports/weather/xls_weather_parameters.py +++ b/hub/imports/weather/xls_weather_parameters.py @@ -10,6 +10,7 @@ import sys from pathlib import Path import pandas as pd import hub.helpers.constants as cte +from hub.hub_logger import logger class XlsWeatherParameters: @@ -32,6 +33,7 @@ class XlsWeatherParameters: 'void', 'global_horiz', 'wind_velocity', 'humidity']) except SystemExit: sys.stderr.write(f'Error reading weather file {self._path}\n') + logger.error(f'Error reading weather file {self._path}\n') sys.exit() for building in self._city.buildings: