2020-06-09 14:07:47 -04:00
|
|
|
"""
|
|
|
|
UsBaseUsageParameters base class to model the usage properties for a building in NYC and US
|
|
|
|
SPDX - License - Identifier: LGPL - 3.0 - or -later
|
|
|
|
Copyright © 2020 Project Author Guille Gutierrez guillermo.gutierrezmorote@concordia.ca
|
2020-11-26 09:26:55 -05:00
|
|
|
Contributors Pilar Monsalvete pilar_monsalvete@yahoo.es
|
2020-06-09 14:07:47 -04:00
|
|
|
"""
|
2020-05-18 13:25:08 -04:00
|
|
|
from pathlib import Path
|
2020-06-16 10:34:17 -04:00
|
|
|
|
2020-06-11 16:55:52 -04:00
|
|
|
import xmltodict
|
2020-06-16 10:34:17 -04:00
|
|
|
|
2020-10-28 13:14:05 -04:00
|
|
|
from city_model_structure.attributes.internal_gains import InternalGains
|
|
|
|
from city_model_structure.attributes.usage_zone import UsageZone
|
2020-05-18 13:25:08 -04:00
|
|
|
|
|
|
|
|
|
|
|
class UsBaseUsageParameters:
|
2020-06-11 16:55:52 -04:00
|
|
|
"""
|
|
|
|
UsBaseUsageParameters class
|
|
|
|
"""
|
2020-05-18 13:25:08 -04:00
|
|
|
def __init__(self, city, function_to_usage):
|
|
|
|
self._city = city
|
2020-06-23 14:48:01 -04:00
|
|
|
# todo: control not archetype found
|
2020-05-18 13:25:08 -04:00
|
|
|
# ToDo: this is using the german library as a temporary approach, need to use/define a library for US
|
2020-10-30 06:23:29 -04:00
|
|
|
path = str(Path(__file__).parent.parent.parent / 'data/usage/de_library.xml')
|
2020-05-18 13:25:08 -04:00
|
|
|
with open(path) as xml:
|
|
|
|
self._library = xmltodict.parse(xml.read(), force_list='zoneUsageVariant')
|
2020-06-16 15:12:18 -04:00
|
|
|
for city_object in self._city.buildings:
|
2020-06-11 16:55:52 -04:00
|
|
|
# ToDo: Right now is just one usage zone but will be multiple in the future
|
2020-05-18 13:25:08 -04:00
|
|
|
usage_zone = UsageZone()
|
|
|
|
usage_zone.usage = function_to_usage(city_object.function)
|
|
|
|
for zone_usage_type in self._library['buildingUsageLibrary']['zoneUsageType']:
|
|
|
|
if zone_usage_type['id'] != usage_zone.usage:
|
|
|
|
if 'zoneUsageVariant' in zone_usage_type:
|
|
|
|
for usage_zone_variant in zone_usage_type['zoneUsageVariant']:
|
|
|
|
if usage_zone_variant['id'] == usage_zone.usage:
|
|
|
|
# pre-initialize the usage zone with the main type
|
|
|
|
usage_zone = UsBaseUsageParameters._parse_zone_usage_type(zone_usage_type, usage_zone)
|
|
|
|
usage_zone = UsBaseUsageParameters._parse_zone_usage_variant(usage_zone_variant, usage_zone)
|
|
|
|
city_object.usage_zone = [usage_zone]
|
|
|
|
break
|
|
|
|
continue
|
2020-06-11 16:55:52 -04:00
|
|
|
city_object.usage_zones = [UsBaseUsageParameters._parse_zone_usage_type(zone_usage_type, usage_zone)]
|
|
|
|
break
|
2020-05-19 18:23:25 -04:00
|
|
|
if city_object.usage_zones is None:
|
2020-05-18 13:25:08 -04:00
|
|
|
raise Exception('Usage not found for building function')
|
|
|
|
|
|
|
|
@staticmethod
|
|
|
|
def _parse_zone_usage_type(zone_usage_type, usage_zone):
|
2020-11-06 05:32:19 -05:00
|
|
|
usage_zone.occupancy_density = zone_usage_type['occupancy']['occupancyDensity']
|
2020-05-18 13:25:08 -04:00
|
|
|
usage_zone.hours_day = zone_usage_type['occupancy']['usageHoursPerDay']
|
|
|
|
usage_zone.days_year = zone_usage_type['occupancy']['usageDaysPerYear']
|
|
|
|
usage_zone.cooling_setpoint = zone_usage_type['endUses']['space_cooling']['coolingSetPointTemperature']
|
|
|
|
usage_zone.heating_setpoint = zone_usage_type['endUses']['space_heating']['heatingSetPointTemperature']
|
|
|
|
usage_zone.heating_setback = zone_usage_type['endUses']['space_heating']['heatingSetBackTemperature']
|
2020-11-06 05:32:19 -05:00
|
|
|
# todo: schedules set points!!!
|
2020-05-18 13:25:08 -04:00
|
|
|
if 'ventilation' in zone_usage_type['endUses'] and zone_usage_type['endUses']['ventilation'] is not None:
|
|
|
|
usage_zone.mechanical_air_change = zone_usage_type['endUses']['ventilation']['mechanicalAirChangeRate']
|
2020-11-06 05:32:19 -05:00
|
|
|
usage_zone.dhw_average_volume_pers_day = \
|
|
|
|
zone_usage_type['endUses']['domestic_hot_water']['averageVolumePerPersAndDay']
|
|
|
|
usage_zone.dhw_preparation_temperature = \
|
|
|
|
zone_usage_type['endUses']['domestic_hot_water']['preparationTemperature']
|
|
|
|
# todo: are there more than one of these electrical values?
|
|
|
|
# todo: schedules!!
|
|
|
|
if 'all_electrical_appliances' in zone_usage_type['endUses']:
|
|
|
|
if 'averageConsumptionPerSqmAndYear' in zone_usage_type['endUses']['all_electrical_appliances']:
|
|
|
|
usage_zone.electrical_app_average_consumption_sqm_year = \
|
|
|
|
zone_usage_type['endUses']['all_electrical_appliances']['averageConsumptionPerSqmAndYear']
|
|
|
|
|
2020-05-18 13:25:08 -04:00
|
|
|
int_gains = InternalGains()
|
|
|
|
int_gains.latent_fraction = zone_usage_type['occupancy']['internGains']['latentFraction']
|
|
|
|
int_gains.convective_fraction = zone_usage_type['occupancy']['internGains']['convectiveFraction']
|
2020-06-10 11:08:38 -04:00
|
|
|
int_gains.average_internal_gain = zone_usage_type['occupancy']['internGains']['averageInternGainPerSqm']
|
2020-05-18 13:25:08 -04:00
|
|
|
int_gains.radiative_fraction = zone_usage_type['occupancy']['internGains']['radiantFraction']
|
|
|
|
usage_zone.internal_gains = [int_gains]
|
|
|
|
return usage_zone
|
|
|
|
|
|
|
|
@staticmethod
|
|
|
|
def _parse_zone_usage_variant(usage_zone_variant, usage_zone):
|
|
|
|
# for the variants all is optional because it mimics the inheritance concept from OOP
|
|
|
|
if 'usageHoursPerDay' in usage_zone_variant['occupancy']:
|
|
|
|
usage_zone.hours_day = usage_zone_variant['occupancy']['usageHoursPerDay']
|
|
|
|
if 'usageDaysPerYear' in usage_zone_variant['occupancy']:
|
|
|
|
usage_zone.days_year = usage_zone_variant['occupancy']['usageDaysPerYear']
|
|
|
|
if 'coolingSetPointTemperature' in usage_zone_variant['endUses']['space_cooling']:
|
|
|
|
usage_zone.cooling_setpoint = usage_zone_variant['endUses']['space_cooling']['coolingSetPointTemperature']
|
|
|
|
if 'heatingSetPointTemperature' in usage_zone_variant['endUses']['space_heating']:
|
|
|
|
usage_zone.heating_setpoint = usage_zone_variant['endUses']['space_heating']['heatingSetPointTemperature']
|
|
|
|
if 'heatingSetBackTemperature' in usage_zone_variant['endUses']['space_heating']:
|
|
|
|
usage_zone.heating_setback = usage_zone_variant['endUses']['space_heating']['heatingSetBackTemperature']
|
|
|
|
if 'ventilation' in usage_zone_variant['endUses'] and usage_zone_variant['endUses']['ventilation'] is not None:
|
|
|
|
usage_zone.mechanical_air_change = usage_zone_variant['endUses']['ventilation']['mechanicalAirChangeRate']
|
|
|
|
if 'latentFraction' in usage_zone_variant['occupancy']['internGains']:
|
|
|
|
usage_zone.int_gains[0].latent_fraction = usage_zone_variant['occupancy']['internGains']['latentFraction']
|
|
|
|
if 'convectiveFraction' in usage_zone_variant['occupancy']['internGains']:
|
|
|
|
usage_zone.int_gains[0].convective_fraction = usage_zone_variant['occupancy']['internGains']['convectiveFraction']
|
|
|
|
if 'averageInternGainPerSqm' in usage_zone_variant['occupancy']['internGains']:
|
2020-06-10 11:08:38 -04:00
|
|
|
usage_zone.int_gains[0].average_internal_gain = \
|
2020-05-18 13:25:08 -04:00
|
|
|
usage_zone_variant['occupancy']['internGains']['averageInternGainPerSqm']
|
|
|
|
if 'radiantFraction' in usage_zone_variant['occupancy']['internGains']:
|
|
|
|
usage_zone.int_gains[0].radiative_fraction = usage_zone_variant['occupancy']['internGains']['radiantFraction']
|
|
|
|
return usage_zone
|