Starting point. Not running version.

This commit is contained in:
Pilar 2021-05-26 16:28:38 -04:00
parent b585e6cac2
commit 4650c3fa47
2 changed files with 23 additions and 18 deletions

View File

@ -6,6 +6,7 @@ Copyright © 2020 Project Author Pilar Monsalvete Alvarez de Uribarri pilar.mons
import pandas as pd
import numpy as np
import calendar as cal
import helpers.constants as cte
@ -22,16 +23,17 @@ class Helper:
"""
array = []
for i in range(0, 12):
total_hours = cte.days_of_month[i] * 24
days_of_month = cal.monthrange(2015, i+1)
total_hours = days_of_month * 24
array = np.concatenate((array, np.full(total_hours, i + 1)))
self._month_hour = pd.DataFrame(array, columns=['month'])
self._month_hour = pd.DataFrame(array, columns=cte.MONTH)
return self._month_hour
def get_mean_values(self, values):
out = None
if values is not None:
if 'month' not in values.columns:
if cte.MONTH not in values.columns:
values = pd.concat([self.month_hour, pd.DataFrame(values)], axis=1)
out = values.groupby('month', as_index=False).mean()
del out['month']
out = values.groupby(cte.MONTH, as_index=False).mean()
del out[cte.MONTH]
return out

View File

@ -14,6 +14,7 @@ from subprocess import SubprocessError, TimeoutExpired, CalledProcessError
from exports.exports_factory import ExportsFactory
from imports.weather_factory import WeatherFactory
from helper.helper import Helper as mv
import helpers.constants as cte
class SimplifiedRadiosityAlgorithm:
@ -44,11 +45,11 @@ class SimplifiedRadiosityAlgorithm:
self._results = None
self._radiation = []
def call_sra(self, keep_files=False):
def call_sra(self, key, keep_files=False):
"""
creates required input files and calls the software
"""
self._create_cli_file()
self._create_cli_file(key)
ExportsFactory('sra', self._city, self._tmp_path).export()
try:
completed = subprocess.run([self._executable, str(Path(self._tmp_path / self._sra_in_file_name).resolve())])
@ -113,28 +114,30 @@ class SimplifiedRadiosityAlgorithm:
building = city.city_object(city_object_name)
for column in radiation.columns.values:
if column == 'month':
if column == cte.MONTH:
continue
header_id = column
surface_id = header_id.split(':')[2]
surface = building.surface_by_id(surface_id)
new_value = pd.DataFrame(radiation[[header_id]].to_numpy(), columns=['sra'])
if mode == 0 or mode == 2:
# todo: this is wrong?? It must be used like this in MEB or what??
month_new_value = mv().get_mean_values(new_value)
if 'month' not in surface.global_irradiance:
surface.global_irradiance['month'] = month_new_value
if cte.MONTH not in surface.global_irradiance:
surface.global_irradiance[cte.MONTH] = month_new_value
else:
pd.concat([surface.global_irradiance['month'], month_new_value], axis=1)
pd.concat([surface.global_irradiance[cte.MONTH], month_new_value], axis=1)
if mode == 1 or mode == 2:
if 'hour' not in surface.global_irradiance:
surface.global_irradiance['hour'] = new_value
if cte.HOUR not in surface.global_irradiance:
surface.global_irradiance[cte.HOUR] = new_value
else:
pd.concat([surface.global_irradiance['hour'], new_value], axis=1)
pd.concat([surface.global_irradiance[cte.HOUR], new_value], axis=1)
def _create_cli_file(self):
def _create_cli_file(self, key):
file = self._city.climate_file
print(file)
days_in_month = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]
WeatherFactory('epw', self._city, file_name=self._weather_file_name).enrich()
WeatherFactory(key, self._city, file_name=self._weather_file_name).enrich()
content = self._city.name + '\n'
content += str(self._city.latitude) + ',' + str(self._city.longitude) + ',0.0,' + str(self._city.time_zone) + '\n'
content += '\ndm m h G_Dh G_Bn\n'
@ -150,8 +153,8 @@ class SimplifiedRadiosityAlgorithm:
i = (total_days+day-1)*24 + hour - 1
representative_building = self._city.buildings[0]
content += str(day) + ' ' + str(month) + ' ' + str(hour) + ' ' \
+ str(representative_building.global_horizontal['hour'].epw[i]) + ' ' \
+ str(representative_building.beam['hour'].epw[i]) + '\n'
+ str(representative_building.global_horizontal[cte.HOUR].epw[i]) + ' ' \
+ str(representative_building.beam[cte.HOUR].epw[i]) + '\n'
with open(file, "w") as file:
file.write(content)
return