2021-01-11 17:11:50 -05:00
|
|
|
"""
|
|
|
|
XlsWeatherParameters class to extract weather parameters from a defined region in .xls format
|
|
|
|
defined and used by the norm iso 52016-1:2017
|
|
|
|
SPDX - License - Identifier: LGPL - 3.0 - or -later
|
|
|
|
Copyright © 2020 Project Author Pilar Monsalvete pilar_monsalvete@yahoo.es
|
|
|
|
"""
|
|
|
|
|
|
|
|
import pandas as pd
|
|
|
|
from pathlib import Path
|
|
|
|
import sys
|
2021-05-25 13:34:57 -04:00
|
|
|
import helpers.constants as cte
|
2021-01-11 17:11:50 -05:00
|
|
|
|
|
|
|
|
|
|
|
class XlsWeatherParameters:
|
|
|
|
"""
|
|
|
|
XlsWeatherParameters class
|
|
|
|
"""
|
|
|
|
def __init__(self, city, path, name):
|
|
|
|
self._weather_values = None
|
|
|
|
self._city = city
|
|
|
|
self._file_name = name
|
|
|
|
file_name = self._file_name + '.xls'
|
|
|
|
self._path = Path(path / file_name)
|
|
|
|
|
|
|
|
if self._weather_values is None:
|
|
|
|
try:
|
|
|
|
self._weather_values = pd.read_excel(self._path, skiprows=4, nrows=9504,
|
|
|
|
names=['hours_calc', 'month', 'week', 'day_of_week', 'hours_of_day',
|
|
|
|
'temperature', 'I_sol_vertical_N', 'I_sol_vertical_E',
|
|
|
|
'I_sol_vertical_S', 'I_sol_vertical_W', 'I_sol_45_N', 'I_sol_45_S',
|
|
|
|
'void', 'global_horiz', 'wind_velocity', 'humidity'])
|
2021-01-13 12:24:46 -05:00
|
|
|
except SystemExit:
|
2021-01-11 17:11:50 -05:00
|
|
|
sys.stderr.write(f'Error reading weather file {self._path}\n')
|
|
|
|
sys.exit()
|
|
|
|
|
|
|
|
for building in self._city.buildings:
|
|
|
|
new_value = pd.DataFrame(self._weather_values[['temperature']].to_numpy(), columns=['iso52016'])
|
2021-05-25 13:34:57 -04:00
|
|
|
if cte.HOUR not in building.external_temperature:
|
|
|
|
building.external_temperature[cte.HOUR] = new_value
|
2021-01-11 17:11:50 -05:00
|
|
|
else:
|
2021-05-25 13:34:57 -04:00
|
|
|
pd.concat([building.external_temperature[cte.HOUR], new_value], axis=1)
|
2021-01-11 17:11:50 -05:00
|
|
|
|
|
|
|
new_value = pd.DataFrame(self._weather_values[['global_horiz']].to_numpy(), columns=['iso52016'])
|
2021-05-25 13:34:57 -04:00
|
|
|
if cte.HOUR not in building.global_horizontal:
|
|
|
|
building.global_horizontal[cte.HOUR] = new_value
|
2021-01-11 17:11:50 -05:00
|
|
|
else:
|
2021-05-25 13:34:57 -04:00
|
|
|
pd.concat([building.global_horizontal[cte.HOUR], new_value], axis=1)
|