Compare commits

...

7 Commits

Author SHA1 Message Date
Peter Yefi
16ae71ecc5 Removed extra space 2023-04-17 17:45:59 -04:00
Peter Yefi
533beef463 test data files 2023-04-17 17:45:12 -04:00
Peter Yefi
1918ee27c5 Switched from file looger to stream logger. 2023-04-17 17:40:55 -04:00
Peter Yefi
e75bf3a367 Switched from file looger to stream logger. 2023-04-17 17:40:27 -04:00
Peter Yefi
77824fd1cb Logging to remove sub polygons that are holes 2023-04-04 22:31:54 -04:00
Peter Yefi
a9caad7cf5 Stashing changes 2023-03-29 19:39:58 -04:00
Peter Yefi
43cb1e5612 Stashing changes 2023-03-29 19:39:36 -04:00
16 changed files with 139 additions and 57 deletions

View File

@ -1,7 +1,19 @@
import logging as logger import logging as logger
from pathlib import Path from pathlib import Path
import os import os
import logging
import sys
def get_logger(file_logger=False):
"""
Returns a logging object
:param file_logger: a boolean to indicate the kind of logging
object to return, true (default) means a file logger is required
:return:
"""
log_format = "%(asctime)s:%(levelname)s:{%(pathname)s:%(funcName)s:%(lineno)d} - %(message)s"
if file_logger:
log_dir = (Path(__file__).parent.parent / 'logs').resolve() log_dir = (Path(__file__).parent.parent / 'logs').resolve()
log_file = (log_dir / 'hub.log').resolve() log_file = (log_dir / 'hub.log').resolve()
try: try:
@ -10,7 +22,11 @@ try:
os.mkdir(log_dir) os.mkdir(log_dir)
with open(log_file, 'x'): with open(log_file, 'x'):
pass pass
logger.basicConfig(filename=log_file, format="%(asctime)s:%(levelname)s:{%(pathname)s:%(funcName)s:%(lineno)d} " logger.basicConfig(filename=log_file, format=log_format, level=logger.DEBUG)
"- %(message)s", level=logger.DEBUG) return logger
except IOError as err: except IOError as err:
print(f'I/O exception: {err}') print(f'I/O exception: {err}')
else:
logging.getLogger().addHandler(logging.StreamHandler(stream=sys.stdout))
logging.getLogger().setLevel(logging.DEBUG)
return logger.getLogger()

View File

@ -7,7 +7,7 @@ Project Coder Pilar Monsalvete Alvarez de Uribarri pilar.monsalvete@concordia.ca
import datetime import datetime
import math import math
import sys import sys
from hub.hub_logger import logger from hub.hub_logger import get_logger
import hub.helpers.constants as cte import hub.helpers.constants as cte
from hub.catalog_factories.construction_catalog_factory import ConstructionCatalogFactory from hub.catalog_factories.construction_catalog_factory import ConstructionCatalogFactory
@ -17,11 +17,14 @@ from hub.helpers.dictionaries import Dictionaries
from hub.imports.construction.helpers.construction_helper import ConstructionHelper from hub.imports.construction.helpers.construction_helper import ConstructionHelper
from hub.imports.construction.helpers.storeys_generation import StoreysGeneration from hub.imports.construction.helpers.storeys_generation import StoreysGeneration
logger = get_logger()
class NrcanPhysicsParameters: class NrcanPhysicsParameters:
""" """
NrcanPhysicsParameters class NrcanPhysicsParameters class
""" """
def __init__(self, city, base_path, divide_in_storeys=False): def __init__(self, city, base_path, divide_in_storeys=False):
self._city = city self._city = city
self._path = base_path self._path = base_path

View File

@ -7,7 +7,7 @@ Code contributors: Pilar Monsalvete Alvarez de Uribarri pilar.monsalvete@concord
""" """
import sys import sys
from hub.hub_logger import logger from hub.hub_logger import get_logger
from hub.catalog_factories.construction_catalog_factory import ConstructionCatalogFactory 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.layer import Layer
from hub.city_model_structure.building_demand.material import Material from hub.city_model_structure.building_demand.material import Material
@ -15,6 +15,8 @@ from hub.helpers.dictionaries import Dictionaries
from hub.imports.construction.helpers.construction_helper import ConstructionHelper from hub.imports.construction.helpers.construction_helper import ConstructionHelper
from hub.imports.construction.helpers.storeys_generation import StoreysGeneration from hub.imports.construction.helpers.storeys_generation import StoreysGeneration
logger = get_logger()
class NrelPhysicsParameters: class NrelPhysicsParameters:
""" """

View File

