Merge branch 'nrcan_catalog_importer' into 'master'

Nrcan catalog importer

See merge request Guille/hub!57
This commit is contained in:
Guillermo Gutierrez Morote 2023-02-22 13:37:26 +00:00
commit 804648a9f0
18 changed files with 22218 additions and 25063 deletions

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -17,9 +17,6 @@ class Plane:
""" """
def __init__(self, origin, normal): def __init__(self, origin, normal):
# todo: other options to define the plane:
# by two lines
# by three points
self._origin = origin self._origin = origin
self._normal = normal self._normal = normal
self._equation = None self._equation = None

View File

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

View File

@ -287,7 +287,6 @@ class Surface:
""" """
Raises not implemented error Raises not implemented error
""" """
# todo: check https://trimsh.org/trimesh.collision.html as an option to implement this method
raise NotImplementedError raise NotImplementedError
def divide(self, z): def divide(self, z):

View File

@ -120,7 +120,7 @@ class ThermalZone:
@property @property
def effective_thermal_capacity(self) -> Union[None, float]: 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: None or float
""" """
return self._effective_thermal_capacity return self._effective_thermal_capacity
@ -128,7 +128,7 @@ class ThermalZone:
@effective_thermal_capacity.setter @effective_thermal_capacity.setter
def effective_thermal_capacity(self, value): 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 :param value: float
""" """
if value is not None: if value is not None:

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] internal_zone = building.internal_zones[0]
thermal_zone = internal_zone.thermal_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.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} ' 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)') parameters.append('1 % BP(9) Usage type (0=standard, 1=IWU)')
# ZONES AND SURFACES # ZONES AND SURFACES

View File

