Compare commits
No commits in common. "d6032b06a46772187a21b116360b95314e8bd066" and "faa2c772bae5b77f30e8954b841e2f2c971c4996" have entirely different histories.
d6032b06a4
...
faa2c772ba
@ -27,7 +27,7 @@ class Building(CityObject):
|
||||
"""
|
||||
Building(CityObject) class
|
||||
"""
|
||||
def __init__(self, name, surfaces, year_of_construction, function, usages=None, terrains=None, city=None):
|
||||
def __init__(self, name, surfaces, year_of_construction, function, terrains=None, city=None):
|
||||
super().__init__(name, surfaces)
|
||||
self._city = city
|
||||
self._households = None
|
||||
@ -36,7 +36,6 @@ class Building(CityObject):
|
||||
self._terrains = terrains
|
||||
self._year_of_construction = year_of_construction
|
||||
self._function = function
|
||||
self._usages = usages
|
||||
self._average_storey_height = None
|
||||
self._storeys_above_ground = None
|
||||
self._floor_area = None
|
||||
@ -258,17 +257,7 @@ class Building(CityObject):
|
||||
:param value: str
|
||||
"""
|
||||
if value is not None:
|
||||
self._function = value
|
||||
|
||||
@property
|
||||
def usages(self) -> Union[None, list]:
|
||||
"""
|
||||
Get building usages, if none, assume usage is function
|
||||
:return: None or list of functions
|
||||
"""
|
||||
if self._usages is None and self._function is not None:
|
||||
self._usages = [{'usage': self._function, 'ratio': 1 }]
|
||||
return self._usages
|
||||
self._function = str(value)
|
||||
|
||||
@property
|
||||
def average_storey_height(self) -> Union[None, float]:
|
||||
@ -605,6 +594,19 @@ class Building(CityObject):
|
||||
"""
|
||||
self._city = value
|
||||
|
||||
@property
|
||||
def usages_percentage(self):
|
||||
"""
|
||||
Get the usages and percentages for the building
|
||||
"""
|
||||
_usage = ''
|
||||
for internal_zone in self.internal_zones:
|
||||
if internal_zone.usages is None:
|
||||
continue
|
||||
for usage in internal_zone.usages:
|
||||
_usage = f'{_usage}{usage.name}_{usage.percentage} '
|
||||
return _usage.rstrip()
|
||||
|
||||
@property
|
||||
def energy_systems(self) -> Union[None, List[EnergySystem]]:
|
||||
"""
|
||||
|
@ -34,7 +34,7 @@ class ThermalZone:
|
||||
volume,
|
||||
footprint_area,
|
||||
number_of_storeys,
|
||||
usages=None):
|
||||
usage_name=None):
|
||||
self._id = None
|
||||
self._parent_internal_zone = parent_internal_zone
|
||||
self._footprint_area = footprint_area
|
||||
@ -51,6 +51,10 @@ class ThermalZone:
|
||||
self._view_factors_matrix = None
|
||||
self._total_floor_area = None
|
||||
self._number_of_storeys = number_of_storeys
|
||||
self._usage_name = usage_name
|
||||
self._usage_from_parent = False
|
||||
if usage_name is None:
|
||||
self._usage_from_parent = True
|
||||
self._hours_day = None
|
||||
self._days_year = None
|
||||
self._mechanical_air_change = None
|
||||
@ -60,12 +64,7 @@ class ThermalZone:
|
||||
self._internal_gains = None
|
||||
self._thermal_control = None
|
||||
self._domestic_hot_water = None
|
||||
self._usage_name = None
|
||||
self._usages = usages
|
||||
self._usage_from_parent = False
|
||||
if usages is None:
|
||||
self._usage_from_parent = True
|
||||
|
||||
self._usages = None
|
||||
|
||||
@property
|
||||
def parent_internal_zone(self) -> InternalZone:
|
||||
@ -78,11 +77,24 @@ class ThermalZone:
|
||||
@property
|
||||
def usages(self):
|
||||
"""
|
||||
Get the thermal zone usages
|
||||
Get the thermal zone usages including percentage with the format [percentage]-usage_[percentage]-usage...
|
||||
Eg: 70-office_30-residential
|
||||
:return: str
|
||||
"""
|
||||
if self._usage_from_parent:
|
||||
self._usages = copy.deepcopy(self._parent_internal_zone.usages)
|
||||
else:
|
||||
values = self._usage_name.split('_')
|
||||
usages = []
|
||||
for value in values:
|
||||
usages.append(value.split('-'))
|
||||
self._usages = []
|
||||
for parent_usage in self._parent_internal_zone.usages:
|
||||
for value in usages:
|
||||
if parent_usage.name == value[1]:
|
||||
new_usage = copy.deepcopy(parent_usage)
|
||||
new_usage.percentage = float(value[0]) / 100
|
||||
self._usages.append(new_usage)
|
||||
return self._usages
|
||||
|
||||
@property
|
||||
|
@ -1,31 +0,0 @@
|
||||
|
||||
class ListUsageToHub:
|
||||
"""
|
||||
Eilat function to hub function class
|
||||
"""
|
||||
|
||||
def __init__(self, function_dictionary=None):
|
||||
self._function_dictionary = function_dictionary
|
||||
|
||||
def _apply_function_dictionary(self, usages):
|
||||
|
||||
function_dictionary = self._function_dictionary
|
||||
|
||||
if function_dictionary is not None:
|
||||
for usage in usages:
|
||||
if usage['usage'] in function_dictionary:
|
||||
usage['usage'] = function_dictionary[usage['usage']]
|
||||
|
||||
return usages
|
||||
|
||||
def parse(self, usages) -> list[dict]:
|
||||
"""
|
||||
Get the dictionary
|
||||
:return: {}
|
||||
"""
|
||||
|
||||
usages = [{"usage": str(i["usage"]), "ratio": float(i["ratio"])} for i in usages]
|
||||
|
||||
usages = self._apply_function_dictionary(usages)
|
||||
|
||||
return usages
|
@ -1,19 +0,0 @@
|
||||
|
||||
class StringUsageToHub:
|
||||
"""
|
||||
Eilat function to hub function class
|
||||
"""
|
||||
|
||||
def parse(self, usages) -> list[dict]:
|
||||
"""
|
||||
Parse usage string in form residential-80_commercial-20
|
||||
:usages: str
|
||||
:return: {}
|
||||
"""
|
||||
|
||||
parsed_usages = []
|
||||
for usage in usages.split('_'):
|
||||
usage_dict = {"usage": str(usage.split('-')[0]), "ratio": float(usage.split('-')[1])/100}
|
||||
parsed_usages.append(usage_dict)
|
||||
|
||||
return parsed_usages
|
@ -1,31 +0,0 @@
|
||||
"""
|
||||
Dictionaries module saves all transformations of functions and usages to access the catalogs
|
||||
SPDX - License - Identifier: LGPL - 3.0 - or -later
|
||||
Copyright © 2023 Concordia CERC group
|
||||
Project Coder Pilar Monsalvete Alvarez de Uribarri pilar.monsalvete@concordia.ca
|
||||
"""
|
||||
|
||||
from hub.helpers.parsers.list_usage_to_hub import ListUsageToHub
|
||||
from hub.helpers.parsers.string_usage_to_hub import StringUsageToHub
|
||||
|
||||
class UsageParsers:
|
||||
"""
|
||||
Dictionaries class
|
||||
"""
|
||||
|
||||
@staticmethod
|
||||
def string_usage_to_hub() -> object:
|
||||
"""
|
||||
Hub usage to HfT usage, transformation dictionary
|
||||
:return: dict
|
||||
"""
|
||||
return StringUsageToHub().parse
|
||||
|
||||
@staticmethod
|
||||
def list_usage_to_hub(function_dictionary=None) -> object:
|
||||
"""
|
||||
Hub usage to HfT usage, transformation dictionary
|
||||
:return: dict
|
||||
"""
|
||||
return ListUsageToHub(function_dictionary).parse
|
||||
|
@ -33,10 +33,21 @@ class NrcanPhysicsParameters:
|
||||
city = self._city
|
||||
nrcan_catalog = ConstructionCatalogFactory('nrcan').catalog
|
||||
for building in city.buildings:
|
||||
if building.function not in Dictionaries().hub_function_to_nrcan_construction_function:
|
||||
logging.error('Building %s has an unknown building function %s', building.name, building.function)
|
||||
main_function = None
|
||||
functions = building.function.split('_')
|
||||
if len(functions) > 1:
|
||||
maximum_percentage = 0
|
||||
for function in functions:
|
||||
percentage_and_function = function.split('-')
|
||||
if float(percentage_and_function[0]) > maximum_percentage:
|
||||
maximum_percentage = float(percentage_and_function[0])
|
||||
main_function = percentage_and_function[-1]
|
||||
else:
|
||||
main_function = functions[-1]
|
||||
if main_function not in Dictionaries().hub_function_to_nrcan_construction_function:
|
||||
logging.error('Building %s has an unknown building function %s', building.name, main_function)
|
||||
continue
|
||||
function = Dictionaries().hub_function_to_nrcan_construction_function[building.function]
|
||||
function = Dictionaries().hub_function_to_nrcan_construction_function[main_function]
|
||||
try:
|
||||
archetype = self._search_archetype(nrcan_catalog, function, building.year_of_construction, self._climate_zone)
|
||||
|
||||
|
@ -35,8 +35,6 @@ class Geojson:
|
||||
year_of_construction_field=None,
|
||||
function_field=None,
|
||||
function_to_hub=None,
|
||||
usages_field=None,
|
||||
usages_to_hub=None,
|
||||
hub_crs=None
|
||||
):
|
||||
self._hub_crs = hub_crs
|
||||
@ -54,8 +52,6 @@ class Geojson:
|
||||
self._year_of_construction_field = year_of_construction_field
|
||||
self._function_field = function_field
|
||||
self._function_to_hub = function_to_hub
|
||||
self._usages_field = usages_field
|
||||
self._usages_to_hub = usages_to_hub
|
||||
with open(path, 'r', encoding='utf8') as json_file:
|
||||
self._geojson = json.loads(json_file.read())
|
||||
|
||||
@ -121,30 +117,41 @@ class Geojson:
|
||||
lod = 0
|
||||
for feature in self._geojson['features']:
|
||||
extrusion_height = 0
|
||||
|
||||
if self._extrusion_height_field is not None:
|
||||
extrusion_height = float(feature['properties'][self._extrusion_height_field])
|
||||
lod = 1
|
||||
self._max_z = max(self._max_z, extrusion_height)
|
||||
year_of_construction = None
|
||||
|
||||
if self._year_of_construction_field is not None:
|
||||
year_of_construction = int(feature['properties'][self._year_of_construction_field])
|
||||
|
||||
function = None
|
||||
if self._function_field is not None:
|
||||
function = str(feature['properties'][self._function_field])
|
||||
if function == 'Mixed use' or function == 'mixed use':
|
||||
function_parts = []
|
||||
if 'usages' in feature['properties']:
|
||||
usages = feature['properties']['usages']
|
||||
for usage in usages:
|
||||
if self._function_to_hub is not None and usage['usage'] in self._function_to_hub:
|
||||
function_parts.append(f"{usage['percentage']}-{self._function_to_hub[usage['usage']]}")
|
||||
else:
|
||||
function_parts.append(f"{usage['percentage']}-{usage['usage']}")
|
||||
else:
|
||||
for key, value in feature['properties'].items():
|
||||
if key.startswith("mixed_type_") and not key.endswith("_percentage"):
|
||||
type_key = key
|
||||
percentage_key = f"{key}_percentage"
|
||||
if percentage_key in feature['properties']:
|
||||
if self._function_to_hub is not None and feature['properties'][type_key] in self._function_to_hub:
|
||||
usage_function = self._function_to_hub[feature['properties'][type_key]]
|
||||
function_parts.append(f"{feature['properties'][percentage_key]}-{usage_function}")
|
||||
else:
|
||||
function_parts.append(f"{feature['properties'][percentage_key]}-{feature['properties'][type_key]}")
|
||||
function = "_".join(function_parts)
|
||||
if self._function_to_hub is not None:
|
||||
# use the transformation dictionary to retrieve the proper function
|
||||
if function in self._function_to_hub:
|
||||
function = self._function_to_hub[function]
|
||||
|
||||
usages = None
|
||||
if self._usages_field is not None:
|
||||
if self._usages_field in feature['properties']:
|
||||
usages = feature['properties'][self._usages_field]
|
||||
if self._usages_to_hub is not None:
|
||||
usages = self._usages_to_hub(usages)
|
||||
|
||||
geometry = feature['geometry']
|
||||
building_aliases = []
|
||||
if 'id' in feature:
|
||||
@ -163,7 +170,6 @@ class Geojson:
|
||||
building_name,
|
||||
building_aliases,
|
||||
function,
|
||||
usages,
|
||||
year_of_construction,
|
||||
extrusion_height))
|
||||
|
||||
@ -172,7 +178,6 @@ class Geojson:
|
||||
building_name,
|
||||
building_aliases,
|
||||
function,
|
||||
usages,
|
||||
year_of_construction,
|
||||
extrusion_height))
|
||||
else:
|
||||
@ -198,7 +203,7 @@ class Geojson:
|
||||
transformed_coordinates = f'{transformed_coordinates} {transformed[self._X]} {transformed[self._Y]} 0.0'
|
||||
return transformed_coordinates.lstrip(' ')
|
||||
|
||||
def _parse_polygon(self, coordinates, building_name, building_aliases, function, usages, year_of_construction, extrusion_height):
|
||||
def _parse_polygon(self, coordinates, building_name, building_aliases, function, year_of_construction, extrusion_height):
|
||||
surfaces = []
|
||||
for polygon_coordinates in coordinates:
|
||||
points = igh.points_from_string(
|
||||
@ -231,7 +236,7 @@ class Geojson:
|
||||
polygon = Polygon(coordinates)
|
||||
polygon.area = igh.ground_area(coordinates)
|
||||
surfaces[-1] = Surface(polygon, polygon)
|
||||
building = Building(f'{building_name}', surfaces, year_of_construction, function, usages=usages)
|
||||
building = Building(f'{building_name}', surfaces, year_of_construction, function)
|
||||
for alias in building_aliases:
|
||||
building.add_alias(alias)
|
||||
if extrusion_height == 0:
|
||||
@ -266,13 +271,13 @@ class Geojson:
|
||||
polygon = Polygon(wall_coordinates)
|
||||
wall = Surface(polygon, polygon)
|
||||
surfaces.append(wall)
|
||||
building = Building(f'{building_name}', surfaces, year_of_construction, function, usages=usages)
|
||||
building = Building(f'{building_name}', surfaces, year_of_construction, function)
|
||||
for alias in building_aliases:
|
||||
building.add_alias(alias)
|
||||
building.volume = volume
|
||||
return building
|
||||
|
||||
def _parse_multi_polygon(self, polygons_coordinates, building_name, building_aliases, function, usages, year_of_construction, extrusion_height):
|
||||
def _parse_multi_polygon(self, polygons_coordinates, building_name, building_aliases, function, year_of_construction, extrusion_height):
|
||||
surfaces = []
|
||||
for coordinates in polygons_coordinates:
|
||||
for polygon_coordinates in coordinates:
|
||||
@ -305,7 +310,7 @@ class Geojson:
|
||||
polygon = Polygon(coordinates)
|
||||
polygon.area = igh.ground_area(coordinates)
|
||||
surfaces[-1] = Surface(polygon, polygon)
|
||||
building = Building(f'{building_name}', surfaces, year_of_construction, function, usages=usages)
|
||||
building = Building(f'{building_name}', surfaces, year_of_construction, function)
|
||||
for alias in building_aliases:
|
||||
building.add_alias(alias)
|
||||
if extrusion_height == 0:
|
||||
@ -340,7 +345,7 @@ class Geojson:
|
||||
polygon = Polygon(wall_coordinates)
|
||||
wall = Surface(polygon, polygon)
|
||||
surfaces.append(wall)
|
||||
building = Building(f'{building_name}', surfaces, year_of_construction, function, usages=usages)
|
||||
building = Building(f'{building_name}', surfaces, year_of_construction, function)
|
||||
for alias in building_aliases:
|
||||
building.add_alias(alias)
|
||||
building.volume = volume
|
||||
|
@ -23,8 +23,6 @@ class GeometryFactory:
|
||||
year_of_construction_field=None,
|
||||
function_field=None,
|
||||
function_to_hub=None,
|
||||
usages_field=None,
|
||||
usages_to_hub=None,
|
||||
hub_crs=None):
|
||||
self._file_type = '_' + file_type.lower()
|
||||
validate_import_export_type(GeometryFactory, file_type)
|
||||
@ -34,8 +32,6 @@ class GeometryFactory:
|
||||
self._year_of_construction_field = year_of_construction_field
|
||||
self._function_field = function_field
|
||||
self._function_to_hub = function_to_hub
|
||||
self._usages_field = usages_field
|
||||
self._usages_to_hub = usages_to_hub
|
||||
self._hub_crs = hub_crs
|
||||
|
||||
@property
|
||||
@ -70,8 +66,6 @@ class GeometryFactory:
|
||||
self._year_of_construction_field,
|
||||
self._function_field,
|
||||
self._function_to_hub,
|
||||
self._usages_field,
|
||||
self._usages_to_hub,
|
||||
self._hub_crs).city
|
||||
|
||||
@property
|
||||
|
@ -38,36 +38,38 @@ class ComnetUsageParameters:
|
||||
city = self._city
|
||||
comnet_catalog = UsageCatalogFactory('comnet').catalog
|
||||
for building in city.buildings:
|
||||
usages = []
|
||||
comnet_archetype_usages = []
|
||||
usages = building.usages
|
||||
building_functions = building.function.split('_')
|
||||
for function in building_functions:
|
||||
usages.append(function.split('-'))
|
||||
for usage in usages:
|
||||
comnet_usage_name = Dictionaries().hub_usage_to_comnet_usage[usage['usage']]
|
||||
comnet_usage_name = Dictionaries().hub_usage_to_comnet_usage[usage[-1]]
|
||||
try:
|
||||
comnet_archetype_usage = self._search_archetypes(comnet_catalog, comnet_usage_name)
|
||||
comnet_archetype_usages.append(comnet_archetype_usage)
|
||||
except KeyError:
|
||||
logging.error('Building %s has unknown usage archetype for usage %s', building.name, comnet_usage_name)
|
||||
continue
|
||||
|
||||
for (i, internal_zone) in enumerate(building.internal_zones):
|
||||
internal_zone_usages = []
|
||||
if len(building.internal_zones) > 1:
|
||||
volume_per_area = 0
|
||||
if internal_zone.area is None:
|
||||
logging.error('Building %s has internal zone area not defined, ACH cannot be calculated for usage %s',
|
||||
building.name, usages[i]['usage'])
|
||||
building.name, usages[i][-1])
|
||||
continue
|
||||
if internal_zone.volume is None:
|
||||
logging.error('Building %s has internal zone volume not defined, ACH cannot be calculated for usage %s',
|
||||
building.name, usages[i]['usage'])
|
||||
building.name, usages[i][-1])
|
||||
continue
|
||||
if internal_zone.area <= 0:
|
||||
logging.error('Building %s has internal zone area equal to 0, ACH cannot be calculated for usage %s',
|
||||
building.name, usages[i]['usage'])
|
||||
building.name, usages[i][-1])
|
||||
continue
|
||||
volume_per_area += internal_zone.volume / internal_zone.area
|
||||
usage = Usage()
|
||||
usage.name = usages[i]['usage']
|
||||
usage.name = usages[i][-1]
|
||||
self._assign_values(usage, comnet_archetype_usages[i], volume_per_area, building.cold_water_temperature)
|
||||
usage.percentage = 1
|
||||
self._calculate_reduced_values_from_extended_library(usage, comnet_archetype_usages[i])
|
||||
@ -78,24 +80,20 @@ class ComnetUsageParameters:
|
||||
logging.error('Building %s no number of storeys assigned, ACH cannot be calculated for usage %s. '
|
||||
'NRCAN construction data for the year %s is used to calculated number of storeys above '
|
||||
'ground', building.name, usages, building.year_of_construction)
|
||||
try:
|
||||
storeys_above_ground = self.average_storey_height_calculator(self._city, building)
|
||||
except ValueError as e:
|
||||
logging.error(e)
|
||||
continue
|
||||
|
||||
volume_per_area = building.volume / building.floor_area / storeys_above_ground
|
||||
for j, usage_type in enumerate(usages):
|
||||
for (j, mixed_usage) in enumerate(usages):
|
||||
usage = Usage()
|
||||
usage.name = usage_type['usage']
|
||||
usage.percentage = float(usage_type['ratio'])
|
||||
|
||||
usage.name = mixed_usage[-1]
|
||||
if len(usages) > 1:
|
||||
usage.percentage = float(mixed_usage[0]) / 100
|
||||
else:
|
||||
usage.percentage = 1
|
||||
self._assign_values(usage, comnet_archetype_usages[j], volume_per_area, building.cold_water_temperature)
|
||||
self._calculate_reduced_values_from_extended_library(usage, comnet_archetype_usages[j])
|
||||
internal_zone_usages.append(usage)
|
||||
|
||||
internal_zone.usages = internal_zone_usages
|
||||
|
||||
@staticmethod
|
||||
def _search_archetypes(comnet_catalog, usage_name):
|
||||
comnet_archetypes = comnet_catalog.entries('archetypes').usages
|
||||
@ -272,11 +270,20 @@ class ComnetUsageParameters:
|
||||
def average_storey_height_calculator(city, building):
|
||||
climate_zone = ConstructionHelper.city_to_nrcan_climate_zone(city.climate_reference_city)
|
||||
nrcan_catalog = ConstructionCatalogFactory('nrcan').catalog
|
||||
|
||||
if building.function not in Dictionaries().hub_function_to_nrcan_construction_function:
|
||||
raise ValueError('Building %s has an unknown building function %s', building.name, building.function)
|
||||
|
||||
function = Dictionaries().hub_function_to_nrcan_construction_function[building.function]
|
||||
main_function = None
|
||||
functions = building.function.split('_')
|
||||
if len(functions) > 1:
|
||||
maximum_percentage = 0
|
||||
for function in functions:
|
||||
percentage_and_function = function.split('-')
|
||||
if float(percentage_and_function[0]) > maximum_percentage:
|
||||
maximum_percentage = float(percentage_and_function[0])
|
||||
main_function = percentage_and_function[-1]
|
||||
else:
|
||||
main_function = functions[-1]
|
||||
if main_function not in Dictionaries().hub_function_to_nrcan_construction_function:
|
||||
logging.error('Building %s has an unknown building function %s', building.name, main_function)
|
||||
function = Dictionaries().hub_function_to_nrcan_construction_function[main_function]
|
||||
construction_archetype = None
|
||||
average_storey_height = None
|
||||
nrcan_archetypes = nrcan_catalog.entries('archetypes')
|
||||
@ -287,7 +294,7 @@ class ComnetUsageParameters:
|
||||
construction_archetype = building_archetype
|
||||
average_storey_height = building_archetype.average_storey_height
|
||||
if construction_archetype is None:
|
||||
raise ValueError('Building %s has unknown construction archetype for building function: %s '
|
||||
logging.error('Building %s has unknown construction archetype for building function: %s '
|
||||
'[%s], building year of construction: %s and climate zone %s', building.name, function,
|
||||
building.function, building.year_of_construction, climate_zone)
|
||||
|
||||
|
@ -37,18 +37,21 @@ class NrcanUsageParameters:
|
||||
nrcan_catalog = UsageCatalogFactory('nrcan').catalog
|
||||
comnet_catalog = UsageCatalogFactory('comnet').catalog
|
||||
for building in city.buildings:
|
||||
usages = []
|
||||
nrcan_archetype_usages = []
|
||||
comnet_archetype_usages = []
|
||||
usages = building.usages
|
||||
building_functions = building.function.split('_')
|
||||
for function in building_functions:
|
||||
usages.append(function.split('-'))
|
||||
for usage in usages:
|
||||
usage_name = Dictionaries().hub_usage_to_nrcan_usage[usage['usage']]
|
||||
usage_name = Dictionaries().hub_usage_to_nrcan_usage[usage[-1]]
|
||||
try:
|
||||
archetype_usage = self._search_archetypes(nrcan_catalog, usage_name)
|
||||
nrcan_archetype_usages.append(archetype_usage)
|
||||
except KeyError:
|
||||
logging.error('Building %s has unknown usage archetype for usage %s', building.name, usage_name)
|
||||
continue
|
||||
comnet_usage_name = Dictionaries().hub_usage_to_comnet_usage[usage['usage']]
|
||||
comnet_usage_name = Dictionaries().hub_usage_to_comnet_usage[usage[-1]]
|
||||
try:
|
||||
comnet_archetype_usage = self._search_archetypes(comnet_catalog, comnet_usage_name)
|
||||
comnet_archetype_usages.append(comnet_archetype_usage)
|
||||
@ -62,19 +65,19 @@ class NrcanUsageParameters:
|
||||
volume_per_area = 0
|
||||
if internal_zone.area is None:
|
||||
logging.error('Building %s has internal zone area not defined, ACH cannot be calculated for usage %s',
|
||||
building.name, usages[i]['usage'])
|
||||
building.name, usages[i][-1])
|
||||
continue
|
||||
if internal_zone.volume is None:
|
||||
logging.error('Building %s has internal zone volume not defined, ACH cannot be calculated for usage %s',
|
||||
building.name, usages[i]['usage'])
|
||||
building.name, usages[i][-1])
|
||||
continue
|
||||
if internal_zone.area <= 0:
|
||||
logging.error('Building %s has internal zone area equal to 0, ACH cannot be calculated for usage %s',
|
||||
building.name, usages[i]['usage'])
|
||||
building.name, usages[i][-1])
|
||||
continue
|
||||
volume_per_area += internal_zone.volume / internal_zone.area
|
||||
usage = Usage()
|
||||
usage.name = usages[i]['usage']
|
||||
usage.name = usages[i][-1]
|
||||
self._assign_values(usage, nrcan_archetype_usages[i], volume_per_area, building.cold_water_temperature)
|
||||
self._assign_comnet_extra_values(usage, comnet_archetype_usages[i], nrcan_archetype_usages[i].occupancy.occupancy_density)
|
||||
usage.percentage = 1
|
||||
@ -83,21 +86,19 @@ class NrcanUsageParameters:
|
||||
else:
|
||||
storeys_above_ground = building.storeys_above_ground
|
||||
if storeys_above_ground is None:
|
||||
logging.error('Building %s no number of storeys assigned, ACH cannot be calculated for function %s. '
|
||||
logging.error('Building %s no number of storeys assigned, ACH cannot be calculated for usage %s. '
|
||||
'NRCAN construction data for the year %s is used to calculated number of storeys above '
|
||||
'ground', building.name, building.function, building.year_of_construction)
|
||||
try:
|
||||
'ground', building.name, usages, building.year_of_construction)
|
||||
storeys_above_ground = self.average_storey_height_calculator(self._city, building)
|
||||
except ValueError as e:
|
||||
logging.error(e)
|
||||
continue
|
||||
|
||||
volume_per_area = building.volume / building.floor_area / storeys_above_ground
|
||||
for j, usage_type in enumerate(usages):
|
||||
for (j, mixed_usage) in enumerate(usages):
|
||||
usage = Usage()
|
||||
usage.name = usage_type['usage']
|
||||
usage.percentage = float(usage_type['ratio'])
|
||||
|
||||
usage.name = mixed_usage[-1]
|
||||
if len(usages) > 1:
|
||||
usage.percentage = float(mixed_usage[0]) / 100
|
||||
else:
|
||||
usage.percentage = 1
|
||||
self._assign_values(usage, nrcan_archetype_usages[j], volume_per_area, building.cold_water_temperature)
|
||||
self._assign_comnet_extra_values(usage, comnet_archetype_usages[j], nrcan_archetype_usages[j].occupancy.occupancy_density)
|
||||
self._calculate_reduced_values_from_extended_library(usage, nrcan_archetype_usages[j])
|
||||
@ -226,11 +227,20 @@ class NrcanUsageParameters:
|
||||
def average_storey_height_calculator(city, building):
|
||||
climate_zone = ConstructionHelper.city_to_nrcan_climate_zone(city.climate_reference_city)
|
||||
nrcan_catalog = ConstructionCatalogFactory('nrcan').catalog
|
||||
|
||||
if building.function not in Dictionaries().hub_function_to_nrcan_construction_function:
|
||||
raise ValueError('Building %s has an unknown building function %s', building.name, building.function)
|
||||
|
||||
function = Dictionaries().hub_function_to_nrcan_construction_function[building.function]
|
||||
main_function = None
|
||||
functions = building.function.split('_')
|
||||
if len(functions) > 1:
|
||||
maximum_percentage = 0
|
||||
for function in functions:
|
||||
percentage_and_function = function.split('-')
|
||||
if float(percentage_and_function[0]) > maximum_percentage:
|
||||
maximum_percentage = float(percentage_and_function[0])
|
||||
main_function = percentage_and_function[-1]
|
||||
else:
|
||||
main_function = functions[-1]
|
||||
if main_function not in Dictionaries().hub_function_to_nrcan_construction_function:
|
||||
logging.error('Building %s has an unknown building function %s', building.name, main_function)
|
||||
function = Dictionaries().hub_function_to_nrcan_construction_function[main_function]
|
||||
construction_archetype = None
|
||||
average_storey_height = None
|
||||
nrcan_archetypes = nrcan_catalog.entries('archetypes')
|
||||
@ -241,7 +251,7 @@ class NrcanUsageParameters:
|
||||
construction_archetype = building_archetype
|
||||
average_storey_height = building_archetype.average_storey_height
|
||||
if construction_archetype is None:
|
||||
raise ValueError('Building %s has unknown construction archetype for building function: %s '
|
||||
logging.error('Building %s has unknown construction archetype for building function: %s '
|
||||
'[%s], building year of construction: %s and climate zone %s', building.name, function,
|
||||
building.function, building.year_of_construction, climate_zone)
|
||||
|
||||
|
1
setup.py
1
setup.py
@ -65,7 +65,6 @@ setup(
|
||||
'hub.helpers',
|
||||
'hub.helpers.peak_calculation',
|
||||
'hub.helpers.data',
|
||||
'hub.helpers.parsers',
|
||||
'hub.imports',
|
||||
'hub.imports.construction',
|
||||
'hub.imports.construction.helpers',
|
||||
|
@ -11,7 +11,6 @@ from hub.imports.geometry_factory import GeometryFactory
|
||||
from hub.imports.construction_factory import ConstructionFactory
|
||||
from hub.imports.usage_factory import UsageFactory
|
||||
from hub.helpers.dictionaries import Dictionaries
|
||||
from hub.helpers.usage_parsers import UsageParsers
|
||||
|
||||
|
||||
class TestUsageFactory(TestCase):
|
||||
@ -76,6 +75,22 @@ class TestUsageFactory(TestCase):
|
||||
self.assertIsNotNone(usage.thermal_control.heating_set_back, 'control heating set back is none')
|
||||
self.assertIsNotNone(usage.thermal_control.mean_cooling_set_point, 'control cooling set point is none')
|
||||
|
||||
def test_import_comnet(self):
|
||||
"""
|
||||
Enrich the city with the usage information from comnet and verify it
|
||||
"""
|
||||
file = 'pluto_building.gml'
|
||||
city = self._get_citygml(file)
|
||||
for building in city.buildings:
|
||||
building.function = Dictionaries().pluto_function_to_hub_function[building.function]
|
||||
|
||||
UsageFactory('comnet', city).enrich()
|
||||
self._check_buildings(city)
|
||||
for building in city.buildings:
|
||||
for internal_zone in building.internal_zones:
|
||||
self.assertIsNot(len(internal_zone.usages), 0, 'no building usage defined')
|
||||
for usage in internal_zone.usages:
|
||||
self._check_usage(usage)
|
||||
self.assertIsNotNone(usage.mechanical_air_change, 'mechanical air change is none')
|
||||
self.assertIsNotNone(usage.thermal_control.heating_set_point_schedules,
|
||||
'control heating set point schedule is none')
|
||||
@ -106,28 +121,11 @@ class TestUsageFactory(TestCase):
|
||||
self.assertIsNotNone(appliances.schedules, 'appliances schedule is none')
|
||||
self.assertIsNotNone(usage.thermal_control.hvac_availability_schedules,
|
||||
'control hvac availability is none')
|
||||
self.assertIsNotNone(usage.domestic_hot_water.density, 'domestic hot water density is none')
|
||||
self.assertIsNotNone(usage.domestic_hot_water.service_temperature,
|
||||
'domestic hot water service temperature is none')
|
||||
self.assertIsNotNone(usage.domestic_hot_water.schedules, 'domestic hot water schedules is none')
|
||||
|
||||
def test_import_comnet(self):
|
||||
"""
|
||||
Enrich the city with the usage information from comnet and verify it
|
||||
"""
|
||||
file = 'pluto_building.gml'
|
||||
city = self._get_citygml(file)
|
||||
for building in city.buildings:
|
||||
building.function = Dictionaries().pluto_function_to_hub_function[building.function]
|
||||
|
||||
UsageFactory('comnet', city).enrich()
|
||||
self._check_buildings(city)
|
||||
for building in city.buildings:
|
||||
for internal_zone in building.internal_zones:
|
||||
self.assertIsNot(len(internal_zone.usages), 0, 'no building usage defined')
|
||||
for usage in internal_zone.usages:
|
||||
self._check_usage(usage)
|
||||
self.assertIsNotNone(usage.domestic_hot_water.density, 'domestic hot water density is none')
|
||||
|
||||
def test_import_nrcan(self):
|
||||
"""
|
||||
Enrich the city with the usage information from nrcan and verify it
|
||||
@ -150,6 +148,40 @@ class TestUsageFactory(TestCase):
|
||||
self.assertIsNot(len(internal_zone.usages), 0, 'no building usage defined')
|
||||
for usage in internal_zone.usages:
|
||||
self._check_usage(usage)
|
||||
self.assertIsNotNone(usage.mechanical_air_change, 'mechanical air change is none')
|
||||
self.assertIsNotNone(usage.thermal_control.heating_set_point_schedules,
|
||||
'control heating set point schedule is none')
|
||||
self.assertIsNotNone(usage.thermal_control.cooling_set_point_schedules,
|
||||
'control cooling set point schedule is none')
|
||||
self.assertIsNotNone(usage.occupancy, 'occupancy is none')
|
||||
occupancy = usage.occupancy
|
||||
self.assertIsNotNone(occupancy.occupancy_density, 'occupancy density is none')
|
||||
self.assertIsNotNone(occupancy.latent_internal_gain, 'occupancy latent internal gain is none')
|
||||
self.assertIsNotNone(occupancy.sensible_convective_internal_gain,
|
||||
'occupancy sensible convective internal gain is none')
|
||||
self.assertIsNotNone(occupancy.sensible_radiative_internal_gain,
|
||||
'occupancy sensible radiant internal gain is none')
|
||||
self.assertIsNotNone(occupancy.occupancy_schedules, 'occupancy schedule is none')
|
||||
self.assertIsNotNone(usage.lighting, 'lighting is none')
|
||||
lighting = usage.lighting
|
||||
self.assertIsNotNone(lighting.density, 'lighting density is none')
|
||||
self.assertIsNotNone(lighting.latent_fraction, 'lighting latent fraction is none')
|
||||
self.assertIsNotNone(lighting.convective_fraction, 'lighting convective fraction is none')
|
||||
self.assertIsNotNone(lighting.radiative_fraction, 'lighting radiant fraction is none')
|
||||
self.assertIsNotNone(lighting.schedules, 'lighting schedule is none')
|
||||
self.assertIsNotNone(usage.appliances, 'appliances is none')
|
||||
appliances = usage.appliances
|
||||
self.assertIsNotNone(appliances.density, 'appliances density is none')
|
||||
self.assertIsNotNone(appliances.latent_fraction, 'appliances latent fraction is none')
|
||||
self.assertIsNotNone(appliances.convective_fraction, 'appliances convective fraction is none')
|
||||
self.assertIsNotNone(appliances.radiative_fraction, 'appliances radiant fraction is none')
|
||||
self.assertIsNotNone(appliances.schedules, 'appliances schedule is none')
|
||||
self.assertIsNotNone(usage.thermal_control.hvac_availability_schedules,
|
||||
'control hvac availability is none')
|
||||
self.assertIsNotNone(usage.domestic_hot_water.peak_flow, 'domestic hot water peak flow is none')
|
||||
self.assertIsNotNone(usage.domestic_hot_water.service_temperature,
|
||||
'domestic hot water service temperature is none')
|
||||
self.assertIsNotNone(usage.domestic_hot_water.schedules, 'domestic hot water schedules is none')
|
||||
|
||||
def test_import_palma(self):
|
||||
"""
|
||||
@ -173,35 +205,38 @@ class TestUsageFactory(TestCase):
|
||||
self.assertIsNot(len(internal_zone.usages), 0, 'no building usage defined')
|
||||
for usage in internal_zone.usages:
|
||||
self._check_usage(usage)
|
||||
self.assertIsNotNone(usage.mechanical_air_change, 'mechanical air change is none')
|
||||
self.assertIsNotNone(usage.thermal_control.heating_set_point_schedules,
|
||||
'control heating set point schedule is none')
|
||||
self.assertIsNotNone(usage.thermal_control.cooling_set_point_schedules,
|
||||
'control cooling set point schedule is none')
|
||||
self.assertIsNotNone(usage.occupancy, 'occupancy is none')
|
||||
occupancy = usage.occupancy
|
||||
self.assertIsNotNone(occupancy.occupancy_density, 'occupancy density is none')
|
||||
self.assertIsNotNone(occupancy.latent_internal_gain, 'occupancy latent internal gain is none')
|
||||
self.assertIsNotNone(occupancy.sensible_convective_internal_gain,
|
||||
'occupancy sensible convective internal gain is none')
|
||||
self.assertIsNotNone(occupancy.sensible_radiative_internal_gain,
|
||||
'occupancy sensible radiant internal gain is none')
|
||||
self.assertIsNotNone(occupancy.occupancy_schedules, 'occupancy schedule is none')
|
||||
self.assertIsNotNone(usage.lighting, 'lighting is none')
|
||||
lighting = usage.lighting
|
||||
self.assertIsNotNone(lighting.density, 'lighting density is none')
|
||||
self.assertIsNotNone(lighting.latent_fraction, 'lighting latent fraction is none')
|
||||
self.assertIsNotNone(lighting.convective_fraction, 'lighting convective fraction is none')
|
||||
self.assertIsNotNone(lighting.radiative_fraction, 'lighting radiant fraction is none')
|
||||
self.assertIsNotNone(lighting.schedules, 'lighting schedule is none')
|
||||
self.assertIsNotNone(usage.appliances, 'appliances is none')
|
||||
appliances = usage.appliances
|
||||
self.assertIsNotNone(appliances.density, 'appliances density is none')
|
||||
self.assertIsNotNone(appliances.latent_fraction, 'appliances latent fraction is none')
|
||||
self.assertIsNotNone(appliances.convective_fraction, 'appliances convective fraction is none')
|
||||
self.assertIsNotNone(appliances.radiative_fraction, 'appliances radiant fraction is none')
|
||||
self.assertIsNotNone(appliances.schedules, 'appliances schedule is none')
|
||||
self.assertIsNotNone(usage.thermal_control.hvac_availability_schedules,
|
||||
'control hvac availability is none')
|
||||
self.assertIsNotNone(usage.domestic_hot_water.peak_flow, 'domestic hot water peak flow is none')
|
||||
self.assertIsNotNone(usage.domestic_hot_water.service_temperature,
|
||||
'domestic hot water service temperature is none')
|
||||
self.assertIsNotNone(usage.domestic_hot_water.schedules, 'domestic hot water schedules is none')
|
||||
|
||||
|
||||
|
||||
def test_import_nrcan_multiusage(self):
|
||||
"""
|
||||
Enrich the city with the usage information from nrcan and verify it
|
||||
"""
|
||||
file = 'test.geojson'
|
||||
file_path = (self._example_path / file).resolve()
|
||||
|
||||
function_dictionary = Dictionaries().montreal_function_to_hub_function
|
||||
usage_parser = UsageParsers().list_usage_to_hub(function_dictionary=function_dictionary)
|
||||
|
||||
city = GeometryFactory('geojson',
|
||||
path=file_path,
|
||||
height_field='citygml_me',
|
||||
year_of_construction_field='ANNEE_CONS',
|
||||
function_field='CODE_UTILI',
|
||||
function_to_hub=function_dictionary,
|
||||
usages_field='usages',
|
||||
usages_to_hub=usage_parser).city
|
||||
|
||||
ConstructionFactory('nrcan', city).enrich()
|
||||
UsageFactory('nrcan', city).enrich()
|
||||
self._check_buildings(city)
|
||||
for building in city.buildings:
|
||||
for internal_zone in building.internal_zones:
|
||||
if internal_zone.usages is not None:
|
||||
self.assertIsNot(len(internal_zone.usages), 0, 'no building usage defined')
|
||||
for usage in internal_zone.usages:
|
||||
self._check_usage(usage)
|
||||
|
File diff suppressed because one or more lines are too long
Loading…
Reference in New Issue
Block a user