@ -7,11 +7,13 @@ Code contributors: Pilar Monsalvete Alvarez de Uribarri pilar.monsalvete@concord
""" """
from pathlib import Path from pathlib import Path
from hub.hub_logger import logger from hub.hub_logger import get_logger
from hub.helpers.utils import validate_import_export_type from hub.helpers.utils import validate_import_export_type
from hub.imports.construction.nrel_physics_parameters import NrelPhysicsParameters from hub.imports.construction.nrel_physics_parameters import NrelPhysicsParameters
from hub.imports.construction.nrcan_physics_parameters import NrcanPhysicsParameters from hub.imports.construction.nrcan_physics_parameters import NrcanPhysicsParameters
logger = get_logger()
class ConstructionFactory: class ConstructionFactory:
""" """

View File

@ -9,7 +9,9 @@ from pathlib import Path
from hub.imports.energy_systems.air_source_hp_parameters import AirSourceHeatPumpParameters from hub.imports.energy_systems.air_source_hp_parameters import AirSourceHeatPumpParameters
from hub.imports.energy_systems.water_to_water_hp_parameters import WaterToWaterHPParameters from hub.imports.energy_systems.water_to_water_hp_parameters import WaterToWaterHPParameters
from hub.helpers.utils import validate_import_export_type from hub.helpers.utils import validate_import_export_type
from hub.hub_logger import logger from hub.hub_logger import get_logger
logger = get_logger()
class EnergySystemsFactory: class EnergySystemsFactory:

View File

@ -18,6 +18,8 @@ from hub.city_model_structure.attributes.polygon import Polygon
from hub.city_model_structure.building import Building from hub.city_model_structure.building import Building
from hub.city_model_structure.building_demand.surface import Surface from hub.city_model_structure.building_demand.surface import Surface
from hub.city_model_structure.city import City from hub.city_model_structure.city import City
from typing import List
from shapely.geometry import Polygon as Poly
class Geojson: class Geojson:
@ -45,6 +47,7 @@ class Geojson:
self._year_of_construction_field = year_of_construction_field self._year_of_construction_field = year_of_construction_field
self._function_field = function_field self._function_field = function_field
self._function_to_hub = function_to_hub self._function_to_hub = function_to_hub
self._building_coordinates = []
with open(path) as json_file: with open(path) as json_file:
self._geojson = json.loads(json_file.read()) self._geojson = json.loads(json_file.read())
@ -175,6 +178,41 @@ class Geojson:
percentage += percentage_ground * percentage_height percentage += percentage_ground * percentage_height
wall.percentage_shared = percentage wall.percentage_shared = percentage
def _unwind_coordinates(self, polygons, coordinates):
"""
Makes list of coordinates from complex coordinate list
:param polygons: complex list of coordinates e.g. [[[3.5, 2.7], [10.7, 11.19]], [[13.5, 22.7], [18.7, 11.9]]]
:param coordinates: and empty list to hold list of coordinates
:return: list of coordinates, e.g. [[3.5, 2.7], [10.7, 11.19], [13.5, 22.7], [18.7, 11.9]]
"""
for polygon in polygons:
if len(polygon) != 2:
return self._unwind_coordinates(polygons[0], coordinates)
else:
coordinates.append(polygon)
return coordinates
def _remove_sub_polygons(self, new_building_coordinate: List):
"""
building a pool of building cooordinates (GeoJSON polygons) while
ignoring polygons that are inside other polygons
:param new_building_coordinate: a new coordinate to be added, this is checked
to make sure it is not inside a polygon or a polygon is not inside it
:return:
"""
processed_coordinates = self._unwind_coordinates(new_building_coordinate[0], [])
is_sub_coordinate = False
for coordinates in self._building_coordinates[:]:
if Poly(processed_coordinates).contains(Poly(coordinates[0])):
self._building_coordinates.remove(coordinates)
elif Poly(coordinates[0]).contains(Poly(processed_coordinates)):
is_sub_coordinate = True
break
if is_sub_coordinate is False:
new_building_coordinate[0] = processed_coordinates
self._building_coordinates.append(new_building_coordinate)
@property @property
def city(self) -> City: def city(self) -> City:
""" """
@ -209,28 +247,30 @@ class Geojson:
else: else:
building_name = f'building_{building_id}' building_name = f'building_{building_id}'
building_id += 1 building_id += 1
for coordinates in geometry['coordinates']:
self._remove_sub_polygons([coordinates, building_name, year_of_construction,
function, extrusion_height])
for part, coordinates in enumerate(self._building_coordinates):
polygons = [] polygons = []
for part, coordinates in enumerate(geometry['coordinates']): polygons = self._get_polygons(polygons, coordinates[0])
polygons = self._get_polygons(polygons, coordinates)
for zone, polygon in enumerate(polygons): for zone, polygon in enumerate(polygons):
if extrusion_height == 0: if coordinates[4] == 0:
buildings = buildings + Geojson._create_buildings_lod0(f'{building_name}_part_{part}', buildings = buildings + Geojson._create_buildings_lod0(f'{coordinates[1]}_part_{part}',
year_of_construction, coordinates[2],
function, coordinates[3],
[polygon]) [polygon])
lod = 0 lod = 0
else: else:
if self._max_z < extrusion_height: if self._max_z < coordinates[4]:
self._max_z = extrusion_height self._max_z = coordinates[4]
buildings = buildings + Geojson._create_buildings_lod1(f'{building_name}_part_{part}', buildings = buildings + Geojson._create_buildings_lod1(f'{coordinates[1]}_part_{part}',
year_of_construction, coordinates[2],
function, coordinates[3],
extrusion_height, coordinates[4],
[polygon]) [polygon])
self._city = City([self._min_x, self._min_y, 0.0], [self._max_x, self._max_y, self._max_z], 'epsg:26911') self._city = City([self._min_x, self._min_y, 0.0], [self._max_x, self._max_y, self._max_z], 'epsg:26911')
for building in buildings: for building in buildings:
# Do not include "small building-like structures" to buildings
if building.floor_area >= 25: if building.floor_area >= 25:
self._city.add_city_object(building) self._city.add_city_object(building)
self._city.level_of_detail.geometry = lod self._city.level_of_detail.geometry = lod
@ -239,4 +279,5 @@ class Geojson:
self._store_shared_percentage_to_walls(self._city, lines_information) self._store_shared_percentage_to_walls(self._city, lines_information)
if len(missing_functions) > 0: if len(missing_functions) > 0:
print(f'There are unknown functions {missing_functions}') print(f'There are unknown functions {missing_functions}')
return self._city return self._city

