added insel.py and monthly_demand_calculation.py
This commit is contained in:
parent
07443138d8
commit
bb874f77d0
18
insel/insel.py
Normal file
18
insel/insel.py
Normal file
|
@ -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
|
64
insel/monthly_demand_calculation.py
Normal file
64
insel/monthly_demand_calculation.py
Normal file
|
@ -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
|
Loading…
Reference in New Issue
Block a user