e9dd9c2221
added example iso 52016-1:2017 added new weather format defined in iso 52016-1:2017 (xls)
48 lines
1.9 KiB
Python
48 lines
1.9 KiB
Python
"""
|
|
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
|
|
|
|
|
|
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'])
|
|
except ValueError:
|
|
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'])
|
|
if 'hour' not in building.external_temperature:
|
|
building.external_temperature['hour'] = new_value
|
|
else:
|
|
pd.concat([building.external_temperature['hour'], new_value], axis=1)
|
|
|
|
new_value = pd.DataFrame(self._weather_values[['global_horiz']].to_numpy(), columns=['iso52016'])
|
|
if 'hour' not in building.global_horizontal:
|
|
building.global_horizontal['hour'] = new_value
|
|
else:
|
|
pd.concat([building.global_horizontal['hour'], new_value], axis=1)
|
|
|