diff --git a/factories/occupancy_feeders/usage_schedules.py b/factories/occupancy_feeders/usage_schedules.py index 40a35de6..d3dac51a 100644 --- a/factories/occupancy_feeders/usage_schedules.py +++ b/factories/occupancy_feeders/usage_schedules.py @@ -17,8 +17,8 @@ class ComnetSchedules: # todo: review for more than one usage_zones per building for building in city.buildings: schedules = dict() - usage_schedules = pd.read_excel(xls, sheet_name=SchedulesHelper.comnet_pluto_schedules_function(building.function), - skiprows=[0, 1, 2, 3], nrows=39, usecols="A:AA") + usage_schedules = pd.read_excel(xls, sheet_name=SchedulesHelper.comnet_pluto_schedules_function(building.function) + , skiprows=[0, 1, 2, 3], nrows=39, usecols="A:AA") # todo: should we save the data type? How? number_of_schedule_types = 13 schedules_per_schedule_type = 3 diff --git a/factories/physics_factory.py b/factories/physics_factory.py index 78c4a83b..5675f52b 100644 --- a/factories/physics_factory.py +++ b/factories/physics_factory.py @@ -27,7 +27,7 @@ class PhysicsFactory: UsPhysicsParameters(self._city, self._base_path) def _ca(self): - CaPhysicsParameters(self._city, self._base_path).fill_buildings() + CaPhysicsParameters(self._city, self._base_path).enrich_buildings() def _de(self): raise NotImplementedError diff --git a/factories/physics_feeders/ca_physics_parameters.py b/factories/physics_feeders/ca_physics_parameters.py index 3cb166de..e318865d 100644 --- a/factories/physics_feeders/ca_physics_parameters.py +++ b/factories/physics_feeders/ca_physics_parameters.py @@ -16,11 +16,8 @@ class CaPhysicsParameters(NrelPhysicsInterface): def __init__(self, city, base_path): super().__init__(base_path, 'ca_constructions_reduced.xml', 'ca_archetypes_reduced.xml') self._city = city - # todo: define climate zones for Canada and substitute this default value by a function that selects the correct one - self._climate_zone = 'Summerland' - self._key_names = ['@function', '@periodOfConstruction'] - def fill_buildings(self): + def enrich_buildings(self): """ Returns the city with the physics parameters assigned to the buildings :return: @@ -30,16 +27,15 @@ class CaPhysicsParameters(NrelPhysicsInterface): for building in city.buildings: archetype = self._search_archetype([building.function, building.year_of_construction]) if archetype is None: - sys.stderr.write('Building ' + building.name + ' has unknown archetype for building function: ' + - building.function + ' and building year of construction: ' + building.year_of_construction + - '\n') + sys.stderr.write(f'Building {building.name} has unknown archetype for building function: {building.function} ' + f'and building year of construction: {building.year_of_construction}\n') continue self._assign_values(building, archetype) def _search_archetype(self, keys): for building_archetype in self._building_archetypes: - a_ft = str(building_archetype.archetype_keys[self._key_names[0]]) - a_pc = str(building_archetype.archetype_keys[self._key_names[1]]) + a_ft = str(building_archetype.archetype_keys['@function']) + a_pc = str(building_archetype.archetype_keys['@periodOfConstruction']) a_yc1 = int(a_pc.split(sep='-')[0]) a_yc2 = int(a_pc.split(sep='-')[1]) if a_ft == str(keys[0]): diff --git a/factories/physics_feeders/nrel_physics_interface.py b/factories/physics_feeders/nrel_physics_interface.py index 52be8aee..6e7d7bfb 100644 --- a/factories/physics_feeders/nrel_physics_interface.py +++ b/factories/physics_feeders/nrel_physics_interface.py @@ -6,10 +6,10 @@ Copyright © 2020 Project Author Pilar Monsalvete pilar_monsalvete@yahoo.es """ import xmltodict -from factories.physics_feeders.data_classes.nrel_building_achetype import NrelBuildingArchetype -from factories.physics_feeders.data_classes.nrel_thermal_boundary_archetype import NrelThermalBoundaryArchetype -from factories.physics_feeders.data_classes.nrel_thermal_opening_archetype import NrelThermalOpeningArchetype -from factories.physics_feeders.data_classes.nrel_layer_archetype import NrelLayerArchetype +from factories.physics_feeders.data_classes.nrel_building_achetype import NrelBuildingArchetype as nba +from factories.physics_feeders.data_classes.nrel_thermal_boundary_archetype import NrelThermalBoundaryArchetype as ntba +from factories.physics_feeders.data_classes.nrel_thermal_opening_archetype import NrelThermalOpeningArchetype as ntoa +from factories.physics_feeders.data_classes.nrel_layer_archetype import NrelLayerArchetype as nla class NrelPhysicsInterface: @@ -60,16 +60,15 @@ class NrelPhysicsInterface: no_mass = 'no_mass' in material_lib if no_mass: thermal_resistance = material_lib['thermal_resistance']['#text'] - layer = NrelLayerArchetype(name, solar_absorptance, thermal_absorptance, visible_absorptance, - no_mass=no_mass, thermal_resistance=thermal_resistance) + layer = nla(name, solar_absorptance, thermal_absorptance, visible_absorptance, no_mass=no_mass, + thermal_resistance=thermal_resistance) else: thickness = current_layer['thickness']['#text'] conductivity = material_lib['conductivity']['#text'] specific_heat = material_lib['specific_heat']['#text'] density = material_lib['density']['#text'] - layer = NrelLayerArchetype(name, solar_absorptance, thermal_absorptance, visible_absorptance, - thickness=thickness, conductivity=conductivity, - specific_heat=specific_heat, density=density) + layer = nla(name, solar_absorptance, thermal_absorptance, visible_absorptance, thickness=thickness, + conductivity=conductivity, specific_heat=specific_heat, density=density) layers.append(layer) thermal_opening = None @@ -86,44 +85,39 @@ class NrelPhysicsInterface: w_lib['back_side_solar_transmittance_at_normal_incidence']['#text'] front_side_solar_transmittance_at_normal_incidence = \ w_lib['front_side_solar_transmittance_at_normal_incidence']['#text'] - thermal_opening = NrelThermalOpeningArchetype(conductivity=conductivity, frame_ratio=frame_ratio, - g_value=g_value, thickness=thickness, - back_side_solar_transmittance_at_normal_incidence= - back_side_solar_transmittance_at_normal_incidence, - front_side_solar_transmittance_at_normal_incidence= - front_side_solar_transmittance_at_normal_incidence) + thermal_opening = ntoa(conductivity=conductivity, frame_ratio=frame_ratio, g_value=g_value, + thickness=thickness, back_side_solar_transmittance_at_normal_incidence= + back_side_solar_transmittance_at_normal_incidence, + front_side_solar_transmittance_at_normal_incidence= + front_side_solar_transmittance_at_normal_incidence) else: overall_u_value = w_lib['overall_u_value']['#text'] g_value = w_lib['g_value'] - thermal_opening = NrelThermalOpeningArchetype(frame_ratio=frame_ratio, g_value=g_value, - overall_u_value=overall_u_value) + thermal_opening = ntoa(frame_ratio=frame_ratio, g_value=g_value, overall_u_value=overall_u_value) if 'outside_thermal_absorptance' in c_lib: outside_solar_absorptance = c_lib['outside_solar_absorptance']['#text'] outside_thermal_absorptance = c_lib['outside_thermal_absorptance']['#text'] outside_visible_absorptance = c_lib['outside_visible_absorptance']['#text'] - thermal_boundary_archetype = NrelThermalBoundaryArchetype(construction_type, window_ratio, construction_name, - layers, thermal_opening, outside_solar_absorptance, - outside_thermal_absorptance, - outside_visible_absorptance) + thermal_boundary_archetype = ntba(construction_type, window_ratio, construction_name, layers, thermal_opening, + outside_solar_absorptance, outside_thermal_absorptance, + outside_visible_absorptance) else: if 'overall_u_value' in c_lib: overall_u_value = c_lib['overall_u_value']['#text'] outside_solar_absorptance = c_lib['outside_solar_absorptance']['#text'] - thermal_boundary_archetype = NrelThermalBoundaryArchetype(construction_type, window_ratio, - construction_name, layers, thermal_opening, - outside_solar_absorptance= - outside_solar_absorptance, - overall_u_value=overall_u_value) + thermal_boundary_archetype = ntba(construction_type, window_ratio, construction_name, layers, + thermal_opening, outside_solar_absorptance=outside_solar_absorptance, + overall_u_value=overall_u_value) else: - thermal_boundary_archetype = NrelThermalBoundaryArchetype(construction_type, window_ratio, - construction_name, layers, thermal_opening) + thermal_boundary_archetype = ntba(construction_type, window_ratio, construction_name, layers, + thermal_opening) thermal_boundary_archetypes.append(thermal_boundary_archetype) - building_archetype = NrelBuildingArchetype(archetype_keys, average_storey_height, storeys_above_ground, - effective_thermal_capacity, additional_thermal_bridge_u_value, - indirectly_heated_area_ratio, infiltration_rate_system_off, - infiltration_rate_system_on, thermal_boundary_archetypes) + building_archetype = nba(archetype_keys, average_storey_height, storeys_above_ground, + effective_thermal_capacity, additional_thermal_bridge_u_value, + indirectly_heated_area_ratio, infiltration_rate_system_off, + infiltration_rate_system_on, thermal_boundary_archetypes) self._building_archetypes.append(building_archetype) def _search_construction_type(self, construction_type, construction_id): @@ -139,11 +133,5 @@ class NrelPhysicsInterface: return thermal_boundary raise Exception('Construction type not found') - def fill_buildings(self): - raise NotImplementedError - - def _search_archetype(self, keys): - raise NotImplementedError - - def _assign_values(self, building, archetype): + def enrich_buildings(self): raise NotImplementedError diff --git a/factories/usage_factory.py b/factories/usage_factory.py index 7631d02b..c09f384f 100644 --- a/factories/usage_factory.py +++ b/factories/usage_factory.py @@ -24,7 +24,7 @@ class UsageFactory: UsNewYorkCityUsageParameters(self._city) def _ca(self): - CaUsageParameters(self._city, self._base_path).fill_buildings() + CaUsageParameters(self._city, self._base_path).enrich_buildings() def _de(self): DeUsageParameters(self._city) diff --git a/factories/usage_feeders/ca_usage_parameters.py b/factories/usage_feeders/ca_usage_parameters.py index c2f64a55..8ae89508 100644 --- a/factories/usage_feeders/ca_usage_parameters.py +++ b/factories/usage_feeders/ca_usage_parameters.py @@ -17,7 +17,7 @@ class CaUsageParameters(HftUsageInterface): super().__init__(base_path, 'ca_archetypes_reduced.xml') self._city = city - def fill_buildings(self): + def enrich_buildings(self): """ Returns the city with the usage parameters assigned to the buildings :return: @@ -26,8 +26,7 @@ class CaUsageParameters(HftUsageInterface): for building in city.buildings: archetype = self._search_archetype(building.function) if archetype is None: - sys.stderr.write('Building ' + building.name + ' has unknown archetype for building usage: ' + - building.function + '\n') + sys.stderr.write(f'Building {building.name} has unknown archetype for building usage: {building.function}\n') continue # todo: what to do with mix-usage usages from gml? mix_usage = False @@ -43,7 +42,8 @@ class CaUsageParameters(HftUsageInterface): return building_archetype return None - def _assign_values(self, usage_zone, archetype): + @staticmethod + def _assign_values(usage_zone, archetype): usage_zone.usage = archetype.usage usage_zone.internal_gains = archetype.internal_gains usage_zone.heating_setpoint = archetype.heating_setpoint diff --git a/factories/usage_feeders/hft_usage_interface.py b/factories/usage_feeders/hft_usage_interface.py index 75e71c5a..b609738a 100644 --- a/factories/usage_feeders/hft_usage_interface.py +++ b/factories/usage_feeders/hft_usage_interface.py @@ -5,8 +5,8 @@ SPDX - License - Identifier: LGPL - 3.0 - or -later Copyright © 2020 Project Author Pilar Monsalvete pilar_monsalvete@yahoo.es """ import xmltodict -from factories.usage_feeders.data_classes.hft_usage_zone_archetype import HftUsageZoneArchetype -from factories.usage_feeders.data_classes.hft_internal_gains_archetype import HftInternalGainsArchetype +from factories.usage_feeders.data_classes.hft_usage_zone_archetype import HftUsageZoneArchetype as huza +from factories.usage_feeders.data_classes.hft_internal_gains_archetype import HftInternalGainsArchetype as higa class HftUsageInterface: @@ -17,17 +17,16 @@ class HftUsageInterface: path = str(base_path / usage_file) self._usage_archetypes = [] with open(path) as xml: - self._archetypes = xmltodict.parse(xml.read(), force_list='zoneUsageVariant') - # todo: how to read all zone_usage_types in file? - zone_usage_type = self._archetypes['buildingUsageLibrary']['zoneUsageType'] - usage = zone_usage_type['id'] - usage_archetype = self._parse_zone_usage_type(usage, zone_usage_type) - self._usage_archetypes.append(usage_archetype) - if 'zoneUsageVariant' in zone_usage_type: - for usage_zone_variant in zone_usage_type['zoneUsageVariant']: - usage = usage_zone_variant['id'] - usage_archetype_variant = self._parse_zone_usage_variant(usage, zone_usage_type, usage_zone_variant) - self._usage_archetypes.append(usage_archetype_variant) + self._archetypes = xmltodict.parse(xml.read(), force_list=('zoneUsageVariant', 'zoneUsageType')) + for zone_usage_type in self._archetypes['buildingUsageLibrary']['zoneUsageType']: + usage = zone_usage_type['id'] + usage_archetype = self._parse_zone_usage_type(usage, zone_usage_type) + self._usage_archetypes.append(usage_archetype) + if 'zoneUsageVariant' in zone_usage_type: + for usage_zone_variant in zone_usage_type['zoneUsageVariant']: + usage = usage_zone_variant['id'] + usage_archetype_variant = self._parse_zone_usage_variant(usage, zone_usage_type, usage_zone_variant) + self._usage_archetypes.append(usage_archetype_variant) @staticmethod def _parse_zone_usage_type(usage, zone_usage_type): @@ -58,18 +57,14 @@ class HftUsageInterface: convective_fraction = zone_usage_type['occupancy']['internGains']['convectiveFraction'] average_internal_gain = zone_usage_type['occupancy']['internGains']['averageInternGainPerSqm'] radiative_fraction = zone_usage_type['occupancy']['internGains']['radiantFraction'] - internal_gains.append(HftInternalGainsArchetype(average_internal_gain, convective_fraction, - radiative_fraction, latent_fraction)) - usage_zone_archetype = HftUsageZoneArchetype(usage=usage, internal_gains=internal_gains, - heating_set_point=heating_setpoint, heating_set_back=heating_setback, - cooling_set_point=cooling_setpoint, - occupancy_density=occupancy_density, hours_day=hours_day, - days_year=days_year, - dhw_average_volume_pers_day=dhw_average_volume_pers_day, - dhw_preparation_temperature=dhw_preparation_temperature, - electrical_app_average_consumption_sqm_year= - electrical_app_average_consumption_sqm_year, - mechanical_air_change=mechanical_air_change) + internal_gains.append(higa(average_internal_gain, convective_fraction, radiative_fraction, latent_fraction)) + usage_zone_archetype = huza(usage=usage, internal_gains=internal_gains, heating_set_point=heating_setpoint, + heating_set_back=heating_setback, cooling_set_point=cooling_setpoint, + occupancy_density=occupancy_density, hours_day=hours_day, days_year=days_year, + dhw_average_volume_pers_day=dhw_average_volume_pers_day, + dhw_preparation_temperature=dhw_preparation_temperature, + electrical_app_average_consumption_sqm_year=electrical_app_average_consumption_sqm_year, + mechanical_air_change=mechanical_air_change) return usage_zone_archetype @staticmethod @@ -118,25 +113,15 @@ class HftUsageInterface: average_internal_gain = usage_zone_variant['occupancy']['internGains']['averageInternGainPerSqm'] if 'radiantFraction' in usage_zone_variant['occupancy']['internGains']: radiative_fraction = usage_zone_variant['occupancy']['internGains']['radiantFraction'] - internal_gains.append(HftInternalGainsArchetype(average_internal_gain, convective_fraction, - radiative_fraction, latent_fraction)) - usage_zone_archetype = HftUsageZoneArchetype(usage=usage, internal_gains=internal_gains, - heating_set_point=heating_setpoint, heating_set_back=heating_setback, - cooling_set_point=cooling_setpoint, - occupancy_density=occupancy_density, hours_day=hours_day, - days_year=days_year, - dhw_average_volume_pers_day=dhw_average_volume_pers_day, - dhw_preparation_temperature=dhw_preparation_temperature, - electrical_app_average_consumption_sqm_year= - electrical_app_average_consumption_sqm_year, - mechanical_air_change=mechanical_air_change) + internal_gains.append(higa(average_internal_gain, convective_fraction, radiative_fraction, latent_fraction)) + usage_zone_archetype = huza(usage=usage, internal_gains=internal_gains, heating_set_point=heating_setpoint, + heating_set_back=heating_setback, cooling_set_point=cooling_setpoint, + occupancy_density=occupancy_density, hours_day=hours_day, days_year=days_year, + dhw_average_volume_pers_day=dhw_average_volume_pers_day, + dhw_preparation_temperature=dhw_preparation_temperature, + electrical_app_average_consumption_sqm_year=electrical_app_average_consumption_sqm_year, + mechanical_air_change=mechanical_air_change) return usage_zone_archetype - def fill_buildings(self): - raise NotImplementedError - - def _search_archetype(self, building_usage): - raise NotImplementedError - - def _assign_values(self, building, archetype): + def enrich_buildings(self): raise NotImplementedError