Partial implementation for idf schedule import (doe_idf)

This commit is contained in:
Guille Gutierrez 2021-08-25 07:23:02 -04:00
parent c2e5cd5970
commit c8bdc0fb0f
9 changed files with 64 additions and 144 deletions

View File

@ -1,4 +1,4 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectRootManager" version="2" project-jdk-name="Python 3.9 (libs_EPlus)" project-jdk-type="Python SDK" />
<component name="ProjectRootManager" version="2" project-jdk-name="Python 3.8 (libs) (2)" project-jdk-type="Python SDK" />
</project>

View File

@ -6,8 +6,6 @@ Contributor Milad milad.aghamohamadnia@concordia.ca
Contributor Guille guille.gutierrezmorote@concordia.ca
"""
from typing import List
from city_model_structure.attributes.node import Node
from city_model_structure.network import Network

View File

@ -4,12 +4,15 @@ SPDX - License - Identifier: LGPL - 3.0 - or -later
Copyright © 2020 Project Author Guille Gutierrez guillermo.gutierrezmorote@concordia.ca
"""
from pathlib import Path
from os.path import exists
from exports.formats.stl import Stl
from exports.formats.obj import Obj
from exports.formats.energy_ade import EnergyAde
from exports.formats.simplified_radiosity_algorithm import SimplifiedRadiosityAlgorithm
from exports.formats.idf import Idf
from pathlib import Path
class ExportsFactory:
@ -67,9 +70,10 @@ class ExportsFactory:
Export the city to Energy+ idf format
:return:
"""
data_path = (Path(__file__).parent / '../tests/tests_data/').resolve()
Idf(self._city, self._path, (data_path / f'minimal.idf').resolve(), (data_path / f'energy+.idd').resolve(),
(data_path / f'montreal.epw').resolve())
idf_data_path = (Path(__file__).parent / './formats/idf_files/').resolve()
# todo: create a get epw file function based on the city
weather_path = (Path(__file__).parent / '../data/weather/epw/CAN_PQ_Montreal.Intl.AP.716270_CWEC.epw').resolve()
Idf(self._city, self._path, (idf_data_path / f'Minimal.idf'), (idf_data_path / f'Energy+.idd'), weather_path)
@property
def _sra(self):

View File

@ -14,14 +14,20 @@ class Idf:
_CONSTRUCTION = 'CONSTRUCTION'
_MATERIAL = 'MATERIAL'
_MATERIAL_NOMASS = 'MATERIAL:NOMASS'
_ROUGHNESS = "MediumRough"
_HOURLY_SCHEDULE = "SCHEDULE:DAY:HOURLY"
_ZONE = "ZONE"
_LIGHTS = "LIGHTS"
_PEOPLE = "PEOPLE"
_ELECTRIC_EQUIPMEN = "ELECTRICEQUIPMENT"
_INFILTRATION = "ZONEINFILTRATION:DESIGNFLOWRATE"
_BUILDING_SURFACE = "BuildingSurfaceDetailed"
_ROUGHNESS = 'MediumRough'
_HOURLY_SCHEDULE = 'SCHEDULE:DAY:HOURLY'
_ZONE = 'ZONE'
_LIGHTS = 'LIGHTS'
_PEOPLE = 'PEOPLE'
_ELECTRIC_EQUIPMENT = 'ELECTRICEQUIPMENT'
_INFILTRATION = 'ZONEINFILTRATION:DESIGNFLOWRATE'
_BUILDING_SURFACE = 'BuildingSurfaceDetailed'
_SCHEDULE_LIMIT = 'SCHEDULETYPELIMITS'
_ON_OFF = 'On/Off'
_FRACTION = 'Fraction'
_ANY_NUMBER = 'Any Number'
_CONTINUOUS = 'CONTINUOUS'
_DISCRETE = 'DISCRETE'
idf_surfaces = {
# todo: make an enum for all the surface types
@ -43,6 +49,11 @@ class Idf:
self._epw_file_path = str(epw_file_path)
IDF.setiddname(self._idd_file_path)
self._idf = IDF(self._idf_file_path, self._epw_file_path)
self._idf.newidfobject(self._SCHEDULE_LIMIT, Name=self._ANY_NUMBER)
self._idf.newidfobject(self._SCHEDULE_LIMIT, Name=self._FRACTION, Lower_Limit_Value=0.0, Upper_Limit_Value=1.0,
Numeric_Type=self._CONTINUOUS)
self._idf.newidfobject(self._SCHEDULE_LIMIT, Name=self._ON_OFF, Lower_Limit_Value=0, Upper_Limit_Value=1,
Numeric_Type=self._DISCRETE)
self._export()
@staticmethod
@ -90,13 +101,12 @@ class Idf:
Visible_Absorptance=layer.material.visible_absorptance
)
def _add_schedule(self, usage_zone, schedule_type):
def _add_schedule(self, usage_zone, schedule_type, limit_name='Any Number'):
for schedule in self._idf.idfobjects[self._HOURLY_SCHEDULE]:
if schedule.Name == f'{schedule_type} schedules {usage_zone.usage}':
return
schedule = self._idf.newidfobject(self._HOURLY_SCHEDULE)
schedule.Name = f'{schedule_type} schedules {usage_zone.usage}'
schedule.Schedule_Type_Limits_Name = 'Any Number'
schedule = self._idf.newidfobject(self._HOURLY_SCHEDULE, Name=f'{schedule_type} schedules {usage_zone.usage}')
schedule.Schedule_Type_Limits_Name = limit_name
schedule.Hour_1 = usage_zone.schedules[schedule_type]["WD"][0]
schedule.Hour_2 = usage_zone.schedules[schedule_type]["WD"][1]
@ -148,7 +158,7 @@ class Idf:
if zone.Name == usage_zone.id:
return
# todo: what does we need to define a zone in energy plus?
self._idf.newidfobject(self._ZONE, Name=usage_zone.id)
self._idf.newidfobject(self._ZONE, Name=usage_zone.id, Volume=usage_zone.volume)
self._add_heating_system(usage_zone)
def _add_thermostat(self, usage_zone):
@ -166,9 +176,9 @@ class Idf:
if air_system.Zone_Name == usage_zone.id:
return
thermostat = self._add_thermostat(usage_zone)
# todo: doesn't the air system have name?
self._idf.newidfobject(self._IDEAL_LOAD_AIR_SYSTEM,
Zone_Name=usage_zone.id,
Cooling_Availability_Schedule_Name=f'Refrigeration schedules {usage_zone.usage}',
Template_Thermostat_Name=thermostat.Name)
def _add_occupancy(self, usage_zone):
@ -193,17 +203,19 @@ class Idf:
def _add_infiltration(self, usage_zone):
for zone in self._idf.idfobjects["ZONE"]:
self._idf.newidfobject(self._INFILTRATION,
Name=f'{usage_zone.id}_infiltration',
Zone_or_ZoneList_Name=usage_zone.id,
Schedule_Name=f'Infiltration schedules {usage_zone.usage}',
Design_Flow_Rate_Calculation_Method='AirChanges/Hour',
Air_Changes_per_Hour=0.35, # todo: change it from usage catalog
Constant_Term_Coefficient=0.606, # todo: change it from usage catalog
Temperature_Term_Coefficient=3.6359996E-02, # todo: change it from usage catalog
Velocity_Term_Coefficient=0.1177165, # todo: change it from usage catalog
Velocity_Squared_Term_Coefficient=0.0000000E+00 # todo: change it from usage catalog
)
if zone.Name == f'{usage_zone.id}_infiltration':
return
self._idf.newidfobject(self._INFILTRATION,
Name=f'{usage_zone.id}_infiltration',
Zone_or_ZoneList_Name=usage_zone.id,
Schedule_Name=f'Infiltration schedules {usage_zone.usage}',
Design_Flow_Rate_Calculation_Method='AirChanges/Hour',
Air_Changes_per_Hour=0.35, # todo: change it from usage catalog
Constant_Term_Coefficient=0.606, # todo: change it from usage catalog
Temperature_Term_Coefficient=3.6359996E-02, # todo: change it from usage catalog
Velocity_Term_Coefficient=0.1177165, # todo: change it from usage catalog
Velocity_Squared_Term_Coefficient=0.0000000E+00 # todo: change it from usage catalog
)
def _export(self):
"""
@ -215,14 +227,17 @@ class Idf:
self._add_schedule(usage_zone, "Infiltration")
self._add_schedule(usage_zone, "Lights")
self._add_schedule(usage_zone, "Occupancy")
self._add_schedule(usage_zone, "Refrigeration", self._ON_OFF)
self._add_zone(usage_zone)
self._add_heating_system(usage_zone)
# self._add_infiltration(usage_zone)
# self._add_occupancy(usage_zone)
for thermal_zone in building.thermal_zones:
for thermal_boundary in thermal_zone.bounded:
self._add_construction(thermal_boundary)
if self._export_type == "Surfaces":
print(len(building.surfaces))
self._add_surfaces(building)
else:
self._add_block(building)
@ -249,10 +264,11 @@ class Idf:
def _add_surfaces(self, building):
for thermal_zone in building.thermal_zones:
for boundary in thermal_zone.bounded:
idf_surface = self.idf_surfaces[boundary.surface.type]
idf_surface_type = self.idf_surfaces[boundary.surface.type]
for usage_zone in thermal_zone.usage_zones:
surface = self._idf.newidfobject(self._SURFACE, Name=f'{boundary.surface.name}',
Surface_Type=idf_surface, Zone_Name=usage_zone.id,
Surface_Type=idf_surface_type, Zone_Name=usage_zone.id,
Construction_Name=boundary.construction_name)
coordinates = self._matrix_to_list(boundary.surface.solid_polygon.coordinates)
surface.setcoords(coordinates)

