hub/factories/weather_feeders/dat_weather_parameters.py

30 lines
1.2 KiB
Python
Raw Normal View History

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
class DatWeatherParameters:
"""
DatWeatherParameters class
"""
def __init__(self, city, path):
self._path = path
2020-10-28 13:42:58 -04:00
self._weather_values = None
self._city = city
2020-10-28 13:42:58 -04:00
def weather_values(self):
# 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:
building._hourly_external_temperature = pd.DataFrame(self._weather_values[['temperature']], columns=['inseldb'])
building._hourly_global_horizontal = pd.DataFrame(self._weather_values[['global_horiz']], columns=['inseldb'])
building._hourly_diffuse = pd.DataFrame(self._weather_values[['diffuse']], columns=['inseldb'])
building._hourly_beam = pd.DataFrame(self._weather_values[['beam']], columns=['inseldb'])