2020-10-28 13:42:58 -04:00
|
|
|
"""
|
2021-01-11 17:11:50 -05:00
|
|
|
DatWeatherParameters class to extract weather parameters from a defined region in .dat format
|
2020-10-28 13:42:58 -04:00
|
|
|
SPDX - License - Identifier: LGPL - 3.0 - or -later
|
2021-06-10 08:29:24 -04:00
|
|
|
Copyright © 2020 Project Author Pilar Monsalvete Alvarez de Uribarri pilar.monsalvete@concordia.ca
|
2020-10-28 13:42:58 -04:00
|
|
|
"""
|
|
|
|
|
2021-01-11 17:11:50 -05:00
|
|
|
import sys
|
2021-08-27 12:51:30 -04:00
|
|
|
from pathlib import Path
|
|
|
|
import pandas as pd
|
2021-05-25 13:34:57 -04:00
|
|
|
import helpers.constants as cte
|
2020-10-28 13:42:58 -04:00
|
|
|
|
|
|
|
|
|
|
|
class DatWeatherParameters:
|
|
|
|
"""
|
|
|
|
DatWeatherParameters class
|
|
|
|
"""
|
2021-08-27 12:51:30 -04:00
|
|
|
|
2021-04-13 15:09:13 -04:00
|
|
|
def __init__(self, city, path):
|
2020-10-28 13:42:58 -04:00
|
|
|
self._weather_values = None
|
2020-10-29 07:40:40 -04:00
|
|
|
self._city = city
|
2021-04-13 19:00:28 -04:00
|
|
|
self._city_name = city.climate_reference_city
|
2020-10-30 06:23:29 -04:00
|
|
|
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
|
|
|
if self._weather_values is None:
|
2021-01-11 17:11:50 -05:00
|
|
|
try:
|
2021-08-27 12:51:30 -04:00
|
|
|
self._weather_values = pd.read_csv(self._path, sep=r'\s+', header=None,
|
2021-01-11 17:11:50 -05:00
|
|
|
names=['hour', 'global_horiz', 'temperature', 'diffuse', 'beam', 'empty'])
|
2021-01-13 12:24:46 -05:00
|
|
|
except SystemExit:
|
2021-01-11 17:11:50 -05:00
|
|
|
sys.stderr.write(f'Error: weather file {self._path} not found\n')
|
|
|
|
sys.exit()
|
|
|
|
|
2020-10-29 07:40:40 -04:00
|
|
|
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'])
|
2021-05-25 13:34:57 -04:00
|
|
|
if cte.HOUR not in building.external_temperature:
|
|
|
|
building.external_temperature[cte.HOUR] = new_value
|
2020-10-30 08:25:36 -04:00
|
|
|
else:
|
2021-05-25 13:34:57 -04:00
|
|
|
pd.concat([building.external_temperature[cte.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'])
|
2021-05-25 13:34:57 -04:00
|
|
|
if cte.HOUR not in building.global_horizontal:
|
|
|
|
building.global_horizontal[cte.HOUR] = new_value
|
2020-10-30 08:25:36 -04:00
|
|
|
else:
|
2021-05-25 13:34:57 -04:00
|
|
|
pd.concat([building.global_horizontal[cte.HOUR], new_value], axis=1)
|
2020-10-30 08:25:36 -04:00
|
|
|
|
|
|
|
new_value = pd.DataFrame(self._weather_values[['diffuse']].to_numpy(), columns=['inseldb'])
|
2021-05-25 13:34:57 -04:00
|
|
|
if cte.HOUR not in building.diffuse:
|
|
|
|
building.diffuse[cte.HOUR] = new_value
|
2020-10-30 08:25:36 -04:00
|
|
|
else:
|
2021-05-25 13:34:57 -04:00
|
|
|
pd.concat([building.diffuse[cte.HOUR], new_value], axis=1)
|
2020-10-30 08:25:36 -04:00
|
|
|
|
|
|
|
new_value = pd.DataFrame(self._weather_values[['beam']].to_numpy(), columns=['inseldb'])
|
2021-05-25 13:34:57 -04:00
|
|
|
if cte.HOUR not in building.beam:
|
|
|
|
building.beam[cte.HOUR] = new_value
|
2020-10-30 08:25:36 -04:00
|
|
|
else:
|
2021-05-25 13:34:57 -04:00
|
|
|
pd.concat([building.beam[cte.HOUR], new_value], axis=1)
|