Merge branch 'mapping' into shared_surfaces_method

This commit is contained in:
Pilar 2023-02-23 07:04:06 -05:00
commit e04b713416
20 changed files with 22338 additions and 25069 deletions

View File

@ -22,15 +22,14 @@ class ConstructionHelper:
}
_nrcan_surfaces_types_to_hub_types = {
'Wall_Outdoors': cte.WALL,
'RoofCeiling_Outdoors': cte.ROOF,
'Floor_Outdoors': cte.ATTIC_FLOOR,
'Window_Outdoors': cte.WINDOW,
'Skylight_Outdoors': cte.SKYLIGHT,
'Door_Outdoors': cte.DOOR,
'Wall_Ground': cte.GROUND_WALL,
'RoofCeiling_Ground': cte.GROUND_WALL,
'Floor_Ground': cte.GROUND
'OutdoorsWall': cte.WALL,
'OutdoorsRoofCeiling': cte.ROOF,
'OutdoorsFloor': cte.ATTIC_FLOOR,
'Window': cte.WINDOW,
'Skylight': cte.SKYLIGHT,
'GroundWall': cte.GROUND_WALL,
'GroundRoofCeiling': cte.GROUND_WALL,
'GroundFloor': cte.GROUND
}
@property

View File

@ -6,119 +6,227 @@ Project Coder Pilar Monsalvete Alvarez de Uribarri pilar.monsalvete@concordia.ca
"""
import json
import urllib.request
import xmltodict
from pathlib import Path
from hub.catalog_factories.catalog import Catalog
from hub.catalog_factories.data_models.usages.content import Content
from hub.catalog_factories.data_models.construction.content import Content
from hub.catalog_factories.construction.construction_helper import ConstructionHelper
from hub.catalog_factories.data_models.construction.construction import Construction
from hub.catalog_factories.data_models.construction.archetype import Archetype
from hub.catalog_factories.data_models.construction.window import Window
from hub.catalog_factories.data_models.construction.material import Material
from hub.catalog_factories.data_models.construction.layer import Layer
class NrcanCatalog(Catalog):
def __init__(self, path):
path = str(path / 'nrcan.xml')
self._content = None
self._g_value_per_hdd = []
self._thermal_transmittance_per_hdd_and_surface = {}
self._window_ratios = {}
with open(path) as xml:
self._metadata = xmltodict.parse(xml.read())
self._base_url_archetypes = self._metadata['nrcan']['@base_url_archetypes']
self._base_url_construction = self._metadata['nrcan']['@base_url_construction']
self._load_window_ratios()
self._load_construction_values()
self._content = Content(self._load_archetypes())
_path_archetypes = Path(path / 'nrcan_archetypes.json').resolve()
_path_constructions = (path / 'nrcan_constructions.json')
with open(_path_archetypes, 'r') as file:
self._archetypes = json.load(file)
with open(_path_constructions, 'r') as file:
self._constructions = json.load(file)
def _load_window_ratios(self):
for standard in self._metadata['nrcan']['standards_per_function']['standard']:
url = f'{self._base_url_archetypes}{standard["file_location"]}'
# todo: read from file
self._window_ratios = {'Mean': 0.2, 'North': 0.2, 'East': 0.2, 'South': 0.2, 'West': 0.2}
self._catalog_windows = self._load_windows()
self._catalog_materials = self._load_materials()
self._catalog_constructions = self._load_constructions()
self._catalog_archetypes = self._load_archetypes()
def _load_construction_values(self):
for standard in self._metadata['nrcan']['standards_per_period']['standard']:
g_value_url = f'{self._base_url_construction}{standard["g_value_location"]}'
punc = '()<?:'
with urllib.request.urlopen(g_value_url) as json_file:
text = json.load(json_file)['tables']['SHGC']['table'][0]['formula']
values = ''.join([o for o in list(text) if o not in punc]).split()
for index in range(int((len(values) - 1)/3)):
self._g_value_per_hdd.append([values[3*index+1], values[3*index+2]])
self._g_value_per_hdd.append(['15000', values[len(values)-1]])
# store the full catalog data model in self._content
self._content = Content(self._catalog_archetypes,
self._catalog_constructions,
self._catalog_materials,
self._catalog_windows)
construction_url = f'{self._base_url_construction}{standard["constructions_location"]}'
with urllib.request.urlopen(construction_url) as json_file:
cases = json.load(json_file)['tables']['surface_thermal_transmittance']['table']
# W/m2K
for case in cases:
surface = \
ConstructionHelper().nrcan_surfaces_types_to_hub_types[f"{case['surface']}_{case['boundary_condition']}"]
thermal_transmittance_per_hdd = []
text = case['formula']
values = ''.join([o for o in list(text) if o not in punc]).split()
for index in range(int((len(values) - 1)/3)):
thermal_transmittance_per_hdd.append([values[3*index+1], values[3*index+2]])
thermal_transmittance_per_hdd.append(['15000', values[len(values)-1]])
self._thermal_transmittance_per_hdd_and_surface[surface] = thermal_transmittance_per_hdd
def _load_windows(self):
_catalog_windows = []
windows = self._constructions['transparent_surfaces']
for window in windows:
name = list(window.keys())[0]
window_id = name
g_value = window[name]['shgc']
window_type = window[name]['type']
frame_ratio = window[name]['frame_ratio']
overall_u_value = window[name]['u_value']
_catalog_windows.append(Window(window_id, frame_ratio, g_value, overall_u_value, name, window_type))
return _catalog_windows
def _load_constructions(self, window_ratio_standard, construction_standard):
constructions = []
# todo: we need to save the total transmittance somehow, we don't do it yet in our archetypes
# todo: it has to be selected the specific thermal_transmittance from
# self._thermal_transmittance_per_hdd_and_surface and window_ratios from self._window_ratios for each standard case
for i, surface_type in enumerate(self._thermal_transmittance_per_hdd_and_surface):
constructions.append(Construction(i, surface_type, None, None, self._window_ratios))
return constructions
def _load_materials(self):
_catalog_materials = []
materials = self._constructions['materials']
for material in materials:
name = list(material.keys())[0]
material_id = name
no_mass = material[name]['no_mass']
thermal_resistance = None
conductivity = None
density = None
specific_heat = None
solar_absorptance = None
thermal_absorptance = None
visible_absorptance = None
if no_mass:
thermal_resistance = material[name]['thermal_resistance']
else:
solar_absorptance = material[name]['solar_absorptance']
thermal_absorptance = str(1 - float(material[name]['thermal_emittance']))
visible_absorptance = material[name]['visible_absorptance']
conductivity = material[name]['conductivity']
density = material[name]['density']
specific_heat = material[name]['specific_heat']
_material = Material(material_id,
name,
solar_absorptance,
thermal_absorptance,
visible_absorptance,
no_mass,
thermal_resistance,
conductivity,
density,
specific_heat)
_catalog_materials.append(_material)
return _catalog_materials
def _load_constructions(self):
_catalog_constructions = []
constructions = self._constructions['opaque_surfaces']
for construction in constructions:
name = list(construction.keys())[0]
construction_id = name
construction_type = ConstructionHelper().nrcan_surfaces_types_to_hub_types[construction[name]['type']]
layers = []
for layer in construction[name]['layers']:
layer_id = layer
layer_name = layer
material_id = layer
thickness = construction[name]['layers'][layer]
for material in self._catalog_materials:
if str(material_id) == str(material.id):
layers.append(Layer(layer_id, layer_name, material, thickness))
break
_catalog_constructions.append(Construction(construction_id, construction_type, name, layers))
return _catalog_constructions
def _load_archetypes(self):
archetypes = []
archetype_id = 0
for window_ratio_standard in self._metadata['nrcan']['standards_per_function']['standard']:
for construction_standard in self._metadata['nrcan']['standards_per_period']['standard']:
archetype_id += 1
function = window_ratio_standard['@function']
climate_zone = 'Montreal'
construction_period = construction_standard['@period_of_construction']
constructions = self._load_constructions(window_ratio_standard, construction_standard)
archetypes.append(Archetype(archetype_id,
None,
function,
climate_zone,
construction_period,
constructions,
None,
None,
None,
None,
None,
None))
return archetypes
_catalog_archetypes = []
archetypes = self._archetypes['archetypes']
for archetype in archetypes:
archetype_id = f'{archetype["function"]}_{archetype["period_of_construction"]}_{archetype["climate_zone"]}'
function = archetype['function']
name = archetype_id
climate_zone = archetype['climate_zone']
construction_period = archetype['period_of_construction']
average_storey_height = archetype['average_storey_height']
thermal_capacity = str(float(archetype['thermal_capacity']) * 1000)
extra_loses_due_to_thermal_bridges = archetype['extra_loses_due_thermal_bridges']
infiltration_rate_for_ventilation_system_off = archetype['infiltration_rate_for_ventilation_system_off']
infiltration_rate_for_ventilation_system_on = archetype['infiltration_rate_for_ventilation_system_on']
archetype_constructions = []
for archetype_construction in archetype['constructions']:
archetype_construction_type = ConstructionHelper().nrcan_surfaces_types_to_hub_types[archetype_construction]
archetype_construction_name = archetype['constructions'][archetype_construction]['opaque_surface_name']
for construction in self._catalog_constructions:
if archetype_construction_type == construction.type and construction.name == archetype_construction_name:
_construction = None
_window = None
_window_ratio = None
if 'transparent_surface_name' in archetype['constructions'][archetype_construction].keys():
_window_ratio = archetype['constructions'][archetype_construction]['transparent_ratio']
_window_id = archetype['constructions'][archetype_construction]['transparent_surface_name']
for window in self._catalog_windows:
if _window_id == window.id:
_window = window
break
_construction = Construction(construction.id,
construction.type,
construction.name,
construction.layers,
_window_ratio,
_window)
archetype_constructions.append(_construction)
break
_catalog_archetypes.append(Archetype(archetype_id,
name,
function,
climate_zone,
construction_period,
archetype_constructions,
average_storey_height,
thermal_capacity,
extra_loses_due_to_thermal_bridges,
None,
infiltration_rate_for_ventilation_system_off,
infiltration_rate_for_ventilation_system_on))
return _catalog_archetypes
def names(self, category=None):
"""
Get the catalog elements names
:parm: for usage catalog category filter does nothing as there is only one category (usages)
:parm: optional category filter
"""
_names = {'usages': []}
for usage in self._content.usages:
_names['usages'].append(usage.name)
if category is None:
_names = {'archetypes': [], 'constructions': [], 'materials': [], 'windows': []}
for archetype in self._content.archetypes:
_names['archetypes'].append(archetype.name)
for construction in self._content.constructions:
_names['constructions'].append(construction.name)
for material in self._content.materials:
_names['materials'].append(material.name)
for window in self._content.windows:
_names['windows'].append(window.name)
else:
_names = {category: []}
if category.lower() == 'archetypes':
for archetype in self._content.archetypes:
_names[category].append(archetype.name)
elif category.lower() == 'constructions':
for construction in self._content.constructions:
_names[category].append(construction.name)
elif category.lower() == 'materials':
for material in self._content.materials:
_names[category].append(material.name)
elif category.lower() == 'windows':
for window in self._content.windows:
_names[category].append(window.name)
else:
raise ValueError(f'Unknown category [{category}]')
return _names
def entries(self, category=None):
"""
Get the catalog elements
:parm: for usage catalog category filter does nothing as there is only one category (usages)
:parm: optional category filter
"""
return self._content
if category is None:
return self._content
else:
if category.lower() == 'archetypes':
return self._content.archetypes
elif category.lower() == 'constructions':
return self._content.constructions
elif category.lower() == 'materials':
return self._content.materials
elif category.lower() == 'windows':
return self._content.windows
else:
raise ValueError(f'Unknown category [{category}]')
def get_entry(self, name):
"""
Get one catalog element by names
:parm: entry name
"""
for usage in self._content.usages:
if usage.name.lower() == name.lower():
return usage
for entry in self._content.archetypes:
if entry.name.lower() == name.lower():
return entry
for entry in self._content.constructions:
if entry.name.lower() == name.lower():
return entry
for entry in self._content.materials:
if entry.name.lower() == name.lower():
return entry
for entry in self._content.windows:
if entry.name.lower() == name.lower():
return entry
raise IndexError(f"{name} doesn't exists in the catalog")

View File

@ -38,7 +38,7 @@ class Archetype:
def id(self):
"""
Get archetype id
:return: int
:return: str
"""
return self._id
@ -85,7 +85,7 @@ class Archetype:
@property
def average_storey_height(self):
"""
Get archetype average storey height
Get archetype average storey height in m
:return: float
"""
return self._average_storey_height
@ -93,23 +93,23 @@ class Archetype:
@property
def thermal_capacity(self):
"""
Get archetype thermal capacity
:return: int
Get archetype thermal capacity in J/m3K
:return: float
"""
return self._thermal_capacity
@property
def extra_loses_due_to_thermal_bridges(self):
"""
Get archetype extra loses due to thermal bridges
:return: int
Get archetype extra loses due to thermal bridges in W/m2K
:return: float
"""
return self._extra_loses_due_to_thermal_bridges
@property
def indirect_heated_ratio(self):
"""
Get archetype indirect heat ratio
Get archetype indirect heated area ratio
:return: float
"""
return self._indirect_heated_ratio
@ -117,7 +117,7 @@ class Archetype:
@property
def infiltration_rate_for_ventilation_system_off(self):
"""
Get archetype infiltration rate for ventilation system off
Get archetype infiltration rate for ventilation system off in ACH
:return: float
"""
return self._infiltration_rate_for_ventilation_system_off
@ -125,7 +125,7 @@ class Archetype:
@property
def infiltration_rate_for_ventilation_system_on(self):
"""
Get archetype infiltration rate for ventilation system on
Get archetype infiltration rate for ventilation system on in ACH
:return: float
"""
return self._infiltration_rate_for_ventilation_system_on

View File

@ -21,7 +21,7 @@ class Construction:
def id(self):
"""
Get construction id
:return: int
:return: str
"""
return self._id
@ -53,7 +53,7 @@ class Construction:
def window_ratio(self):
"""
Get construction window ratio
:return: float
:return: dict
"""
return self._window_ratio

View File

@ -17,7 +17,7 @@ class Layer:
def id(self):
"""
Get layer id
:return: int
:return: str
"""
return self._id

View File

@ -32,7 +32,7 @@ class Material:
def id(self):
"""
Get material id
:return: int
:return: str
"""
return self._id

View File

@ -7,12 +7,13 @@ Project Coder Guille Gutierrez guillermo.gutierrezmorote@concordia.ca
class Window:
def __init__(self, window_id, frame_ratio, g_value, overall_u_value, name):
def __init__(self, window_id, frame_ratio, g_value, overall_u_value, name, window_type=None):
self._id = window_id
self._frame_ratio = frame_ratio
self._g_value = g_value
self._overall_u_value = overall_u_value
self._name = name
self._type = window_type
@property
def id(self):
@ -53,3 +54,11 @@ class Window:
:return: float
"""
return self._overall_u_value
@property
def type(self):
"""
Get transparent surface type, 'window' or 'skylight'
:return: str
"""
return self.type

