fix: small fix in geojson class, new version of idf.py is added

This commit is contained in:
Saeed Ranjbar 2024-08-14 13:08:09 -04:00
parent 71aa95401e
commit 0fcc9a2a5f
2 changed files with 35 additions and 21 deletions

View File

@ -7,6 +7,9 @@ Code contributors: Pilar Monsalvete Alvarez de Uribarri pilar.monsalvete@concord
Oriol Gavalda Torrellas oriol.gavalda@concordia.ca Oriol Gavalda Torrellas oriol.gavalda@concordia.ca
""" """
import copy import copy
import datetime
import glob
import os
from pathlib import Path from pathlib import Path
from geomeppy import IDF from geomeppy import IDF
import hub.helpers.constants as cte import hub.helpers.constants as cte
@ -275,11 +278,12 @@ class Idf:
_kwargs[f'Field_{counter + 2}'] = 'Until: 24:00,0.0' _kwargs[f'Field_{counter + 2}'] = 'Until: 24:00,0.0'
self._idf.newidfobject(self._COMPACT_SCHEDULE, **_kwargs) self._idf.newidfobject(self._COMPACT_SCHEDULE, **_kwargs)
def _write_schedules_file(self, usage, schedule): def _write_schedules_file(self, schedule, usage):
file_name = str((Path(self._output_path) / f'{schedule.type} schedules {usage}.csv').resolve()) file_name = str((Path(self._output_path) / f'{schedule.type} schedules {usage.replace("/","_")}.csv').resolve())
with open(file_name, 'w', encoding='utf8') as file: if not Path(file_name).exists():
for value in schedule.values: with open(file_name, 'w', encoding='utf8') as file:
file.write(f'{str(value)},\n') for value in schedule.values:
file.write(f'{str(value)},\n')
return Path(file_name).name return Path(file_name).name
def _add_file_schedule(self, usage, schedule, file_name): def _add_file_schedule(self, usage, schedule, file_name):
@ -304,7 +308,7 @@ class Idf:
for schedule in self._idf.idfobjects[self._FILE_SCHEDULE]: for schedule in self._idf.idfobjects[self._FILE_SCHEDULE]:
if schedule.Name == f'{schedule_type} schedules {usage}': if schedule.Name == f'{schedule_type} schedules {usage}':
return return
file_name = self._write_schedules_file(usage, new_schedules[0]) file_name = self._write_schedules_file(new_schedules[0], usage)
self._add_file_schedule(usage, new_schedules[0], file_name) self._add_file_schedule(usage, new_schedules[0], file_name)
return return
@ -321,7 +325,7 @@ class Idf:
if construction.Name == vegetation_name: if construction.Name == vegetation_name:
return return
else: else:
if construction.Name == thermal_boundary.construction_name: if construction.Name == f'{thermal_boundary.construction_name} {thermal_boundary.parent_surface.type}':
return return
if thermal_boundary.layers is None: if thermal_boundary.layers is None:
for material in self._idf.idfobjects[self._MATERIAL]: for material in self._idf.idfobjects[self._MATERIAL]:
@ -340,7 +344,8 @@ class Idf:
for i in range(0, len(layers) - 1): for i in range(0, len(layers) - 1):
_kwargs[f'Layer_{i + 2}'] = layers[i].material_name _kwargs[f'Layer_{i + 2}'] = layers[i].material_name
else: else:
_kwargs = {'Name': thermal_boundary.construction_name, 'Outside_Layer': layers[0].material_name} _kwargs = {'Name': f'{thermal_boundary.construction_name} {thermal_boundary.parent_surface.type}',
'Outside_Layer': layers[0].material_name}
for i in range(1, len(layers) - 1): for i in range(1, len(layers) - 1):
_kwargs[f'Layer_{i + 1}'] = layers[i].material_name _kwargs[f'Layer_{i + 1}'] = layers[i].material_name
self._idf.newidfobject(self._CONSTRUCTION, **_kwargs) self._idf.newidfobject(self._CONSTRUCTION, **_kwargs)
@ -470,7 +475,7 @@ class Idf:
Air_Changes_per_Hour=_air_change Air_Changes_per_Hour=_air_change
) )
def _add_dhw(self, thermal_zone, zone_name): def _add_dhw(self, thermal_zone, zone_name, usage):
peak_flow_rate = thermal_zone.domestic_hot_water.peak_flow * thermal_zone.total_floor_area peak_flow_rate = thermal_zone.domestic_hot_water.peak_flow * thermal_zone.total_floor_area
self._idf.newidfobject(self._DHW, self._idf.newidfobject(self._DHW,
Name=f'DHW {zone_name}', Name=f'DHW {zone_name}',
@ -478,7 +483,7 @@ class Idf:
Flow_Rate_Fraction_Schedule_Name=f'DHW_prof schedules {thermal_zone.usage_name}', Flow_Rate_Fraction_Schedule_Name=f'DHW_prof schedules {thermal_zone.usage_name}',
Target_Temperature_Schedule_Name=f'DHW_temp schedules {thermal_zone.usage_name}', Target_Temperature_Schedule_Name=f'DHW_temp schedules {thermal_zone.usage_name}',
Hot_Water_Supply_Temperature_Schedule_Name=f'DHW_temp schedules {thermal_zone.usage_name}', Hot_Water_Supply_Temperature_Schedule_Name=f'DHW_temp schedules {thermal_zone.usage_name}',
Cold_Water_Supply_Temperature_Schedule_Name=f'cold_temp schedules {zone_name}', Cold_Water_Supply_Temperature_Schedule_Name=f'cold_temp schedules {usage}',
EndUse_Subcategory=f'DHW {zone_name}', EndUse_Subcategory=f'DHW {zone_name}',
Zone_Name=zone_name Zone_Name=zone_name
) )
@ -512,19 +517,25 @@ class Idf:
self._rename_building(self._city.name) self._rename_building(self._city.name)
self._lod = self._city.level_of_detail.geometry self._lod = self._city.level_of_detail.geometry
for building in self._city.buildings: for building in self._city.buildings:
is_target = building.name in self._target_buildings or building.name in self._adjacent_buildings
for internal_zone in building.internal_zones: for internal_zone in building.internal_zones:
if internal_zone.thermal_zones_from_internal_zones is None: if internal_zone.thermal_zones_from_internal_zones is None:
self._add_shading(building) # if the building has not archetype use it as shadow object self._target_buildings.remoidf_surface_typeve(building.name)
is_target = False
continue continue
for thermal_zone in internal_zone.thermal_zones_from_internal_zones: for thermal_zone in internal_zone.thermal_zones_from_internal_zones:
for thermal_boundary in thermal_zone.thermal_boundaries: for thermal_boundary in thermal_zone.thermal_boundaries:
self._add_construction(thermal_boundary) self._add_construction(thermal_boundary)
if thermal_boundary.parent_surface.vegetation is not None: if thermal_boundary.parent_surface.vegetation is not None:
self._add_vegetation_material(thermal_boundary.parent_surface.vegetation) self._add_vegetation_material(thermal_boundary.parent_surface.vegetation)
for thermal_opening in thermal_boundary.thermal_openings: for thermal_opening in thermal_boundary.thermal_openings:
self._add_window_construction_and_material(thermal_opening) self._add_window_construction_and_material(thermal_opening)
usage = thermal_zone.usage_name
if building.name in self._target_buildings or building.name in self._adjacent_buildings: if is_target:
start = datetime.datetime.now()
service_temperature = thermal_zone.domestic_hot_water.service_temperature
usage = thermal_zone.usage_name
_new_schedules = self._create_infiltration_schedules(thermal_zone) _new_schedules = self._create_infiltration_schedules(thermal_zone)
self._add_schedules(usage, 'Infiltration', _new_schedules) self._add_schedules(usage, 'Infiltration', _new_schedules)
_new_schedules = self._create_ventilation_schedules(thermal_zone) _new_schedules = self._create_ventilation_schedules(thermal_zone)
@ -536,11 +547,10 @@ class Idf:
self._add_schedules(usage, 'Lighting', thermal_zone.lighting.schedules) self._add_schedules(usage, 'Lighting', thermal_zone.lighting.schedules)
self._add_schedules(usage, 'Appliance', thermal_zone.appliances.schedules) self._add_schedules(usage, 'Appliance', thermal_zone.appliances.schedules)
self._add_schedules(usage, 'DHW_prof', thermal_zone.domestic_hot_water.schedules) self._add_schedules(usage, 'DHW_prof', thermal_zone.domestic_hot_water.schedules)
_new_schedules = self._create_yearly_values_schedules('cold_temp', _new_schedules = self._create_yearly_values_schedules('cold_temp', building.cold_water_temperature[cte.HOUR])
building.cold_water_temperature[cte.HOUR]) self._add_schedules(usage, 'cold_temp', _new_schedules)
self._add_schedules(building.name, 'cold_temp', _new_schedules)
value = thermal_zone.domestic_hot_water.service_temperature _new_schedules = self._create_constant_value_schedules('DHW_temp', service_temperature)
_new_schedules = self._create_constant_value_schedules('DHW_temp', value)
self._add_schedules(usage, 'DHW_temp', _new_schedules) self._add_schedules(usage, 'DHW_temp', _new_schedules)
_occ = thermal_zone.occupancy _occ = thermal_zone.occupancy
if _occ.occupancy_density == 0: if _occ.occupancy_density == 0:
@ -557,11 +567,13 @@ class Idf:
self._add_occupancy(thermal_zone, building.name) self._add_occupancy(thermal_zone, building.name)
self._add_lighting(thermal_zone, building.name) self._add_lighting(thermal_zone, building.name)
self._add_appliances(thermal_zone, building.name) self._add_appliances(thermal_zone, building.name)
self._add_dhw(thermal_zone, building.name) self._add_dhw(thermal_zone, building.name, usage)
if self._export_type == "Surfaces": if self._export_type == "Surfaces":
if building.name in self._target_buildings or building.name in self._adjacent_buildings: if is_target:
if building.thermal_zones_from_internal_zones is not None: if building.thermal_zones_from_internal_zones is not None:
start = datetime.datetime.now()
self._add_surfaces(building, building.name) self._add_surfaces(building, building.name)
print(f'add surfaces {datetime.datetime.now() - start}')
else: else:
self._add_pure_geometry(building, building.name) self._add_pure_geometry(building, building.name)
else: else:
@ -717,7 +729,7 @@ class Idf:
if boundary.parent_surface.vegetation is not None: if boundary.parent_surface.vegetation is not None:
construction_name = f'{boundary.construction_name}_{boundary.parent_surface.vegetation.name}' construction_name = f'{boundary.construction_name}_{boundary.parent_surface.vegetation.name}'
else: else:
construction_name = boundary.construction_name construction_name = f'{boundary.construction_name} {boundary.parent_surface.type}'
_kwargs['Construction_Name'] = construction_name _kwargs['Construction_Name'] = construction_name
surface = self._idf.newidfobject(self._SURFACE, **_kwargs) surface = self._idf.newidfobject(self._SURFACE, **_kwargs)

View File

@ -135,6 +135,8 @@ class Geojson:
building_aliases = [] building_aliases = []
if 'id' in feature: if 'id' in feature:
building_name = feature['id'] building_name = feature['id']
elif 'id' in feature['properties']:
building_name = feature['properties']['id']
else: else:
building_name = uuid.uuid4() building_name = uuid.uuid4()
if self._aliases_field is not None: if self._aliases_field is not None: