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