View File

@ -28,7 +28,7 @@ class Material:
def id(self):
"""
Get material id
:return: int
:return: str
"""
return self._id
@ -36,9 +36,9 @@ class Material:
def id(self, value):
"""
Set material id
:param value: int
:param value: str
"""
self._id = int(value)
self._id = value
@property
def name(self):

View File

@ -120,7 +120,7 @@ class ThermalZone:
@property
def effective_thermal_capacity(self) -> Union[None, float]:
"""
Get thermal zone effective thermal capacity in J/m2K
Get thermal zone effective thermal capacity in J/m3K
:return: None or float
"""
return self._effective_thermal_capacity
@ -128,7 +128,7 @@ class ThermalZone:
@effective_thermal_capacity.setter
def effective_thermal_capacity(self, value):
"""
Set thermal zone effective thermal capacity in J/m2K
Set thermal zone effective thermal capacity in J/m3K
:param value: float
"""
if value is not None:

View File

@ -458,3 +458,5 @@ class City:
:return: LevelOfDetail
"""
return self._level_of_detail

View File

@ -5,11 +5,13 @@ Copyright © 2022 Concordia CERC group
Project Coder Guille Gutierrez guillermo.gutierrezmorote@concordia.ca
"""
from __future__ import annotations
from typing import List, Union
from hub.city_model_structure.iot.sensor import Sensor
from hub.city_model_structure.building_demand.surface import Surface
from hub.city_model_structure.attributes.polyhedron import Polyhedron
from hub.helpers.configuration_helper import ConfigurationHelper
@ -225,3 +227,17 @@ class CityObject:
:param value: [Sensor]
"""
self._sensors = value
@property
def neighbours(self) -> Union[None, List[CityObject]]:
"""
Get the list of neighbour_objects and their properties associated to the current city_object
"""
return self._neighbours
@neighbours.setter
def neighbours(self, value):
"""
Set the list of neighbour_objects and their properties associated to the current city_object
"""
self._neighbours = value

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@ -71,9 +71,10 @@ class InselMonthlyEnergyBalance(Insel):
internal_zone = building.internal_zones[0]
thermal_zone = internal_zone.thermal_zones[0]
parameters.append(f'{thermal_zone.indirectly_heated_area_ratio} % BP(6) Indirectly heated area ratio')
parameters.append(f'{thermal_zone.effective_thermal_capacity / 3600} % BP(7) Effective heat capacity (Wh/m2K)')
parameters.append(f'{thermal_zone.effective_thermal_capacity / 3600 / building.average_storey_height}'
f' % BP(7) Effective heat capacity (Wh/m2K)')
parameters.append(f'{thermal_zone.additional_thermal_bridge_u_value} '
f'% BP(8) Additional U-value for heat bridge (Wh/m2K)')
f'% BP(8) Additional U-value for heat bridge (W/m2K)')
parameters.append('1 % BP(9) Usage type (0=standard, 1=IWU)')
# ZONES AND SURFACES

View File

@ -13,8 +13,14 @@ from trimesh import intersections
from hub.city_model_structure.attributes.polygon import Polygon
from hub.city_model_structure.attributes.polyhedron import Polyhedron
from hub.helpers.location import Location
from hub.helpers.configuration_helper import ConfigurationHelper
class MapPoint:
def __init__(self, x, y):
self.x = int(x)
self.y = int(y)
def __str__(self):
return f'({self.x}, {self.y})'
class GeometryHelper:
"""
@ -29,15 +35,76 @@ class GeometryHelper:
self._area_delta = area_delta
@staticmethod
def adjacent_locations(location1, location2):
"""
Determine when two attributes may be adjacent or not based in the dis
:param location1:
:param location2:
:return: Boolean
"""
max_distance = ConfigurationHelper().max_location_distance_for_shared_walls
return GeometryHelper.distance_between_points(location1, location2) < max_distance
def coordinate_to_map_point(coordinate, city):
return MapPoint((city.upper_corner[0] - coordinate[0])/2, (city.upper_corner[1] - coordinate[1])/2)
@staticmethod
def point_between_point(point_1, point_2, x):
m = (point_1.y - point_2.y)/(point_1.x - point_2.x)
c = point_2.y - (m*point_2.x)
y = (m*x)+c
return MapPoint(x,y)
@staticmethod
def city_mapping(city, building_names=None):
if building_names is None:
building_names = [b.name for b in city.buildings]
x = int((city.upper_corner[0] - city.lower_corner[0]) / 2)
y = int((city.upper_corner[1] - city.lower_corner[1]) / 2)
city_map = [['' for _ in range(y+1)] for _ in range(x+1)]
city_image = [[0 for _ in range(y+1)] for _ in range(x+1)]
for building_name in building_names:
building = city.city_object(building_name)
for ground in building.grounds:
length = len(ground.perimeter_polygon.coordinates) - 1
for i, coordinate in enumerate(ground.perimeter_polygon.coordinates):
j = i+1
if i == length:
j = 0
next_coordinate = ground.perimeter_polygon.coordinates[j]
point_1 = GeometryHelper.coordinate_to_map_point(coordinate, city)
point_2 = GeometryHelper.coordinate_to_map_point(next_coordinate, city)
for x in range(point_1.x, point_2.x):
y = GeometryHelper.point_between_point(point_1, point_2, x).y
if city_map[x][y] == '':
city_map[x][y] = building.name
city_image[x][y] = 1
elif city_map[x][y] != building.name:
neighbour = city.city_object(city_map[x][y])
if building.neighbours is None:
building.neighbours = [neighbour]
elif neighbour not in building.neighbours:
building.neighbours.append(neighbour)
if neighbour.neighbours is None:
neighbour.neighbours = [building]
elif building not in neighbour.neighbours:
neighbour.neighbours.append(building)
"""
x = int((city.upper_corner[0] - coordinate[0]) / 2)
y = int((city.upper_corner[1] - coordinate[1]) / 2)
if city_map[x][y] == '':
city_map[x][y] = building.name
city_image[x][y] = 1
elif city_map[x][y] != building.name:
neighbour = city.city_object(city_map[x][y])
if building.neighbours is None:
building.neighbours = [neighbour]
elif neighbour not in building.neighbours:
building.neighbours.append(neighbour)
if neighbour.neighbours is None:
neighbour.neighbours = [building]
elif building not in neighbour.neighbours:
neighbour.neighbours.append(building)
"""
@staticmethod
def segment_list_to_trimesh(lines) -> Trimesh:

