Compare commits
7 Commits
main
...
data_clean
Author | SHA1 | Date | |
---|---|---|---|
|
16ae71ecc5 | ||
|
533beef463 | ||
|
1918ee27c5 | ||
|
e75bf3a367 | ||
|
77824fd1cb | ||
|
a9caad7cf5 | ||
|
43cb1e5612 |
@ -1,16 +1,32 @@
|
||||
import logging as logger
|
||||
from pathlib import Path
|
||||
import os
|
||||
import logging
|
||||
import sys
|
||||
|
||||
log_dir = (Path(__file__).parent.parent / 'logs').resolve()
|
||||
log_file = (log_dir / 'hub.log').resolve()
|
||||
try:
|
||||
if not os.path.isfile(log_file):
|
||||
if not os.path.exists(log_dir):
|
||||
os.mkdir(log_dir)
|
||||
with open(log_file, 'x'):
|
||||
pass
|
||||
logger.basicConfig(filename=log_file, format="%(asctime)s:%(levelname)s:{%(pathname)s:%(funcName)s:%(lineno)d} "
|
||||
"- %(message)s", level=logger.DEBUG)
|
||||
except IOError as err:
|
||||
print(f'I/O exception: {err}')
|
||||
|
||||
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_file = (log_dir / 'hub.log').resolve()
|
||||
try:
|
||||
if not os.path.isfile(log_file):
|
||||
if not os.path.exists(log_dir):
|
||||
os.mkdir(log_dir)
|
||||
with open(log_file, 'x'):
|
||||
pass
|
||||
logger.basicConfig(filename=log_file, format=log_format, level=logger.DEBUG)
|
||||
return logger
|
||||
except IOError as err:
|
||||
print(f'I/O exception: {err}')
|
||||
else:
|
||||
logging.getLogger().addHandler(logging.StreamHandler(stream=sys.stdout))
|
||||
logging.getLogger().setLevel(logging.DEBUG)
|
||||
return logger.getLogger()
|
||||
|
@ -7,7 +7,7 @@ Project Coder Pilar Monsalvete Alvarez de Uribarri pilar.monsalvete@concordia.ca
|
||||
import datetime
|
||||
import math
|
||||
import sys
|
||||
from hub.hub_logger import logger
|
||||
from hub.hub_logger import get_logger
|
||||
|
||||
import hub.helpers.constants as cte
|
||||
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.storeys_generation import StoreysGeneration
|
||||
|
||||
logger = get_logger()
|
||||
|
||||
|
||||
class NrcanPhysicsParameters:
|
||||
"""
|
||||
NrcanPhysicsParameters class
|
||||
"""
|
||||
|
||||
def __init__(self, city, base_path, divide_in_storeys=False):
|
||||
self._city = city
|
||||
self._path = base_path
|
||||
@ -79,7 +82,7 @@ class NrcanPhysicsParameters:
|
||||
construction_period_limits = building_archetype.construction_period.split('_')
|
||||
if int(construction_period_limits[0]) <= int(year_of_construction) <= int(construction_period_limits[1]):
|
||||
if (str(function) == str(building_archetype.function)) and \
|
||||
(climate_zone == str(building_archetype.climate_zone)):
|
||||
(climate_zone == str(building_archetype.climate_zone)):
|
||||
return building_archetype
|
||||
raise KeyError('archetype not found')
|
||||
|
||||
|
@ -7,7 +7,7 @@ Code contributors: Pilar Monsalvete Alvarez de Uribarri pilar.monsalvete@concord
|
||||
"""
|
||||
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.city_model_structure.building_demand.layer import Layer
|
||||
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.storeys_generation import StoreysGeneration
|
||||
|
||||
logger = get_logger()
|
||||
|
||||
|
||||
class NrelPhysicsParameters:
|
||||
"""
|
||||
|
@ -7,11 +7,13 @@ Code contributors: Pilar Monsalvete Alvarez de Uribarri pilar.monsalvete@concord
|
||||
"""
|
||||
|
||||
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.imports.construction.nrel_physics_parameters import NrelPhysicsParameters
|
||||
from hub.imports.construction.nrcan_physics_parameters import NrcanPhysicsParameters
|
||||
|
||||
logger = get_logger()
|
||||
|
||||
|
||||
class ConstructionFactory:
|
||||
"""
|
||||
|
@ -9,7 +9,9 @@ from pathlib import Path
|
||||
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.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:
|
||||
|
@ -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_demand.surface import Surface
|
||||
from hub.city_model_structure.city import City
|
||||
from typing import List
|
||||
from shapely.geometry import Polygon as Poly
|
||||
|
||||
|
||||
class Geojson:
|
||||
@ -45,6 +47,7 @@ class Geojson:
|
||||
self._year_of_construction_field = year_of_construction_field
|
||||
self._function_field = function_field
|
||||
self._function_to_hub = function_to_hub
|
||||
self._building_coordinates = []
|
||||
with open(path) as json_file:
|
||||
self._geojson = json.loads(json_file.read())
|
||||
|
||||
@ -175,6 +178,41 @@ class Geojson:
|
||||
percentage += percentage_ground * percentage_height
|
||||
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
|
||||
def city(self) -> City:
|
||||
"""
|
||||
@ -209,34 +247,37 @@ class Geojson:
|
||||
else:
|
||||
building_name = f'building_{building_id}'
|
||||
building_id += 1
|
||||
polygons = []
|
||||
for part, coordinates in enumerate(geometry['coordinates']):
|
||||
polygons = self._get_polygons(polygons, coordinates)
|
||||
for zone, polygon in enumerate(polygons):
|
||||
if extrusion_height == 0:
|
||||
buildings = buildings + Geojson._create_buildings_lod0(f'{building_name}_part_{part}',
|
||||
year_of_construction,
|
||||
function,
|
||||
[polygon])
|
||||
lod = 0
|
||||
else:
|
||||
if self._max_z < extrusion_height:
|
||||
self._max_z = extrusion_height
|
||||
buildings = buildings + Geojson._create_buildings_lod1(f'{building_name}_part_{part}',
|
||||
year_of_construction,
|
||||
function,
|
||||
extrusion_height,
|
||||
[polygon])
|
||||
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 = self._get_polygons(polygons, coordinates[0])
|
||||
for zone, polygon in enumerate(polygons):
|
||||
if coordinates[4] == 0:
|
||||
buildings = buildings + Geojson._create_buildings_lod0(f'{coordinates[1]}_part_{part}',
|
||||
coordinates[2],
|
||||
coordinates[3],
|
||||
[polygon])
|
||||
lod = 0
|
||||
else:
|
||||
if self._max_z < coordinates[4]:
|
||||
self._max_z = coordinates[4]
|
||||
buildings = buildings + Geojson._create_buildings_lod1(f'{coordinates[1]}_part_{part}',
|
||||
coordinates[2],
|
||||
coordinates[3],
|
||||
coordinates[4],
|
||||
[polygon])
|
||||
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:
|
||||
if building.floor_area >= 25:
|
||||
self._city.add_city_object(building)
|
||||
self._city.level_of_detail.geometry = lod
|
||||
if lod == 1:
|
||||
lines_information = GeometryHelper.city_mapping(self._city, plot=False)
|
||||
self._store_shared_percentage_to_walls(self._city, lines_information)
|
||||
if len(missing_functions) > 0:
|
||||
print(f'There are unknown functions {missing_functions}')
|
||||
|
||||
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:
|
||||
# Do not include "small building-like structures" to buildings
|
||||
if building.floor_area >= 25:
|
||||
self._city.add_city_object(building)
|
||||
self._city.level_of_detail.geometry = lod
|
||||
if lod == 1:
|
||||
lines_information = GeometryHelper.city_mapping(self._city, plot=False)
|
||||
self._store_shared_percentage_to_walls(self._city, lines_information)
|
||||
if len(missing_functions) > 0:
|
||||
print(f'There are unknown functions {missing_functions}')
|
||||
return self._city
|
||||
|
@ -13,7 +13,9 @@ from hub.imports.geometry.rhino import Rhino
|
||||
from hub.imports.geometry.gpandas import GPandas
|
||||
from hub.imports.geometry.geojson import Geojson
|
||||
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:
|
||||
|
@ -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_material import LcaMaterial
|
||||
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:
|
||||
|
@ -8,11 +8,13 @@ Code contributors: Pilar Monsalvete Alvarez de Uribarri pilar.monsalvete@concord
|
||||
from pathlib import Path
|
||||
|
||||
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.insel_monthly_energry_balance import InselMonthlyEnergyBalance
|
||||
from hub.imports.results.insel_heatpump_energy_demand import InselHeatPumpEnergyDemand
|
||||
|
||||
logger = get_logger()
|
||||
|
||||
|
||||
class ResultFactory:
|
||||
"""
|
||||
|
@ -6,9 +6,11 @@ Project Coder Guille Gutierrez guillermo.gutierrezmorote@concordia.ca
|
||||
Code contributors: Pilar Monsalvete Alvarez de Uribarri pilar.monsalvete@concordia.ca
|
||||
"""
|
||||
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
|
||||
|
||||
logger = get_logger(False)
|
||||
|
||||
|
||||
class SensorsFactory:
|
||||
"""
|
||||
|
@ -8,7 +8,7 @@ import copy
|
||||
import sys
|
||||
import numpy
|
||||
|
||||
from hub.hub_logger import logger
|
||||
from hub.hub_logger import get_logger
|
||||
import hub.helpers.constants as cte
|
||||
from hub.helpers.dictionaries import Dictionaries
|
||||
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.catalog_factories.usage_catalog_factory import UsageCatalogFactory
|
||||
|
||||
logger = get_logger()
|
||||
|
||||
|
||||
class ComnetUsageParameters:
|
||||
"""
|
||||
|
@ -7,7 +7,7 @@ Project Coder Pilar Monsalvete Alvarez de Uribarri pilar.monsalvete@concordia.ca
|
||||
|
||||
import sys
|
||||
|
||||
from hub.hub_logger import logger
|
||||
from hub.hub_logger import get_logger
|
||||
import hub.helpers.constants as cte
|
||||
from hub.helpers.dictionaries import Dictionaries
|
||||
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.catalog_factories.usage_catalog_factory import UsageCatalogFactory
|
||||
|
||||
logger = get_logger()
|
||||
|
||||
|
||||
class NrcanUsageParameters:
|
||||
"""
|
||||
|
@ -9,9 +9,11 @@ Code contributors: Pilar Monsalvete Alvarez de Uribarri pilar.monsalvete@concord
|
||||
from pathlib import Path
|
||||
from hub.imports.usage.comnet_usage_parameters import ComnetUsageParameters
|
||||
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
|
||||
|
||||
logger = get_logger()
|
||||
|
||||
|
||||
class UsageFactory:
|
||||
"""
|
||||
|
@ -7,9 +7,11 @@ Project Coder Pilar Monsalvete Alvarez de Uribarri pilar.monsalvete@concordia.ca
|
||||
from pathlib import Path
|
||||
from hub.imports.weather.xls_weather_parameters import XlsWeatherParameters
|
||||
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
|
||||
|
||||
logger = get_logger()
|
||||
|
||||
|
||||
class WeatherFactory:
|
||||
"""
|
||||
|
@ -105,7 +105,6 @@ class TestGeometryFactory(TestCase):
|
||||
file = 'FZK_Haus_LoD_2.gml'
|
||||
city = self._get_city(file, 'citygml')
|
||||
self.assertTrue(len(city.buildings) == 1)
|
||||
self._check_buildings(city)
|
||||
for building in city.buildings:
|
||||
self._check_surfaces(building)
|
||||
city = ConstructionFactory('nrel', city).enrich()
|
||||
@ -141,7 +140,7 @@ class TestGeometryFactory(TestCase):
|
||||
year_of_construction_field='ANNEE_CONS',
|
||||
function_field='CODE_UTILI',
|
||||
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')
|
||||
|
||||
def test_map_neighbours(self):
|
||||
|
@ -24,4 +24,5 @@ geopandas
|
||||
triangle
|
||||
psycopg2-binary
|
||||
Pillow
|
||||
pathlib
|
||||
shapely==2.0.1
|
||||
pathlib
|
||||
|
Loading…
Reference in New Issue
Block a user