city_retrofit/hub/imports/weather_factory.py

51 lines
1.7 KiB
Python
Raw Normal View History

2020-10-28 13:42:58 -04:00
"""
WeatherFactory retrieve the specific weather module for the given source format
SPDX - License - Identifier: LGPL - 3.0 - or -later
Copyright © 2022 Concordia CERC group
Project Coder Pilar Monsalvete Alvarez de Uribarri pilar.monsalvete@concordia.ca
2020-10-28 13:42:58 -04:00
"""
from pathlib import Path
from hub.helpers.utils import validate_import_export_type
from hub.imports.weather.epw_weather_parameters import EpwWeatherParameters
from hub.imports.weather.xls_weather_parameters import XlsWeatherParameters
2020-10-28 13:42:58 -04:00
class WeatherFactory:
"""
WeatherFactory class
"""
2021-09-22 07:25:53 -04:00
def __init__(self, handler, city, base_path=None, file_name=None):
if base_path is None:
base_path = Path(Path(__file__).parent.parent / 'data/weather')
2020-10-28 13:42:58 -04:00
self._handler = '_' + handler.lower().replace(' ', '_')
validate_import_export_type(WeatherFactory, handler)
2020-10-28 13:42:58 -04:00
self._city = city
self._base_path = base_path
2021-04-13 15:09:13 -04:00
self._file_name = file_name
2020-10-28 13:42:58 -04:00
2021-04-13 15:09:13 -04:00
def _epw(self):
2021-09-22 07:25:53 -04:00
"""
Enrich the city with energy plus weather file
"""
2021-04-13 15:09:13 -04:00
# EnergyPlus Weather
# to download files: https://energyplus.net/weather
# description of the format: https://energyplus.net/sites/default/files/pdfs_v8.3.0/AuxiliaryPrograms.pdf
_path = Path(self._base_path / 'epw').resolve()
2021-08-26 13:27:43 -04:00
return EpwWeatherParameters(self._city, _path, self._file_name)
2021-04-13 15:09:13 -04:00
def _xls(self):
2021-09-22 07:25:53 -04:00
"""
Enrich the city with ISO_52016_1_BESTEST_ClimData_2016.08.24 weather file
"""
name = 'ISO_52016_1_BESTEST_ClimData_2016.08.24'
2021-08-26 13:27:43 -04:00
return XlsWeatherParameters(self._city, self._base_path, name)
def enrich(self):
2020-10-28 13:42:58 -04:00
"""
2021-09-22 07:25:53 -04:00
Enrich the city given to the class using the given weather handler
2020-10-28 13:42:58 -04:00
:return: None
"""
getattr(self, self._handler, lambda: None)()