View File

@ -47,6 +47,10 @@ class ConstructionHelper:
cte.ROOF: 'roof'
}
_reference_city_to_nrcan_climate_zone = {
'Montreal': '6'
}
@staticmethod
def yoc_to_nrel_standard(year_of_construction):
"""
@ -68,9 +72,9 @@ class ConstructionHelper:
:return: str
"""
# todo: Dummy function that needs to be implemented
reference_city = 'Baltimore'
reference_city = 'Montreal'
if city is not None:
reference_city = 'Baltimore'
reference_city = 'Montreal'
return reference_city
@staticmethod
@ -80,5 +84,15 @@ class ConstructionHelper:
:param city: str
:return: str
"""
reference_city = ConstructionHelper.city_to_reference_city(city)
reference_city = 'Baltimore'
return ConstructionHelper._reference_city_to_nrel_climate_zone[reference_city]
@staticmethod
def city_to_nrcan_climate_zone(city):
"""
City name to NRCAN climate zone
:param city: str
:return: str
"""
reference_city = ConstructionHelper.city_to_reference_city(city)
return ConstructionHelper._reference_city_to_nrcan_climate_zone[reference_city]

View File

@ -4,8 +4,10 @@ SPDX - License - Identifier: LGPL - 3.0 - or -later
Copyright © 2022 Concordia CERC group
Project Coder Pilar Monsalvete Alvarez de Uribarri pilar.monsalvete@concordia.ca
"""
import math
import sys
import hub.helpers.constants as cte
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
@ -22,25 +24,23 @@ class NrcanPhysicsParameters:
self._city = city
self._path = base_path
self._divide_in_storeys = divide_in_storeys
self._climate_zone = ConstructionHelper.city_to_nrel_climate_zone(city.name)
self._climate_zone = ConstructionHelper.city_to_nrcan_climate_zone(city.name)
def enrich_buildings(self):
"""
Returns the city with the construction parameters assigned to the buildings
"""
city = self._city
canel_catalog = ConstructionCatalogFactory('nrcan').catalog
nrcan_catalog = ConstructionCatalogFactory('nrcan').catalog
for building in city.buildings:
try:
function = Dictionaries().hub_function_to_nrcan_construction_function[building.function]
archetype = self._search_archetype(canel_catalog, function, building.year_of_construction,
self._climate_zone)
archetype = self._search_archetype(nrcan_catalog, function, building.year_of_construction, self._climate_zone)
except KeyError:
sys.stderr.write(f'Building {building.name} has unknown construction archetype for building function: '
f'{building.function} and building year of construction: {building.year_of_construction} '
f'and climate zone reference norm {self._climate_zone}\n')
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
if len(building.internal_zones) == 1:
@ -65,12 +65,10 @@ class NrcanPhysicsParameters:
self._calculate_view_factors(thermal_zone)
@staticmethod
def _search_archetype(nrel_catalog, function, year_of_construction, climate_zone):
nrel_archetypes = nrel_catalog.entries('archetypes')
for building_archetype in nrel_archetypes:
construction_period_limits = building_archetype.construction_period.split(' - ')
if construction_period_limits[1] == 'PRESENT':
construction_period_limits[1] = 3000
def _search_archetype(nrcan_catalog, function, year_of_construction, climate_zone):
nrcan_archetypes = nrcan_catalog.entries('archetypes')
for building_archetype in nrcan_archetypes:
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)):
@ -96,7 +94,21 @@ class NrcanPhysicsParameters:
construction_archetype = self._search_construction_in_archetype(archetype, thermal_boundary.type)
thermal_boundary.construction_name = construction_archetype.name
try:
thermal_boundary.window_ratio = construction_archetype.window_ratio
thermal_boundary.window_ratio = 0
if thermal_boundary.type == cte.WALL or thermal_boundary.type == cte.ROOF:
if construction_archetype.window is not None:
if math.pi / 4 <= thermal_boundary.parent_surface.azimuth < 3 * math.pi / 4:
thermal_boundary.window_ratio = \
float(construction_archetype.window_ratio['east']) / 100
elif 3 * math.pi / 4 <= thermal_boundary.parent_surface.azimuth < 5 * math.pi / 4:
thermal_boundary.window_ratio = \
float(construction_archetype.window_ratio['south']) / 100
elif 5 * math.pi / 4 <= thermal_boundary.parent_surface.azimuth < 7 * math.pi / 4:
thermal_boundary.window_ratio = \
float(construction_archetype.window_ratio['west']) / 100
else:
thermal_boundary.window_ratio = \
float(construction_archetype.window_ratio['north']) / 100
except ValueError:
# This is the normal operation way when the windows are defined in the geometry
continue

