2020-10-28 13:42:58 -04:00
|
|
|
"""
|
|
|
|
CliWeatherParameters class to extract weather parameters from a defined region in .dat format
|
|
|
|
SPDX - License - Identifier: LGPL - 3.0 - or -later
|
|
|
|
Copyright © 2020 Project Author Pilar Monsalvete pilar_monsalvete@yahoo.es
|
|
|
|
"""
|
|
|
|
|
|
|
|
import pandas as pd
|
2020-10-30 06:23:29 -04:00
|
|
|
from pathlib import Path
|
2020-10-28 13:42:58 -04:00
|
|
|
|
|
|
|
|
|
|
|
class DatWeatherParameters:
|
|
|
|
"""
|
|
|
|
DatWeatherParameters class
|
|
|
|
"""
|
2020-10-30 06:23:29 -04:00
|
|
|
def __init__(self, city, path, name):
|
2020-10-28 13:42:58 -04:00
|
|
|
self._weather_values = None
|
2020-10-29 07:40:40 -04:00
|
|
|
self._city = city
|
2020-10-30 06:23:29 -04:00
|
|
|
self._city_name = name
|
|
|
|
file_name = 'inseldb_' + self._city_name + '.dat'
|
|
|
|
self._path = Path(path / file_name)
|
2020-10-28 13:42:58 -04:00
|
|
|
|
2020-10-29 07:40:40 -04:00
|
|
|
# TODO: catch error if file does not exist
|
|
|
|
if self._weather_values is None:
|
|
|
|
self._weather_values = pd.read_csv(self._path, sep='\s+', header=None,
|
|
|
|
names=['hour', 'global_horiz', 'temperature', 'diffuse', 'beam', 'empty'])
|
|
|
|
for building in self._city.buildings:
|
2020-10-30 08:25:36 -04:00
|
|
|
new_value = pd.DataFrame(self._weather_values[['temperature']].to_numpy(), columns=['inseldb'])
|
|
|
|
if 'hour' not in building.external_temperature:
|
|
|
|
building.external_temperature['hour'] = new_value
|
|
|
|
else:
|
|
|
|
pd.concat([building.external_temperature['hour'], new_value], axis=1)
|
2020-10-29 07:40:40 -04:00
|
|
|
|
2020-10-30 08:25:36 -04:00
|
|
|
new_value = pd.DataFrame(self._weather_values[['global_horiz']].to_numpy(), columns=['inseldb'])
|
|
|
|
if 'hour' not in building.global_horizontal:
|
|
|
|
building.global_horizontal['hour'] = new_value
|
|
|
|
else:
|
|
|
|
pd.concat([building.global_horizontal['hour'], new_value], axis=1)
|
|
|
|
|
|
|
|
new_value = pd.DataFrame(self._weather_values[['diffuse']].to_numpy(), columns=['inseldb'])
|
|
|
|
if 'hour' not in building.diffuse:
|
|
|
|
building.diffuse['hour'] = new_value
|
|
|
|
else:
|
|
|
|
pd.concat([building.diffuse['hour'], new_value], axis=1)
|
|
|
|
|
|
|
|
new_value = pd.DataFrame(self._weather_values[['beam']].to_numpy(), columns=['inseldb'])
|
|
|
|
if 'hour' not in building.beam:
|
|
|
|
building.beam['hour'] = new_value
|
|
|
|
else:
|
|
|
|
pd.concat([building.beam['hour'], new_value], axis=1)
|