added nrcan catalog

This commit is contained in:
Pilar 2023-02-21 10:14:55 -05:00
parent bdc8598bc6
commit 8469674b18
7 changed files with 23547 additions and 24586 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

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

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

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

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