View File

@ -3,6 +3,7 @@ TestConstructionCatalog
SPDX - License - Identifier: LGPL - 3.0 - or -later
Copyright © 2022 Concordia CERC group
Project Coder Guille Gutierrez guillermo.gutierrezmorote@concordia.ca
Contributors Pilar Monsalvete Alvarez de Uribarri pilar.monsalvete@concordia.ca
"""
from unittest import TestCase
@ -17,9 +18,29 @@ class TestConstructionCatalog(TestCase):
constructions = catalog.names('constructions')
windows = catalog.names('windows')
materials = catalog.names('materials')
self.assertTrue(len(constructions['constructions']), 24)
self.assertTrue(len(windows['windows']), 4)
self.assertTrue(len(materials['materials']), 19)
self.assertEqual(24, len(constructions['constructions']))
self.assertEqual(4, len(windows['windows']))
self.assertEqual(19, len(materials['materials']))
with self.assertRaises(ValueError):
catalog.names('unknown')
# retrieving all the entries should not raise any exceptions
for category in catalog_categories:
for value in catalog_categories[category]:
catalog.get_entry(value)
with self.assertRaises(IndexError):
catalog.get_entry('unknown')
def test_nrcan_catalog(self):
catalog = ConstructionCatalogFactory('nrcan').catalog
catalog_categories = catalog.names()
constructions = catalog.names('constructions')
windows = catalog.names('windows')
materials = catalog.names('materials')
self.assertEqual(180, len(constructions['constructions']))
self.assertEqual(36, len(windows['windows']))
self.assertEqual(192, len(materials['materials']))
with self.assertRaises(ValueError):
catalog.names('unknown')

View File

@ -113,8 +113,6 @@ class TestConstructionFactory(TestCase):
self.assertTrue(len(thermal_zone.thermal_boundaries) > 0, 'thermal_zone thermal_boundaries not defined')
self.assertIsNotNone(thermal_zone.additional_thermal_bridge_u_value, 'additional_thermal_bridge_u_value is none')
self.assertIsNotNone(thermal_zone.effective_thermal_capacity, 'thermal_zone effective_thermal_capacity is none')
self.assertIsNotNone(thermal_zone.indirectly_heated_area_ratio,
'thermal_zone indirectly_heated_area_ratio is none')
self.assertIsNotNone(thermal_zone.infiltration_rate_system_off,
'thermal_zone infiltration_rate_system_off is none')
self.assertIsNotNone(thermal_zone.infiltration_rate_system_on, 'thermal_zone infiltration_rate_system_on is none')
@ -153,7 +151,7 @@ class TestConstructionFactory(TestCase):
def _check_thermal_openings(self, thermal_boundary):
for thermal_opening in thermal_boundary.thermal_openings:
self.assertIsNotNone(thermal_opening.id, 'thermal opening id is not none')
self.assertIsNotNone(thermal_opening.construction_name, 'thermal opening construction is not none')
self.assertIsNotNone(thermal_opening.construction_name, 'thermal opening construction is none')
self.assertIsNotNone(thermal_opening.area, 'thermal opening area is not none')
self.assertIsNotNone(thermal_opening.frame_ratio, 'thermal opening frame_ratio is none')
self.assertIsNotNone(thermal_opening.g_value, 'thermal opening g_value is none')
@ -176,10 +174,64 @@ class TestConstructionFactory(TestCase):
"""
Enrich the city with the construction information and verify it
"""
file = 'one_building_in_kelowna.gml'
city = self._get_citygml(file)
for building in city.buildings:
building.year_of_construction = 1980
building.function = self._internal_function('hft', building.function)
ConstructionFactory('nrcan', city).enrich()
self._check_buildings(city)
for building in city.buildings:
for internal_zone in building.internal_zones:
self._check_thermal_zones(internal_zone)
for thermal_zone in internal_zone.thermal_zones:
self._check_thermal_boundaries(thermal_zone)
for thermal_boundary in thermal_zone.thermal_boundaries:
self.assertIsNotNone(thermal_boundary.layers, 'layers is none')
self._check_thermal_openings(thermal_boundary)
self._check_surfaces(thermal_boundary)
file = 'pluto_building.gml'
city = self._get_citygml(file)
for building in city.buildings:
building.year_of_construction = 2005
building.year_of_construction = 1980
building.function = self._internal_function('pluto', building.function)
ConstructionFactory('nrcan', city).enrich()
self._check_buildings(city)
for building in city.buildings:
for internal_zone in building.internal_zones:
self._check_thermal_zones(internal_zone)
for thermal_zone in internal_zone.thermal_zones:
self._check_thermal_boundaries(thermal_zone)
for thermal_boundary in thermal_zone.thermal_boundaries:
self.assertIsNotNone(thermal_boundary.layers, 'layers is none')
self._check_thermal_openings(thermal_boundary)
self._check_surfaces(thermal_boundary)
file = 'one_building_in_kelowna.gml'
city = self._get_citygml(file)
for building in city.buildings:
building.year_of_construction = 2006
building.function = self._internal_function('hft', building.function)
ConstructionFactory('nrel', city).enrich()
self._check_buildings(city)
for building in city.buildings:
for internal_zone in building.internal_zones:
self._check_thermal_zones(internal_zone)
for thermal_zone in internal_zone.thermal_zones:
self._check_thermal_boundaries(thermal_zone)
for thermal_boundary in thermal_zone.thermal_boundaries:
self.assertIsNotNone(thermal_boundary.layers, 'layers is none')
self._check_thermal_openings(thermal_boundary)
self._check_surfaces(thermal_boundary)
file = 'pluto_building.gml'
city = self._get_citygml(file)
for building in city.buildings:
building.year_of_construction = 2006
building.function = self._internal_function('pluto', building.function)
ConstructionFactory('nrel', city).enrich()
@ -194,6 +246,45 @@ class TestConstructionFactory(TestCase):
self._check_thermal_openings(thermal_boundary)
self._check_surfaces(thermal_boundary)
file = 'one_building_in_kelowna.gml'
city = self._get_citygml(file)
for building in city.buildings:
building.year_of_construction = 1980
building.function = self._internal_function('hft', building.function)
ConstructionFactory('nrcan', city).enrich()
self._check_buildings(city)
for building in city.buildings:
for internal_zone in building.internal_zones:
self._check_thermal_zones(internal_zone)
for thermal_zone in internal_zone.thermal_zones:
self._check_thermal_boundaries(thermal_zone)
for thermal_boundary in thermal_zone.thermal_boundaries:
self.assertIsNotNone(thermal_boundary.layers, 'layers is none')
self._check_thermal_openings(thermal_boundary)
self._check_surfaces(thermal_boundary)
file_path = (self._example_path / 'concordia.geojson').resolve()
self._city = GeometryFactory('geojson',
path=file_path,
height_field='citygml_me',
year_of_construction_field='ANNEE_CONS',
function_field='LIBELLE_UT',
function_to_hub=Dictionaries().montreal_function_to_hub_function).city
ConstructionFactory('nrcan', city).enrich()
self._check_buildings(city)
for building in city.buildings:
for internal_zone in building.internal_zones:
self._check_thermal_zones(internal_zone)
for thermal_zone in internal_zone.thermal_zones:
self._check_thermal_boundaries(thermal_zone)
for thermal_boundary in thermal_zone.thermal_boundaries:
self.assertIsNotNone(thermal_boundary.layers, 'layers is none')
self._check_thermal_openings(thermal_boundary)
self._check_surfaces(thermal_boundary)
def test_archetype_not_found(self):
file = 'pluto_building.gml'
city = self._get_citygml(file)

View File

@ -4,8 +4,10 @@ SPDX - License - Identifier: LGPL - 3.0 - or -later
Copyright © 2022 Concordia CERC group
Project Coder Pilar Monsalvete Alvarez de Uribarri pilar.monsalvete@concordia.ca
"""
import datetime
from pathlib import Path
from unittest import TestCase
from hub.helpers.geometry_helper import GeometryHelper
from numpy import inf
@ -146,3 +148,26 @@ class TestGeometryFactory(TestCase):
hub.exports.exports_factory.ExportsFactory('obj', city, self._output_path).export()
self.assertEqual(207, len(city.buildings), 'wrong number of buildings')
self._check_buildings(city)
def test_map_neighbours(self):
"""
Test neighbours map creation
"""
start = datetime.datetime.now()
file = 'concordia.geojson'
city = self._get_city(file, 'geojson',
height_field='citygml_me',
year_of_construction_field='ANNEE_CONS',
function_field='LIBELLE_UT')
city_end = datetime.datetime.now()
print(f'city load {city_end-start}')
GeometryHelper.city_mapping(city)
end = datetime.datetime.now()
print(f'city map {end-city_end}')
for building in city.buildings:
if building.neighbours is not None:
print(f'{building.name} [{[b.name for b in building.neighbours]}]')
else:
print(f'{building.name} has no neighbours')
self.assertTrue(False)