View File

@ -13,7 +13,9 @@ from hub.imports.geometry.rhino import Rhino
from hub.imports.geometry.gpandas import GPandas from hub.imports.geometry.gpandas import GPandas
from hub.imports.geometry.geojson import Geojson from hub.imports.geometry.geojson import Geojson
from hub.helpers.utils import validate_import_export_type from hub.helpers.utils import validate_import_export_type
from hub.hub_logger import logger from hub.hub_logger import get_logger
logger = get_logger()
class GeometryFactory: class GeometryFactory:

View File

@ -11,7 +11,9 @@ from hub.imports.life_cycle_assessment.lca_vehicle import LcaVehicle
from hub.imports.life_cycle_assessment.lca_machine import LcaMachine from hub.imports.life_cycle_assessment.lca_machine import LcaMachine
from hub.imports.life_cycle_assessment.lca_material import LcaMaterial from hub.imports.life_cycle_assessment.lca_material import LcaMaterial
from hub.helpers.utils import validate_import_export_type from hub.helpers.utils import validate_import_export_type
from hub.hub_logger import logger from hub.hub_logger import get_logger
logger = get_logger()
class LifeCycleAssessment: class LifeCycleAssessment:

View File

@ -8,11 +8,13 @@ Code contributors: Pilar Monsalvete Alvarez de Uribarri pilar.monsalvete@concord
from pathlib import Path from pathlib import Path
from hub.helpers.utils import validate_import_export_type from hub.helpers.utils import validate_import_export_type
from hub.hub_logger import logger from hub.hub_logger import get_logger
from hub.imports.results.simplified_radiosity_algorithm import SimplifiedRadiosityAlgorithm from hub.imports.results.simplified_radiosity_algorithm import SimplifiedRadiosityAlgorithm
from hub.imports.results.insel_monthly_energry_balance import InselMonthlyEnergyBalance from hub.imports.results.insel_monthly_energry_balance import InselMonthlyEnergyBalance
from hub.imports.results.insel_heatpump_energy_demand import InselHeatPumpEnergyDemand from hub.imports.results.insel_heatpump_energy_demand import InselHeatPumpEnergyDemand
logger = get_logger()
class ResultFactory: class ResultFactory:
""" """

View File

@ -6,9 +6,11 @@ Project Coder Guille Gutierrez guillermo.gutierrezmorote@concordia.ca
Code contributors: Pilar Monsalvete Alvarez de Uribarri pilar.monsalvete@concordia.ca Code contributors: Pilar Monsalvete Alvarez de Uribarri pilar.monsalvete@concordia.ca
""" """
from pathlib import Path from pathlib import Path
from hub.hub_logger import logger from hub.hub_logger import get_logger
from hub.helpers.utils import validate_import_export_type from hub.helpers.utils import validate_import_export_type
logger = get_logger(False)
class SensorsFactory: class SensorsFactory:
""" """

View File

