Compare commits

...

2 Commits

Author SHA1 Message Date
Connor Brackley
44e6820ce6 Improve documentation and error handling 2024-11-27 22:06:22 +00:00
Connor Brackley
66dbda5525 Update usage handling in thermal zones 2024-11-27 22:06:03 +00:00
4 changed files with 23 additions and 41 deletions

View File

@ -262,8 +262,8 @@ class Building(CityObject):
@property @property
def usages(self) -> Union[None, list]: def usages(self) -> Union[None, list]:
""" """
Get building function Get building usages, if none, assume useage is function
:return: None or str :return: None or list of functions
""" """
if self._usages is None and self._function is not None: if self._usages is None and self._function is not None:
self._usages = [{'usage': self._function, 'ratio': 1 }] self._usages = [{'usage': self._function, 'ratio': 1 }]
@ -604,19 +604,6 @@ class Building(CityObject):
""" """
self._city = value 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 @property
def energy_systems(self) -> Union[None, List[EnergySystem]]: def energy_systems(self) -> Union[None, List[EnergySystem]]:
""" """

View File

@ -34,7 +34,7 @@ class ThermalZone:
volume, volume,
footprint_area, footprint_area,
number_of_storeys, number_of_storeys,
usage_name=None): usages=None):
self._id = None self._id = None
self._parent_internal_zone = parent_internal_zone self._parent_internal_zone = parent_internal_zone
self._footprint_area = footprint_area self._footprint_area = footprint_area
@ -51,10 +51,6 @@ class ThermalZone:
self._view_factors_matrix = None self._view_factors_matrix = None
self._total_floor_area = None self._total_floor_area = None
self._number_of_storeys = number_of_storeys 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._hours_day = None
self._days_year = None self._days_year = None
self._mechanical_air_change = None self._mechanical_air_change = None
@ -64,7 +60,8 @@ class ThermalZone:
self._internal_gains = None self._internal_gains = None
self._thermal_control = None self._thermal_control = None
self._domestic_hot_water = None self._domestic_hot_water = None
self._usages = None self._usage_name = None
self._usages = usages
@property @property
def parent_internal_zone(self) -> InternalZone: def parent_internal_zone(self) -> InternalZone:
@ -81,20 +78,8 @@ class ThermalZone:
Eg: 70-office_30-residential Eg: 70-office_30-residential
:return: str :return: str
""" """
if self._usage_from_parent: if self._usages is not None:
self._usages = copy.deepcopy(self._parent_internal_zone.usages) 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 return self._usages
@property @property

View File

@ -78,7 +78,12 @@ class ComnetUsageParameters:
logging.error('Building %s no number of storeys assigned, ACH cannot be calculated for usage %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 ' 'NRCAN construction data for the year %s is used to calculated number of storeys above '
'ground', building.name, usages, building.year_of_construction) 'ground', building.name, usages, building.year_of_construction)
try:
storeys_above_ground = self.average_storey_height_calculator(self._city, building) 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 volume_per_area = building.volume / building.floor_area / storeys_above_ground
for j, usage_type in enumerate(usages): for j, usage_type in enumerate(usages):
usage = Usage() usage = Usage()
@ -90,6 +95,7 @@ class ComnetUsageParameters:
internal_zone_usages.append(usage) internal_zone_usages.append(usage)
internal_zone.usages = internal_zone_usages internal_zone.usages = internal_zone_usages
@staticmethod @staticmethod
def _search_archetypes(comnet_catalog, usage_name): def _search_archetypes(comnet_catalog, usage_name):
comnet_archetypes = comnet_catalog.entries('archetypes').usages comnet_archetypes = comnet_catalog.entries('archetypes').usages
@ -268,7 +274,7 @@ class ComnetUsageParameters:
nrcan_catalog = ConstructionCatalogFactory('nrcan').catalog nrcan_catalog = ConstructionCatalogFactory('nrcan').catalog
if building.function not in Dictionaries().hub_function_to_nrcan_construction_function: 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) raise ValueError('Building %s has an unknown building function %s', building.name, building.function)
function = Dictionaries().hub_function_to_nrcan_construction_function[building.function] function = Dictionaries().hub_function_to_nrcan_construction_function[building.function]
construction_archetype = None construction_archetype = None
@ -281,7 +287,7 @@ class ComnetUsageParameters:
construction_archetype = building_archetype construction_archetype = building_archetype
average_storey_height = building_archetype.average_storey_height average_storey_height = building_archetype.average_storey_height
if construction_archetype is None: if construction_archetype is None:
logging.error('Building %s has unknown construction archetype for building function: %s ' raise ValueError('Building %s has unknown construction archetype for building function: %s '
'[%s], building year of construction: %s and climate zone %s', building.name, function, '[%s], building year of construction: %s and climate zone %s', building.name, function,
building.function, building.year_of_construction, climate_zone) building.function, building.year_of_construction, climate_zone)

View File

@ -86,8 +86,12 @@ class NrcanUsageParameters:
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 function %s. '
'NRCAN construction data for the year %s is used to calculated number of storeys above ' 'NRCAN construction data for the year %s is used to calculated number of storeys above '
'ground', building.name, building.function, building.year_of_construction) 'ground', building.name, building.function, building.year_of_construction)
try:
storeys_above_ground = self.average_storey_height_calculator(self._city, building) storeys_above_ground = self.average_storey_height_calculator(self._city, building)
except ValueError as e:
logging.error(e)
continue continue
volume_per_area = building.volume / building.floor_area / storeys_above_ground volume_per_area = building.volume / building.floor_area / storeys_above_ground
for j, usage_type in enumerate(usages): for j, usage_type in enumerate(usages):
usage = Usage() usage = Usage()
@ -224,7 +228,7 @@ class NrcanUsageParameters:
nrcan_catalog = ConstructionCatalogFactory('nrcan').catalog nrcan_catalog = ConstructionCatalogFactory('nrcan').catalog
if building.function not in Dictionaries().hub_function_to_nrcan_construction_function: 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) raise ValueError('Building %s has an unknown building function %s', building.name, building.function)
function = Dictionaries().hub_function_to_nrcan_construction_function[building.function] function = Dictionaries().hub_function_to_nrcan_construction_function[building.function]
construction_archetype = None construction_archetype = None
@ -237,7 +241,7 @@ class NrcanUsageParameters:
construction_archetype = building_archetype construction_archetype = building_archetype
average_storey_height = building_archetype.average_storey_height average_storey_height = building_archetype.average_storey_height
if construction_archetype is None: if construction_archetype is None:
logging.error('Building %s has unknown construction archetype for building function: %s ' raise ValueError('Building %s has unknown construction archetype for building function: %s '
'[%s], building year of construction: %s and climate zone %s', building.name, function, '[%s], building year of construction: %s and climate zone %s', building.name, function,
building.function, building.year_of_construction, climate_zone) building.function, building.year_of_construction, climate_zone)