View File

@ -1,105 +0,0 @@
import pandas as pd
from imports.schedules.helpers.schedules_helper import SchedulesHelper
import parseidf
class IDFParser:
_OCCUPANCY_SCHEDULE = ("BLDG_OCC_SCH_wo_SB", "Occupancy")
_Activity_Schedule = "ACTIVITY_SCH"
_Electrical_Equipent_Schedule = "BLDG_EQUIP_SCH"
_Lighting_Schedule = "BLDG_LIGHT_SCH"
_Infiltration_Ventilation_Schedule = "INFIL_QUARTER_ON_SCH"
def __init__(self, city, base_path):
self._city = city
self._idf_schedules_path = base_path / 'ASHRAE901_OfficeSmall_STD2019_Buffalo.idf'
with open(self._idf_schedules_path, 'r') as f:
idf = parseidf.parse(f.read())
print(idf.keys()) # lists the object types in the idf file
print(idf['SCHEDULE:COMPACT']) # lists all the Output:Variable objects in the idf file
Holiday = []
Winterdesignday = []
Summerdesignday = []
Customday1 = []
Customday2 = []
Weekday = []
Weekend = []
dayType = []
compactKeywords = ['Weekdays', 'Weekends', 'Alldays', 'AllOtherDays', 'Sunday', 'Monday', 'Tuesday', 'Wednesday',
'Thursday', 'Friday', 'Saturday', 'Holiday', 'Winterdesignday', 'Summerdesignday', 'Customday1',
'Customday2']
for val in idf['SCHEDULE:COMPACT']:
if val[1] == 'BLDG_LIGHT_SCH':
count = 0
for words in val:
dayType.append(words.title().split('For: ')[-1])
index = []
for count, word_dayType in enumerate(dayType):
if word_dayType in compactKeywords:
index.append(count)
index.append(len(dayType))
for i in range(len(index) - 1):
numberOfDaySch = list(dayType[index[i] + 1:index[i + 1]])
hourlyValues = list(range(24))
startHour = 0
for num in range(int(len(numberOfDaySch) / 2)):
untilTime = list(map(int, (numberOfDaySch[2 * num].split('Until: ')[-1]).split(":")[0:]))
endHour = int(untilTime[0] + untilTime[1] / 60)
value = float(numberOfDaySch[2 * num + 1])
for hour in range(startHour, endHour):
hourlyValues[hour] = value
print(hour, value)
startHour = endHour
if dayType[index[i]] == 'Weekdays':
Weekday.append(hourlyValues)
elif dayType[index[i]] == 'Weekends':
Weekend.append(hourlyValues)
elif dayType[index[i]] == 'Holiday':
Holiday.append(hourlyValues)
elif dayType[index[i]] == 'Winterdesignday':
Winterdesignday.append(hourlyValues)
elif dayType[index[i]] == 'Summerdesignday':
Summerdesignday.append(hourlyValues)
elif dayType[index[i]] == 'Customday1':
Customday1.append(hourlyValues)
elif dayType[index[i]] == 'Customday2':
Customday2.append(hourlyValues)
else:
print('its none of them')
idf_schedules = pd.DataFrame(
{'week_day': Weekday,
'Weekends': Weekend,
'Holiday': Holiday,
'Winterdesignday': Winterdesignday,
'Summerdesignday': Summerdesignday,
'Customday1': Customday1,
'Customday2': Customday2,
})
print(idf_schedules)
for building in city.buildings:
schedules = dict()
for usage_zone in building.usage_zones:
usage_schedules = idf_schedules
# todo: should we save the data type? How?
number_of_schedule_types = 5
schedules_per_schedule_type = 6
idf_day_types = dict({'week_day': 0, 'Weekends': 1, 'Holiday': 2, 'Winterdesignday': 3, 'Summerdesignday': 4, 'Customday1': 5, 'Customday2': 6})
for schedule_types in range(0, number_of_schedule_types):
data = pd.DataFrame()
columns_names = []
name = ''
for schedule_day in range(0, len(idf_schedules)):
row_cells = usage_schedules.iloc[schedules_per_schedule_type*schedule_types + schedule_day]
if schedule_day == idf_day_types['week_day']:
name = row_cells[0]
columns_names.append(row_cells[2])
data1 = row_cells[schedules_per_schedule_type:]
data = pd.concat([data, data1], axis=1)
data.columns = columns_names
schedules[name] = data
usage_zone.schedules = schedules

