Update ep to include hot water, update how results are saved, update requirements.txt
This commit is contained in:
parent
175041e2df
commit
fc5fca955e
|
@ -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,6 +248,7 @@ 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'
|
||||||
|
|
||||||
|
try:
|
||||||
# starting sra
|
# starting sra
|
||||||
print(f'{building_id} starting sra')
|
print(f'{building_id} starting sra')
|
||||||
ExportsFactory('sra', city, self.tmp_folder,
|
ExportsFactory('sra', city, self.tmp_folder,
|
||||||
|
@ -239,6 +273,13 @@ class EnergyValidation:
|
||||||
results = MEBResults(city, Path('./results/meb/').resolve())
|
results = MEBResults(city, Path('./results/meb/').resolve())
|
||||||
results.print()
|
results.print()
|
||||||
|
|
||||||
|
# run energyplus
|
||||||
|
print(f'{building_id} starting energy plus')
|
||||||
|
idf_file = EnergyBuildingsExportsFactory('idf', city, self.ep_folder).export()
|
||||||
|
ep_start = datetime.datetime.now()
|
||||||
|
idf_file.run()
|
||||||
|
ep_end = datetime.datetime.now() - ep_start
|
||||||
|
|
||||||
# save meb results to energy_validation_results
|
# save meb results to energy_validation_results
|
||||||
total_m2 = city.buildings[0].internal_zones[0].thermal_zones[0].total_floor_area
|
total_m2 = city.buildings[0].internal_zones[0].thermal_zones[0].total_floor_area
|
||||||
meb_results = pd.read_csv(Path(f'{self.meb_folder}/demand.csv').resolve(),
|
meb_results = pd.read_csv(Path(f'{self.meb_folder}/demand.csv').resolve(),
|
||||||
|
@ -247,15 +288,8 @@ class EnergyValidation:
|
||||||
encoding=self.encoding)
|
encoding=self.encoding)
|
||||||
self._save_meb_results(meb_results, meb_metadata, total_m2)
|
self._save_meb_results(meb_results, meb_metadata, total_m2)
|
||||||
|
|
||||||
# run energyplus
|
|
||||||
print(f'{building_id} starting energy plus')
|
|
||||||
idf_file = EnergyBuildingsExportsFactory('idf', city, self.ep_folder).export_debug()
|
|
||||||
ep_start = datetime.datetime.now()
|
|
||||||
idf_file.run()
|
|
||||||
ep_end = datetime.datetime.now() - ep_start
|
|
||||||
|
|
||||||
# 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)
|
||||||
|
|
||||||
|
@ -263,5 +297,29 @@ class EnergyValidation:
|
||||||
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)]
|
|
@ -1 +1 @@
|
||||||
cerc-hub
|
xlsxwriter
|
Binary file not shown.
Loading…
Reference in New Issue
Block a user