diff --git a/insel/insel.py b/insel/insel.py new file mode 100644 index 0000000..0f22827 --- /dev/null +++ b/insel/insel.py @@ -0,0 +1,18 @@ +import os +from pathlib import Path +from abc import ABC + + +class Insel(ABC): + def __init__(self, path): + self._path = path + self._results = None + + def run(self): + paths = sorted(Path(self._path).glob('*.insel')) + for file in paths: + os.system('insel ' + str(file)) + + @property + def results(self): + raise NotImplementedError diff --git a/insel/monthly_demand_calculation.py b/insel/monthly_demand_calculation.py new file mode 100644 index 0000000..d6f4a3d --- /dev/null +++ b/insel/monthly_demand_calculation.py @@ -0,0 +1,64 @@ +""" +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 +import csv +from insel.insel import Insel + + +class MonthlyDemandCalculation(Insel): + def __init__(self, city, main_path, weather_format): + super().__init__(main_path) + self._city = city + self._weather_format = weather_format + + def results(self): + for building in self._city.buildings: + file_name = building.name + '.out' + full_path_out = Path(self._path / file_name).resolve() + full_path_out.parent.mkdir(parents=True, exist_ok=True) + try: + building.heating['month'], building.cooling['month'] = self._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 + + @staticmethod + def _demand(insel_outputs_path): + heating = [] + cooling = [] + with open(Path(insel_outputs_path).resolve()) as csv_file: + csv_reader = csv.reader(csv_file) + for line in csv_reader: + demand = str(line).replace("['", '').replace("']", '').split() + for i in range(0, 2): + if demand[i] != 'NaN': + aux = float(demand[i])*1000 # kWh to Wh + demand[i] = str(aux) + heating.append(demand[0]) + cooling.append(demand[1]) + monthly_heating = pd.DataFrame(heating, columns=['INSEL']) + monthly_cooling = pd.DataFrame(cooling, columns=['INSEL']) + return monthly_heating, monthly_cooling