View File

@ -6,6 +6,7 @@ Copyright © 2020 Project Author Guille Gutierrez guillermo.gutierrezmorote@conc
from pathlib import Path
from imports.schedules.comnet_schedules_parameters import ComnetSchedules
from imports.schedules.doe_idf import DoeIdf
class SchedulesFactory:
@ -20,6 +21,10 @@ class SchedulesFactory:
def _comnet(self):
ComnetSchedules(self._city, self._base_path)
def _doe_idf(self):
print('Idf handler call')
DoeIdf(self._city, self._base_path)
def enrich(self):
"""
Enrich the city with the schedules information

View File

@ -41,6 +41,7 @@ class CaUsageParameters(HftUsageInterface):
# just one usage_zone
for thermal_zone in building.thermal_zones:
usage_zone = UsageZone()
usage_zone.volume = thermal_zone.volume
self._assign_values(usage_zone, archetype)
thermal_zone.usage_zones = [usage_zone]

View File

@ -12,3 +12,5 @@ PyWavefront~=1.3.3
xlrd~=2.0.1
openpyxl~=3.0.7
networkx~=2.5.1
parseidf~=1.0.0
ply~=3.11

View File

@ -13,7 +13,7 @@
! HVAC: None.
!
Version,9.4;
Version,9.5;
Timestep,4;
@ -148,4 +148,3 @@
Output:Table:SummaryReports,
AllSummary; !- Report 1 Name