Add logger messages to all sys.out

This commit is contained in:
Koa Wells 2023-03-16 12:17:39 -04:00
parent 725e7a098f
commit 63b91c4d67
13 changed files with 45 additions and 5 deletions

View File

@ -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')

View File

@ -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:

View File

@ -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

View File

@ -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:

View File

@ -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)

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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:

View File

@ -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:

View File

@ -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:

View File

@ -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:

View File

@ -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: