Update ep to include hot water, update how results are saved, update requirements.txt

This commit is contained in:
Koa Wells 2023-04-17 14:41:43 -04:00
parent 175041e2df
commit fc5fca955e
3 changed files with 107 additions and 49 deletions

View File

@ -5,6 +5,7 @@ from pathlib import Path
import pandas as pd import pandas as pd
import platform import platform
import os import os
import xlsxwriter
from hub.imports.geometry_factory import GeometryFactory from hub.imports.geometry_factory import GeometryFactory
from hub.imports.weather_factory import WeatherFactory from hub.imports.weather_factory import WeatherFactory
@ -28,14 +29,40 @@ class EnergyValidation:
self.climate_file = Path(f'{self.storage_path}/{self.climate_file_name}.cli').resolve() self.climate_file = Path(f'{self.storage_path}/{self.climate_file_name}.cli').resolve()
self.meb_folder = Path('./results/meb').resolve() self.meb_folder = Path('./results/meb').resolve()
self.ep_folder = Path('./results/ep').resolve() self.ep_folder = Path('./results/ep').resolve()
self.result_file = Path('./results/energy_validation_results.xlsx').resolve()
self.result_file = Path(f'./results/{datetime.datetime.now().strftime("%m-%d-%Y_%H-%M-%S")}'
f'_energy_validation_results.xlsx').resolve()
results_xlsx = xlsxwriter.Workbook(self.result_file)
simulation_data_worksheet = results_xlsx.add_worksheet('Simulation data')
metadata_worksheet = results_xlsx.add_worksheet('Metadata')
bold = results_xlsx.add_format({'bold': True})
simulation_data_worksheet.write('A1', 'Building', bold)
simulation_data_worksheet.write('B1', 'Month', bold)
simulation_data_worksheet.write('C1', 'Heating demand (kWh/m2)', bold)
simulation_data_worksheet.write('D1', 'Cooling demand (kWh/m2)', bold)
simulation_data_worksheet.write('E1', 'Appliances demand (kWh/m2)', bold)
simulation_data_worksheet.write('F1', 'Lighting demand (kWh/m2)', bold)
simulation_data_worksheet.write('G1', 'Domestic hot water demand (kWh/m2)', bold)
simulation_data_worksheet.write('H1', 'Source of simulation (kWh/m2)', bold)
metadata_worksheet.write('A1', 'Building id', bold)
metadata_worksheet.write('B1', 'Storeys', bold)
metadata_worksheet.write('C1', 'M2 per storey', bold)
metadata_worksheet.write('D1', 'Total m2', bold)
metadata_worksheet.write('E1', 'Total m3', bold)
metadata_worksheet.write('F1', 'Year building', bold)
metadata_worksheet.write('G1', 'Type of building', bold)
results_xlsx.close()
if platform.system() == 'Windows': if platform.system() == 'Windows':
self.encoding = 'windows-1252' self.encoding = 'windows-1252'
else: else:
self.encoding = 'utf-8' self.encoding = 'utf-8'
def _sort_buildings(self, buildings_to_simulate): @staticmethod
def _sort_buildings(buildings_to_simulate):
sorted_buildings = {} sorted_buildings = {}
for building in buildings_to_simulate: for building in buildings_to_simulate:
code_utili = building['properties']['CODE_UTILI'] code_utili = building['properties']['CODE_UTILI']
@ -123,12 +150,13 @@ class EnergyValidation:
index=False, index=False,
header=False, header=False,
) )
def _save_ep_results(self, demand, building_area, building_name): def _save_ep_results(self, demand, building_area, building_name):
demand.drop('Date/Time', axis=1, inplace=True) demand.drop('Date/Time', axis=1, inplace=True)
# convert from J to kWh/m^2 # convert from J to kWh/m^2
demand *= 2.77778e-7/building_area demand *= (2.77778e-7/building_area)
# replace indexes with month/day/year format # insert date in month/day/year format
months = [ months = [
'1/1/2023', '1/1/2023',
'2/1/2023', '2/1/2023',
@ -146,15 +174,20 @@ class EnergyValidation:
demand.insert(0, 'month', months) demand.insert(0, 'month', months)
# insert building_name to first column # insert building_name
demand.insert(0, 'building_name', building_name) demand.insert(0, 'building_name', building_name)
# TODO: add water usage once working from ep # insert hot water demand
demand['water_usage'] = 'NA' demand['water_usage'] = demand.iloc[:,5] - demand.iloc[:,2]
# add simulation source as ep # add simulation source as ep
demand['source'] = 'ep' demand['source'] = 'ep'
# drop unneeded columns
demand.drop(4)
demand.drop(5)
demand.drop(6)
# last, but not least, append our lovely reformatted data to the results spreadsheet # last, but not least, append our lovely reformatted data to the results spreadsheet
with pd.ExcelWriter(self.result_file, engine='openpyxl', if_sheet_exists='overlay', mode='a') as writer: with pd.ExcelWriter(self.result_file, engine='openpyxl', if_sheet_exists='overlay', mode='a') as writer:
demand.to_excel( demand.to_excel(
@ -215,53 +248,78 @@ class EnergyValidation:
city.climate_file = self.climate_file city.climate_file = self.climate_file
city.name = f'{building_id}_energy_validation' city.name = f'{building_id}_energy_validation'
# starting sra try:
print(f'{building_id} starting sra') # starting sra
ExportsFactory('sra', city, self.tmp_folder, print(f'{building_id} starting sra')
weather_file=self.weather_file, weather_format='epw').export() ExportsFactory('sra', city, self.tmp_folder,
sra_file = (self.tmp_folder / f'{city.name}_sra.xml').resolve() weather_file=self.weather_file, weather_format='epw').export()
sra_start = datetime.datetime.now() sra_file = (self.tmp_folder / f'{city.name}_sra.xml').resolve()
Sra(sra_file, self.tmp_folder).run() sra_start = datetime.datetime.now()
sra_end = datetime.datetime.now() - sra_start Sra(sra_file, self.tmp_folder).run()
ResultFactory('sra', city, self.tmp_folder).enrich() sra_end = datetime.datetime.now() - sra_start
ResultFactory('sra', city, self.tmp_folder).enrich()
# run meb # run meb
print(f'{building_id} starting meb') print(f'{building_id} starting meb')
for building in city.buildings: for building in city.buildings:
building.attic_heated = 0 building.attic_heated = 0
building.basement_heated = 1 building.basement_heated = 1
EnergyBuildingsExportsFactory('insel_monthly_energy_balance', city, self.tmp_folder).export() EnergyBuildingsExportsFactory('insel_monthly_energy_balance', city, self.tmp_folder).export()
meb_start = datetime.datetime.now() meb_start = datetime.datetime.now()
Meb(self.tmp_folder).run() Meb(self.tmp_folder).run()
meb_end = datetime.datetime.now() - meb_start meb_end = datetime.datetime.now() - meb_start
ResultFactory('insel_meb', city, self.tmp_folder).enrich() ResultFactory('insel_meb', city, self.tmp_folder).enrich()
results = MEBResults(city, Path('./results/meb/').resolve()) results = MEBResults(city, Path('./results/meb/').resolve())
results.print() results.print()
# save meb results to energy_validation_results # run energyplus
total_m2 = city.buildings[0].internal_zones[0].thermal_zones[0].total_floor_area print(f'{building_id} starting energy plus')
meb_results = pd.read_csv(Path(f'{self.meb_folder}/demand.csv').resolve(), idf_file = EnergyBuildingsExportsFactory('idf', city, self.ep_folder).export()
encoding=self.encoding) ep_start = datetime.datetime.now()
meb_metadata = pd.read_csv(Path(f'{self.meb_folder}/metadata.csv').resolve(), idf_file.run()
encoding=self.encoding) ep_end = datetime.datetime.now() - ep_start
self._save_meb_results(meb_results, meb_metadata, total_m2)
# run energyplus # save meb results to energy_validation_results
print(f'{building_id} starting energy plus') total_m2 = city.buildings[0].internal_zones[0].thermal_zones[0].total_floor_area
idf_file = EnergyBuildingsExportsFactory('idf', city, self.ep_folder).export_debug() meb_results = pd.read_csv(Path(f'{self.meb_folder}/demand.csv').resolve(),
ep_start = datetime.datetime.now() encoding=self.encoding)
idf_file.run() meb_metadata = pd.read_csv(Path(f'{self.meb_folder}/metadata.csv').resolve(),
ep_end = datetime.datetime.now() - ep_start encoding=self.encoding)
self._save_meb_results(meb_results, meb_metadata, total_m2)
# save ep results to energy_validation_results # save ep results to energy_validation_results
ep_results = pd.read_csv(Path(f'{self.ep_folder}/{building_id}_energy_validation_mtr.csv').resolve(), ep_results = pd.read_csv(Path(f'{self.ep_folder}/{building_id}_energy_validation_out.csv').resolve(),
encoding=self.encoding) encoding=self.encoding)
self._save_ep_results(ep_results, total_m2, city.buildings[0].name) self._save_ep_results(ep_results, total_m2, city.buildings[0].name)
print(f"{building_id} sra time: {sra_end}") print(f"{building_id} sra time: {sra_end}")
print(f"{building_id} meb time: {meb_end}") print(f"{building_id} meb time: {meb_end}")
print(f"{building_id} ep time: {ep_end}") print(f"{building_id} ep time: {ep_end}")
except:
building_with_error = pd.DataFrame([
building_id,
'NA',
'NA',
'NA',
'NA',
'NA',
'NA',
'NA',
'NA'
]).transpose()
print(building_with_error)
# with pd.ExcelWriter(self.result_file, engine='openpyxl', if_sheet_exists='overlay',
# mode='a') as writer:
# building_with_error.to_excel(
# writer,
# startrow=writer.sheets['Simulation data'].max_row,
# sheet_name='Simulation data',
# index=False,
# header=False,
# )
if cleanup is True: if cleanup is True:
[os.remove(os.path.join(self.tmp_folder, file)) for file in os.listdir(self.tmp_folder)] [os.remove(os.path.join(self.tmp_folder, file)) for file in os.listdir(self.tmp_folder)]

View File

@ -1 +1 @@
cerc-hub xlsxwriter