50 lines
1.9 KiB
Python
50 lines
1.9 KiB
Python
|
"""
|
||
|
Monthly demand calculation using the monthly energy balance methodology based on the norm...
|
||
|
SPDX - License - Identifier: LGPL - 3.0 - or -later
|
||
|
Copyright © 2020 Project Author Pilar Monsalvete Alvarez de Uribarri pilar.monsalvete@concordia.ca
|
||
|
"""
|
||
|
|
||
|
from pathlib import Path
|
||
|
import pandas as pd
|
||
|
import sys
|
||
|
|
||
|
from insel.templates.monthly_energy_balance import MonthlyEnergyBalance as templates
|
||
|
from insel.insel import Insel
|
||
|
|
||
|
|
||
|
class MonthlyDemandCalculation:
|
||
|
def __init__(self, city, main_path, weather_format):
|
||
|
self._city = city
|
||
|
self._main_path = main_path
|
||
|
self._weather_format = weather_format
|
||
|
|
||
|
def monthly_demand(self):
|
||
|
for building in self._city.buildings:
|
||
|
full_path_out = Path(self._main_path + '/outputs/' + building.name + '_insel.out').resolve()
|
||
|
full_path_out.parent.mkdir(parents=True, exist_ok=True)
|
||
|
insel_file_name = building.name + '.insel'
|
||
|
try:
|
||
|
content = templates.generate_meb_template(building, full_path_out, self._weather_format)
|
||
|
insel = Insel(Path(self._main_path).resolve(), insel_file_name, content, mode=2, keep_files=True).run()
|
||
|
building.heating['month'], building.cooling['month'] = templates.demand(full_path_out)
|
||
|
heating_year = 0
|
||
|
for value in building.heating['month']['INSEL']:
|
||
|
if value == 'NaN':
|
||
|
value = '0'
|
||
|
heating_year += float(value)
|
||
|
yearly_heating = pd.DataFrame([heating_year], columns=['INSEL'])
|
||
|
building.heating['year'] = yearly_heating
|
||
|
|
||
|
cooling_year = 0
|
||
|
for value in building.cooling['month']['INSEL']:
|
||
|
if value == 'NaN':
|
||
|
value = '0'
|
||
|
cooling_year += float(value)
|
||
|
yearly_cooling = pd.DataFrame([cooling_year], columns=['INSEL'])
|
||
|
building.cooling['year'] = yearly_cooling
|
||
|
|
||
|
except ValueError:
|
||
|
print(sys.exc_info()[1])
|
||
|
print('Building ' + building.name + ' could not be processed')
|
||
|
continue
|