@ -47,6 +47,10 @@ class ConstructionHelper:
cte.ROOF: 'roof' cte.ROOF: 'roof'
} }
_reference_city_to_nrcan_climate_zone = {
'Montreal': '6'
}
@staticmethod @staticmethod
def yoc_to_nrel_standard(year_of_construction): def yoc_to_nrel_standard(year_of_construction):
""" """
@ -68,9 +72,9 @@ class ConstructionHelper:
:return: str :return: str
""" """
# todo: Dummy function that needs to be implemented # todo: Dummy function that needs to be implemented
reference_city = 'Baltimore' reference_city = 'Montreal'
if city is not None: if city is not None:
reference_city = 'Baltimore' reference_city = 'Montreal'
return reference_city return reference_city
@staticmethod @staticmethod
@ -80,5 +84,15 @@ class ConstructionHelper:
:param city: str :param city: str
:return: str :return: str
""" """
reference_city = ConstructionHelper.city_to_reference_city(city) reference_city = 'Baltimore'
return ConstructionHelper._reference_city_to_nrel_climate_zone[reference_city] 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 Copyright © 2022 Concordia CERC group
Project Coder Pilar Monsalvete Alvarez de Uribarri pilar.monsalvete@concordia.ca Project Coder Pilar Monsalvete Alvarez de Uribarri pilar.monsalvete@concordia.ca
""" """
import math
import sys import sys
import hub.helpers.constants as cte
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
@ -22,25 +24,23 @@ class NrcanPhysicsParameters:
self._city = city self._city = city
self._path = base_path self._path = base_path
self._divide_in_storeys = divide_in_storeys 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): def enrich_buildings(self):
""" """
Returns the city with the construction parameters assigned to the buildings Returns the city with the construction parameters assigned to the buildings
""" """
city = self._city city = self._city
canel_catalog = ConstructionCatalogFactory('nrcan').catalog nrcan_catalog = ConstructionCatalogFactory('nrcan').catalog
for building in city.buildings: for building in city.buildings:
try: try:
function = Dictionaries().hub_function_to_nrcan_construction_function[building.function] function = Dictionaries().hub_function_to_nrcan_construction_function[building.function]
archetype = self._search_archetype(canel_catalog, function, building.year_of_construction, archetype = self._search_archetype(nrcan_catalog, function, building.year_of_construction, self._climate_zone)
self._climate_zone)
except KeyError: except KeyError:
sys.stderr.write(f'Building {building.name} has unknown construction archetype for building function: ' 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'{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 return
# if building has no thermal zones defined from geometry, and the building will be divided in storeys, # if building has no thermal zones defined from geometry, and the building will be divided in storeys,
# one thermal zone per storey is assigned # one thermal zone per storey is assigned
if len(building.internal_zones) == 1: if len(building.internal_zones) == 1:
@ -65,12 +65,10 @@ class NrcanPhysicsParameters:
self._calculate_view_factors(thermal_zone) self._calculate_view_factors(thermal_zone)
@staticmethod @staticmethod
def _search_archetype(nrel_catalog, function, year_of_construction, climate_zone): def _search_archetype(nrcan_catalog, function, year_of_construction, climate_zone):
nrel_archetypes = nrel_catalog.entries('archetypes') nrcan_archetypes = nrcan_catalog.entries('archetypes')
for building_archetype in nrel_archetypes: for building_archetype in nrcan_archetypes:
construction_period_limits = building_archetype.construction_period.split(' - ') construction_period_limits = building_archetype.construction_period.split('_')
if construction_period_limits[1] == 'PRESENT':
construction_period_limits[1] = 3000
if int(construction_period_limits[0]) <= int(year_of_construction) < int(construction_period_limits[1]): if int(construction_period_limits[0]) <= int(year_of_construction) < int(construction_period_limits[1]):
if (str(function) == str(building_archetype.function)) and \ if (str(function) == str(building_archetype.function)) and \
(climate_zone == str(building_archetype.climate_zone)): (climate_zone == str(building_archetype.climate_zone)):
@ -96,7 +94,21 @@ class NrcanPhysicsParameters:
construction_archetype = self._search_construction_in_archetype(archetype, thermal_boundary.type) construction_archetype = self._search_construction_in_archetype(archetype, thermal_boundary.type)
thermal_boundary.construction_name = construction_archetype.name thermal_boundary.construction_name = construction_archetype.name
try: 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: except ValueError:
# This is the normal operation way when the windows are defined in the geometry # This is the normal operation way when the windows are defined in the geometry
continue continue

View File

@ -3,6 +3,7 @@ TestConstructionCatalog
SPDX - License - Identifier: LGPL - 3.0 - or -later SPDX - License - Identifier: LGPL - 3.0 - or -later
Copyright © 2022 Concordia CERC group Copyright © 2022 Concordia CERC group
Project Coder Guille Gutierrez guillermo.gutierrezmorote@concordia.ca Project Coder Guille Gutierrez guillermo.gutierrezmorote@concordia.ca
Contributors Pilar Monsalvete Alvarez de Uribarri pilar.monsalvete@concordia.ca
""" """
from unittest import TestCase from unittest import TestCase
@ -17,9 +18,29 @@ class TestConstructionCatalog(TestCase):
constructions = catalog.names('constructions') constructions = catalog.names('constructions')
windows = catalog.names('windows') windows = catalog.names('windows')
materials = catalog.names('materials') materials = catalog.names('materials')
self.assertTrue(len(constructions['constructions']), 24) self.assertEqual(24, len(constructions['constructions']))
self.assertTrue(len(windows['windows']), 4) self.assertEqual(4, len(windows['windows']))
self.assertTrue(len(materials['materials']), 19) 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): with self.assertRaises(ValueError):
catalog.names('unknown') 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.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.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.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, self.assertIsNotNone(thermal_zone.infiltration_rate_system_off,
'thermal_zone infiltration_rate_system_off is none') 'thermal_zone infiltration_rate_system_off is none')
self.assertIsNotNone(thermal_zone.infiltration_rate_system_on, 'thermal_zone infiltration_rate_system_on 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): def _check_thermal_openings(self, thermal_boundary):
for thermal_opening in thermal_boundary.thermal_openings: for thermal_opening in thermal_boundary.thermal_openings:
self.assertIsNotNone(thermal_opening.id, 'thermal opening id is not none') 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.area, 'thermal opening area is not none')
self.assertIsNotNone(thermal_opening.frame_ratio, 'thermal opening frame_ratio is 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') 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 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' file = 'pluto_building.gml'
city = self._get_citygml(file) city = self._get_citygml(file)
for building in city.buildings: 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) building.function = self._internal_function('pluto', building.function)
ConstructionFactory('nrel', city).enrich() ConstructionFactory('nrel', city).enrich()
@ -194,6 +246,45 @@ class TestConstructionFactory(TestCase):
self._check_thermal_openings(thermal_boundary) self._check_thermal_openings(thermal_boundary)
self._check_surfaces(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): def test_archetype_not_found(self):
file = 'pluto_building.gml' file = 'pluto_building.gml'
city = self._get_citygml(file) city = self._get_citygml(file)