@ -8,7 +8,7 @@ import copy
import sys import sys
import numpy import numpy
from hub.hub_logger import logger from hub.hub_logger import get_logger
import hub.helpers.constants as cte import hub.helpers.constants as cte
from hub.helpers.dictionaries import Dictionaries from hub.helpers.dictionaries import Dictionaries
from hub.city_model_structure.building_demand.usage import Usage from hub.city_model_structure.building_demand.usage import Usage
@ -21,6 +21,8 @@ from hub.city_model_structure.attributes.schedule import Schedule
from hub.city_model_structure.building_demand.internal_gain import InternalGain from hub.city_model_structure.building_demand.internal_gain import InternalGain
from hub.catalog_factories.usage_catalog_factory import UsageCatalogFactory from hub.catalog_factories.usage_catalog_factory import UsageCatalogFactory
logger = get_logger()
class ComnetUsageParameters: class ComnetUsageParameters:
""" """

View File

@ -7,7 +7,7 @@ Project Coder Pilar Monsalvete Alvarez de Uribarri pilar.monsalvete@concordia.ca
import sys import sys
from hub.hub_logger import logger from hub.hub_logger import get_logger
import hub.helpers.constants as cte import hub.helpers.constants as cte
from hub.helpers.dictionaries import Dictionaries from hub.helpers.dictionaries import Dictionaries
from hub.city_model_structure.building_demand.usage import Usage from hub.city_model_structure.building_demand.usage import Usage
@ -18,6 +18,8 @@ from hub.city_model_structure.building_demand.thermal_control import ThermalCont
from hub.city_model_structure.building_demand.domestic_hot_water import DomesticHotWater from hub.city_model_structure.building_demand.domestic_hot_water import DomesticHotWater
from hub.catalog_factories.usage_catalog_factory import UsageCatalogFactory from hub.catalog_factories.usage_catalog_factory import UsageCatalogFactory
logger = get_logger()
class NrcanUsageParameters: class NrcanUsageParameters:
""" """

View File

@ -9,9 +9,11 @@ Code contributors: Pilar Monsalvete Alvarez de Uribarri pilar.monsalvete@concord
from pathlib import Path from pathlib import Path
from hub.imports.usage.comnet_usage_parameters import ComnetUsageParameters from hub.imports.usage.comnet_usage_parameters import ComnetUsageParameters
from hub.imports.usage.nrcan_usage_parameters import NrcanUsageParameters from hub.imports.usage.nrcan_usage_parameters import NrcanUsageParameters
from hub.hub_logger import logger from hub.hub_logger import get_logger
from hub.helpers.utils import validate_import_export_type from hub.helpers.utils import validate_import_export_type
logger = get_logger()
class UsageFactory: class UsageFactory:
""" """

View File

@ -7,9 +7,11 @@ Project Coder Pilar Monsalvete Alvarez de Uribarri pilar.monsalvete@concordia.ca
from pathlib import Path from pathlib import Path
from hub.imports.weather.xls_weather_parameters import XlsWeatherParameters from hub.imports.weather.xls_weather_parameters import XlsWeatherParameters
from hub.imports.weather.epw_weather_parameters import EpwWeatherParameters from hub.imports.weather.epw_weather_parameters import EpwWeatherParameters
from hub.hub_logger import logger from hub.hub_logger import get_logger
from hub.helpers.utils import validate_import_export_type from hub.helpers.utils import validate_import_export_type
logger = get_logger()
class WeatherFactory: class WeatherFactory:
""" """

View File

@ -105,7 +105,6 @@ class TestGeometryFactory(TestCase):
file = 'FZK_Haus_LoD_2.gml' file = 'FZK_Haus_LoD_2.gml'
city = self._get_city(file, 'citygml') city = self._get_city(file, 'citygml')
self.assertTrue(len(city.buildings) == 1) self.assertTrue(len(city.buildings) == 1)
self._check_buildings(city)
for building in city.buildings: for building in city.buildings:
self._check_surfaces(building) self._check_surfaces(building)
city = ConstructionFactory('nrel', city).enrich() city = ConstructionFactory('nrel', city).enrich()
@ -141,7 +140,7 @@ class TestGeometryFactory(TestCase):
year_of_construction_field='ANNEE_CONS', year_of_construction_field='ANNEE_CONS',
function_field='CODE_UTILI', function_field='CODE_UTILI',
function_to_hub=MontrealFunctionToHubFunction().dictionary).city function_to_hub=MontrealFunctionToHubFunction().dictionary).city
# include 25 square meter condition for a building reduces buildings number from 2289 to 2057 # including 25 square meter condition for a building reduces buildings number from 2289 to 2057
self.assertEqual(2057, len(city.buildings), 'wrong number of buildings') self.assertEqual(2057, len(city.buildings), 'wrong number of buildings')
def test_map_neighbours(self): def test_map_neighbours(self):

View File

@ -24,4 +24,5 @@ geopandas
triangle triangle
psycopg2-binary psycopg2-binary
Pillow Pillow
shapely==2.0.1
pathlib pathlib