results_factory.py is modified

The enrich method is added to energy_plus_workflow.py
The Levis_out.csv is added to test_data
This commit is contained in:
Saeed Ranjbar 2023-09-07 18:16:07 -04:00
parent a0d2f7e5bc
commit 1392c05489
3 changed files with 8838 additions and 73 deletions

View File

@ -5,7 +5,6 @@ Copyright © 2022 Concordia CERC group
Project Coder Saeed Ranjbar saeed.ranjbar@concordia.ca Project Coder Saeed Ranjbar saeed.ranjbar@concordia.ca
Project collaborator Pilar Monsalvete Alvarez de Uribarri pilar.monsalvete@concordia.ca Project collaborator Pilar Monsalvete Alvarez de Uribarri pilar.monsalvete@concordia.ca
""" """
import logging
from pathlib import Path from pathlib import Path
import csv import csv
@ -13,81 +12,87 @@ import hub.helpers.constants as cte
class EnergyPlusWorkflow: class EnergyPlusWorkflow:
def __init__(self, base_path): def __init__(self, city, base_path):
self._city = city
self._base_path = base_path self._base_path = base_path
@staticmethod @staticmethod
def _energy_plus_output_file(energy_plus_output_file_path): def _building_energy_demands(energy_plus_output_file_path):
with open(Path(energy_plus_output_file_path).resolve(), 'r', encoding='utf8') as csv_file: with open(Path(energy_plus_output_file_path).resolve(), 'r', encoding='utf8') as csv_file:
csv_output = csv.reader(csv_file) csv_output = csv.reader(csv_file)
return csv_output headers = next(csv_output)
building_energy_demands = {
'Heating (J)': [],
'Cooling (J)': [],
'DHW (J)': [],
'Appliances (J)': [],
'Lighting (J)': []
}
heating_column_index = []
cooling_column_index = []
dhw_column_index = []
appliance_column_index = []
lighting_column_index = []
for index, header in enumerate(headers):
if "Total Heating" in header:
heating_column_index.append(index)
elif "Total Cooling" in header:
cooling_column_index.append(index)
elif "DHW" in header:
dhw_column_index.append(index)
elif "InteriorEquipment" in header:
appliance_column_index.append(index)
elif "InteriorLights" in header:
lighting_column_index.append(index)
@staticmethod for line in csv_output:
def _headers(csv_file): total_heating_demand = 0
headers = next(csv_file) total_cooling_demand = 0
return headers total_dhw_demand = 0
total_appliance_demand = 0
total_lighting_demand = 0
for heating_index in heating_column_index:
total_heating_demand += float(line[heating_index])
building_energy_demands['Heating (J)'].append(total_heating_demand)
for cooling_index in cooling_column_index:
total_cooling_demand += float(line[cooling_index])
building_energy_demands['Cooling (J)'].append(total_cooling_demand)
for dhw_index in dhw_column_index:
total_dhw_demand += float(line[dhw_index]) * 3600
building_energy_demands['DHW (J)'].append(total_dhw_demand)
for appliance_index in appliance_column_index:
total_appliance_demand += float(line[appliance_index])
building_energy_demands['Appliances (J)'].append(total_appliance_demand)
for lighting_index in lighting_column_index:
total_lighting_demand += float(line[lighting_index])
building_energy_demands['Lighting (J)'].append(total_lighting_demand)
@staticmethod return building_energy_demands
def _heating_columns(headers_list):
heating_column_index = []
for index, header in enumerate(headers_list):
if "Total Heating" in header:
heating_column_index.append(index)
return heating_column_index
@staticmethod
def _cooling_columns(headers_list):
cooling_column_index = []
for index, header in enumerate(headers_list):
if "Total Cooling" in header:
cooling_column_index.append(index)
return cooling_column_index
@staticmethod
def _dhw_columns(headers_list):
dhw_column_index = []
for index, header in enumerate(headers_list):
if "DHW" in header:
dhw_column_index.append(index)
return dhw_column_index
@staticmethod
def _appliance_columns(headers_list):
appliance_column_index = []
for index, header in enumerate(headers_list):
if "InteriorEquipment" in header:
appliance_column_index.append(index)
return appliance_column_index
@staticmethod
def _lighting_columns(headers_list):
lighting_column_index = []
for index, header in enumerate(headers_list):
if "InteriorLights" in header:
lighting_column_index.append(index)
return lighting_column_index
def _heating_loads(self, csv_file_path):
csv_file = self._energy_plus_output_file(csv_file_path)
headers = self._headers(csv_file)
heating_columns_index = self._heating_columns(headers)
building_heating_demand = []
for line in csv_file:
total_heating_demand = 0
for index in heating_columns_index:
total_heating_demand += float(line[index])
building_heating_demand.append(total_heating_demand)
return building_heating_demand
def _cooling_loads(self, csv_file_path):
csv_file = self._energy_plus_output_file(csv_file_path)
headers = self._headers(csv_file)
cooling_columns_index = self._heating_columns(headers)
building_cooling_demand = []
for line in csv_file:
total_cooling_demand = 0
for index in cooling_columns_index:
total_cooling_demand += float(line[index])
building_cooling_demand.append(total_cooling_demand)
return building_cooling_demand
def enrich(self):
"""
Enrich the city by using the energy plus workflow output files (J)
:return: None
"""
for building in self._city.buildings:
file_name = building.name + '_out' + '.csv'
energy_plus_output_file_path = Path(self._base_path / file_name).resolve()
if energy_plus_output_file_path.is_file():
building.heating_demand[cte.HOUR] = self._building_energy_demands(energy_plus_output_file_path)['Heating (J)']
building.cooling_demand[cte.HOUR] = self._building_energy_demands(energy_plus_output_file_path)['Cooling (J)']
building.domestic_hot_water_heat_demand[cte.HOUR] = (
self._building_energy_demands(energy_plus_output_file_path))['DHW (J)']
building.appliances_electrical_demand[cte.HOUR] = (
self._building_energy_demands(energy_plus_output_file_path))['Appliances (J)']
building.lighting_electrical_demand[cte.HOUR] = (
self._building_energy_demands(energy_plus_output_file_path))['Lighting (J)']
building.heating_demand[cte.MONTH] = [sum(building.heating_demand[cte.HOUR])]
building.cooling_demand[cte.MONTH] = [sum(building.cooling_demand[cte.HOUR])]
building.domestic_hot_water_heat_demand[cte.MONTH] = [sum(building.domestic_hot_water_heat_demand[cte.HOUR])]
building.appliances_electrical_demand[cte.MONTH] = [sum(building.appliances_electrical_demand[cte.HOUR])]
building.lighting_electrical_demand[cte.MONTH] = [sum(building.lighting_electrical_demand[cte.HOUR])]
building.heating_demand[cte.YEAR] = [sum(building.heating_demand[cte.MONTH])]
building.cooling_demand[cte.YEAR] = [sum(building.cooling_demand[cte.MONTH])]
building.domestic_hot_water_heat_demand[cte.YEAR] = [sum(building.domestic_hot_water_heat_demand[cte.MONTH])]
building.appliances_electrical_demand[cte.YEAR] = [sum(building.appliances_electrical_demand[cte.MONTH])]
building.lighting_electrical_demand[cte.YEAR] = [sum(building.lighting_electrical_demand[cte.MONTH])]

View File

@ -50,8 +50,7 @@ class ResultFactory:
""" """
Enrich the city with energy plus results Enrich the city with energy plus results
""" """
EnergyPlusWorkflow EnergyPlusWorkflow(self._city, self._base_path).enrich()
def enrich(self): def enrich(self):
""" """

File diff suppressed because it is too large Load Diff